package com.discord.widgets.announcements; import android.content.Context; import c.d.b.a.a; import com.discord.api.channel.Channel; import com.discord.app.AppComponent; import com.discord.app.AppViewModel; import com.discord.models.guild.Guild; import com.discord.restapi.RestAPIParams; import com.discord.stores.StoreChannels; import com.discord.stores.StoreGuilds; import com.discord.stores.StorePermissions; import com.discord.stores.StoreStream; import com.discord.utilities.error.Error; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import d0.z.d.m; import d0.z.d.o; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; import rx.subjects.BehaviorSubject; import rx.subjects.PublishSubject; /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public final class WidgetChannelFollowSheetViewModel extends AppViewModel implements AppComponent { private final PublishSubject eventSubject; private final BehaviorSubject selectedChannelSubject; private final BehaviorSubject selectedGuildSubject; private final long sourceChannelId; private final long sourceGuildId; private final StoreChannels storeChannels; private final StoreGuilds storeGuilds; private final StorePermissions storePermissions; /* compiled from: WidgetChannelFollowSheetViewModel.kt */ /* renamed from: com.discord.widgets.announcements.WidgetChannelFollowSheetViewModel$1 reason: invalid class name */ public static final class AnonymousClass1 extends o implements Function1 { public final /* synthetic */ WidgetChannelFollowSheetViewModel this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public AnonymousClass1(WidgetChannelFollowSheetViewModel widgetChannelFollowSheetViewModel) { super(1); this.this$0 = widgetChannelFollowSheetViewModel; } /* 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(ViewState.Loaded loaded) { invoke(loaded); return Unit.a; } public final void invoke(ViewState.Loaded loaded) { m.checkNotNullParameter(loaded, "viewState"); WidgetChannelFollowSheetViewModel.access$updateViewState(this.this$0, loaded); } } /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public static abstract class Event { /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public static final class FollowSuccess extends Event { public static final FollowSuccess INSTANCE = new FollowSuccess(); private FollowSuccess() { super(null); } } private Event() { } public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public static abstract class ViewState { /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public static final class Loaded extends ViewState { private final Set availableChannels; private final Set availableGuilds; private final Integer errorTextRes; private final Channel selectedChannel; private final Guild selectedGuild; private final Channel sourceChannel; private final Guild sourceGuild; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Loaded(Channel channel, Guild guild, Guild guild2, Channel channel2, Set set, Set set2, Integer num) { super(null); m.checkNotNullParameter(set, "availableGuilds"); m.checkNotNullParameter(set2, "availableChannels"); this.sourceChannel = channel; this.sourceGuild = guild; this.selectedGuild = guild2; this.selectedChannel = channel2; this.availableGuilds = set; this.availableChannels = set2; this.errorTextRes = num; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ Loaded(Channel channel, Guild guild, Guild guild2, Channel channel2, Set set, Set set2, Integer num, int i, DefaultConstructorMarker defaultConstructorMarker) { this(channel, guild, guild2, channel2, set, set2, (i & 64) != 0 ? null : num); } /* JADX DEBUG: Multi-variable search result rejected for r5v0, resolved type: com.discord.widgets.announcements.WidgetChannelFollowSheetViewModel$ViewState$Loaded */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Loaded copy$default(Loaded loaded, Channel channel, Guild guild, Guild guild2, Channel channel2, Set set, Set set2, Integer num, int i, Object obj) { if ((i & 1) != 0) { channel = loaded.sourceChannel; } if ((i & 2) != 0) { guild = loaded.sourceGuild; } if ((i & 4) != 0) { guild2 = loaded.selectedGuild; } if ((i & 8) != 0) { channel2 = loaded.selectedChannel; } if ((i & 16) != 0) { set = loaded.availableGuilds; } if ((i & 32) != 0) { set2 = loaded.availableChannels; } if ((i & 64) != 0) { num = loaded.errorTextRes; } return loaded.copy(channel, guild, guild2, channel2, set, set2, num); } public final Channel component1() { return this.sourceChannel; } public final Guild component2() { return this.sourceGuild; } public final Guild component3() { return this.selectedGuild; } public final Channel component4() { return this.selectedChannel; } public final Set component5() { return this.availableGuilds; } public final Set component6() { return this.availableChannels; } public final Integer component7() { return this.errorTextRes; } public final Loaded copy(Channel channel, Guild guild, Guild guild2, Channel channel2, Set set, Set set2, Integer num) { m.checkNotNullParameter(set, "availableGuilds"); m.checkNotNullParameter(set2, "availableChannels"); return new Loaded(channel, guild, guild2, channel2, set, set2, num); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Loaded)) { return false; } Loaded loaded = (Loaded) obj; return m.areEqual(this.sourceChannel, loaded.sourceChannel) && m.areEqual(this.sourceGuild, loaded.sourceGuild) && m.areEqual(this.selectedGuild, loaded.selectedGuild) && m.areEqual(this.selectedChannel, loaded.selectedChannel) && m.areEqual(this.availableGuilds, loaded.availableGuilds) && m.areEqual(this.availableChannels, loaded.availableChannels) && m.areEqual(this.errorTextRes, loaded.errorTextRes); } public final Set getAvailableChannels() { return this.availableChannels; } public final Set getAvailableGuilds() { return this.availableGuilds; } public final Integer getErrorTextRes() { return this.errorTextRes; } public final Channel getSelectedChannel() { return this.selectedChannel; } public final Guild getSelectedGuild() { return this.selectedGuild; } public final Channel getSourceChannel() { return this.sourceChannel; } public final Guild getSourceGuild() { return this.sourceGuild; } public int hashCode() { Channel channel = this.sourceChannel; int i = 0; int hashCode = (channel != null ? channel.hashCode() : 0) * 31; Guild guild = this.sourceGuild; int hashCode2 = (hashCode + (guild != null ? guild.hashCode() : 0)) * 31; Guild guild2 = this.selectedGuild; int hashCode3 = (hashCode2 + (guild2 != null ? guild2.hashCode() : 0)) * 31; Channel channel2 = this.selectedChannel; int hashCode4 = (hashCode3 + (channel2 != null ? channel2.hashCode() : 0)) * 31; Set set = this.availableGuilds; int hashCode5 = (hashCode4 + (set != null ? set.hashCode() : 0)) * 31; Set set2 = this.availableChannels; int hashCode6 = (hashCode5 + (set2 != null ? set2.hashCode() : 0)) * 31; Integer num = this.errorTextRes; if (num != null) { i = num.hashCode(); } return hashCode6 + i; } public String toString() { StringBuilder K = a.K("Loaded(sourceChannel="); K.append(this.sourceChannel); K.append(", sourceGuild="); K.append(this.sourceGuild); K.append(", selectedGuild="); K.append(this.selectedGuild); K.append(", selectedChannel="); K.append(this.selectedChannel); K.append(", availableGuilds="); K.append(this.availableGuilds); K.append(", availableChannels="); K.append(this.availableChannels); K.append(", errorTextRes="); return a.z(K, this.errorTextRes, ")"); } } /* compiled from: WidgetChannelFollowSheetViewModel.kt */ public static final class Uninitialized extends ViewState { public static final Uninitialized INSTANCE = new Uninitialized(); private Uninitialized() { super(null); } } private ViewState() { } public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public WidgetChannelFollowSheetViewModel(long j, long j2, StoreGuilds storeGuilds, StoreChannels storeChannels, StorePermissions storePermissions) { super(ViewState.Uninitialized.INSTANCE); m.checkNotNullParameter(storeGuilds, "storeGuilds"); m.checkNotNullParameter(storeChannels, "storeChannels"); m.checkNotNullParameter(storePermissions, "storePermissions"); this.sourceGuildId = j; this.sourceChannelId = j2; this.storeGuilds = storeGuilds; this.storeChannels = storeChannels; this.storePermissions = storePermissions; this.selectedGuildSubject = BehaviorSubject.l0(null); this.selectedChannelSubject = BehaviorSubject.l0(null); this.eventSubject = PublishSubject.k0(); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observeViewStateFromStores()), this, null, 2, null), WidgetChannelFollowSheetViewModel.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 */ WidgetChannelFollowSheetViewModel(long j, long j2, StoreGuilds storeGuilds, StoreChannels storeChannels, StorePermissions storePermissions, int i, DefaultConstructorMarker defaultConstructorMarker) { this(j, j2, (i & 4) != 0 ? StoreStream.Companion.getGuilds() : storeGuilds, (i & 8) != 0 ? StoreStream.Companion.getChannels() : storeChannels, (i & 16) != 0 ? StoreStream.Companion.getPermissions() : storePermissions); } public static final /* synthetic */ PublishSubject access$getEventSubject$p(WidgetChannelFollowSheetViewModel widgetChannelFollowSheetViewModel) { return widgetChannelFollowSheetViewModel.eventSubject; } public static final /* synthetic */ void access$handleChannelFollowError(WidgetChannelFollowSheetViewModel widgetChannelFollowSheetViewModel, Error error) { widgetChannelFollowSheetViewModel.handleChannelFollowError(error); } public static final /* synthetic */ void access$updateViewState(WidgetChannelFollowSheetViewModel widgetChannelFollowSheetViewModel, ViewState viewState) { widgetChannelFollowSheetViewModel.updateViewState(viewState); } private final Observable>> calculateChannelsWithPermissions() { return this.storePermissions.observePermissionsForAllChannels().r().Y(new WidgetChannelFollowSheetViewModel$calculateChannelsWithPermissions$1(this)); } private final void handleChannelFollowError(Error error) { Error.Response response = error.getResponse(); m.checkNotNullExpressionValue(response, "error.response"); int i = response.getCode() != 30007 ? 2131888536 : 2131888540; ViewState viewState = getViewState(); Objects.requireNonNull(viewState, "null cannot be cast to non-null type com.discord.widgets.announcements.WidgetChannelFollowSheetViewModel.ViewState.Loaded"); updateViewState(ViewState.Loaded.copy$default((ViewState.Loaded) viewState, null, null, null, null, null, null, Integer.valueOf(i), 63, null)); } private final Observable observeViewStateFromStores() { Observable g = Observable.g(this.storeGuilds.observeGuild(this.sourceGuildId), this.storeChannels.observeChannel(this.sourceChannelId), calculateChannelsWithPermissions(), this.selectedGuildSubject.Y(new WidgetChannelFollowSheetViewModel$observeViewStateFromStores$1(this)), this.selectedChannelSubject.Y(new WidgetChannelFollowSheetViewModel$observeViewStateFromStores$2(this)), WidgetChannelFollowSheetViewModel$observeViewStateFromStores$3.INSTANCE); m.checkNotNullExpressionValue(g, "Observable.combineLatest… )\n\n expected\n }"); return g; } public final void followChannel(long j) { ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().createChannelFollower(this.sourceChannelId, new RestAPIParams.ChannelFollowerPost(j)), false, 1, null), this, null, 2, null), WidgetChannelFollowSheetViewModel.class, (Context) null, (Function1) null, new WidgetChannelFollowSheetViewModel$followChannel$1(this), (Function0) null, (Function0) null, new WidgetChannelFollowSheetViewModel$followChannel$2(this), 54, (Object) null); } public final StoreChannels getStoreChannels() { return this.storeChannels; } public final StoreGuilds getStoreGuilds() { return this.storeGuilds; } public final StorePermissions getStorePermissions() { return this.storePermissions; } public final Observable observeEvents() { PublishSubject publishSubject = this.eventSubject; m.checkNotNullExpressionValue(publishSubject, "eventSubject"); return publishSubject; } public final void selectChannel(long j) { this.selectedChannelSubject.onNext(Long.valueOf(j)); } public final void selectGuild(long j) { this.selectedGuildSubject.onNext(Long.valueOf(j)); } }