package com.discord.widgets.guildscheduledevent; import android.content.Context; import c.d.b.a.a; import com.discord.api.channel.Channel; import com.discord.api.guildscheduledevent.GuildScheduledEvent; import com.discord.api.guildscheduledevent.GuildScheduledEventStatus; import com.discord.api.permission.Permission; import com.discord.app.AppViewModel; import com.discord.stores.StoreChannels; import com.discord.stores.StoreGuildScheduledEvents; import com.discord.stores.StorePermissions; import com.discord.stores.StoreStream; import com.discord.utilities.analytics.AnalyticsTracker; import com.discord.utilities.guildscheduledevent.GuildScheduledEventUtilities; import com.discord.utilities.permissions.PermissionUtils; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.widgets.guildscheduledevent.GuildScheduledEventListItem; import d0.t.h0; import d0.t.o; import d0.z.d.k; import d0.z.d.m; import java.util.ArrayList; import java.util.Comparator; import java.util.List; 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; /* compiled from: GuildScheduledEventListViewModel.kt */ public final class GuildScheduledEventListViewModel extends AppViewModel { public static final Companion Companion = new Companion(null); private final StoreChannels channelsStore; private final long guildId; private final StoreGuildScheduledEvents guildScheduledEventsStore; private final StorePermissions permissionsStore; /* compiled from: GuildScheduledEventListViewModel.kt */ /* renamed from: com.discord.widgets.guildscheduledevent.GuildScheduledEventListViewModel$1 reason: invalid class name */ public static final /* synthetic */ class AnonymousClass1 extends k implements Function1 { public AnonymousClass1(GuildScheduledEventListViewModel guildScheduledEventListViewModel) { super(1, guildScheduledEventListViewModel, GuildScheduledEventListViewModel.class, "handleStoreState", "handleStoreState(Lcom/discord/widgets/guildscheduledevent/GuildScheduledEventListViewModel$StoreState;)V", 0); } /* 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, "p1"); GuildScheduledEventListViewModel.access$handleStoreState((GuildScheduledEventListViewModel) this.receiver, storeState); } } /* compiled from: GuildScheduledEventListViewModel.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public static final /* synthetic */ Observable access$observeStores(Companion companion, long j, StoreGuildScheduledEvents storeGuildScheduledEvents, StoreChannels storeChannels, StorePermissions storePermissions) { return companion.observeStores(j, storeGuildScheduledEvents, storeChannels, storePermissions); } private final Observable observeStores(long j, StoreGuildScheduledEvents storeGuildScheduledEvents, StoreChannels storeChannels, StorePermissions storePermissions) { Observable g = Observable.g(StoreGuildScheduledEvents.observeGuildScheduledEvents$default(storeGuildScheduledEvents, j, false, false, 6, null), storeGuildScheduledEvents.observeUserGuildScheduledEvents(), StoreChannels.observeChannelsForGuild$default(storeChannels, j, null, 2, null), storePermissions.observeChannelPermissionsForGuild(j), GuildScheduledEventUtilities.Companion.observeGuildScheduledEventCreatableChannelsForGuild$default(GuildScheduledEventUtilities.Companion, j, null, null, 6, null), GuildScheduledEventListViewModel$Companion$observeStores$1.INSTANCE); m.checkNotNullExpressionValue(g, "Observable.combineLatest…mpty(),\n )\n }"); return g; } } /* compiled from: GuildScheduledEventListViewModel.kt */ public static final class GuildScheduledEventsComparator implements Comparator { public static final GuildScheduledEventsComparator INSTANCE = new GuildScheduledEventsComparator(); private GuildScheduledEventsComparator() { } /* JADX WARNING: Code restructure failed: missing block: B:9:0x0017, code lost: if ((r7 != null ? r7.h() : null) != r2) goto L_0x0019; */ public int compare(GuildScheduledEvent guildScheduledEvent, GuildScheduledEvent guildScheduledEvent2) { GuildScheduledEventStatus guildScheduledEventStatus = null; GuildScheduledEventStatus h = guildScheduledEvent != null ? guildScheduledEvent.h() : null; GuildScheduledEventStatus guildScheduledEventStatus2 = GuildScheduledEventStatus.ACTIVE; if (h == guildScheduledEventStatus2) { } if ((guildScheduledEvent != null ? guildScheduledEvent.h() : null) != guildScheduledEventStatus2) { if (guildScheduledEvent2 != null) { guildScheduledEventStatus = guildScheduledEvent2.h(); } if (guildScheduledEventStatus == guildScheduledEventStatus2) { return 1; } } if (guildScheduledEvent != null && guildScheduledEvent2 != null) { return guildScheduledEvent.g().compareTo(guildScheduledEvent2.g()); } if (guildScheduledEvent == null) { return 1; } return guildScheduledEvent2 == null ? -1 : 0; } } /* compiled from: GuildScheduledEventListViewModel.kt */ public static final class StoreState { private final boolean canCreateEvents; private final Map guildChannelPermissions; private final Map guildChannels; private final List guildScheduledEvents; private final Map userGuildScheduledEvents; public StoreState(List list, Map map, Map map2, Map map3, boolean z2) { m.checkNotNullParameter(list, "guildScheduledEvents"); m.checkNotNullParameter(map, "userGuildScheduledEvents"); m.checkNotNullParameter(map2, "guildChannels"); m.checkNotNullParameter(map3, "guildChannelPermissions"); this.guildScheduledEvents = list; this.userGuildScheduledEvents = map; this.guildChannels = map2; this.guildChannelPermissions = map3; this.canCreateEvents = z2; } /* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.discord.widgets.guildscheduledevent.GuildScheduledEventListViewModel$StoreState */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ StoreState copy$default(StoreState storeState, List list, Map map, Map map2, Map map3, boolean z2, int i, Object obj) { if ((i & 1) != 0) { list = storeState.guildScheduledEvents; } if ((i & 2) != 0) { map = storeState.userGuildScheduledEvents; } if ((i & 4) != 0) { map2 = storeState.guildChannels; } if ((i & 8) != 0) { map3 = storeState.guildChannelPermissions; } if ((i & 16) != 0) { z2 = storeState.canCreateEvents; } return storeState.copy(list, map, map2, map3, z2); } public final List component1() { return this.guildScheduledEvents; } public final Map component2() { return this.userGuildScheduledEvents; } public final Map component3() { return this.guildChannels; } public final Map component4() { return this.guildChannelPermissions; } public final boolean component5() { return this.canCreateEvents; } public final StoreState copy(List list, Map map, Map map2, Map map3, boolean z2) { m.checkNotNullParameter(list, "guildScheduledEvents"); m.checkNotNullParameter(map, "userGuildScheduledEvents"); m.checkNotNullParameter(map2, "guildChannels"); m.checkNotNullParameter(map3, "guildChannelPermissions"); return new StoreState(list, map, map2, map3, 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.guildScheduledEvents, storeState.guildScheduledEvents) && m.areEqual(this.userGuildScheduledEvents, storeState.userGuildScheduledEvents) && m.areEqual(this.guildChannels, storeState.guildChannels) && m.areEqual(this.guildChannelPermissions, storeState.guildChannelPermissions) && this.canCreateEvents == storeState.canCreateEvents; } public final boolean getCanCreateEvents() { return this.canCreateEvents; } public final Map getGuildChannelPermissions() { return this.guildChannelPermissions; } public final Map getGuildChannels() { return this.guildChannels; } public final List getGuildScheduledEvents() { return this.guildScheduledEvents; } public final Map getUserGuildScheduledEvents() { return this.userGuildScheduledEvents; } public int hashCode() { List list = this.guildScheduledEvents; int i = 0; int hashCode = (list != null ? list.hashCode() : 0) * 31; Map map = this.userGuildScheduledEvents; int hashCode2 = (hashCode + (map != null ? map.hashCode() : 0)) * 31; Map map2 = this.guildChannels; int hashCode3 = (hashCode2 + (map2 != null ? map2.hashCode() : 0)) * 31; Map map3 = this.guildChannelPermissions; if (map3 != null) { i = map3.hashCode(); } int i2 = (hashCode3 + i) * 31; boolean z2 = this.canCreateEvents; if (z2) { z2 = true; } int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = z2 ? 1 : 0; return i2 + i3; } public String toString() { StringBuilder K = a.K("StoreState(guildScheduledEvents="); K.append(this.guildScheduledEvents); K.append(", userGuildScheduledEvents="); K.append(this.userGuildScheduledEvents); K.append(", guildChannels="); K.append(this.guildChannels); K.append(", guildChannelPermissions="); K.append(this.guildChannelPermissions); K.append(", canCreateEvents="); return a.F(K, this.canCreateEvents, ")"); } } /* compiled from: GuildScheduledEventListViewModel.kt */ public static abstract class ViewState { /* compiled from: GuildScheduledEventListViewModel.kt */ public static final class Initial extends ViewState { public static final Initial INSTANCE = new Initial(); private Initial() { super(null); } } /* compiled from: GuildScheduledEventListViewModel.kt */ public static final class Loaded extends ViewState { private final boolean canCreateEvents; private final List guildScheduledEvents; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Loaded(List list, boolean z2) { super(null); m.checkNotNullParameter(list, "guildScheduledEvents"); this.guildScheduledEvents = list; this.canCreateEvents = z2; } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.guildscheduledevent.GuildScheduledEventListViewModel$ViewState$Loaded */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Loaded copy$default(Loaded loaded, List list, boolean z2, int i, Object obj) { if ((i & 1) != 0) { list = loaded.guildScheduledEvents; } if ((i & 2) != 0) { z2 = loaded.canCreateEvents; } return loaded.copy(list, z2); } public final List component1() { return this.guildScheduledEvents; } public final boolean component2() { return this.canCreateEvents; } public final Loaded copy(List list, boolean z2) { m.checkNotNullParameter(list, "guildScheduledEvents"); return new Loaded(list, z2); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Loaded)) { return false; } Loaded loaded = (Loaded) obj; return m.areEqual(this.guildScheduledEvents, loaded.guildScheduledEvents) && this.canCreateEvents == loaded.canCreateEvents; } public final boolean getCanCreateEvents() { return this.canCreateEvents; } public final List getGuildScheduledEvents() { return this.guildScheduledEvents; } public int hashCode() { List list = this.guildScheduledEvents; int hashCode = (list != null ? list.hashCode() : 0) * 31; boolean z2 = this.canCreateEvents; 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("Loaded(guildScheduledEvents="); K.append(this.guildScheduledEvents); K.append(", canCreateEvents="); return a.F(K, this.canCreateEvents, ")"); } } private ViewState() { } public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public GuildScheduledEventListViewModel(long j, StoreGuildScheduledEvents storeGuildScheduledEvents, StoreChannels storeChannels, StorePermissions storePermissions, Observable observable) { super(ViewState.Initial.INSTANCE); m.checkNotNullParameter(storeGuildScheduledEvents, "guildScheduledEventsStore"); m.checkNotNullParameter(storeChannels, "channelsStore"); m.checkNotNullParameter(storePermissions, "permissionsStore"); m.checkNotNullParameter(observable, "storeStateObservable"); this.guildId = j; this.guildScheduledEventsStore = storeGuildScheduledEvents; this.channelsStore = storeChannels; this.permissionsStore = storePermissions; ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), GuildScheduledEventListViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null); } /* JADX WARNING: Illegal instructions before constructor call */ public /* synthetic */ GuildScheduledEventListViewModel(long j, StoreGuildScheduledEvents storeGuildScheduledEvents, StoreChannels storeChannels, StorePermissions storePermissions, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) { this(j, storeGuildScheduledEvents, storeChannels, storePermissions, (i & 16) != 0 ? Companion.access$observeStores(Companion, j, storeGuildScheduledEvents, storeChannels, storePermissions) : observable); storeGuildScheduledEvents = (i & 2) != 0 ? StoreStream.Companion.getGuildScheduledEvents() : storeGuildScheduledEvents; storeChannels = (i & 4) != 0 ? StoreStream.Companion.getChannels() : storeChannels; storePermissions = (i & 8) != 0 ? StoreStream.Companion.getPermissions() : storePermissions; } public static final /* synthetic */ void access$handleStoreState(GuildScheduledEventListViewModel guildScheduledEventListViewModel, StoreState storeState) { guildScheduledEventListViewModel.handleStoreState(storeState); } private final void handleStoreState(StoreState storeState) { if (!(getViewState() instanceof ViewState.Loaded)) { AnalyticsTracker.INSTANCE.openGuildScheduledEventSheet(this.guildId, storeState.getGuildScheduledEvents().size()); } List guildScheduledEvents = storeState.getGuildScheduledEvents(); ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(guildScheduledEvents, 10)); for (GuildScheduledEvent guildScheduledEvent : guildScheduledEvents) { boolean contains = storeState.getUserGuildScheduledEvents().keySet().contains(Long.valueOf(guildScheduledEvent.e())); Channel channel = (Channel) h0.getValue(storeState.getGuildChannels(), Long.valueOf(guildScheduledEvent.b())); Long l = storeState.getGuildChannelPermissions().get(Long.valueOf(guildScheduledEvent.b())); arrayList.add(new GuildScheduledEventListItem.Event(guildScheduledEvent, channel, contains, l != null ? PermissionUtils.can(Permission.START_STAGE_EVENT, Long.valueOf(l.longValue())) : false)); } updateViewState(new ViewState.Loaded(arrayList, storeState.getCanCreateEvents())); } public final void toggleRsvp(GuildScheduledEvent guildScheduledEvent) { m.checkNotNullParameter(guildScheduledEvent, "guildScheduledEvent"); this.guildScheduledEventsStore.toggleRsvpGuildScheduledEvent(guildScheduledEvent); } }