Add group descriptions

This commit is contained in:
AsamK 2021-05-13 20:05:46 +02:00
parent 8e8eed7b06
commit dd0effc10c
8 changed files with 108 additions and 10 deletions

View file

@ -783,17 +783,17 @@ public class Manager implements Closeable {
}
public Pair<GroupId, List<SendMessageResult>> updateGroup(
GroupId groupId, String name, List<String> members, File avatarFile
GroupId groupId, String name, String description, List<String> members, File avatarFile
) throws IOException, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
final var membersRecipientIds = members == null ? null : getSignalServiceAddresses(members);
if (membersRecipientIds != null) {
membersRecipientIds.remove(account.getSelfRecipientId());
}
return sendUpdateGroupMessage(groupId, name, membersRecipientIds, avatarFile);
return sendUpdateGroupMessage(groupId, name, description, membersRecipientIds, avatarFile);
}
private Pair<GroupId, List<SendMessageResult>> sendUpdateGroupMessage(
GroupId groupId, String name, Set<RecipientId> members, File avatarFile
GroupId groupId, String name, String description, Set<RecipientId> members, File avatarFile
) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
GroupInfo g;
SignalServiceDataMessage.Builder messageBuilder;
@ -809,6 +809,7 @@ public class Manager implements Closeable {
messageBuilder = getGroupUpdateMessageBuilder(gv1);
g = gv1;
} else {
// TODO set description as well
final var gv2 = gv2Pair.first();
final var decryptedGroup = gv2Pair.second();
@ -843,8 +844,8 @@ public class Manager implements Closeable {
groupGroupChangePair.second());
}
}
if (result == null || name != null || avatarFile != null) {
var groupGroupChangePair = groupHelper.updateGroupV2(groupInfoV2, name, avatarFile);
if (result == null || name != null || description != null || avatarFile != null) {
var groupGroupChangePair = groupHelper.updateGroupV2(groupInfoV2, name, description, avatarFile);
if (avatarFile != null) {
avatarStore.storeGroupAvatar(groupInfoV2.getGroupId(),
outputStream -> IOUtils.copyFileToStream(avatarFile, outputStream));

View file

@ -196,13 +196,17 @@ public class GroupHelper {
}
public Pair<DecryptedGroup, GroupChange> updateGroupV2(
GroupInfoV2 groupInfoV2, String name, File avatarFile
GroupInfoV2 groupInfoV2, String name, String description, File avatarFile
) throws IOException {
final var groupSecretParams = GroupSecretParams.deriveFromMasterKey(groupInfoV2.getMasterKey());
var groupOperations = groupsV2Operations.forGroup(groupSecretParams);
var change = name != null ? groupOperations.createModifyGroupTitle(name) : GroupChange.Actions.newBuilder();
if (description != null) {
change.setModifyDescription(groupOperations.createModifyGroupDescription(description));
}
if (avatarFile != null) {
final var avatarBytes = readAvatarBytes(avatarFile);
var avatarCdnKey = groupsV2Api.uploadAvatar(avatarBytes,

View file

@ -14,6 +14,10 @@ public abstract class GroupInfo {
public abstract String getTitle();
public String getDescription() {
return null;
}
public abstract GroupInviteLinkUrl getGroupInviteLink();
public abstract Set<RecipientId> getMembers();

View file

@ -59,6 +59,14 @@ public class GroupInfoV2 extends GroupInfo {
return this.group.getTitle();
}
@Override
public String getDescription() {
if (this.group == null) {
return null;
}
return this.group.getDescription();
}
@Override
public GroupInviteLinkUrl getGroupInviteLink() {
if (this.group == null || this.group.getInviteLinkPassword() == null || (