mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Show name of message sender for groups in conversation list.
This commit is contained in:
@@ -1381,6 +1381,7 @@ public class ThreadDatabase extends Database {
|
||||
private @Nullable Extra getExtrasFor(MessageRecord record) {
|
||||
boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, record.getThreadId());
|
||||
RecipientId threadRecipientId = getRecipientIdForThreadId(record.getThreadId());
|
||||
RecipientId individualRecipient = record.getIndividualRecipient().getId();
|
||||
|
||||
if (!messageRequestAccepted && threadRecipientId != null) {
|
||||
Recipient resolved = Recipient.resolved(threadRecipientId);
|
||||
@@ -1391,35 +1392,42 @@ public class ThreadDatabase extends Database {
|
||||
RecipientId from = RecipientId.from(inviteAddState.getAddedOrInvitedBy(), null);
|
||||
if (inviteAddState.isInvited()) {
|
||||
Log.i(TAG, "GV2 invite message request from " + from);
|
||||
return Extra.forGroupV2invite(from);
|
||||
return Extra.forGroupV2invite(from, individualRecipient);
|
||||
} else {
|
||||
Log.i(TAG, "GV2 message request from " + from);
|
||||
return Extra.forGroupMessageRequest(from);
|
||||
return Extra.forGroupMessageRequest(from, individualRecipient);
|
||||
}
|
||||
}
|
||||
Log.w(TAG, "Falling back to unknown message request state for GV2 message");
|
||||
return Extra.forMessageRequest();
|
||||
return Extra.forMessageRequest(individualRecipient);
|
||||
} else {
|
||||
RecipientId recipientId = DatabaseFactory.getMmsSmsDatabase(context).getGroupAddedBy(record.getThreadId());
|
||||
|
||||
if (recipientId != null) {
|
||||
return Extra.forGroupMessageRequest(recipientId);
|
||||
return Extra.forGroupMessageRequest(recipientId, individualRecipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Extra.forMessageRequest();
|
||||
return Extra.forMessageRequest(individualRecipient);
|
||||
}
|
||||
|
||||
if (record.isRemoteDelete()) {
|
||||
return Extra.forRemoteDelete();
|
||||
return Extra.forRemoteDelete(individualRecipient);
|
||||
} else if (record.isViewOnce()) {
|
||||
return Extra.forViewOnce();
|
||||
return Extra.forViewOnce(individualRecipient);
|
||||
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
|
||||
StickerSlide slide = Objects.requireNonNull(((MmsMessageRecord) record).getSlideDeck().getStickerSlide());
|
||||
return Extra.forSticker(slide.getEmoji());
|
||||
return Extra.forSticker(slide.getEmoji(), individualRecipient);
|
||||
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() > 1) {
|
||||
return Extra.forAlbum();
|
||||
return Extra.forAlbum(individualRecipient);
|
||||
}
|
||||
|
||||
if (threadRecipientId != null) {
|
||||
Recipient resolved = Recipient.resolved(threadRecipientId);
|
||||
if (resolved.isGroup()) {
|
||||
return Extra.forDefault(individualRecipient);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -1590,6 +1598,7 @@ public class ThreadDatabase extends Database {
|
||||
@JsonProperty private final boolean isMessageRequestAccepted;
|
||||
@JsonProperty private final boolean isGv2Invite;
|
||||
@JsonProperty private final String groupAddedBy;
|
||||
@JsonProperty private final String individualRecipientId;
|
||||
|
||||
public Extra(@JsonProperty("isRevealable") boolean isRevealable,
|
||||
@JsonProperty("isSticker") boolean isSticker,
|
||||
@@ -1598,7 +1607,8 @@ public class ThreadDatabase extends Database {
|
||||
@JsonProperty("isRemoteDelete") boolean isRemoteDelete,
|
||||
@JsonProperty("isMessageRequestAccepted") boolean isMessageRequestAccepted,
|
||||
@JsonProperty("isGv2Invite") boolean isGv2Invite,
|
||||
@JsonProperty("groupAddedBy") String groupAddedBy)
|
||||
@JsonProperty("groupAddedBy") String groupAddedBy,
|
||||
@JsonProperty("individualRecipientId") String individualRecipientId)
|
||||
{
|
||||
this.isRevealable = isRevealable;
|
||||
this.isSticker = isSticker;
|
||||
@@ -1608,34 +1618,39 @@ public class ThreadDatabase extends Database {
|
||||
this.isMessageRequestAccepted = isMessageRequestAccepted;
|
||||
this.isGv2Invite = isGv2Invite;
|
||||
this.groupAddedBy = groupAddedBy;
|
||||
this.individualRecipientId = individualRecipientId;
|
||||
}
|
||||
|
||||
public static @NonNull Extra forViewOnce() {
|
||||
return new Extra(true, false, null, false, false, true, false, null);
|
||||
public static @NonNull Extra forViewOnce(@NonNull RecipientId individualRecipient) {
|
||||
return new Extra(true, false, null, false, false, true, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forSticker(@Nullable String emoji) {
|
||||
return new Extra(false, true, emoji, false, false, true, false, null);
|
||||
public static @NonNull Extra forSticker(@Nullable String emoji, @NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, true, emoji, false, false, true, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forAlbum() {
|
||||
return new Extra(false, false, null, true, false, true, false, null);
|
||||
public static @NonNull Extra forAlbum(@NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, true, false, true, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forRemoteDelete() {
|
||||
return new Extra(false, false, null, false, true, true, false, null);
|
||||
public static @NonNull Extra forRemoteDelete(@NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, false, true, true, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forMessageRequest() {
|
||||
return new Extra(false, false, null, false, false, false, false, null);
|
||||
public static @NonNull Extra forMessageRequest(@NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, false, false, false, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forGroupMessageRequest(RecipientId recipientId) {
|
||||
return new Extra(false, false, null, false, false, false, false, recipientId.serialize());
|
||||
public static @NonNull Extra forGroupMessageRequest(@NonNull RecipientId recipientId, @NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, false, false, false, false, recipientId.serialize(), individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forGroupV2invite(RecipientId recipientId) {
|
||||
return new Extra(false, false, null, false, false, false, true, recipientId.serialize());
|
||||
public static @NonNull Extra forGroupV2invite(@NonNull RecipientId recipientId, @NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, false, false, false, true, recipientId.serialize(), individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public static @NonNull Extra forDefault(@NonNull RecipientId individualRecipient) {
|
||||
return new Extra(false, false, null, false, false, true, false, null, individualRecipient.serialize());
|
||||
}
|
||||
|
||||
public boolean isViewOnce() {
|
||||
@@ -1669,6 +1684,10 @@ public class ThreadDatabase extends Database {
|
||||
public @Nullable String getGroupAddedBy() {
|
||||
return groupAddedBy;
|
||||
}
|
||||
|
||||
public @Nullable String getIndividualRecipientId() {
|
||||
return individualRecipientId;
|
||||
}
|
||||
}
|
||||
|
||||
enum ReadStatus {
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class LiveUpdateMessage {
|
||||
* recreates the string asynchronously when they change.
|
||||
*/
|
||||
@AnyThread
|
||||
public static LiveData<Spannable> fromMessageDescription(@NonNull Context context, @NonNull UpdateDescription updateDescription, @ColorInt int defaultTint) {
|
||||
public static LiveData<SpannableString> fromMessageDescription(@NonNull Context context, @NonNull UpdateDescription updateDescription, @ColorInt int defaultTint) {
|
||||
if (updateDescription.isStringStatic()) {
|
||||
return LiveDataUtil.just(toSpannable(context, updateDescription, updateDescription.getStaticString(), defaultTint));
|
||||
}
|
||||
@@ -49,13 +49,13 @@ public final class LiveUpdateMessage {
|
||||
/**
|
||||
* Observes a single recipient and recreates the string asynchronously when they change.
|
||||
*/
|
||||
public static LiveData<Spannable> recipientToStringAsync(@NonNull RecipientId recipientId,
|
||||
@NonNull Function<Recipient, Spannable> createStringInBackground)
|
||||
public static LiveData<SpannableString> recipientToStringAsync(@NonNull RecipientId recipientId,
|
||||
@NonNull Function<Recipient, SpannableString> createStringInBackground)
|
||||
{
|
||||
return LiveDataUtil.mapAsync(Recipient.live(recipientId).getLiveData(), createStringInBackground);
|
||||
return LiveDataUtil.mapAsync(Recipient.live(recipientId).getLiveDataResolved(), createStringInBackground);
|
||||
}
|
||||
|
||||
private static @NonNull Spannable toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint) {
|
||||
private static @NonNull SpannableString toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint) {
|
||||
boolean isDarkTheme = ThemeUtil.isDarkTheme(context);
|
||||
int drawableResource = updateDescription.getIconResource();
|
||||
int tint = isDarkTheme ? updateDescription.getDarkTint() : updateDescription.getLightTint();
|
||||
|
||||
@@ -40,6 +40,7 @@ public final class ThreadRecord {
|
||||
private final long threadId;
|
||||
private final String body;
|
||||
private final Recipient recipient;
|
||||
private final Recipient sender;
|
||||
private final long type;
|
||||
private final long date;
|
||||
private final long deliveryStatus;
|
||||
@@ -61,6 +62,7 @@ public final class ThreadRecord {
|
||||
this.threadId = builder.threadId;
|
||||
this.body = builder.body;
|
||||
this.recipient = builder.recipient;
|
||||
this.sender = builder.sender;
|
||||
this.date = builder.date;
|
||||
this.type = builder.type;
|
||||
this.deliveryStatus = builder.deliveryStatus;
|
||||
@@ -184,6 +186,29 @@ public final class ThreadRecord {
|
||||
else return null;
|
||||
}
|
||||
|
||||
public @NonNull RecipientId getIndividualRecipientId() {
|
||||
if (extra != null && extra.getIndividualRecipientId() != null) {
|
||||
return RecipientId.from(extra.getIndividualRecipientId());
|
||||
} else {
|
||||
if (getRecipient().isGroup()) {
|
||||
return RecipientId.UNKNOWN;
|
||||
} else {
|
||||
return getRecipient().getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NonNull RecipientId getGroupMessageSender() {
|
||||
RecipientId threadRecipientId = getRecipient().getId();
|
||||
RecipientId individualRecipientId = getIndividualRecipientId();
|
||||
|
||||
if (threadRecipientId.equals(individualRecipientId)) {
|
||||
return Recipient.self().getId();
|
||||
} else {
|
||||
return individualRecipientId;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGv2Invite() {
|
||||
return extra != null && extra.isGv2Invite();
|
||||
}
|
||||
@@ -249,7 +274,8 @@ public final class ThreadRecord {
|
||||
public static class Builder {
|
||||
private long threadId;
|
||||
private String body;
|
||||
private Recipient recipient;
|
||||
private Recipient recipient = Recipient.UNKNOWN;
|
||||
private Recipient sender = Recipient.UNKNOWN;
|
||||
private long type;
|
||||
private long date;
|
||||
private long deliveryStatus;
|
||||
@@ -281,6 +307,11 @@ public final class ThreadRecord {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSender(@NonNull Recipient sender) {
|
||||
this.sender = sender;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setType(long type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user