mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-13 04:12:00 +10:00
Put reaction and GIF helpers in charge of encoding
This commit is contained in:
@@ -9,7 +9,7 @@ class GifHelper {
|
|||||||
/// include a trailing slash.
|
/// include a trailing slash.
|
||||||
///
|
///
|
||||||
/// Returns null if text is not a valid GIF format
|
/// Returns null if text is not a valid GIF format
|
||||||
static String? parseGifId(String text) {
|
static String? parseGif(String text) {
|
||||||
final trimmed = text.trim();
|
final trimmed = text.trim();
|
||||||
final match = RegExp(r'^g:([A-Za-z0-9_-]+)$').firstMatch(trimmed);
|
final match = RegExp(r'^g:([A-Za-z0-9_-]+)$').firstMatch(trimmed);
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
@@ -30,4 +30,9 @@ class GifHelper {
|
|||||||
).firstMatch(trimmed);
|
).firstMatch(trimmed);
|
||||||
return pageMatch?.group(1);
|
return pageMatch?.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode a GIF in a format that parseGif() can parse.
|
||||||
|
static String encodeGif(String gifId) {
|
||||||
|
return 'g:$gifId';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,4 +109,9 @@ class ReactionHelper {
|
|||||||
|
|
||||||
return ReactionInfo(targetHash: match.group(1)!, emoji: emoji);
|
return ReactionInfo(targetHash: match.group(1)!, emoji: emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encode a reaction message that parseReaction() can parse.
|
||||||
|
static String encodeReaction(String hash, String emojiIndex) {
|
||||||
|
return 'r:$hash:$emojiIndex';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
final settingsService = context.watch<AppSettingsService>();
|
final settingsService = context.watch<AppSettingsService>();
|
||||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||||
final isOutgoing = message.isOutgoing;
|
final isOutgoing = message.isOutgoing;
|
||||||
final gifId = GifHelper.parseGifId(message.text);
|
final gifId = GifHelper.parseGif(message.text);
|
||||||
final poi = _parsePoiMessage(message.text);
|
final poi = _parsePoiMessage(message.text);
|
||||||
final translatedDisplayText =
|
final translatedDisplayText =
|
||||||
message.translatedText != null &&
|
message.translatedText != null &&
|
||||||
@@ -700,7 +700,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
final previewTextColor = colorScheme.onSurface.withValues(alpha: 0.7);
|
final previewTextColor = colorScheme.onSurface.withValues(alpha: 0.7);
|
||||||
|
|
||||||
final gifId = GifHelper.parseGifId(replyText);
|
final gifId = GifHelper.parseGif(replyText);
|
||||||
final poi = _parsePoiMessage(replyText);
|
final poi = _parsePoiMessage(replyText);
|
||||||
|
|
||||||
Widget contentPreview;
|
Widget contentPreview;
|
||||||
@@ -892,7 +892,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
builder: (context) => GifPicker(
|
builder: (context) => GifPicker(
|
||||||
onGifSelected: (gifId) {
|
onGifSelected: (gifId) {
|
||||||
_textController.text = 'g:$gifId';
|
_textController.text = GifHelper.encodeGif(gifId);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -1048,7 +1048,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
child: ValueListenableBuilder<TextEditingValue>(
|
child: ValueListenableBuilder<TextEditingValue>(
|
||||||
valueListenable: _textController,
|
valueListenable: _textController,
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
final gifId = GifHelper.parseGifId(value.text);
|
final gifId = GifHelper.parseGif(value.text);
|
||||||
if (gifId != null) {
|
if (gifId != null) {
|
||||||
return Focus(
|
return Focus(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
@@ -1316,7 +1316,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
message.senderName,
|
message.senderName,
|
||||||
message.text,
|
message.text,
|
||||||
);
|
);
|
||||||
final reactionText = 'r:$hash:$emojiIndex';
|
final reactionText = ReactionHelper.encodeReaction(hash, emojiIndex);
|
||||||
connector.sendChannelMessage(widget.channel, reactionText);
|
connector.sendChannelMessage(widget.channel, reactionText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
child: ValueListenableBuilder<TextEditingValue>(
|
child: ValueListenableBuilder<TextEditingValue>(
|
||||||
valueListenable: _textController,
|
valueListenable: _textController,
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
final gifId = GifHelper.parseGifId(value.text);
|
final gifId = GifHelper.parseGif(value.text);
|
||||||
if (gifId != null) {
|
if (gifId != null) {
|
||||||
return Focus(
|
return Focus(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
@@ -605,7 +605,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
builder: (context) => GifPicker(
|
builder: (context) => GifPicker(
|
||||||
onGifSelected: (gifId) {
|
onGifSelected: (gifId) {
|
||||||
_textController.text = 'g:$gifId';
|
_textController.text = GifHelper.encodeGif(gifId);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -1538,7 +1538,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||||||
senderName,
|
senderName,
|
||||||
message.text,
|
message.text,
|
||||||
);
|
);
|
||||||
final reactionText = 'r:$hash:$emojiIndex';
|
final reactionText = ReactionHelper.encodeReaction(hash, emojiIndex);
|
||||||
connector.sendMessage(_resolveContact(connector), reactionText);
|
connector.sendMessage(_resolveContact(connector), reactionText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1568,7 +1568,7 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||||
final isOutgoing = message.isOutgoing;
|
final isOutgoing = message.isOutgoing;
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
final gifId = GifHelper.parseGifId(message.text);
|
final gifId = GifHelper.parseGif(message.text);
|
||||||
final poi = _parsePoiMessage(message.text);
|
final poi = _parsePoiMessage(message.text);
|
||||||
final isFailed = message.status == MessageStatus.failed;
|
final isFailed = message.status == MessageStatus.failed;
|
||||||
final bubbleColor = isFailed
|
final bubbleColor = isFailed
|
||||||
|
|||||||
Reference in New Issue
Block a user