456 lines
18 KiB
Java
456 lines
18 KiB
Java
package com.discord.widgets.channels.settings;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.StringRes;
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StorePermissions;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.threads.ThreadUtils;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.PublishSubject;
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public final class WidgetThreadSettingsViewModel extends AppViewModel<ViewState> {
|
|
private final long channelId;
|
|
private final PublishSubject<Event> eventSubject = PublishSubject.k0();
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.settings.WidgetThreadSettingsViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1 extends o implements Function0<StoreState> {
|
|
public final /* synthetic */ StoreChannels $channelStore;
|
|
public final /* synthetic */ StorePermissions $permissionStore;
|
|
public final /* synthetic */ StoreUser $userStore;
|
|
public final /* synthetic */ WidgetThreadSettingsViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel, StoreChannels storeChannels, StoreUser storeUser, StorePermissions storePermissions) {
|
|
super(0);
|
|
this.this$0 = widgetThreadSettingsViewModel;
|
|
this.$channelStore = storeChannels;
|
|
this.$userStore = storeUser;
|
|
this.$permissionStore = storePermissions;
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public final StoreState mo1invoke() {
|
|
Channel channel = this.$channelStore.getChannel(this.this$0.getChannelId());
|
|
return new StoreState(channel, channel != null ? ThreadUtils.INSTANCE.canManageThread(this.$userStore.getMe(), channel, (Long) a.o0(channel, this.$permissionStore.getPermissionsByChannel())) : false);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.settings.WidgetThreadSettingsViewModel$2 reason: invalid class name */
|
|
public static final class AnonymousClass2 extends o implements Function1<StoreState, Unit> {
|
|
public final /* synthetic */ WidgetThreadSettingsViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass2(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel) {
|
|
super(1);
|
|
this.this$0 = widgetThreadSettingsViewModel;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
|
|
invoke(storeState);
|
|
return Unit.a;
|
|
}
|
|
|
|
public final void invoke(StoreState storeState) {
|
|
WidgetThreadSettingsViewModel widgetThreadSettingsViewModel = this.this$0;
|
|
m.checkNotNullExpressionValue(storeState, "storeState");
|
|
WidgetThreadSettingsViewModel.access$handleStoreState(widgetThreadSettingsViewModel, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class ShowToast extends Event {
|
|
private final int messageStringRes;
|
|
|
|
public ShowToast(@StringRes int i) {
|
|
super(null);
|
|
this.messageStringRes = i;
|
|
}
|
|
|
|
public static /* synthetic */ ShowToast copy$default(ShowToast showToast, int i, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = showToast.messageStringRes;
|
|
}
|
|
return showToast.copy(i);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public final ShowToast copy(@StringRes int i) {
|
|
return new ShowToast(i);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof ShowToast) && this.messageStringRes == ((ShowToast) obj).messageStringRes;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final int getMessageStringRes() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.w(a.K("ShowToast(messageStringRes="), this.messageStringRes, ")");
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class StoreState {
|
|
private final boolean canManageThread;
|
|
private final Channel channel;
|
|
|
|
public StoreState(Channel channel, boolean z2) {
|
|
this.channel = channel;
|
|
this.canManageThread = z2;
|
|
}
|
|
|
|
public static /* synthetic */ StoreState copy$default(StoreState storeState, Channel channel, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
channel = storeState.channel;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
z2 = storeState.canManageThread;
|
|
}
|
|
return storeState.copy(channel, z2);
|
|
}
|
|
|
|
public final Channel component1() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final boolean component2() {
|
|
return this.canManageThread;
|
|
}
|
|
|
|
public final StoreState copy(Channel channel, boolean z2) {
|
|
return new StoreState(channel, z2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof StoreState)) {
|
|
return false;
|
|
}
|
|
StoreState storeState = (StoreState) obj;
|
|
return m.areEqual(this.channel, storeState.channel) && this.canManageThread == storeState.canManageThread;
|
|
}
|
|
|
|
public final boolean getCanManageThread() {
|
|
return this.canManageThread;
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Channel channel = this.channel;
|
|
int hashCode = (channel != null ? channel.hashCode() : 0) * 31;
|
|
boolean z2 = this.canManageThread;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i = z2 ? 1 : 0;
|
|
int i2 = z2 ? 1 : 0;
|
|
int i3 = z2 ? 1 : 0;
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("StoreState(channel=");
|
|
K.append(this.channel);
|
|
K.append(", canManageThread=");
|
|
return a.F(K, this.canManageThread, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class Invalid extends ViewState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class Valid extends ViewState {
|
|
private final Channel channel;
|
|
private final String channelNameDraft;
|
|
private final boolean hasUnsavedChanges;
|
|
private final boolean showDeleteOption;
|
|
private final int slowModeCooldownDraft;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(Channel channel, String str, int i, boolean z2, boolean z3) {
|
|
super(null);
|
|
m.checkNotNullParameter(channel, "channel");
|
|
this.channel = channel;
|
|
this.channelNameDraft = str;
|
|
this.slowModeCooldownDraft = i;
|
|
this.hasUnsavedChanges = z2;
|
|
this.showDeleteOption = z3;
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, Channel channel, String str, int i, boolean z2, boolean z3, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
channel = valid.channel;
|
|
}
|
|
if ((i2 & 2) != 0) {
|
|
str = valid.channelNameDraft;
|
|
}
|
|
if ((i2 & 4) != 0) {
|
|
i = valid.slowModeCooldownDraft;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
z2 = valid.hasUnsavedChanges;
|
|
}
|
|
if ((i2 & 16) != 0) {
|
|
z3 = valid.showDeleteOption;
|
|
}
|
|
return valid.copy(channel, str, i, z2, z3);
|
|
}
|
|
|
|
public final Channel component1() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final String component2() {
|
|
return this.channelNameDraft;
|
|
}
|
|
|
|
public final int component3() {
|
|
return this.slowModeCooldownDraft;
|
|
}
|
|
|
|
public final boolean component4() {
|
|
return this.hasUnsavedChanges;
|
|
}
|
|
|
|
public final boolean component5() {
|
|
return this.showDeleteOption;
|
|
}
|
|
|
|
public final Valid copy(Channel channel, String str, int i, boolean z2, boolean z3) {
|
|
m.checkNotNullParameter(channel, "channel");
|
|
return new Valid(channel, str, i, z2, z3);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Valid)) {
|
|
return false;
|
|
}
|
|
Valid valid = (Valid) obj;
|
|
return m.areEqual(this.channel, valid.channel) && m.areEqual(this.channelNameDraft, valid.channelNameDraft) && this.slowModeCooldownDraft == valid.slowModeCooldownDraft && this.hasUnsavedChanges == valid.hasUnsavedChanges && this.showDeleteOption == valid.showDeleteOption;
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final String getChannelNameDraft() {
|
|
return this.channelNameDraft;
|
|
}
|
|
|
|
public final boolean getHasUnsavedChanges() {
|
|
return this.hasUnsavedChanges;
|
|
}
|
|
|
|
public final boolean getShowDeleteOption() {
|
|
return this.showDeleteOption;
|
|
}
|
|
|
|
public final int getSlowModeCooldownDraft() {
|
|
return this.slowModeCooldownDraft;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Channel channel = this.channel;
|
|
int i = 0;
|
|
int hashCode = (channel != null ? channel.hashCode() : 0) * 31;
|
|
String str = this.channelNameDraft;
|
|
if (str != null) {
|
|
i = str.hashCode();
|
|
}
|
|
int i2 = (((hashCode + i) * 31) + this.slowModeCooldownDraft) * 31;
|
|
boolean z2 = this.hasUnsavedChanges;
|
|
int i3 = 1;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i4 = z2 ? 1 : 0;
|
|
int i5 = z2 ? 1 : 0;
|
|
int i6 = z2 ? 1 : 0;
|
|
int i7 = (i2 + i4) * 31;
|
|
boolean z3 = this.showDeleteOption;
|
|
if (!z3) {
|
|
i3 = z3 ? 1 : 0;
|
|
}
|
|
return i7 + i3;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("Valid(channel=");
|
|
K.append(this.channel);
|
|
K.append(", channelNameDraft=");
|
|
K.append(this.channelNameDraft);
|
|
K.append(", slowModeCooldownDraft=");
|
|
K.append(this.slowModeCooldownDraft);
|
|
K.append(", hasUnsavedChanges=");
|
|
K.append(this.hasUnsavedChanges);
|
|
K.append(", showDeleteOption=");
|
|
return a.F(K, this.showDeleteOption, ")");
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public WidgetThreadSettingsViewModel(long j) {
|
|
super(null, 1, null);
|
|
this.channelId = j;
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
StoreChannels channels = companion.getChannels();
|
|
StorePermissions permissions = companion.getPermissions();
|
|
StoreUser users = companion.getUsers();
|
|
Observable r = ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{channels, permissions, users}, false, null, null, new AnonymousClass1(this, channels, users, permissions), 14, null).r();
|
|
m.checkNotNullExpressionValue(r, "ObservationDeckProvider.… .distinctUntilChanged()");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(r, this, null, 2, null), WidgetThreadSettingsViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass2(this), 62, (Object) null);
|
|
}
|
|
|
|
public static final /* synthetic */ PublishSubject access$getEventSubject$p(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel) {
|
|
return widgetThreadSettingsViewModel.eventSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel, StoreState storeState) {
|
|
widgetThreadSettingsViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
@MainThread
|
|
private final void handleStoreState(StoreState storeState) {
|
|
Channel channel = storeState.getChannel();
|
|
String str = null;
|
|
if ((channel != null ? channel.m() : null) == null || !AnimatableValueParser.A1(channel)) {
|
|
updateViewState(ViewState.Invalid.INSTANCE);
|
|
return;
|
|
}
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
str = valid.getChannelNameDraft();
|
|
}
|
|
if (str != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, channel, null, 0, false, false, 30, null));
|
|
} else {
|
|
updateViewState(new ViewState.Valid(channel, channel.m(), channel.u(), false, storeState.getCanManageThread()));
|
|
}
|
|
}
|
|
|
|
public final long getChannelId() {
|
|
return this.channelId;
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
@MainThread
|
|
public final void onChannelNameInputChanged(String str) {
|
|
m.checkNotNullParameter(str, "value");
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, null, str, 0, true, false, 21, null));
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
public final void onSlowModeInputChanged(int i) {
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, null, null, i, true, false, 19, null));
|
|
}
|
|
}
|
|
|
|
public final void onThreadDeleted(long j) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().deleteChannel(j), false, 1, null), this, null, 2, null), WidgetThreadSettingsViewModel.class, (Context) null, (Function1) null, new WidgetThreadSettingsViewModel$onThreadDeleted$2(this), (Function0) null, (Function0) null, new WidgetThreadSettingsViewModel$onThreadDeleted$1(this), 54, (Object) null);
|
|
}
|
|
|
|
public final void saveThread() {
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(RestAPI.editTextChannel$default(RestAPI.Companion.getApi(), this.channelId, m.areEqual(valid.getChannel().m(), valid.getChannelNameDraft()) ^ true ? valid.getChannelNameDraft() : null, null, null, null, valid.getChannel().u() != valid.getSlowModeCooldownDraft() ? Integer.valueOf(valid.getSlowModeCooldownDraft()) : null, null, 92, null), this, null, 2, null), WidgetThreadSettingsViewModel.class, (Context) null, (Function1) null, new WidgetThreadSettingsViewModel$saveThread$2(this), (Function0) null, (Function0) null, new WidgetThreadSettingsViewModel$saveThread$1(this), 54, (Object) null);
|
|
}
|
|
}
|
|
}
|