From 03e584f59103c8dda960c64637bd7ee40e8186f7 Mon Sep 17 00:00:00 2001 From: kanat <> Date: Wed, 26 Apr 2023 15:32:51 -0700 Subject: [PATCH 1/5] [1505] fix emoji regexp to exclude non-emoji chars --- .../stream_chat_flutter/lib/src/utils/extensions.dart | 2 +- .../test/src/utils/extension_test.dart | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/stream_chat_flutter/lib/src/utils/extensions.dart b/packages/stream_chat_flutter/lib/src/utils/extensions.dart index 67b622db..06b02aae 100644 --- a/packages/stream_chat_flutter/lib/src/utils/extensions.dart +++ b/packages/stream_chat_flutter/lib/src/utils/extensions.dart @@ -34,7 +34,7 @@ extension StringExtension on String { if (trimmedString.isEmpty) return false; if (trimmedString.characters.length > 3) return false; final emojiRegex = RegExp( - r'^(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])+$', + r'^(\u00a9|\u00ae|\u200d|[\ufe00-\ufe0f]|[\u2600-\u27FF]|[\u2300-\u2bFF]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])+$', multiLine: true, caseSensitive: false, ); diff --git a/packages/stream_chat_flutter/test/src/utils/extension_test.dart b/packages/stream_chat_flutter/test/src/utils/extension_test.dart index 26980727..c8e75f81 100644 --- a/packages/stream_chat_flutter/test/src/utils/extension_test.dart +++ b/packages/stream_chat_flutter/test/src/utils/extension_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; @@ -81,6 +82,16 @@ void main() { expect('🌢1'.isOnlyEmoji, false); expect('πŸ‘¨β€πŸ‘¨πŸ‘¨β€πŸ‘¨'.isOnlyEmoji, true); expect('πŸ‘¨β€πŸ‘¨πŸ‘¨β€πŸ‘¨ '.isOnlyEmoji, true); + expect('πŸ‘¨πŸ‘¨πŸ‘¨πŸ‘¨'.isOnlyEmoji, false); + expect('⭐⭐⭐'.isOnlyEmoji, true); + expect('⭕⭕⭐'.isOnlyEmoji, true); + expect('βœ…'.isOnlyEmoji, true); + expect('☺️'.isOnlyEmoji, true); + }); + + test('korean symbols', () { + expect('γ…Žγ…Žγ…Ž'.isOnlyEmoji, false); + expect('γ…Žγ…Žγ…Žγ…Ž'.isOnlyEmoji, false); }); }); } From 79b260d3c56b46635a65a086290cef6791273f7a Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 27 Apr 2023 14:36:21 +0530 Subject: [PATCH 2/5] test: add more tests Signed-off-by: xsahil03x --- .../test/src/utils/extension_test.dart | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/packages/stream_chat_flutter/test/src/utils/extension_test.dart b/packages/stream_chat_flutter/test/src/utils/extension_test.dart index c8e75f81..eef7677e 100644 --- a/packages/stream_chat_flutter/test/src/utils/extension_test.dart +++ b/packages/stream_chat_flutter/test/src/utils/extension_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; @@ -89,7 +88,62 @@ void main() { expect('☺️'.isOnlyEmoji, true); }); - test('korean symbols', () { + test('Korean vowels', () { + expect('ㅏ'.isOnlyEmoji, false); + expect('γ…‘'.isOnlyEmoji, false); + expect('γ…“'.isOnlyEmoji, false); + expect('γ…•'.isOnlyEmoji, false); + expect('γ…—'.isOnlyEmoji, false); + expect('γ…›'.isOnlyEmoji, false); + expect('γ…œ'.isOnlyEmoji, false); + expect('γ… '.isOnlyEmoji, false); + expect('γ…‘'.isOnlyEmoji, false); + expect('γ…£'.isOnlyEmoji, false); + }); + + test('Korean consonants', () { + expect('γ„±'.isOnlyEmoji, false); + expect('γ„΄'.isOnlyEmoji, false); + expect('γ„·'.isOnlyEmoji, false); + expect('γ„Ή'.isOnlyEmoji, false); + expect('ㅁ'.isOnlyEmoji, false); + expect('γ…‚'.isOnlyEmoji, false); + expect('γ……'.isOnlyEmoji, false); + expect('γ…‡'.isOnlyEmoji, false); + expect('γ…ˆ'.isOnlyEmoji, false); + expect('γ…Š'.isOnlyEmoji, false); + expect('γ…‹'.isOnlyEmoji, false); + expect('γ…Œ'.isOnlyEmoji, false); + expect('ㅍ'.isOnlyEmoji, false); + expect('γ…Ž'.isOnlyEmoji, false); + }); + + test('Korean syllables', () { + expect('κ°€'.isOnlyEmoji, false); + expect('λ‚˜'.isOnlyEmoji, false); + expect('λ‹€'.isOnlyEmoji, false); + expect('라'.isOnlyEmoji, false); + expect('마'.isOnlyEmoji, false); + expect('λ°”'.isOnlyEmoji, false); + expect('사'.isOnlyEmoji, false); + expect('μ•„'.isOnlyEmoji, false); + expect('자'.isOnlyEmoji, false); + expect('μ°¨'.isOnlyEmoji, false); + expect('μΉ΄'.isOnlyEmoji, false); + expect('타'.isOnlyEmoji, false); + expect('파'.isOnlyEmoji, false); + expect('ν•˜'.isOnlyEmoji, false); + }); + + // https://github.com/GetStream/stream-chat-flutter/issues/1502 + test('Issue:#1502', () { + expect('γ„΄'.isOnlyEmoji, false); + expect('γ„΄γ…‡'.isOnlyEmoji, false); + expect('γ…‡γ…‹'.isOnlyEmoji, false); + }); + + // https://github.com/GetStream/stream-chat-flutter/issues/1505 + test('Issue:#1505', () { expect('γ…Žγ…Žγ…Ž'.isOnlyEmoji, false); expect('γ…Žγ…Žγ…Žγ…Ž'.isOnlyEmoji, false); }); From 3ed48fafba116d02e3bdf72ae2a49f9af13cef6a Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Thu, 27 Apr 2023 14:41:04 +0530 Subject: [PATCH 3/5] chore: update CHANGELOG.md Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index dea27923..277d2484 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -1,3 +1,12 @@ +## Upcoming + +🐞 Fixed + +- [#1502](https://github.com/GetStream/stream-chat-flutter/issues/1502) Fixed `isOnlyEmoji` method Detects Single Hangul + Consonants as Emoji. +- [#1505](https://github.com/GetStream/stream-chat-flutter/issues/1505) Fixed Message bubble disappears for Hangul + Consonants. + ## 6.0.0 🐞 Fixed From e4e6fca3111b79b57f5750e269baeb416be1f140 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 1 May 2023 17:53:48 +0530 Subject: [PATCH 4/5] fix(ui): `editMessageInputBuilder` property not used in message edit widget. Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 48 +++++++++++++------ .../src/message_widget/message_widget.dart | 1 + 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 277d2484..1a04f07c 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -2,31 +2,38 @@ 🐞 Fixed -- [#1502](https://github.com/GetStream/stream-chat-flutter/issues/1502) Fixed `isOnlyEmoji` method Detects Single Hangul +- [[#1502]](https://github.com/GetStream/stream-chat-flutter/issues/1502) Fixed `isOnlyEmoji` method Detects Single + Hangul Consonants as Emoji. -- [#1505](https://github.com/GetStream/stream-chat-flutter/issues/1505) Fixed Message bubble disappears for Hangul +- [[#1505]](https://github.com/GetStream/stream-chat-flutter/issues/1505) Fixed Message bubble disappears for Hangul Consonants. +- [[#1490]](https://github.com/GetStream/stream-chat-flutter/issues/1490) Fixed `editMessageInputBuilder` property not + used in message edit widget. ## 6.0.0 🐞 Fixed -- [#1456](https://github.com/GetStream/stream-chat-flutter/issues/1456) Fixed logic for showing that a message was read using sending indicator. -- [#1462](https://github.com/GetStream/stream-chat-flutter/issues/1462) Fixed support for iPad in the share button for images. -- [#1475](https://github.com/GetStream/stream-chat-flutter/issues/1475) Fixed typo to fix compilation. +- [[#1456]](https://github.com/GetStream/stream-chat-flutter/issues/1456) Fixed logic for showing that a message was + read using sending indicator. +- [[#1462]](https://github.com/GetStream/stream-chat-flutter/issues/1462) Fixed support for iPad in the share button for + images. +- [[#1475]](https://github.com/GetStream/stream-chat-flutter/issues/1475) Fixed typo to fix compilation. βœ… Added - Now it is possible to customize the max lines of the title of a url attachment. Before it was always 1 line. -- Added `attachmentActionsModalBuilder` parameter to `StreamMessageWidget` that allows to customize `AttachmentActionsModal`. -- Added `StreamMessageInput.sendMessageKeyPredicate` and `StreamMessageInput.clearQuotedMessageKeyPredicate` to customize the keys used to send and clear the quoted message. +- Added `attachmentActionsModalBuilder` parameter to `StreamMessageWidget` that allows to + customize `AttachmentActionsModal`. +- Added `StreamMessageInput.sendMessageKeyPredicate` and `StreamMessageInput.clearQuotedMessageKeyPredicate` to + customize the keys used to send and clear the quoted message. πŸ”„ Changed - Updated dependencies to resolvable versions. πŸš€ Improved -- + - Improved draw of reaction options. [#1455](https://github.com/GetStream/stream-chat-flutter/pull/1455) ## 5.3.0 @@ -36,17 +43,22 @@ - Updated `photo_manager` dependency to `^2.5.2` 🐞 Fixed -- [[#1424]](https://github.com/GetStream/stream-chat-flutter/issues/1424) Fixed a render issue when showing messages starting with 4 whitespaces. + +- [[#1424]](https://github.com/GetStream/stream-chat-flutter/issues/1424) Fixed a render issue when showing messages + starting with 4 whitespaces. - Fixed a bug where the `AttachmentPickerBottomSheet` was not able to identify the mobile browser. - Fixed uploading files on Windows - fixed temp file path. βœ… Added + - New `noPhotoOrVideoLabel` displayed when there is no files to choose. ## 5.2.0 βœ… Added -- Added a new `bottomRowBuilderWithDefaultWidget` parameter to `StreamMessageWidget` which contains a third parameter (default `BottomRow` widget with `copyWith` method available) to allow easier customization. + +- Added a new `bottomRowBuilderWithDefaultWidget` parameter to `StreamMessageWidget` which contains a third parameter ( + default `BottomRow` widget with `copyWith` method available) to allow easier customization. πŸ”„ Changed @@ -56,14 +68,20 @@ - Updated `dart_vlc` dependency to `^0.4.0` - Updated `file_picker` dependency to `^5.2.4` - Deprecated `StreamMessageWidget.bottomRowBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. -- Deprecated `StreamMessageWidget.deletedBottomRowBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. +- Deprecated `StreamMessageWidget.deletedBottomRowBuilder` in favor + of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. - Deprecated `StreamMessageWidget.usernameBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. 🐞 Fixed -- [[#1379]](https://github.com/GetStream/stream-chat-flutter/issues/1379) Fixed "Issues with photo attachments on web", where the cached image attachment would not render while uploading. -- Fix render overflow issue with `MessageSearchListTileTitle`. It now uses `Text.rich` instead of `Row`. Better default behaviour and allows `TextOverflow`. -- [[1346]](https://github.com/GetStream/stream-chat-flutter/issues/1346) Fixed a render issue while uploading video on web. -- [[#1347]](https://github.com/GetStream/stream-chat-flutter/issues/1347) `onReply` not working in `AttachmentActionsModal` which is used by `StreamImageAttachment` and `StreamImageGroup`. + +- [[#1379]](https://github.com/GetStream/stream-chat-flutter/issues/1379) Fixed "Issues with photo attachments on web", + where the cached image attachment would not render while uploading. +- Fix render overflow issue with `MessageSearchListTileTitle`. It now uses `Text.rich` instead of `Row`. Better default + behaviour and allows `TextOverflow`. +- [[1346]](https://github.com/GetStream/stream-chat-flutter/issues/1346) Fixed a render issue while uploading video on + web. +- [[#1347]](https://github.com/GetStream/stream-chat-flutter/issues/1347) `onReply` not working + in `AttachmentActionsModal` which is used by `StreamImageAttachment` and `StreamImageGroup`. ## 5.1.0 diff --git a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart index 7d51eb8b..267c96d4 100644 --- a/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart +++ b/packages/stream_chat_flutter/lib/src/message_widget/message_widget.dart @@ -1035,6 +1035,7 @@ class _StreamMessageWidgetState extends State builder: (_) => EditMessageSheet( message: widget.message, channel: StreamChannel.of(context).channel, + editMessageInputBuilder: widget.editMessageInputBuilder, ), ); }, From 0abacb37694ba6a96150096db1e1415dbc548bd7 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 1 May 2023 19:37:58 +0530 Subject: [PATCH 5/5] feat(ui): Added `StreamMessageInput.ogPreviewFilter` to allow users to filter out the og preview links. Signed-off-by: xsahil03x --- packages/stream_chat_flutter/CHANGELOG.md | 56 +++++++++++++++---- .../message_input/stream_message_input.dart | 32 +++++++++-- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 277d2484..1a5443c4 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -7,19 +7,41 @@ - [#1505](https://github.com/GetStream/stream-chat-flutter/issues/1505) Fixed Message bubble disappears for Hangul Consonants. +βœ… Added + +- Added `StreamMessageInput.ogPreviewFilter` to allow users to filter out the og preview + links. [#1338](https://github.com/GetStream/stream-chat-flutter/issues/1338) + + ```dart + StreamMessageInput( + ogPreviewFilter: (matchedUri, messageText) { + final url = matchedUri.toString(); + if (url.contains('giphy.com')) { + // Return false to prevent the OG preview from being built. + return false; + } + // Return true to build the OG preview. + return true; + ), + ``` + ## 6.0.0 🐞 Fixed -- [#1456](https://github.com/GetStream/stream-chat-flutter/issues/1456) Fixed logic for showing that a message was read using sending indicator. -- [#1462](https://github.com/GetStream/stream-chat-flutter/issues/1462) Fixed support for iPad in the share button for images. +- [#1456](https://github.com/GetStream/stream-chat-flutter/issues/1456) Fixed logic for showing that a message was read + using sending indicator. +- [#1462](https://github.com/GetStream/stream-chat-flutter/issues/1462) Fixed support for iPad in the share button for + images. - [#1475](https://github.com/GetStream/stream-chat-flutter/issues/1475) Fixed typo to fix compilation. βœ… Added - Now it is possible to customize the max lines of the title of a url attachment. Before it was always 1 line. -- Added `attachmentActionsModalBuilder` parameter to `StreamMessageWidget` that allows to customize `AttachmentActionsModal`. -- Added `StreamMessageInput.sendMessageKeyPredicate` and `StreamMessageInput.clearQuotedMessageKeyPredicate` to customize the keys used to send and clear the quoted message. +- Added `attachmentActionsModalBuilder` parameter to `StreamMessageWidget` that allows to + customize `AttachmentActionsModal`. +- Added `StreamMessageInput.sendMessageKeyPredicate` and `StreamMessageInput.clearQuotedMessageKeyPredicate` to + customize the keys used to send and clear the quoted message. πŸ”„ Changed @@ -27,6 +49,7 @@ πŸš€ Improved - + - Improved draw of reaction options. [#1455](https://github.com/GetStream/stream-chat-flutter/pull/1455) ## 5.3.0 @@ -36,17 +59,22 @@ - Updated `photo_manager` dependency to `^2.5.2` 🐞 Fixed -- [[#1424]](https://github.com/GetStream/stream-chat-flutter/issues/1424) Fixed a render issue when showing messages starting with 4 whitespaces. + +- [[#1424]](https://github.com/GetStream/stream-chat-flutter/issues/1424) Fixed a render issue when showing messages + starting with 4 whitespaces. - Fixed a bug where the `AttachmentPickerBottomSheet` was not able to identify the mobile browser. - Fixed uploading files on Windows - fixed temp file path. βœ… Added + - New `noPhotoOrVideoLabel` displayed when there is no files to choose. ## 5.2.0 βœ… Added -- Added a new `bottomRowBuilderWithDefaultWidget` parameter to `StreamMessageWidget` which contains a third parameter (default `BottomRow` widget with `copyWith` method available) to allow easier customization. + +- Added a new `bottomRowBuilderWithDefaultWidget` parameter to `StreamMessageWidget` which contains a third parameter ( + default `BottomRow` widget with `copyWith` method available) to allow easier customization. πŸ”„ Changed @@ -56,14 +84,20 @@ - Updated `dart_vlc` dependency to `^0.4.0` - Updated `file_picker` dependency to `^5.2.4` - Deprecated `StreamMessageWidget.bottomRowBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. -- Deprecated `StreamMessageWidget.deletedBottomRowBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. +- Deprecated `StreamMessageWidget.deletedBottomRowBuilder` in favor + of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. - Deprecated `StreamMessageWidget.usernameBuilder` in favor of `StreamMessageWidget.bottomRowBuilderWithDefaultWidget`. 🐞 Fixed -- [[#1379]](https://github.com/GetStream/stream-chat-flutter/issues/1379) Fixed "Issues with photo attachments on web", where the cached image attachment would not render while uploading. -- Fix render overflow issue with `MessageSearchListTileTitle`. It now uses `Text.rich` instead of `Row`. Better default behaviour and allows `TextOverflow`. -- [[1346]](https://github.com/GetStream/stream-chat-flutter/issues/1346) Fixed a render issue while uploading video on web. -- [[#1347]](https://github.com/GetStream/stream-chat-flutter/issues/1347) `onReply` not working in `AttachmentActionsModal` which is used by `StreamImageAttachment` and `StreamImageGroup`. + +- [[#1379]](https://github.com/GetStream/stream-chat-flutter/issues/1379) Fixed "Issues with photo attachments on web", + where the cached image attachment would not render while uploading. +- Fix render overflow issue with `MessageSearchListTileTitle`. It now uses `Text.rich` instead of `Row`. Better default + behaviour and allows `TextOverflow`. +- [[1346]](https://github.com/GetStream/stream-chat-flutter/issues/1346) Fixed a render issue while uploading video on + web. +- [[#1347]](https://github.com/GetStream/stream-chat-flutter/issues/1347) `onReply` not working + in `AttachmentActionsModal` which is used by `StreamImageAttachment` and `StreamImageGroup`. ## 5.1.0 diff --git a/packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart b/packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart index b479b5ce..d7768a09 100644 --- a/packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input/stream_message_input.dart @@ -25,6 +25,13 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'; const _kCommandTrigger = '/'; const _kMentionTrigger = '@'; +/// Signature for the function that determines if a [matchedUri] should be +/// previewed as an OG Attachment. +typedef OgPreviewFilter = bool Function( + Uri matchedUri, + String messageText, +); + /// Inactive state: /// /// ![screenshot](https://raw.githubusercontent.com/GetStream/stream-chat-flutter/master/packages/stream_chat_flutter/screenshots/message_input.png) @@ -114,6 +121,7 @@ class StreamMessageInput extends StatefulWidget { this.sendMessageKeyPredicate = _defaultSendMessageKeyPredicate, this.clearQuotedMessageKeyPredicate = _defaultClearQuotedMessageKeyPredicate, + this.ogPreviewFilter = _defaultOgPreviewFilter, }); /// The predicate used to send a message on desktop/web @@ -259,6 +267,18 @@ class StreamMessageInput extends StatefulWidget { /// Callback for when the quoted message is cleared final VoidCallback? onQuotedMessageCleared; + /// The filter used to determine if a link should be shown as an OpenGraph + /// preview. + final OgPreviewFilter ogPreviewFilter; + + static bool _defaultOgPreviewFilter( + Uri matchedUri, + String messageText, + ) { + // Show the preview for all links + return true; + } + static bool _defaultValidator(Message message) => message.text?.isNotEmpty == true || message.attachments.isNotEmpty; @@ -990,11 +1010,13 @@ class StreamMessageInputState extends State if (_lastSearchedContainsUrlText == value) return; _lastSearchedContainsUrlText = value; - final matchedUrls = _urlRegex.allMatches(value).toList() - ..removeWhere((it) { - final _parsedMatch = Uri.tryParse(it.group(0) ?? '')?.withScheme; - return _parsedMatch?.host.split('.').last.isValidTLD() == false; - }); + final matchedUrls = _urlRegex.allMatches(value).where((it) { + final _parsedMatch = Uri.tryParse(it.group(0) ?? '')?.withScheme; + if (_parsedMatch == null) return false; + + return _parsedMatch.host.split('.').last.isValidTLD() && + widget.ogPreviewFilter.call(_parsedMatch, value); + }).toList(); // Reset the og attachment if the text doesn't contain any url if (matchedUrls.isEmpty ||