use of org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult in project Signal-Android by WhisperSystems.
the class GroupManagerV1 method createGroup.
@NonNull
static GroupActionResult createGroup(@NonNull Context context, @NonNull Set<RecipientId> memberIds, @Nullable byte[] avatarBytes, @Nullable String name, boolean mms) {
final GroupDatabase groupDatabase = SignalDatabase.groups();
final SecureRandom secureRandom = new SecureRandom();
final GroupId groupId = mms ? GroupId.createMms(secureRandom) : GroupId.createV1(secureRandom);
final RecipientId groupRecipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupId);
final Recipient groupRecipient = Recipient.resolved(groupRecipientId);
memberIds.add(Recipient.self().getId());
if (groupId.isV1()) {
GroupId.V1 groupIdV1 = groupId.requireV1();
groupDatabase.create(groupIdV1, name, memberIds, null, null);
try {
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
} catch (IOException e) {
Log.w(TAG, "Failed to save avatar!", e);
}
groupDatabase.onAvatarUpdated(groupIdV1, avatarBytes != null);
SignalDatabase.recipients().setProfileSharing(groupRecipient.getId(), true);
return sendGroupUpdate(context, groupIdV1, memberIds, name, avatarBytes, memberIds.size() - 1);
} else {
groupDatabase.create(groupId.requireMms(), name, memberIds);
try {
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
} catch (IOException e) {
Log.w(TAG, "Failed to save avatar!", e);
}
groupDatabase.onAvatarUpdated(groupId, avatarBytes != null);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient, ThreadDatabase.DistributionTypes.CONVERSATION);
return new GroupActionResult(groupRecipient, threadId, memberIds.size() - 1, Collections.emptyList());
}
}
use of org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult in project Signal-Android by WhisperSystems.
the class GroupManagerV1 method sendGroupUpdate.
private static GroupActionResult sendGroupUpdate(@NonNull Context context, @NonNull GroupId.V1 groupId, @NonNull Set<RecipientId> members, @Nullable String groupName, @Nullable byte[] avatar, int newMemberCount) {
Attachment avatarAttachment = null;
RecipientId groupRecipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupId);
Recipient groupRecipient = Recipient.resolved(groupRecipientId);
List<GroupContext.Member> uuidMembers = new ArrayList<>(members.size());
List<String> e164Members = new ArrayList<>(members.size());
for (RecipientId member : members) {
Recipient recipient = Recipient.resolved(member);
if (recipient.hasE164()) {
e164Members.add(recipient.requireE164());
uuidMembers.add(GroupV1MessageProcessor.createMember(recipient.requireE164()));
}
}
GroupContext.Builder groupContextBuilder = GroupContext.newBuilder().setId(ByteString.copyFrom(groupId.getDecodedId())).setType(GroupContext.Type.UPDATE).addAllMembersE164(e164Members).addAllMembers(uuidMembers);
if (groupName != null)
groupContextBuilder.setName(groupName);
GroupContext groupContext = groupContextBuilder.build();
if (avatar != null) {
Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory();
avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, false, false, null, null, null, null, null);
}
OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0, false, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
return new GroupActionResult(groupRecipient, threadId, newMemberCount, Collections.emptyList());
}
use of org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult in project Signal-Android by WhisperSystems.
the class GroupManagerV1 method updateGroup.
static GroupActionResult updateGroup(@NonNull Context context, @NonNull GroupId groupId, @NonNull Set<RecipientId> memberAddresses, @Nullable byte[] avatarBytes, @Nullable String name, int newMemberCount) {
final GroupDatabase groupDatabase = SignalDatabase.groups();
final RecipientId groupRecipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupId);
memberAddresses.add(Recipient.self().getId());
groupDatabase.updateMembers(groupId, new LinkedList<>(memberAddresses));
if (groupId.isPush()) {
GroupId.V1 groupIdV1 = groupId.requireV1();
groupDatabase.updateTitle(groupIdV1, name);
groupDatabase.onAvatarUpdated(groupIdV1, avatarBytes != null);
try {
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
} catch (IOException e) {
Log.w(TAG, "Failed to save avatar!", e);
}
return sendGroupUpdate(context, groupIdV1, memberAddresses, name, avatarBytes, newMemberCount);
} else {
Recipient groupRecipient = Recipient.resolved(groupRecipientId);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
return new GroupActionResult(groupRecipient, threadId, newMemberCount, Collections.emptyList());
}
}
use of org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult in project Signal-Android by WhisperSystems.
the class GroupManagerV1 method updateGroup.
static GroupActionResult updateGroup(@NonNull Context context, @NonNull GroupId.Mms groupId, @Nullable byte[] avatarBytes, @Nullable String name) {
GroupDatabase groupDatabase = SignalDatabase.groups();
RecipientId groupRecipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupId);
Recipient groupRecipient = Recipient.resolved(groupRecipientId);
long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
groupDatabase.updateTitle(groupId, name);
groupDatabase.onAvatarUpdated(groupId, avatarBytes != null);
try {
AvatarHelper.setAvatar(context, groupRecipientId, avatarBytes != null ? new ByteArrayInputStream(avatarBytes) : null);
} catch (IOException e) {
Log.w(TAG, "Failed to save avatar!", e);
}
return new GroupActionResult(groupRecipient, threadId, 0, Collections.emptyList());
}
Aggregations