172 lines
6.9 KiB
Java
172 lines
6.9 KiB
Java
|
package com.discord.widgets.channels.permissions;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import c.d.b.a.a;
|
||
|
import com.discord.api.channel.Channel;
|
||
|
import com.discord.api.permission.PermissionOverwrite;
|
||
|
import com.discord.app.AppViewModel;
|
||
|
import com.discord.restapi.RestAPIParams;
|
||
|
import com.discord.stores.StoreChannels;
|
||
|
import com.discord.stores.StoreStream;
|
||
|
import com.discord.utilities.rest.RestAPI;
|
||
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
||
|
import com.discord.widgets.channels.permissions.PermissionOwner;
|
||
|
import d0.t.n;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import kotlin.NoWhenBranchMatchedException;
|
||
|
import kotlin.jvm.functions.Function0;
|
||
|
import kotlin.jvm.functions.Function1;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
/* compiled from: ConfirmRemovePermissionDialogViewModel.kt */
|
||
|
public final class ConfirmRemovePermissionDialogViewModel extends AppViewModel<ViewState> {
|
||
|
private final long channelId;
|
||
|
private final StoreChannels channelStore;
|
||
|
private final PermissionOwner permissionOwner;
|
||
|
|
||
|
/* compiled from: ConfirmRemovePermissionDialogViewModel.kt */
|
||
|
public static abstract class ViewState {
|
||
|
|
||
|
/* compiled from: ConfirmRemovePermissionDialogViewModel.kt */
|
||
|
public static final class Complete extends ViewState {
|
||
|
public static final Complete INSTANCE = new Complete();
|
||
|
|
||
|
private Complete() {
|
||
|
super(null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: ConfirmRemovePermissionDialogViewModel.kt */
|
||
|
public static final class Default extends ViewState {
|
||
|
private final boolean isSubmitting;
|
||
|
|
||
|
public Default(boolean z2) {
|
||
|
super(null);
|
||
|
this.isSubmitting = z2;
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ Default copy$default(Default r0, boolean z2, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
z2 = r0.isSubmitting;
|
||
|
}
|
||
|
return r0.copy(z2);
|
||
|
}
|
||
|
|
||
|
public final boolean component1() {
|
||
|
return this.isSubmitting;
|
||
|
}
|
||
|
|
||
|
public final Default copy(boolean z2) {
|
||
|
return new Default(z2);
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (this != obj) {
|
||
|
return (obj instanceof Default) && this.isSubmitting == ((Default) obj).isSubmitting;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
boolean z2 = this.isSubmitting;
|
||
|
if (z2) {
|
||
|
return 1;
|
||
|
}
|
||
|
return z2 ? 1 : 0;
|
||
|
}
|
||
|
|
||
|
public final boolean isSubmitting() {
|
||
|
return this.isSubmitting;
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
return a.F(a.K("Default(isSubmitting="), this.isSubmitting, ")");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private ViewState() {
|
||
|
}
|
||
|
|
||
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
||
|
public ConfirmRemovePermissionDialogViewModel(PermissionOwner permissionOwner, long j, StoreChannels storeChannels) {
|
||
|
super(new ViewState.Default(false));
|
||
|
m.checkNotNullParameter(permissionOwner, "permissionOwner");
|
||
|
m.checkNotNullParameter(storeChannels, "channelStore");
|
||
|
this.permissionOwner = permissionOwner;
|
||
|
this.channelId = j;
|
||
|
this.channelStore = storeChannels;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
||
|
public /* synthetic */ ConfirmRemovePermissionDialogViewModel(PermissionOwner permissionOwner, long j, StoreChannels storeChannels, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this(permissionOwner, j, (i & 4) != 0 ? StoreStream.Companion.getChannels() : storeChannels);
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$handleSubmissionComplete(ConfirmRemovePermissionDialogViewModel confirmRemovePermissionDialogViewModel) {
|
||
|
confirmRemovePermissionDialogViewModel.handleSubmissionComplete();
|
||
|
}
|
||
|
|
||
|
private final PermissionOverwrite getNewPermissionOverwrite() {
|
||
|
List<PermissionOverwrite> list;
|
||
|
PermissionOverwrite.Type type;
|
||
|
Object obj;
|
||
|
boolean z2;
|
||
|
Channel channel = this.channelStore.getChannel(this.channelId);
|
||
|
if (channel == null || (list = channel.s()) == null) {
|
||
|
list = n.emptyList();
|
||
|
}
|
||
|
PermissionOwner permissionOwner = this.permissionOwner;
|
||
|
if (permissionOwner instanceof PermissionOwner.Role) {
|
||
|
type = PermissionOverwrite.Type.ROLE;
|
||
|
} else if (permissionOwner instanceof PermissionOwner.Member) {
|
||
|
type = PermissionOverwrite.Type.MEMBER;
|
||
|
} else {
|
||
|
throw new NoWhenBranchMatchedException();
|
||
|
}
|
||
|
Iterator<T> it = list.iterator();
|
||
|
while (true) {
|
||
|
if (!it.hasNext()) {
|
||
|
obj = null;
|
||
|
break;
|
||
|
}
|
||
|
obj = it.next();
|
||
|
PermissionOverwrite permissionOverwrite = (PermissionOverwrite) obj;
|
||
|
if (permissionOverwrite.f() == type && permissionOverwrite.e() == this.permissionOwner.getEntityId()) {
|
||
|
z2 = true;
|
||
|
continue;
|
||
|
} else {
|
||
|
z2 = false;
|
||
|
continue;
|
||
|
}
|
||
|
if (z2) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
PermissionOverwrite permissionOverwrite2 = (PermissionOverwrite) obj;
|
||
|
if (permissionOverwrite2 == null) {
|
||
|
return null;
|
||
|
}
|
||
|
PermissionOverwrite b = PermissionOverwrite.b(permissionOverwrite2, 0, null, -20971537 & permissionOverwrite2.c(), 0, 11);
|
||
|
if (b.c() == 0 && b.d() == 0) {
|
||
|
return null;
|
||
|
}
|
||
|
return b;
|
||
|
}
|
||
|
|
||
|
private final void handleSubmissionComplete() {
|
||
|
updateViewState(ViewState.Complete.INSTANCE);
|
||
|
}
|
||
|
|
||
|
public final void submit() {
|
||
|
updateViewState(new ViewState.Default(true));
|
||
|
PermissionOverwrite newPermissionOverwrite = getNewPermissionOverwrite();
|
||
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(newPermissionOverwrite != null ? RestAPI.Companion.getApi().updatePermissionOverwrites(this.channelId, newPermissionOverwrite.e(), RestAPIParams.ChannelPermissionOverwrites.Companion.fromPermissionOverwrite(newPermissionOverwrite)) : RestAPI.Companion.getApi().deletePermissionOverwrites(this.channelId, this.permissionOwner.getEntityId()), false, 1, null), this, null, 2, null), ConfirmRemovePermissionDialogViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new ConfirmRemovePermissionDialogViewModel$submit$1(this), 62, (Object) null);
|
||
|
}
|
||
|
}
|