Add support for Group V2 description field.

This commit is contained in:
Cody Henthorne
2021-05-07 13:43:31 -04:00
committed by Greyson Parrelli
parent b3aec58e69
commit 8c9df8d3be
56 changed files with 892 additions and 117 deletions

View File

@@ -920,6 +920,14 @@ public final class GroupDatabase extends Database {
return title;
}
public @NonNull String getDescription() {
if (v2GroupProperties == null) {
return "";
} else {
return v2GroupProperties.getDecryptedGroup().getDescription();
}
}
public @NonNull List<RecipientId> getMembers() {
return members;
}

View File

@@ -98,6 +98,7 @@ final class GroupsV2UpdateMessageProducer {
describeUnknownEditorRevokedInvitations(change, updates);
describeUnknownEditorPromotePending(change, updates);
describeUnknownEditorNewTitle(change, updates);
describeUnknownEditorNewDescription(change, updates);
describeUnknownEditorNewAvatar(change, updates);
describeUnknownEditorNewTimer(change, updates);
describeUnknownEditorNewAttributeAccess(change, updates);
@@ -121,6 +122,7 @@ final class GroupsV2UpdateMessageProducer {
describeRevokedInvitations(change, updates);
describePromotePending(change, updates);
describeNewTitle(change, updates);
describeNewDescription(change, updates);
describeNewAvatar(change, updates);
describeNewTimer(change, updates);
describeNewAttributeAccess(change, updates);
@@ -431,12 +433,30 @@ final class GroupsV2UpdateMessageProducer {
}
}
private void describeNewDescription(@NonNull DecryptedGroupChange change, @NonNull List<UpdateDescription> updates) {
boolean editorIsYou = change.getEditor().equals(selfUuidBytes);
if (change.hasNewDescription()) {
if (editorIsYou) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_you_changed_the_group_description), R.drawable.ic_update_group_name_16));
} else {
updates.add(updateDescription(change.getEditor(), editor -> context.getString(R.string.MessageRecord_s_changed_the_group_description, editor), R.drawable.ic_update_group_name_16));
}
}
}
private void describeUnknownEditorNewTitle(@NonNull DecryptedGroupChange change, @NonNull List<UpdateDescription> updates) {
if (change.hasNewTitle()) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_the_group_name_has_changed_to_s, StringUtil.isolateBidi(change.getNewTitle().getValue())), R.drawable.ic_update_group_name_16));
}
}
private void describeUnknownEditorNewDescription(@NonNull DecryptedGroupChange change, @NonNull List<UpdateDescription> updates) {
if (change.hasNewDescription()) {
updates.add(updateDescription(context.getString(R.string.MessageRecord_the_group_description_has_changed), R.drawable.ic_update_group_name_16));
}
}
private void describeNewAvatar(@NonNull DecryptedGroupChange change, @NonNull List<UpdateDescription> updates) {
boolean editorIsYou = change.getEditor().equals(selfUuidBytes);

View File

@@ -360,6 +360,22 @@ public abstract class MessageRecord extends DisplayRecord {
return UpdateDescription.mentioning(joinedMembers, stringFactory, R.drawable.ic_video_16);
}
public boolean isGroupV2DescriptionUpdate() {
DecryptedGroupV2Context decryptedGroupV2Context = getDecryptedGroupV2Context();
if (decryptedGroupV2Context != null) {
return decryptedGroupV2Context.hasChange() && getDecryptedGroupV2Context().getChange().hasNewDescription();
}
return false;
}
public @NonNull String getGroupV2DescriptionUpdate() {
DecryptedGroupV2Context decryptedGroupV2Context = getDecryptedGroupV2Context();
if (decryptedGroupV2Context != null) {
return decryptedGroupV2Context.getChange().hasNewDescription() ? decryptedGroupV2Context.getChange().getNewDescription().getValue() : "";
}
return "";
}
/**
* Describes a UUID by it's corresponding recipient's {@link Recipient#getDisplayName(Context)}.
*/