2015-11-05 10:41:43 -08:00
|
|
|
package org.thoughtcrime.securesms.groups;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Bitmap;
|
2019-07-22 11:33:45 -04:00
|
|
|
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2015-11-05 10:41:43 -08:00
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2015-11-05 10:41:43 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
2015-11-05 10:41:43 -08:00
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-07-22 11:33:45 -04:00
|
|
|
public final class GroupManager {
|
2017-07-26 09:59:15 -07:00
|
|
|
|
2015-11-05 10:41:43 -08:00
|
|
|
public static @NonNull GroupActionResult createGroup(@NonNull Context context,
|
|
|
|
@NonNull Set<Recipient> members,
|
|
|
|
@Nullable Bitmap avatar,
|
2017-08-01 08:56:00 -07:00
|
|
|
@Nullable String name,
|
|
|
|
boolean mms)
|
2015-11-05 10:41:43 -08:00
|
|
|
{
|
2019-07-22 11:33:45 -04:00
|
|
|
Set<Address> addresses = getMemberAddresses(members);
|
2015-11-05 10:41:43 -08:00
|
|
|
|
2019-07-22 11:33:45 -04:00
|
|
|
return V1GroupManager.createGroup(context, addresses, avatar, name, mms);
|
2015-11-05 10:41:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static GroupActionResult updateGroup(@NonNull Context context,
|
2017-08-01 08:56:00 -07:00
|
|
|
@NonNull String groupId,
|
2015-11-05 10:41:43 -08:00
|
|
|
@NonNull Set<Recipient> members,
|
|
|
|
@Nullable Bitmap avatar,
|
|
|
|
@Nullable String name)
|
|
|
|
throws InvalidNumberException
|
|
|
|
{
|
2019-07-22 11:33:45 -04:00
|
|
|
Set<Address> addresses = getMemberAddresses(members);
|
2017-08-01 08:56:00 -07:00
|
|
|
|
2019-07-22 11:33:45 -04:00
|
|
|
return V1GroupManager.updateGroup(context, groupId, addresses, avatar, name);
|
2017-08-01 08:56:00 -07:00
|
|
|
}
|
2015-11-05 10:41:43 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private static Set<Address> getMemberAddresses(Collection<Recipient> recipients) {
|
|
|
|
final Set<Address> results = new HashSet<>();
|
|
|
|
for (Recipient recipient : recipients) {
|
|
|
|
results.add(recipient.getAddress());
|
2015-11-05 10:41:43 -08:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
return results;
|
2015-11-05 10:41:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class GroupActionResult {
|
2019-07-22 11:33:45 -04:00
|
|
|
private final Recipient groupRecipient;
|
|
|
|
private final long threadId;
|
2015-11-05 10:41:43 -08:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public GroupActionResult(Recipient groupRecipient, long threadId) {
|
2015-11-05 10:41:43 -08:00
|
|
|
this.groupRecipient = groupRecipient;
|
|
|
|
this.threadId = threadId;
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public Recipient getGroupRecipient() {
|
2015-11-05 10:41:43 -08:00
|
|
|
return groupRecipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getThreadId() {
|
|
|
|
return threadId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|