From 84b89aacb261eea368f5f2b05fc2f686504c0bdd Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 17 Feb 2024 17:12:56 +0100 Subject: [PATCH 1/7] in self-chat, always show avatar for non-self messages (they're forwarded) --- src/main/java/org/thoughtcrime/securesms/ConversationItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationItem.java b/src/main/java/org/thoughtcrime/securesms/ConversationItem.java index ff908166bd..a48e794f16 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationItem.java @@ -176,7 +176,7 @@ public void bind(@NonNull DcMsg messageRecord, { bind(messageRecord, dcChat, batchSelected, pulseHighlight, recipients); this.glideRequests = glideRequests; - this.showSender = (dcChat.isMultiUser() && !messageRecord.isOutgoing()) || messageRecord.getOverrideSenderName() != null; + this.showSender = ((dcChat.isMultiUser() || dcChat.isSelfTalk()) && !messageRecord.isOutgoing()) || messageRecord.getOverrideSenderName() != null; if (showSender) { this.dcContact = dcContext.getContact(messageRecord.getFromId()); From 3a21727f5bd9775261f92d761e78bb854efb7fca Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 18 Feb 2024 15:54:37 +0100 Subject: [PATCH 2/7] add getOriginalMsg() api --- jni/dc_wrapper.c | 6 ++++++ src/main/java/com/b44t/messenger/DcMsg.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index cb349315c3..eb6eb206bb 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -1723,6 +1723,12 @@ JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getParentCPtr(JNIEnv *env, jobject } +JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getOriginalMsgCPtr(JNIEnv *env, jobject obj) +{ + return (jlong)dc_msg_get_original_msg(get_dc_msg(env, obj)); +} + + JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getError(JNIEnv *env, jobject obj) { char* temp = dc_msg_get_error(get_dc_msg(env, obj)); diff --git a/src/main/java/com/b44t/messenger/DcMsg.java b/src/main/java/com/b44t/messenger/DcMsg.java index 52a4c110d5..ef8e94dbee 100644 --- a/src/main/java/com/b44t/messenger/DcMsg.java +++ b/src/main/java/com/b44t/messenger/DcMsg.java @@ -184,6 +184,11 @@ public DcMsg getParent() { return cPtr != 0 ? new DcMsg(cPtr) : null; } + public DcMsg getOriginalMsg() { + long cPtr = getOriginalMsgCPtr(); + return cPtr != 0 ? new DcMsg(cPtr) : null; + } + public File getFileAsFile() { if(getFile()==null) throw new AssertionError("expected a file to be present."); @@ -249,5 +254,6 @@ public boolean isSeen() { private native void setQuoteCPtr (long quoteCPtr); private native long getQuotedMsgCPtr (); private native long getParentCPtr (); + private native long getOriginalMsgCPtr(); private native String getWebxdcInfoJson (); }; From 353e1343e4638655ab330460cd587d2fdf5c4bbb Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 18 Feb 2024 16:46:23 +0100 Subject: [PATCH 3/7] add 'show in chat' menu entry to 'saved messages' --- .../org/thoughtcrime/securesms/ConversationFragment.java | 5 +++++ .../util/views/ConversationAdaptiveActionsToolbar.java | 4 +++- src/main/res/menu/conversation_context.xml | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java index 87fd5359ea..9e7579b5bb 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java @@ -327,6 +327,7 @@ protected void setCorrectMenuVisibility(Menu menu) { menu.findItem(R.id.menu_context_reply).setVisible(false); menu.findItem(R.id.menu_context_reply_privately).setVisible(false); menu.findItem(R.id.menu_add_to_home_screen).setVisible(false); + menu.findItem(R.id.menu_show_in_chat).setVisible(false); } else { DcMsg messageRecord = messageRecords.iterator().next(); DcChat chat = getListAdapter().getChat(); @@ -337,6 +338,7 @@ protected void setCorrectMenuVisibility(Menu menu) { boolean showReplyPrivately = chat.isMultiUser() && !messageRecord.isOutgoing() && canReply; menu.findItem(R.id.menu_context_reply_privately).setVisible(showReplyPrivately); menu.findItem(R.id.menu_add_to_home_screen).setVisible(messageRecord.getType() == DcMsg.DC_MSG_WEBXDC); + menu.findItem(R.id.menu_show_in_chat).setVisible(messageRecord.getOriginalMsg() != null); } // if one of the selected items cannot be saved, disable saving. @@ -961,6 +963,9 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { case R.id.menu_resend: handleResendMessage(getListAdapter().getSelectedItems()); return true; + case R.id.menu_show_in_chat: + handleShowInChat(getSelectedMessageRecord(getListAdapter().getSelectedItems()).getOriginalMsg()); + return true; } return false; diff --git a/src/main/java/org/thoughtcrime/securesms/util/views/ConversationAdaptiveActionsToolbar.java b/src/main/java/org/thoughtcrime/securesms/util/views/ConversationAdaptiveActionsToolbar.java index f61d39bf31..e23e8f6082 100644 --- a/src/main/java/org/thoughtcrime/securesms/util/views/ConversationAdaptiveActionsToolbar.java +++ b/src/main/java/org/thoughtcrime/securesms/util/views/ConversationAdaptiveActionsToolbar.java @@ -27,6 +27,7 @@ public class ConversationAdaptiveActionsToolbar extends Toolbar { private static final int ID_NEVER_SHOW_AS_ACTION_2 = R.id.menu_add_to_home_screen; private static final int ID_NEVER_SHOW_AS_ACTION_3 = R.id.menu_context_save_attachment; private static final int ID_NEVER_SHOW_AS_ACTION_4 = R.id.menu_resend; + private static final int ID_NEVER_SHOW_AS_ACTION_5 = R.id.menu_show_in_chat; private static final int ID_ALWAYS_SHOW_AS_ACTION = R.id.menu_context_forward; private final int maxShown; @@ -83,7 +84,8 @@ public static void adjustMenuActions(@NonNull Menu menu, int maxToShow, int tool boolean neverShowAsAction = item.getItemId() == ID_NEVER_SHOW_AS_ACTION_1 || item.getItemId() == ID_NEVER_SHOW_AS_ACTION_2 || item.getItemId() == ID_NEVER_SHOW_AS_ACTION_3 - || item.getItemId() == ID_NEVER_SHOW_AS_ACTION_4; + || item.getItemId() == ID_NEVER_SHOW_AS_ACTION_4 + || item.getItemId() == ID_NEVER_SHOW_AS_ACTION_5; boolean alwaysShowAsAction = item.getItemId() == ID_ALWAYS_SHOW_AS_ACTION; if (alwaysShowAsAction) continue; diff --git a/src/main/res/menu/conversation_context.xml b/src/main/res/menu/conversation_context.xml index 7be2b04a75..7fbcc8c2c3 100644 --- a/src/main/res/menu/conversation_context.xml +++ b/src/main/res/menu/conversation_context.xml @@ -44,6 +44,10 @@ android:id="@+id/menu_context_reply_privately" app:showAsAction="never" /> + + From 440c855401e6e2c1f1334f6569e20355801825e2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 13 Oct 2024 18:48:55 +0200 Subject: [PATCH 4/7] go to original chat, even if saved message was deleted --- jni/dc_wrapper.c | 6 ++++++ src/main/java/com/b44t/messenger/DcMsg.java | 3 +++ .../thoughtcrime/securesms/ConversationFragment.java | 4 ++-- .../securesms/MessageSelectorFragment.java | 11 ++++++++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index eb6eb206bb..530b6ca902 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -1729,6 +1729,12 @@ JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getOriginalMsgCPtr(JNIEnv *env, jo } +JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getOriginalChatId(JNIEnv *env, jobject obj) +{ + return (jint)dc_msg_get_original_chat_id(get_dc_msg(env, obj)); +} + + JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getError(JNIEnv *env, jobject obj) { char* temp = dc_msg_get_error(get_dc_msg(env, obj)); diff --git a/src/main/java/com/b44t/messenger/DcMsg.java b/src/main/java/com/b44t/messenger/DcMsg.java index ef8e94dbee..153f99cc79 100644 --- a/src/main/java/com/b44t/messenger/DcMsg.java +++ b/src/main/java/com/b44t/messenger/DcMsg.java @@ -189,6 +189,9 @@ public DcMsg getOriginalMsg() { return cPtr != 0 ? new DcMsg(cPtr) : null; } + public native int getOriginalChatId (); + public boolean hasOriginal () { return getOriginalChatId() != 0; } + public File getFileAsFile() { if(getFile()==null) throw new AssertionError("expected a file to be present."); diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java index 9e7579b5bb..3e024f031f 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java @@ -338,7 +338,7 @@ protected void setCorrectMenuVisibility(Menu menu) { boolean showReplyPrivately = chat.isMultiUser() && !messageRecord.isOutgoing() && canReply; menu.findItem(R.id.menu_context_reply_privately).setVisible(showReplyPrivately); menu.findItem(R.id.menu_add_to_home_screen).setVisible(messageRecord.getType() == DcMsg.DC_MSG_WEBXDC); - menu.findItem(R.id.menu_show_in_chat).setVisible(messageRecord.getOriginalMsg() != null); + menu.findItem(R.id.menu_show_in_chat).setVisible(messageRecord.hasOriginal()); } // if one of the selected items cannot be saved, disable saving. @@ -964,7 +964,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { handleResendMessage(getListAdapter().getSelectedItems()); return true; case R.id.menu_show_in_chat: - handleShowInChat(getSelectedMessageRecord(getListAdapter().getSelectedItems()).getOriginalMsg()); + handleShowInChat(getSelectedMessageRecord(getListAdapter().getSelectedItems())); return true; } diff --git a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java index adfc1c326a..8e11c33ff3 100644 --- a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java @@ -109,10 +109,15 @@ private void performSave(Set messageRecords) { if (actionMode != null) actionMode.finish(); } - protected void handleShowInChat(final DcMsg dcMsg) { + protected void handleShowInChat(final DcMsg savedMsg) { Intent intent = new Intent(getContext(), ConversationActivity.class); - intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsg.getChatId()); - intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(dcMsg, dcContext)); + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, savedMsg.getOriginalChatId()); + + DcMsg originalMsg = savedMsg.getOriginalMsg(); + if (originalMsg != null) { + intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(originalMsg, dcContext)); + } + startActivity(intent); } From b491b18e06f82fe15c4ea7e7f210c71b3d450389 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 14 Oct 2024 00:54:46 +0200 Subject: [PATCH 5/7] mark saved messages --- jni/dc_wrapper.c | 6 ++++++ src/main/java/com/b44t/messenger/DcMsg.java | 7 ++++--- .../securesms/components/ConversationItemFooter.java | 6 +++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 530b6ca902..ddca8971ea 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -1735,6 +1735,12 @@ JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getOriginalChatId(JNIEnv *env, jobj } +JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getSavedMsgId(JNIEnv *env, jobject obj) +{ + return (jint)dc_msg_get_saved_msg_id(get_dc_msg(env, obj)); +} + + JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getError(JNIEnv *env, jobject obj) { char* temp = dc_msg_get_error(get_dc_msg(env, obj)); diff --git a/src/main/java/com/b44t/messenger/DcMsg.java b/src/main/java/com/b44t/messenger/DcMsg.java index 153f99cc79..70e721cf85 100644 --- a/src/main/java/com/b44t/messenger/DcMsg.java +++ b/src/main/java/com/b44t/messenger/DcMsg.java @@ -184,14 +184,15 @@ public DcMsg getParent() { return cPtr != 0 ? new DcMsg(cPtr) : null; } + public boolean hasOriginal () { return getOriginalChatId() != 0; } + public native int getOriginalChatId (); + public native int getSavedMsgId (); + public DcMsg getOriginalMsg() { long cPtr = getOriginalMsgCPtr(); return cPtr != 0 ? new DcMsg(cPtr) : null; } - public native int getOriginalChatId (); - public boolean hasOriginal () { return getOriginalChatId() != 0; } - public File getFileAsFile() { if(getFile()==null) throw new AssertionError("expected a file to be present."); diff --git a/src/main/java/org/thoughtcrime/securesms/components/ConversationItemFooter.java b/src/main/java/org/thoughtcrime/securesms/components/ConversationItemFooter.java index 624ddbd6f4..46fe126fe4 100644 --- a/src/main/java/org/thoughtcrime/securesms/components/ConversationItemFooter.java +++ b/src/main/java/org/thoughtcrime/securesms/components/ConversationItemFooter.java @@ -72,7 +72,11 @@ private void setTextColor(int color) { private void presentDate(@NonNull DcMsg messageRecord) { dateView.forceLayout(); - dateView.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), messageRecord.getTimestamp())); + String text = DateUtils.getExtendedRelativeTimeSpanString(getContext(), messageRecord.getTimestamp()); + if (messageRecord.getSavedMsgId() != 0) { + text += " ★"; + } + dateView.setText(text); } private void presentDeliveryStatus(@NonNull DcMsg messageRecord) { From dd8cd642b9770f862ad6ec5fa99fe9e66f05824a Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 14 Oct 2024 15:25:53 +0200 Subject: [PATCH 6/7] adapt to simplified api --- jni/dc_wrapper.c | 12 ++++-------- src/main/java/com/b44t/messenger/DcMsg.java | 7 +------ .../securesms/MessageSelectorFragment.java | 6 +++--- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index ddca8971ea..c1ad895d92 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -1722,25 +1722,21 @@ JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getParentCPtr(JNIEnv *env, jobject return (jlong)dc_msg_get_parent(get_dc_msg(env, obj)); } - -JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getOriginalMsgCPtr(JNIEnv *env, jobject obj) -{ - return (jlong)dc_msg_get_original_msg(get_dc_msg(env, obj)); -} - - JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getOriginalChatId(JNIEnv *env, jobject obj) { return (jint)dc_msg_get_original_chat_id(get_dc_msg(env, obj)); } +JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getOriginalMsgId(JNIEnv *env, jobject obj) +{ + return (jint)dc_msg_get_original_msg_id(get_dc_msg(env, obj)); +} JNIEXPORT jint Java_com_b44t_messenger_DcMsg_getSavedMsgId(JNIEnv *env, jobject obj) { return (jint)dc_msg_get_saved_msg_id(get_dc_msg(env, obj)); } - JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getError(JNIEnv *env, jobject obj) { char* temp = dc_msg_get_error(get_dc_msg(env, obj)); diff --git a/src/main/java/com/b44t/messenger/DcMsg.java b/src/main/java/com/b44t/messenger/DcMsg.java index 70e721cf85..72365e6539 100644 --- a/src/main/java/com/b44t/messenger/DcMsg.java +++ b/src/main/java/com/b44t/messenger/DcMsg.java @@ -186,13 +186,9 @@ public DcMsg getParent() { public boolean hasOriginal () { return getOriginalChatId() != 0; } public native int getOriginalChatId (); + public native int getOriginalMsgId (); public native int getSavedMsgId (); - public DcMsg getOriginalMsg() { - long cPtr = getOriginalMsgCPtr(); - return cPtr != 0 ? new DcMsg(cPtr) : null; - } - public File getFileAsFile() { if(getFile()==null) throw new AssertionError("expected a file to be present."); @@ -258,6 +254,5 @@ public boolean isSeen() { private native void setQuoteCPtr (long quoteCPtr); private native long getQuotedMsgCPtr (); private native long getParentCPtr (); - private native long getOriginalMsgCPtr(); private native String getWebxdcInfoJson (); }; diff --git a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java index 8e11c33ff3..5185f00742 100644 --- a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java @@ -113,9 +113,9 @@ protected void handleShowInChat(final DcMsg savedMsg) { Intent intent = new Intent(getContext(), ConversationActivity.class); intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, savedMsg.getOriginalChatId()); - DcMsg originalMsg = savedMsg.getOriginalMsg(); - if (originalMsg != null) { - intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(originalMsg, dcContext)); + int originalMsgId = savedMsg.getOriginalMsgId(); + if (originalMsgId != 0) { + intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(dcContext.getMsg(originalMsgId), dcContext)); } startActivity(intent); From af1ba4a1f29770a3ac3a4a2ba6875639f1a2bfd6 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 16 Oct 2024 17:59:35 +0200 Subject: [PATCH 7/7] fix original handleShowInChat() --- .../thoughtcrime/securesms/ConversationFragment.java | 12 +++++++++++- .../securesms/MessageSelectorFragment.java | 11 +++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java index 3e024f031f..ec2d1f209b 100644 --- a/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/ConversationFragment.java @@ -964,7 +964,17 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) { handleResendMessage(getListAdapter().getSelectedItems()); return true; case R.id.menu_show_in_chat: - handleShowInChat(getSelectedMessageRecord(getListAdapter().getSelectedItems())); + DcMsg savedMsg = getSelectedMessageRecord(getListAdapter().getSelectedItems()); + int originalChatId = savedMsg.getOriginalChatId(); + if (originalChatId != 0) { + Intent intent = new Intent(getContext(), ConversationActivity.class); + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, originalChatId); + int originalMsgId = savedMsg.getOriginalMsgId(); + if (originalMsgId != 0) { + intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(dcContext.getMsg(originalMsgId), dcContext)); + } + startActivity(intent); + } return true; } diff --git a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java index 5185f00742..adfc1c326a 100644 --- a/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java +++ b/src/main/java/org/thoughtcrime/securesms/MessageSelectorFragment.java @@ -109,15 +109,10 @@ private void performSave(Set messageRecords) { if (actionMode != null) actionMode.finish(); } - protected void handleShowInChat(final DcMsg savedMsg) { + protected void handleShowInChat(final DcMsg dcMsg) { Intent intent = new Intent(getContext(), ConversationActivity.class); - intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, savedMsg.getOriginalChatId()); - - int originalMsgId = savedMsg.getOriginalMsgId(); - if (originalMsgId != 0) { - intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(dcContext.getMsg(originalMsgId), dcContext)); - } - + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsg.getChatId()); + intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, DcMsg.getMessagePosition(dcMsg, dcContext)); startActivity(intent); }