New group management screen.

This commit is contained in:
Alan Evans
2020-04-27 16:27:31 -03:00
committed by Greyson Parrelli
parent e0502c24e1
commit 723639d928
30 changed files with 1621 additions and 175 deletions

View File

@@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.IdentityDatabase;
import org.thoughtcrime.securesms.groups.GroupId;
import org.thoughtcrime.securesms.recipients.Recipient;
@@ -16,44 +15,29 @@ import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
final class RecipientDialogRepository {
@NonNull private final GroupDatabase groupDatabase;
@NonNull private final Context context;
@NonNull private final RecipientId recipientId;
@Nullable private final GroupId groupId;
@NonNull private final Context context;
@NonNull private final RecipientId recipientId;
@Nullable private final GroupId groupId;
RecipientDialogRepository(@NonNull Context context,
@NonNull RecipientId recipientId,
@Nullable GroupId groupId)
{
this.context = context;
this.groupDatabase = DatabaseFactory.getGroupDatabase(context);
this.recipientId = recipientId;
this.groupId = groupId;
this.context = context;
this.recipientId = recipientId;
this.groupId = groupId;
}
@NonNull RecipientId getRecipientId() {
@NonNull
RecipientId getRecipientId() {
return recipientId;
}
@Nullable GroupId getGroupId() {
@Nullable
GroupId getGroupId() {
return groupId;
}
void isAdminOfGroup(@NonNull RecipientId recipientId, @NonNull AdminCallback callback) {
SimpleTask.run(SignalExecutors.BOUNDED,
() -> {
if (groupId != null) {
Recipient recipient = Recipient.resolved(recipientId);
return groupDatabase.getGroup(groupId)
.transform(g -> g.isAdmin(recipient))
.or(false);
} else {
return false;
}
},
callback::isAdmin);
}
void getIdentity(@NonNull IdentityCallback callback) {
SimpleTask.run(SignalExecutors.BOUNDED,
() -> DatabaseFactory.getIdentityDatabase(context)
@@ -62,16 +46,12 @@ final class RecipientDialogRepository {
callback::remoteIdentity);
}
public void getRecipient(@NonNull RecipientCallback recipientCallback) {
void getRecipient(@NonNull RecipientCallback recipientCallback) {
SimpleTask.run(SignalExecutors.BOUNDED,
() -> Recipient.resolved(recipientId),
recipientCallback::onRecipient);
}
interface AdminCallback {
void isAdmin(boolean admin);
}
interface IdentityCallback {
void remoteIdentity(@Nullable IdentityDatabase.IdentityRecord identityRecord);
}

View File

@@ -8,7 +8,6 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
@@ -17,12 +16,12 @@ import org.thoughtcrime.securesms.RecipientPreferenceActivity;
import org.thoughtcrime.securesms.VerifyIdentityActivity;
import org.thoughtcrime.securesms.database.IdentityDatabase;
import org.thoughtcrime.securesms.groups.GroupId;
import org.thoughtcrime.securesms.groups.LiveGroup;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.recipients.RecipientUtil;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
import org.thoughtcrime.securesms.util.livedata.LiveDataPair;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
final class RecipientDialogViewModel extends ViewModel {
@@ -39,24 +38,23 @@ final class RecipientDialogViewModel extends ViewModel {
this.recipientDialogRepository = recipientDialogRepository;
this.identity = new MutableLiveData<>();
MutableLiveData<Boolean> localIsAdmin = new DefaultValueLiveData<>(false);
MutableLiveData<Boolean> recipientIsAdmin = new DefaultValueLiveData<>(false);
boolean recipientIsSelf = recipientDialogRepository.getRecipientId().equals(Recipient.self().getId());
if (recipientDialogRepository.getGroupId() != null && recipientDialogRepository.getGroupId().isV2()) {
recipientDialogRepository.isAdminOfGroup(Recipient.self().getId(), localIsAdmin::setValue);
recipientDialogRepository.isAdminOfGroup(recipientDialogRepository.getRecipientId(), recipientIsAdmin::setValue);
if (recipientDialogRepository.getGroupId() != null && recipientDialogRepository.getGroupId().isV2() && !recipientIsSelf) {
LiveGroup source = new LiveGroup(recipientDialogRepository.getGroupId());
LiveData<Boolean> localIsAdmin = source.isSelfAdmin();
LiveData<Boolean> recipientIsAdmin = source.getRecipientIsAdmin(recipientDialogRepository.getRecipientId());
adminActionStatus = LiveDataUtil.combineLatest(localIsAdmin, recipientIsAdmin,
(localAdmin, recipientAdmin) ->
new AdminActionStatus(localAdmin,
localAdmin && !recipientAdmin,
localAdmin && recipientAdmin));
} else {
adminActionStatus = new MutableLiveData<>(new AdminActionStatus(false, false, false));
}
adminActionStatus = Transformations.map(new LiveDataPair<>(localIsAdmin, recipientIsAdmin, false, false),
pair -> {
boolean localAdmin = pair.first();
boolean recipientAdmin = pair.second();
return new AdminActionStatus(localAdmin,
localAdmin && !recipientAdmin,
localAdmin && recipientAdmin);
});
recipient = Recipient.live(recipientDialogRepository.getRecipientId()).getLiveData();
recipientDialogRepository.getIdentity(identity::setValue);