455 lines
20 KiB
Java
455 lines
20 KiB
Java
package com.discord.widgets.channels.settings;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.domain.ModelNotificationSettings;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUserGuildSettings;
|
|
import com.discord.utilities.icon.IconUtils;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.g;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import kotlin.Lazy;
|
|
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: ChannelGroupDMSettingsViewModel.kt */
|
|
public final class ChannelGroupDMSettingsViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final long channelId;
|
|
private final PublishSubject<Event> eventSubject;
|
|
private final RestAPI restApi;
|
|
private final StoreUserGuildSettings storeUserGuildSettings;
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.settings.ChannelGroupDMSettingsViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
|
|
public final /* synthetic */ ChannelGroupDMSettingsViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(ChannelGroupDMSettingsViewModel channelGroupDMSettingsViewModel) {
|
|
super(1);
|
|
this.this$0 = channelGroupDMSettingsViewModel;
|
|
}
|
|
|
|
/* 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) {
|
|
m.checkNotNullParameter(storeState, "storeState");
|
|
ChannelGroupDMSettingsViewModel.access$handleStoreState(this.this$0, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private final Observable<StoreState> observeStoreState(long j, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings) {
|
|
Observable<R> Y = storeChannels.observeChannel(j).Y(new ChannelGroupDMSettingsViewModel$Companion$observeStoreState$1(storeUserGuildSettings));
|
|
m.checkNotNullExpressionValue(Y, "storeChannels\n … }\n }");
|
|
return Y;
|
|
}
|
|
|
|
public static /* synthetic */ Observable observeStoreState$default(Companion companion, long j, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
storeChannels = StoreStream.Companion.getChannels();
|
|
}
|
|
if ((i & 4) != 0) {
|
|
storeUserGuildSettings = StoreStream.Companion.getUserGuildSettings();
|
|
}
|
|
return companion.observeStoreState(j, storeChannels, storeUserGuildSettings);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class LeaveGroupSuccess extends Event {
|
|
public static final LeaveGroupSuccess INSTANCE = new LeaveGroupSuccess();
|
|
|
|
private LeaveGroupSuccess() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class SettingsSaved extends Event {
|
|
public static final SettingsSaved INSTANCE = new SettingsSaved();
|
|
|
|
private SettingsSaved() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static abstract class StoreState {
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class Invalid extends StoreState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class Valid extends StoreState {
|
|
private final Channel channel;
|
|
private final ModelNotificationSettings notificationSettings;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(Channel channel, ModelNotificationSettings modelNotificationSettings) {
|
|
super(null);
|
|
m.checkNotNullParameter(channel, "channel");
|
|
m.checkNotNullParameter(modelNotificationSettings, "notificationSettings");
|
|
this.channel = channel;
|
|
this.notificationSettings = modelNotificationSettings;
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, Channel channel, ModelNotificationSettings modelNotificationSettings, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
channel = valid.channel;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
modelNotificationSettings = valid.notificationSettings;
|
|
}
|
|
return valid.copy(channel, modelNotificationSettings);
|
|
}
|
|
|
|
public final Channel component1() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final ModelNotificationSettings component2() {
|
|
return this.notificationSettings;
|
|
}
|
|
|
|
public final Valid copy(Channel channel, ModelNotificationSettings modelNotificationSettings) {
|
|
m.checkNotNullParameter(channel, "channel");
|
|
m.checkNotNullParameter(modelNotificationSettings, "notificationSettings");
|
|
return new Valid(channel, modelNotificationSettings);
|
|
}
|
|
|
|
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.notificationSettings, valid.notificationSettings);
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final ModelNotificationSettings getNotificationSettings() {
|
|
return this.notificationSettings;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Channel channel = this.channel;
|
|
int i = 0;
|
|
int hashCode = (channel != null ? channel.hashCode() : 0) * 31;
|
|
ModelNotificationSettings modelNotificationSettings = this.notificationSettings;
|
|
if (modelNotificationSettings != null) {
|
|
i = modelNotificationSettings.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("Valid(channel=");
|
|
K.append(this.channel);
|
|
K.append(", notificationSettings=");
|
|
K.append(this.notificationSettings);
|
|
K.append(")");
|
|
return K.toString();
|
|
}
|
|
}
|
|
|
|
private StoreState() {
|
|
}
|
|
|
|
public /* synthetic */ StoreState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class Invalid extends ViewState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ChannelGroupDMSettingsViewModel.kt */
|
|
public static final class Valid extends ViewState {
|
|
private final ChannelSettings channelSettings;
|
|
private final String editedIconUrl;
|
|
private final boolean hasUnsavedIconChange;
|
|
private final Lazy isDefaultPhoto$delegate = g.lazy(new ChannelGroupDMSettingsViewModel$ViewState$Valid$isDefaultPhoto$2(this));
|
|
private final String originalIconUrl;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(ChannelSettings channelSettings, String str, String str2) {
|
|
super(null);
|
|
m.checkNotNullParameter(channelSettings, "channelSettings");
|
|
this.channelSettings = channelSettings;
|
|
this.originalIconUrl = str;
|
|
this.editedIconUrl = str2;
|
|
this.hasUnsavedIconChange = !m.areEqual(str, str2);
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, ChannelSettings channelSettings, String str, String str2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
channelSettings = valid.channelSettings;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
str = valid.originalIconUrl;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
str2 = valid.editedIconUrl;
|
|
}
|
|
return valid.copy(channelSettings, str, str2);
|
|
}
|
|
|
|
public final ChannelSettings component1() {
|
|
return this.channelSettings;
|
|
}
|
|
|
|
public final String component2() {
|
|
return this.originalIconUrl;
|
|
}
|
|
|
|
public final String component3() {
|
|
return this.editedIconUrl;
|
|
}
|
|
|
|
public final Valid copy(ChannelSettings channelSettings, String str, String str2) {
|
|
m.checkNotNullParameter(channelSettings, "channelSettings");
|
|
return new Valid(channelSettings, str, str2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Valid)) {
|
|
return false;
|
|
}
|
|
Valid valid = (Valid) obj;
|
|
return m.areEqual(this.channelSettings, valid.channelSettings) && m.areEqual(this.originalIconUrl, valid.originalIconUrl) && m.areEqual(this.editedIconUrl, valid.editedIconUrl);
|
|
}
|
|
|
|
public final ChannelSettings getChannelSettings() {
|
|
return this.channelSettings;
|
|
}
|
|
|
|
public final String getCurrentIconUrl() {
|
|
if (!this.hasUnsavedIconChange) {
|
|
return IconUtils.getForChannel(this.channelSettings.getChannel(), null);
|
|
}
|
|
String str = this.editedIconUrl;
|
|
return str != null ? str : IconUtils.INSTANCE.getDefaultForGroupDM(this.channelSettings.getChannel().h());
|
|
}
|
|
|
|
public final String getEditedIconUrl() {
|
|
return this.editedIconUrl;
|
|
}
|
|
|
|
public final boolean getHasUnsavedIconChange() {
|
|
return this.hasUnsavedIconChange;
|
|
}
|
|
|
|
public final String getOriginalIconUrl() {
|
|
return this.originalIconUrl;
|
|
}
|
|
|
|
public int hashCode() {
|
|
ChannelSettings channelSettings = this.channelSettings;
|
|
int i = 0;
|
|
int hashCode = (channelSettings != null ? channelSettings.hashCode() : 0) * 31;
|
|
String str = this.originalIconUrl;
|
|
int hashCode2 = (hashCode + (str != null ? str.hashCode() : 0)) * 31;
|
|
String str2 = this.editedIconUrl;
|
|
if (str2 != null) {
|
|
i = str2.hashCode();
|
|
}
|
|
return hashCode2 + i;
|
|
}
|
|
|
|
public final boolean isDefaultPhoto() {
|
|
return ((Boolean) this.isDefaultPhoto$delegate.getValue()).booleanValue();
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("Valid(channelSettings=");
|
|
K.append(this.channelSettings);
|
|
K.append(", originalIconUrl=");
|
|
K.append(this.originalIconUrl);
|
|
K.append(", editedIconUrl=");
|
|
return a.C(K, this.editedIconUrl, ")");
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public ChannelGroupDMSettingsViewModel(long j, RestAPI restAPI, StoreUserGuildSettings storeUserGuildSettings, Observable<StoreState> observable) {
|
|
super(null, 1, null);
|
|
m.checkNotNullParameter(restAPI, "restApi");
|
|
m.checkNotNullParameter(storeUserGuildSettings, "storeUserGuildSettings");
|
|
m.checkNotNullParameter(observable, "storeStateObservable");
|
|
this.channelId = j;
|
|
this.restApi = restAPI;
|
|
this.storeUserGuildSettings = storeUserGuildSettings;
|
|
this.eventSubject = PublishSubject.k0();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), ChannelGroupDMSettingsViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ ChannelGroupDMSettingsViewModel(long j, RestAPI restAPI, StoreUserGuildSettings storeUserGuildSettings, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(j, (i & 2) != 0 ? RestAPI.Companion.getApi() : restAPI, (i & 4) != 0 ? StoreStream.Companion.getUserGuildSettings() : storeUserGuildSettings, (i & 8) != 0 ? Companion.observeStoreState$default(Companion, j, null, null, 6, null) : observable);
|
|
}
|
|
|
|
public static final /* synthetic */ PublishSubject access$getEventSubject$p(ChannelGroupDMSettingsViewModel channelGroupDMSettingsViewModel) {
|
|
return channelGroupDMSettingsViewModel.eventSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(ChannelGroupDMSettingsViewModel channelGroupDMSettingsViewModel, StoreState storeState) {
|
|
channelGroupDMSettingsViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$updateViewState(ChannelGroupDMSettingsViewModel channelGroupDMSettingsViewModel, ViewState viewState) {
|
|
channelGroupDMSettingsViewModel.updateViewState(viewState);
|
|
}
|
|
|
|
@MainThread
|
|
private final void handleStoreState(StoreState storeState) {
|
|
if (m.areEqual(storeState, StoreState.Invalid.INSTANCE)) {
|
|
updateViewState(ViewState.Invalid.INSTANCE);
|
|
} else if (storeState instanceof StoreState.Valid) {
|
|
StoreState.Valid valid = (StoreState.Valid) storeState;
|
|
Channel channel = valid.getChannel();
|
|
ChannelSettings createFromNotificationSettings = ChannelSettings.Companion.createFromNotificationSettings(channel, valid.getNotificationSettings());
|
|
ViewState viewState = getViewState();
|
|
updateViewState(viewState instanceof ViewState.Valid ? ViewState.Valid.copy$default((ViewState.Valid) viewState, createFromNotificationSettings, null, null, 6, null) : new ViewState.Valid(createFromNotificationSettings, IconUtils.getForChannel(channel, null), IconUtils.getForChannel(channel, null)));
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
public final void editGroup(long j, String str) {
|
|
String str2;
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
if (valid.getHasUnsavedIconChange()) {
|
|
str2 = valid.getEditedIconUrl();
|
|
if (str2 == null) {
|
|
str2 = "";
|
|
}
|
|
} else {
|
|
str2 = valid.getOriginalIconUrl();
|
|
}
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(this.restApi.editGroupDM(j, new RestAPIParams.GroupDM(str, str2)), false, 1, null), this, null, 2, null), ChannelGroupDMSettingsViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new ChannelGroupDMSettingsViewModel$editGroup$1(this, valid), 62, (Object) null);
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
public final void leaveGroup() {
|
|
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(ObservableExtensionsKt.restSubscribeOn$default(this.restApi.deleteChannel(valid.getChannelSettings().getChannel().h()), false, 1, null), this, null, 2, null), ChannelGroupDMSettingsViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new ChannelGroupDMSettingsViewModel$leaveGroup$1(this), 62, (Object) null);
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
@MainThread
|
|
public final void onIconEdited(String str) {
|
|
m.checkNotNullParameter(str, "iconUrl");
|
|
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, str, 3, null));
|
|
}
|
|
}
|
|
|
|
@MainThread
|
|
public final void removeEditedIcon() {
|
|
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, null, 3, null));
|
|
}
|
|
}
|
|
|
|
public final void unmute(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
this.storeUserGuildSettings.setChannelMuted(context, this.channelId, false, null);
|
|
}
|
|
}
|