2015-11-05 19:41:43 +01:00
|
|
|
package org.thoughtcrime.securesms.groups;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Bitmap;
|
2019-07-22 17:33:45 +02:00
|
|
|
|
2019-06-05 21:47:14 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2020-03-05 16:18:44 +01:00
|
|
|
import androidx.annotation.WorkerThread;
|
2015-11-05 19:41:43 +01:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2019-08-07 20:22:51 +02:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2016-03-23 18:34:41 +01:00
|
|
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
2015-11-05 19:41:43 +01:00
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-07-22 17:33:45 +02:00
|
|
|
public final class GroupManager {
|
2017-07-26 18:59:15 +02:00
|
|
|
|
2015-11-05 19:41:43 +01:00
|
|
|
public static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
|
|
|
@NonNull Set<Recipient> members,
|
|
|
|
@Nullable Bitmap avatar,
|
2017-08-01 17:56:00 +02:00
|
|
|
@Nullable String name,
|
|
|
|
boolean mms)
|
2015-11-05 19:41:43 +01:00
|
|
|
{
|
2019-08-07 20:22:51 +02:00
|
|
|
Set<RecipientId> addresses = getMemberIds(members);
|
2015-11-05 19:41:43 +01:00
|
|
|
|
2019-07-22 17:33:45 +02:00
|
|
|
return V1GroupManager.createGroup(context, addresses, avatar, name, mms);
|
2015-11-05 19:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static GroupActionResult updateGroup(@NonNull Context context,
|
2020-03-26 15:00:17 +01:00
|
|
|
@NonNull GroupId groupId,
|
2015-11-05 19:41:43 +01:00
|
|
|
@NonNull Set<Recipient> members,
|
|
|
|
@Nullable Bitmap avatar,
|
|
|
|
@Nullable String name)
|
|
|
|
throws InvalidNumberException
|
|
|
|
{
|
2019-08-07 20:22:51 +02:00
|
|
|
Set<RecipientId> addresses = getMemberIds(members);
|
2017-08-01 17:56:00 +02:00
|
|
|
|
2019-07-22 17:33:45 +02:00
|
|
|
return V1GroupManager.updateGroup(context, groupId, addresses, avatar, name);
|
2017-08-01 17:56:00 +02:00
|
|
|
}
|
2015-11-05 19:41:43 +01:00
|
|
|
|
2019-08-07 20:22:51 +02:00
|
|
|
private static Set<RecipientId> getMemberIds(Collection<Recipient> recipients) {
|
|
|
|
final Set<RecipientId> results = new HashSet<>();
|
2017-08-01 17:56:00 +02:00
|
|
|
for (Recipient recipient : recipients) {
|
2019-08-07 20:22:51 +02:00
|
|
|
results.add(recipient.getId());
|
2015-11-05 19:41:43 +01:00
|
|
|
}
|
|
|
|
|
2017-08-01 17:56:00 +02:00
|
|
|
return results;
|
2015-11-05 19:41:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 16:18:44 +01:00
|
|
|
@WorkerThread
|
|
|
|
public static boolean leaveGroup(@NonNull Context context, @NonNull Recipient groupRecipient) {
|
2020-03-26 15:00:17 +01:00
|
|
|
GroupId groupId = groupRecipient.requireGroupId();
|
2020-03-05 16:18:44 +01:00
|
|
|
|
2020-03-27 15:28:48 +01:00
|
|
|
return V1GroupManager.leaveGroup(context, groupId.requireV1(), groupRecipient);
|
2020-03-05 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 19:41:43 +01:00
|
|
|
public static class GroupActionResult {
|
2019-07-22 17:33:45 +02:00
|
|
|
private final Recipient groupRecipient;
|
|
|
|
private final long threadId;
|
2015-11-05 19:41:43 +01:00
|
|
|
|
2017-08-01 17:56:00 +02:00
|
|
|
public GroupActionResult(Recipient groupRecipient, long threadId) {
|
2015-11-05 19:41:43 +01:00
|
|
|
this.groupRecipient = groupRecipient;
|
|
|
|
this.threadId = threadId;
|
|
|
|
}
|
|
|
|
|
2017-08-01 17:56:00 +02:00
|
|
|
public Recipient getGroupRecipient() {
|
2015-11-05 19:41:43 +01:00
|
|
|
return groupRecipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|