Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace emojis in text view #2742

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,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 @@ -448,7 +463,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 @@ -458,7 +473,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