discord-jadx/app/src/main/java/com/discord/widgets/status/WidgetThreadStatusViewModel...

564 lines
23 KiB
Java

package com.discord.widgets.status;
import android.content.Context;
import b.a.d.d0;
import b.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.api.channel.ChannelUtils;
import com.discord.api.thread.ThreadMetadata;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreChannels;
import com.discord.stores.StoreChannelsSelected;
import com.discord.stores.StoreExperiments;
import com.discord.stores.StorePermissions;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreThreadsActiveJoined;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$1;
import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$2;
import com.discord.widgets.status.WidgetThreadStatus;
import d0.z.d.m;
import d0.z.d.o;
import java.util.Map;
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: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public final class WidgetThreadStatusViewModel extends d0<ViewState> {
public static final Companion Companion = new Companion(null);
private StoreState currentStoreState;
private final PublishSubject<WidgetThreadStatus.Event> eventSubject;
private final Observable<StoreState> storeStateObservable;
/* compiled from: WidgetThreadStatusViewModel.kt */
/* renamed from: com.discord.widgets.status.WidgetThreadStatusViewModel$1 reason: invalid class name */
/* loaded from: classes2.dex */
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
public AnonymousClass1() {
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
invoke2(storeState);
return Unit.a;
}
/* renamed from: invoke reason: avoid collision after fix types in other method */
public final void invoke2(StoreState storeState) {
m.checkNotNullParameter(storeState, "storeState");
WidgetThreadStatusViewModel.access$handleStoreState(WidgetThreadStatusViewModel.this, storeState);
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private final Observable<StoreState> observeStoreState(StoreThreadsActiveJoined storeThreadsActiveJoined, StoreChannelsSelected storeChannelsSelected, StoreChannels storeChannels, StorePermissions storePermissions, StoreExperiments storeExperiments) {
Observable<R> G = storeChannelsSelected.observeSelectedChannel().y(ObservableExtensionsKt$filterNull$1.INSTANCE).G(ObservableExtensionsKt$filterNull$2.INSTANCE);
m.checkNotNullExpressionValue(G, "filter { it != null }.map { it!! }");
Observable<StoreState> Y = G.Y(new WidgetThreadStatusViewModel$Companion$observeStoreState$1(storeThreadsActiveJoined, storePermissions, storeChannels, storeExperiments));
m.checkNotNullExpressionValue(Y, "storeChannelsSelected.ob…ntilChanged()\n }");
return Y;
}
public static /* synthetic */ Observable observeStoreState$default(Companion companion, StoreThreadsActiveJoined storeThreadsActiveJoined, StoreChannelsSelected storeChannelsSelected, StoreChannels storeChannels, StorePermissions storePermissions, StoreExperiments storeExperiments, int i, Object obj) {
if ((i & 1) != 0) {
storeThreadsActiveJoined = StoreStream.Companion.getThreadsActiveJoined();
}
if ((i & 2) != 0) {
storeChannelsSelected = StoreStream.Companion.getChannelsSelected();
}
if ((i & 4) != 0) {
storeChannels = StoreStream.Companion.getChannels();
}
if ((i & 8) != 0) {
storePermissions = StoreStream.Companion.getPermissions();
}
if ((i & 16) != 0) {
storeExperiments = StoreStream.Companion.getExperiments();
}
return companion.observeStoreState(storeThreadsActiveJoined, storeChannelsSelected, storeChannels, storePermissions, storeExperiments);
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static abstract class Status {
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class Archived extends Status {
private final boolean canArchive;
private final boolean isLocked;
public Archived(boolean z2, boolean z3) {
super(null);
this.isLocked = z2;
this.canArchive = z3;
}
public static /* synthetic */ Archived copy$default(Archived archived, boolean z2, boolean z3, int i, Object obj) {
if ((i & 1) != 0) {
z2 = archived.isLocked;
}
if ((i & 2) != 0) {
z3 = archived.canArchive;
}
return archived.copy(z2, z3);
}
public final boolean component1() {
return this.isLocked;
}
public final boolean component2() {
return this.canArchive;
}
public final Archived copy(boolean z2, boolean z3) {
return new Archived(z2, z3);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Archived)) {
return false;
}
Archived archived = (Archived) obj;
return this.isLocked == archived.isLocked && this.canArchive == archived.canArchive;
}
public final boolean getCanArchive() {
return this.canArchive;
}
public int hashCode() {
boolean z2 = this.isLocked;
int i = 1;
if (z2) {
z2 = true;
}
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = i2 * 31;
boolean z3 = this.canArchive;
if (!z3) {
i = z3 ? 1 : 0;
}
return i5 + i;
}
public final boolean isLocked() {
return this.isLocked;
}
public String toString() {
StringBuilder R = a.R("Archived(isLocked=");
R.append(this.isLocked);
R.append(", canArchive=");
return a.M(R, this.canArchive, ")");
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class Hide extends Status {
public static final Hide INSTANCE = new Hide();
private Hide() {
super(null);
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class Unjoined extends Status {
public static final Unjoined INSTANCE = new Unjoined();
private Unjoined() {
super(null);
}
}
private Status() {
}
public /* synthetic */ Status(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class StoreState {
private final Map<Long, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> activeJoinedThreads;
private final boolean canAccessRedesignedForumChannels;
private final boolean canArchive;
private final boolean isModerator;
private final Channel parentChannel;
private final Channel selectedChannel;
/* JADX WARN: Multi-variable type inference failed */
public StoreState(Map<Long, ? extends Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> map, Channel channel, Channel channel2, boolean z2, boolean z3, boolean z4) {
m.checkNotNullParameter(map, "activeJoinedThreads");
this.activeJoinedThreads = map;
this.selectedChannel = channel;
this.parentChannel = channel2;
this.canArchive = z2;
this.isModerator = z3;
this.canAccessRedesignedForumChannels = z4;
}
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ StoreState copy$default(StoreState storeState, Map map, Channel channel, Channel channel2, boolean z2, boolean z3, boolean z4, int i, Object obj) {
if ((i & 1) != 0) {
map = storeState.activeJoinedThreads;
}
if ((i & 2) != 0) {
channel = storeState.selectedChannel;
}
if ((i & 4) != 0) {
channel2 = storeState.parentChannel;
}
if ((i & 8) != 0) {
z2 = storeState.canArchive;
}
if ((i & 16) != 0) {
z3 = storeState.isModerator;
}
if ((i & 32) != 0) {
z4 = storeState.canAccessRedesignedForumChannels;
}
return storeState.copy(map, channel, channel2, z2, z3, z4);
}
public final Map<Long, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> component1() {
return this.activeJoinedThreads;
}
public final Channel component2() {
return this.selectedChannel;
}
public final Channel component3() {
return this.parentChannel;
}
public final boolean component4() {
return this.canArchive;
}
public final boolean component5() {
return this.isModerator;
}
public final boolean component6() {
return this.canAccessRedesignedForumChannels;
}
public final StoreState copy(Map<Long, ? extends Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> map, Channel channel, Channel channel2, boolean z2, boolean z3, boolean z4) {
m.checkNotNullParameter(map, "activeJoinedThreads");
return new StoreState(map, channel, channel2, z2, z3, z4);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StoreState)) {
return false;
}
StoreState storeState = (StoreState) obj;
return m.areEqual(this.activeJoinedThreads, storeState.activeJoinedThreads) && m.areEqual(this.selectedChannel, storeState.selectedChannel) && m.areEqual(this.parentChannel, storeState.parentChannel) && this.canArchive == storeState.canArchive && this.isModerator == storeState.isModerator && this.canAccessRedesignedForumChannels == storeState.canAccessRedesignedForumChannels;
}
public final Map<Long, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> getActiveJoinedThreads() {
return this.activeJoinedThreads;
}
public final boolean getCanAccessRedesignedForumChannels() {
return this.canAccessRedesignedForumChannels;
}
public final boolean getCanArchive() {
return this.canArchive;
}
public final Channel getParentChannel() {
return this.parentChannel;
}
public final Channel getSelectedChannel() {
return this.selectedChannel;
}
public int hashCode() {
Map<Long, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> map = this.activeJoinedThreads;
int i = 0;
int hashCode = (map != null ? map.hashCode() : 0) * 31;
Channel channel = this.selectedChannel;
int hashCode2 = (hashCode + (channel != null ? channel.hashCode() : 0)) * 31;
Channel channel2 = this.parentChannel;
if (channel2 != null) {
i = channel2.hashCode();
}
int i2 = (hashCode2 + i) * 31;
boolean z2 = this.canArchive;
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.isModerator;
if (z3) {
z3 = true;
}
int i8 = z3 ? 1 : 0;
int i9 = z3 ? 1 : 0;
int i10 = z3 ? 1 : 0;
int i11 = (i7 + i8) * 31;
boolean z4 = this.canAccessRedesignedForumChannels;
if (!z4) {
i3 = z4 ? 1 : 0;
}
return i11 + i3;
}
public final boolean isModerator() {
return this.isModerator;
}
public String toString() {
StringBuilder R = a.R("StoreState(activeJoinedThreads=");
R.append(this.activeJoinedThreads);
R.append(", selectedChannel=");
R.append(this.selectedChannel);
R.append(", parentChannel=");
R.append(this.parentChannel);
R.append(", canArchive=");
R.append(this.canArchive);
R.append(", isModerator=");
R.append(this.isModerator);
R.append(", canAccessRedesignedForumChannels=");
return a.M(R, this.canAccessRedesignedForumChannels, ")");
}
}
/* compiled from: WidgetThreadStatusViewModel.kt */
/* loaded from: classes2.dex */
public static final class ViewState {
private final boolean isLoading;
private final Status threadStatus;
public ViewState(Status status, boolean z2) {
m.checkNotNullParameter(status, "threadStatus");
this.threadStatus = status;
this.isLoading = z2;
}
public /* synthetic */ ViewState(Status status, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(status, (i & 2) != 0 ? false : z2);
}
public static /* synthetic */ ViewState copy$default(ViewState viewState, Status status, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
status = viewState.threadStatus;
}
if ((i & 2) != 0) {
z2 = viewState.isLoading;
}
return viewState.copy(status, z2);
}
public final Status component1() {
return this.threadStatus;
}
public final boolean component2() {
return this.isLoading;
}
public final ViewState copy(Status status, boolean z2) {
m.checkNotNullParameter(status, "threadStatus");
return new ViewState(status, z2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ViewState)) {
return false;
}
ViewState viewState = (ViewState) obj;
return m.areEqual(this.threadStatus, viewState.threadStatus) && this.isLoading == viewState.isLoading;
}
public final Status getThreadStatus() {
return this.threadStatus;
}
public int hashCode() {
Status status = this.threadStatus;
int hashCode = (status != null ? status.hashCode() : 0) * 31;
boolean z2 = this.isLoading;
if (z2) {
z2 = true;
}
int i = z2 ? 1 : 0;
int i2 = z2 ? 1 : 0;
int i3 = z2 ? 1 : 0;
return hashCode + i;
}
public final boolean isLoading() {
return this.isLoading;
}
public String toString() {
StringBuilder R = a.R("ViewState(threadStatus=");
R.append(this.threadStatus);
R.append(", isLoading=");
return a.M(R, this.isLoading, ")");
}
}
public WidgetThreadStatusViewModel() {
this(null, 1, null);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public WidgetThreadStatusViewModel(Observable<StoreState> observable) {
super(null, 1, null);
m.checkNotNullParameter(observable, "storeStateObservable");
this.storeStateObservable = observable;
this.eventSubject = PublishSubject.k0();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), WidgetThreadStatusViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(), 62, (Object) null);
}
public /* synthetic */ WidgetThreadStatusViewModel(Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? Companion.observeStoreState$default(Companion, null, null, null, null, null, 31, null) : observable);
}
public static final /* synthetic */ void access$emitError(WidgetThreadStatusViewModel widgetThreadStatusViewModel, int i) {
widgetThreadStatusViewModel.emitError(i);
}
public static final /* synthetic */ void access$handleStoreState(WidgetThreadStatusViewModel widgetThreadStatusViewModel, StoreState storeState) {
widgetThreadStatusViewModel.handleStoreState(storeState);
}
public static final /* synthetic */ void access$updateViewLoading(WidgetThreadStatusViewModel widgetThreadStatusViewModel, boolean z2) {
widgetThreadStatusViewModel.updateViewLoading(z2);
}
private final void emitError(int i) {
PublishSubject<WidgetThreadStatus.Event> publishSubject = this.eventSubject;
publishSubject.k.onNext(new WidgetThreadStatus.Event.Error(i));
}
private final void handleStoreState(StoreState storeState) {
Status status;
this.currentStoreState = storeState;
Channel selectedChannel = storeState.getSelectedChannel();
Channel parentChannel = storeState.getParentChannel();
Map<Long, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> activeJoinedThreads = storeState.getActiveJoinedThreads();
Channel selectedChannel2 = storeState.getSelectedChannel();
StoreThreadsActiveJoined.ActiveJoinedThread activeJoinedThread = null;
Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread> map = activeJoinedThreads.get(selectedChannel2 != null ? Long.valueOf(selectedChannel2.u()) : null);
if (map != null) {
Channel selectedChannel3 = storeState.getSelectedChannel();
if (selectedChannel3 != null) {
activeJoinedThread = Long.valueOf(selectedChannel3.k());
}
activeJoinedThread = map.get(activeJoinedThread);
}
boolean z2 = false;
boolean z3 = activeJoinedThread != null;
if (selectedChannel == null || !ChannelUtils.F(selectedChannel)) {
status = Status.Hide.INSTANCE;
} else if (parentChannel == null || !ChannelUtils.q(parentChannel) || !storeState.getCanAccessRedesignedForumChannels()) {
ThreadMetadata B = selectedChannel.B();
if (B == null || !B.b()) {
status = z3 ? Status.Hide.INSTANCE : Status.Unjoined.INSTANCE;
} else {
ThreadMetadata B2 = selectedChannel.B();
if (B2 != null && B2.d()) {
z2 = true;
}
status = new Status.Archived(z2, storeState.getCanArchive());
}
} else {
status = Status.Hide.INSTANCE;
}
updateViewWithStatus(status);
}
private final void updateViewLoading(boolean z2) {
ViewState viewState = getViewState();
if (viewState != null) {
updateViewState(ViewState.copy$default(viewState, null, z2, 1, null));
}
}
private final void updateViewWithStatus(Status status) {
updateViewState(new ViewState(status, false, 2, null));
}
public final Observable<StoreState> getStoreStateObservable() {
return this.storeStateObservable;
}
public final Observable<WidgetThreadStatus.Event> observeEvents() {
PublishSubject<WidgetThreadStatus.Event> publishSubject = this.eventSubject;
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
return publishSubject;
}
public final void onJoinTapped() {
StoreState storeState = this.currentStoreState;
if (storeState != null) {
if (storeState.getSelectedChannel() != null) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().joinThread(storeState.getSelectedChannel().k(), "Banner", new RestAPIParams.EmptyBody()), false, 1, null), this, null, 2, null), WidgetThreadStatusViewModel.class, (Context) null, (Function1) null, new WidgetThreadStatusViewModel$onJoinTapped$$inlined$let$lambda$1(this), (Function0) null, new WidgetThreadStatusViewModel$onJoinTapped$$inlined$let$lambda$2(this), WidgetThreadStatusViewModel$onJoinTapped$1$2.INSTANCE, 22, (Object) null);
} else {
return;
}
}
updateViewLoading(true);
}
public final void onUnarchiveTapped() {
StoreState storeState = this.currentStoreState;
if (storeState != null) {
if (storeState.getSelectedChannel() != null) {
RestAPI api = RestAPI.Companion.getApi();
long k = storeState.getSelectedChannel().k();
Boolean bool = Boolean.FALSE;
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(api.editThread(k, new RestAPIParams.ThreadSettings(bool, storeState.isModerator() ? bool : null, null, 4, null)), false, 1, null), this, null, 2, null), WidgetThreadStatusViewModel.class, (Context) null, (Function1) null, new WidgetThreadStatusViewModel$onUnarchiveTapped$$inlined$let$lambda$1(this), (Function0) null, new WidgetThreadStatusViewModel$onUnarchiveTapped$$inlined$let$lambda$2(this), WidgetThreadStatusViewModel$onUnarchiveTapped$1$2.INSTANCE, 22, (Object) null);
} else {
return;
}
}
updateViewLoading(true);
}
}