Skip to content

Commit

Permalink
Merge pull request #2742 from OpenBubbles/emoji
Browse files Browse the repository at this point in the history
Replace emojis in text view
  • Loading branch information
zlshames authored Oct 4, 2024
2 parents f273b3d + d9824f8 commit 1d8fb4b
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,26 @@ class ConversationTextFieldState extends CustomState<ConversationTextField, void
super.dispose();
}

String Function(dynamic) replaceEmoji(String emoji) {
return (match) {
if (match.group(1) == "\\") {
return '${match.group(2)}${match.group(3)}';
}
return '${match.group(1)}$emoji${match.group(3)}';
};
}

Future<void> sendMessage({String? effect}) async {
final text = controller.textController.text
.replaceAllMapped(RegExp(r'([\s\\])(:\))(\s|$)'), replaceEmoji("🙂"))
.replaceAllMapped(RegExp(r'([\s\\])(:P)(\s|$)'), replaceEmoji("😛"))
.replaceAllMapped(RegExp(r'([\s\\])(XD)(\s|$)'), replaceEmoji("😆"))
.replaceAllMapped(RegExp(r'([\s\\])(;\))(\s|$)'), replaceEmoji("😉"))
.replaceAllMapped(RegExp(r'([\s\\])(:D)(\s|$)'), replaceEmoji("😀"));
if (controller.scheduledDate.value != null) {
final date = controller.scheduledDate.value!;
if (date.isBefore(DateTime.now())) return showSnackbar("Error", "Pick a date in the future!");
if (controller.textController.text.contains(MentionTextEditingController.escapingChar)) {
if (text.contains(MentionTextEditingController.escapingChar)) {
return showSnackbar("Error", "Mentions are not allowed in scheduled messages!");
}
showDialog(
Expand All @@ -469,7 +484,7 @@ class ConversationTextFieldState extends CustomState<ConversationTextField, void
);
},
);
final response = await http.createScheduled(chat.guid, controller.textController.text, date.toUtc(), {"type": "once"});
final response = await http.createScheduled(chat.guid, text, date.toUtc(), {"type": "once"});
Navigator.of(context).pop();
if (response.statusCode == 200 && response.data != null) {
showSnackbar("Notice", "Message scheduled successfully for ${buildFullDate(date)}");
Expand All @@ -479,7 +494,6 @@ class ConversationTextFieldState extends CustomState<ConversationTextField, void
showSnackbar("Error", "Something went wrong!");
}
} else {
final text = controller.textController.text;
if (text.isEmpty && controller.subjectTextController.text.isEmpty && !ss.settings.privateAPIAttachmentSend.value) {
if (controller.replyToMessage != null) {
return showSnackbar("Error", "Turn on Private API Attachment Send to send replies with media!");
Expand Down

0 comments on commit 1d8fb4b

Please sign in to comment.