From 80ed95077dabcfaaff9b1373df3ec3c9ce4b5643 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 12 Oct 2023 22:42:49 +0200 Subject: [PATCH] allow to react with single-emoji reply and to remove reaction --- .../securesms/ConversationActivity.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index b191f5283..5b3a02843 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -1021,6 +1021,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity protected static final int ACTION_SEND_OUT = 1; protected static final int ACTION_SAVE_DRAFT = 2; + private String getSelfReaction(int msgId) { + try { + final String [] selfReactions = rpc.getMsgReactions(dcContext.getAccountId(), msgId).getReactionsByContact().get(DcContact.DC_CONTACT_ID_SELF); + if (selfReactions != null && selfReactions.length > 0) return selfReactions[0]; + } catch(Exception e) { e.printStackTrace(); } + return null; + } + protected ListenableFuture processComposeControls(int action) { return processComposeControls(action, composeText.getTextTrimmed(), attachmentManager.isAttachmentPresent() ? @@ -1078,15 +1086,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity e.printStackTrace(); } } - else if (false && action == ACTION_SEND_OUT && quote.isPresent() && EmojiProvider.getInstance(this).isEmoji(body)){ + else if (action == ACTION_SEND_OUT && quote.isPresent() && EmojiProvider.getInstance(this).isEmoji(body)){ + int quotedMsg = quote.get().getQuotedMsg().getId(); try { - rpc.sendReaction(dcContext.getAccountId(), quote.get().getQuotedMsg().getId(), body); - future.set(chatId); - return future; + rpc.sendReaction(dcContext.getAccountId(), quotedMsg, body.equals(getSelfReaction(quotedMsg))? "" : body); + future.set(chatId); + return future; } catch (RpcException e) { - e.printStackTrace(); - msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT); - msg.setText(body); + e.printStackTrace(); + msg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT); + msg.setText(body); } } else if (!body.isEmpty()){