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

improve saved messages #3073

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions jni/dc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,20 @@ JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getParentCPtr(JNIEnv *env, jobject
return (jlong)dc_msg_get_parent(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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/b44t/messenger/DcMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public DcMsg getParent() {
return cPtr != 0 ? new DcMsg(cPtr) : null;
}

public boolean hasOriginal () { return getOriginalChatId() != 0; }
public native int getOriginalChatId ();
public native int getOriginalMsgId ();
public native int getSavedMsgId ();

public File getFileAsFile() {
if(getFile()==null)
throw new AssertionError("expected a file to be present.");
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/thoughtcrime/securesms/ConversationFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.hasOriginal());
}

// if one of the selected items cannot be saved, disable saving.
Expand Down Expand Up @@ -961,6 +963,19 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
case R.id.menu_resend:
handleResendMessage(getListAdapter().getSelectedItems());
return true;
case R.id.menu_show_in_chat:
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;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/menu/conversation_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
android:id="@+id/menu_context_reply_privately"
app:showAsAction="never" />

<item android:title="@string/show_in_chat"
android:id="@+id/menu_show_in_chat"
app:showAsAction="never" />

<item android:title="@string/resend"
android:id="@+id/menu_resend"
app:showAsAction="never" />
Expand Down
Loading