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

add 'verified by' to contact profiles #2666

Merged
merged 7 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
15 changes: 15 additions & 0 deletions jni/dc_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,21 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContact_isVerified(JNIEnv *env, job
}


JNIEXPORT jstring Java_com_b44t_messenger_DcContact_getVerifierAddr(JNIEnv *env, jobject obj)
{
char* temp = dc_contact_get_verifier_addr(get_dc_contact(env, obj));
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
return ret;
}


JNIEXPORT jint Java_com_b44t_messenger_DcContact_getVerifierId(JNIEnv *env, jobject obj)
{
return dc_contact_get_verifier_id(get_dc_contact(env, obj));
}


/*******************************************************************************
* DcLot
******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions res/layout/profile_settings_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<TextView android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="7dp"
android:gravity="start|center_vertical"
android:textColor="?attr/emoji_text_color"
android:textSize="16sp"/>
Expand Down
2 changes: 2 additions & 0 deletions src/com/b44t/messenger/DcContact.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public String toString() {
public native boolean wasSeenRecently();
public native boolean isBlocked ();
public native boolean isVerified ();
public native String getVerifierAddr();
public native int getVerifierId ();

// working with raw c-data
private long contactCPtr; // CAVE: the name is referenced in the JNI
Expand Down
47 changes: 33 additions & 14 deletions src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
public class ProfileSettingsAdapter extends RecyclerView.Adapter
implements StickyHeaderAdapter<ProfileSettingsAdapter.HeaderViewHolder>
{
public static final int SETTING_VERIFIED = 118;
public static final int SETTING_LAST_SEEN = 119;
public static final int SETTING_SEND_MESSAGE = 120;

private final @NonNull Context context;
Expand Down Expand Up @@ -61,21 +63,25 @@ static class ItemData {
int chatlistIndex;
int settingsId;
String label;
int labelColor;
int iconLeft;

ItemData(int type, int settingsId, String label) {
this(type, 0, 0, settingsId, label);
ItemData(int type, int settingsId, String label, int labelColor, int iconLeft) {
this(type, 0, 0, settingsId, label, labelColor, iconLeft);
}

ItemData(int type, int contactId, int chatlistIndex) {
this(type, contactId, chatlistIndex, 0, null);
this(type, contactId, chatlistIndex, 0, null, 0, 0);
}

ItemData(int type, int contactId, int chatlistIndex, int settingsId, @Nullable String label) {
ItemData(int type, int contactId, int chatlistIndex, int settingsId, @Nullable String label, int labelColor, int iconLeft) {
this.type = type;
this.contactId = contactId;
this.chatlistIndex = chatlistIndex;
this.settingsId = settingsId;
this.label = label;
this.labelColor = labelColor;
this.iconLeft = iconLeft;
}
};

Expand Down Expand Up @@ -191,7 +197,7 @@ else if(holder.itemView instanceof ProfileSettingsItem) {
int settingsId = itemData.get(i).settingsId;
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) holder.itemView;
profileSettingsItem.setOnClickListener(view -> clickListener.onSettingsClicked(settingsId));
profileSettingsItem.set(itemData.get(i).label);
profileSettingsItem.set(itemData.get(i).label, itemData.get(i).labelColor, itemData.get(i).iconLeft);
}
}

Expand Down Expand Up @@ -235,13 +241,7 @@ public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
txt = context.getString(R.string.profile_shared_chats);
break;
case ItemData.TYPE_PRIMARY_SETTING:
long lastSeen = (itemDataContact!=null? itemDataContact.getLastSeen() : 0);
if (lastSeen == 0) {
txt = context.getString(R.string.last_seen_unknown);
}
else {
txt = context.getString(R.string.last_seen_at, DateUtils.getExtendedTimeSpanString(context, locale, lastSeen));
}
txt = context.getString(R.string.info);
break;
case ItemData.TYPE_STATUS:
txt = context.getString(R.string.pref_default_status_label);
Expand Down Expand Up @@ -312,12 +312,31 @@ else if (sharedChats!=null && dcContact!=null) {

itemDataContact = dcContact;
if (!chatIsDeviceTalk) {
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_SEND_MESSAGE, context.getString(R.string.send_message)));
if (dcContact.isVerified()) {
String verifiedInfo = context.getString(R.string.verified);
if (!dcContact.getVerifierAddr().isEmpty()) {
verifiedInfo = context.getString(R.string.verified_by, dcContact.getVerifierAddr());
}
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_VERIFIED, verifiedInfo, 0, R.drawable.ic_verified));
}

long lastSeenTimestamp = (itemDataContact!=null? itemDataContact.getLastSeen() : 0);
String lastSeenTxt;
if (lastSeenTimestamp == 0) {
lastSeenTxt = context.getString(R.string.last_seen_unknown);
}
else {
lastSeenTxt = context.getString(R.string.last_seen_at, DateUtils.getExtendedTimeSpanString(context, locale, lastSeenTimestamp));
}
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_LAST_SEEN, lastSeenTxt, 0, 0));


itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_SEND_MESSAGE, context.getString(R.string.send_message), R.color.delta_accent, 0));
}

itemDataStatusText = dcContact.getStatus();
if (!itemDataStatusText.isEmpty()) {
itemData.add(new ItemData(ItemData.TYPE_STATUS, 0, itemDataStatusText));
itemData.add(new ItemData(ItemData.TYPE_STATUS, 0, itemDataStatusText, 0, 0));
}

itemDataSharedChats = sharedChats;
Expand Down
15 changes: 15 additions & 0 deletions src/org/thoughtcrime/securesms/ProfileSettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public void onSettingsClicked(int settingsId) {
case ProfileSettingsAdapter.SETTING_SEND_MESSAGE:
onSendMessage();
break;
case ProfileSettingsAdapter.SETTING_VERIFIED:
onVerifiedByClicked();
break;
}
}

Expand Down Expand Up @@ -233,6 +236,18 @@ public void onSharedChatClicked(int chatId) {
getActivity().finish();
}

private void onVerifiedByClicked() {
DcContact dcContact = dcContext.getContact(contactId);
if (dcContact.isVerified()) {
int verifierId = dcContact.getVerifierId();
if (verifierId != 0 && verifierId != contactId) {
Copy link
Member

@adbenitez adbenitez Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this gets fixed in core then here we need to change and check if verifierId != SELF_CONTACT_ID

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's see what the outcome of deltachat/deltachat-core-rust#4748 will be - if we did sth. wrong or there will be a fix in core. currently we seem to have the same state as desktop, so i think, we can merge this pr in and iterate over in a subsequent pr as needed

Intent intent = new Intent(getContext(), ProfileActivity.class);
intent.putExtra(ProfileActivity.CONTACT_ID_EXTRA, verifierId);
startActivity(intent);
}
}
}

private void onSendMessage() {
DcContact dcContact = dcContext.getContact(contactId);
int chatId = dcContext.createChatByContactId(dcContact.getId());
Expand Down
14 changes: 13 additions & 1 deletion src/org/thoughtcrime/securesms/ProfileSettingsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import org.thoughtcrime.securesms.util.ResUtil;

public class ProfileSettingsItem extends LinearLayout {

private TextView labelView;
Expand All @@ -23,7 +27,15 @@ protected void onFinishInflate() {
labelView = findViewById(R.id.label);
}

public void set(String label) {
public void set(String label, int labelColor, int iconLeft) {
labelView.setText(label==null? "" : label);
labelView.setCompoundDrawablesWithIntrinsicBounds(iconLeft, 0,0,0);

// we need different color getters as `labelColor` is `R.color.name` while default is `R.attr.name`
if (labelColor != 0) {
labelView.setTextColor(ContextCompat.getColor(getContext(), labelColor));
} else {
labelView.setTextColor(ResUtil.getColor(getContext(), R.attr.emoji_text_color)); //
r10s marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading