discord-jadx/app/src/main/java/com/discord/widgets/guilds/invite/GuildInviteShareSheetViewMo...

865 lines
42 KiB
Java

package com.discord.widgets.guilds.invite;
import a0.a.a.b;
import android.content.Context;
import androidx.annotation.MainThread;
import c.d.b.a.a;
import com.discord.BuildConfig;
import com.discord.api.channel.Channel;
import com.discord.api.channel.ChannelUtils;
import com.discord.api.stageinstance.StageInstance;
import com.discord.app.AppLog;
import com.discord.app.AppViewModel;
import com.discord.models.domain.ModelInvite;
import com.discord.models.guild.Guild;
import com.discord.models.user.MeUser;
import com.discord.models.user.User;
import com.discord.stores.StoreAnalytics;
import com.discord.stores.StoreChannels;
import com.discord.stores.StoreGuilds;
import com.discord.stores.StoreInviteSettings;
import com.discord.stores.StoreMessages;
import com.discord.stores.StoreStageInstances;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUser;
import com.discord.utilities.guilds.GuildUtilsKt;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.widgets.guilds.invite.GuildInvite;
import com.discord.widgets.guilds.invite.InviteSuggestion;
import com.discord.widgets.guilds.invite.InviteSuggestionItemV2;
import d0.g0.t;
import d0.g0.w;
import d0.t.h0;
import d0.t.n0;
import d0.t.u;
import d0.z.d.m;
import d0.z.d.o;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import kotlin.NoWhenBranchMatchedException;
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;
/* compiled from: GuildInviteShareSheetViewModel.kt */
public final class GuildInviteShareSheetViewModel extends AppViewModel<ViewState> {
public static final Companion Companion = new Companion(null);
private final Long channelId;
private StoreState currentStoreState;
private final long guildId;
private boolean hasTrackedSuggestionsViewed;
private GuildInvite invite;
private final Logger logger;
private String searchQuery;
private BehaviorSubject<String> searchQuerySubject;
private Map<String, ? extends Set<Long>> sentInvites;
private final StoreAnalytics storeAnalytics;
private final StoreInviteSettings storeInviteSettings;
private final StoreMessages storeMessages;
private Channel targetChannel;
private final TargetChannelSelector targetChannelSelector;
/* compiled from: GuildInviteShareSheetViewModel.kt */
/* renamed from: com.discord.widgets.guilds.invite.GuildInviteShareSheetViewModel$1 reason: invalid class name */
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
public final /* synthetic */ GuildInviteShareSheetViewModel this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass1(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel) {
super(1);
this.this$0 = guildInviteShareSheetViewModel;
}
/* 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");
GuildInviteShareSheetViewModel.access$handleStoreState(this.this$0, storeState);
}
}
/* compiled from: GuildInviteShareSheetViewModel.kt */
/* renamed from: com.discord.widgets.guilds.invite.GuildInviteShareSheetViewModel$2 reason: invalid class name */
public static final class AnonymousClass2 extends o implements Function1<String, Unit> {
public final /* synthetic */ GuildInviteShareSheetViewModel this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass2(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel) {
super(1);
this.this$0 = guildInviteShareSheetViewModel;
}
/* 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(String str) {
invoke(str);
return Unit.a;
}
public final void invoke(String str) {
GuildInviteShareSheetViewModel guildInviteShareSheetViewModel = this.this$0;
m.checkNotNullExpressionValue(str, "searchQuery");
GuildInviteShareSheetViewModel.access$updateSearchQuery(guildInviteShareSheetViewModel, str);
}
}
/* compiled from: GuildInviteShareSheetViewModel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Observable access$observeStoreState(Companion companion, long j, InviteSuggestionsManager inviteSuggestionsManager, StoreInviteSettings storeInviteSettings, StoreUser storeUser, StoreChannels storeChannels, StoreGuilds storeGuilds, StoreStageInstances storeStageInstances) {
return companion.observeStoreState(j, inviteSuggestionsManager, storeInviteSettings, storeUser, storeChannels, storeGuilds, storeStageInstances);
}
private final Observable<StoreState> observeStoreState(long j, InviteSuggestionsManager inviteSuggestionsManager, StoreInviteSettings storeInviteSettings, StoreUser storeUser, StoreChannels storeChannels, StoreGuilds storeGuilds, StoreStageInstances storeStageInstances) {
Observable<StoreState> e = Observable.e(storeInviteSettings.getInviteSettings(), storeInviteSettings.getInvitableChannels(j), StoreUser.observeMe$default(storeUser, false, 1, null), storeChannels.observeDMs(), storeGuilds.observeGuild(j), inviteSuggestionsManager.observeInviteSuggestions(), storeStageInstances.observeStageInstancesForGuild(j), GuildInviteShareSheetViewModel$Companion$observeStoreState$1.INSTANCE);
m.checkNotNullExpressionValue(e, "Observable.combineLatest… )\n }\n }");
return e;
}
}
/* compiled from: GuildInviteShareSheetViewModel.kt */
public static abstract class StoreState {
/* compiled from: GuildInviteShareSheetViewModel.kt */
public static final class Invalid extends StoreState {
public static final Invalid INSTANCE = new Invalid();
private Invalid() {
super(null);
}
}
/* compiled from: GuildInviteShareSheetViewModel.kt */
public static final class Valid extends StoreState {
private final List<Channel> dms;
private final Guild guild;
private final Map<Long, StageInstance> guildStageInstances;
private final Map<Long, Channel> invitableChannels;
private final ModelInvite.Settings inviteSettings;
private final List<InviteSuggestion> inviteSuggestions;
/* renamed from: me reason: collision with root package name */
private final MeUser f2256me;
/* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: java.util.List<? extends com.discord.widgets.guilds.invite.InviteSuggestion> */
/* JADX WARN: Multi-variable type inference failed */
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Valid(ModelInvite.Settings settings, Map<Long, Channel> map, MeUser meUser, List<Channel> list, Guild guild, List<? extends InviteSuggestion> list2, Map<Long, StageInstance> map2) {
super(null);
m.checkNotNullParameter(settings, "inviteSettings");
m.checkNotNullParameter(map, "invitableChannels");
m.checkNotNullParameter(meUser, "me");
m.checkNotNullParameter(list, "dms");
m.checkNotNullParameter(guild, "guild");
m.checkNotNullParameter(list2, "inviteSuggestions");
m.checkNotNullParameter(map2, "guildStageInstances");
this.inviteSettings = settings;
this.invitableChannels = map;
this.f2256me = meUser;
this.dms = list;
this.guild = guild;
this.inviteSuggestions = list2;
this.guildStageInstances = map2;
}
/* JADX DEBUG: Multi-variable search result rejected for r5v0, resolved type: com.discord.widgets.guilds.invite.GuildInviteShareSheetViewModel$StoreState$Valid */
/* JADX WARN: Multi-variable type inference failed */
public static /* synthetic */ Valid copy$default(Valid valid, ModelInvite.Settings settings, Map map, MeUser meUser, List list, Guild guild, List list2, Map map2, int i, Object obj) {
if ((i & 1) != 0) {
settings = valid.inviteSettings;
}
if ((i & 2) != 0) {
map = valid.invitableChannels;
}
if ((i & 4) != 0) {
meUser = valid.f2256me;
}
if ((i & 8) != 0) {
list = valid.dms;
}
if ((i & 16) != 0) {
guild = valid.guild;
}
if ((i & 32) != 0) {
list2 = valid.inviteSuggestions;
}
if ((i & 64) != 0) {
map2 = valid.guildStageInstances;
}
return valid.copy(settings, map, meUser, list, guild, list2, map2);
}
public final ModelInvite.Settings component1() {
return this.inviteSettings;
}
public final Map<Long, Channel> component2() {
return this.invitableChannels;
}
public final MeUser component3() {
return this.f2256me;
}
public final List<Channel> component4() {
return this.dms;
}
public final Guild component5() {
return this.guild;
}
public final List<InviteSuggestion> component6() {
return this.inviteSuggestions;
}
public final Map<Long, StageInstance> component7() {
return this.guildStageInstances;
}
public final Valid copy(ModelInvite.Settings settings, Map<Long, Channel> map, MeUser meUser, List<Channel> list, Guild guild, List<? extends InviteSuggestion> list2, Map<Long, StageInstance> map2) {
m.checkNotNullParameter(settings, "inviteSettings");
m.checkNotNullParameter(map, "invitableChannels");
m.checkNotNullParameter(meUser, "me");
m.checkNotNullParameter(list, "dms");
m.checkNotNullParameter(guild, "guild");
m.checkNotNullParameter(list2, "inviteSuggestions");
m.checkNotNullParameter(map2, "guildStageInstances");
return new Valid(settings, map, meUser, list, guild, list2, map2);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Valid)) {
return false;
}
Valid valid = (Valid) obj;
return m.areEqual(this.inviteSettings, valid.inviteSettings) && m.areEqual(this.invitableChannels, valid.invitableChannels) && m.areEqual(this.f2256me, valid.f2256me) && m.areEqual(this.dms, valid.dms) && m.areEqual(this.guild, valid.guild) && m.areEqual(this.inviteSuggestions, valid.inviteSuggestions) && m.areEqual(this.guildStageInstances, valid.guildStageInstances);
}
public final List<Channel> getDms() {
return this.dms;
}
public final Guild getGuild() {
return this.guild;
}
public final Map<Long, StageInstance> getGuildStageInstances() {
return this.guildStageInstances;
}
public final Map<Long, Channel> getInvitableChannels() {
return this.invitableChannels;
}
public final ModelInvite.Settings getInviteSettings() {
return this.inviteSettings;
}
public final List<InviteSuggestion> getInviteSuggestions() {
return this.inviteSuggestions;
}
public final MeUser getMe() {
return this.f2256me;
}
public int hashCode() {
ModelInvite.Settings settings = this.inviteSettings;
int i = 0;
int hashCode = (settings != null ? settings.hashCode() : 0) * 31;
Map<Long, Channel> map = this.invitableChannels;
int hashCode2 = (hashCode + (map != null ? map.hashCode() : 0)) * 31;
MeUser meUser = this.f2256me;
int hashCode3 = (hashCode2 + (meUser != null ? meUser.hashCode() : 0)) * 31;
List<Channel> list = this.dms;
int hashCode4 = (hashCode3 + (list != null ? list.hashCode() : 0)) * 31;
Guild guild = this.guild;
int hashCode5 = (hashCode4 + (guild != null ? guild.hashCode() : 0)) * 31;
List<InviteSuggestion> list2 = this.inviteSuggestions;
int hashCode6 = (hashCode5 + (list2 != null ? list2.hashCode() : 0)) * 31;
Map<Long, StageInstance> map2 = this.guildStageInstances;
if (map2 != null) {
i = map2.hashCode();
}
return hashCode6 + i;
}
public String toString() {
StringBuilder R = a.R("Valid(inviteSettings=");
R.append(this.inviteSettings);
R.append(", invitableChannels=");
R.append(this.invitableChannels);
R.append(", me=");
R.append(this.f2256me);
R.append(", dms=");
R.append(this.dms);
R.append(", guild=");
R.append(this.guild);
R.append(", inviteSuggestions=");
R.append(this.inviteSuggestions);
R.append(", guildStageInstances=");
return a.K(R, this.guildStageInstances, ")");
}
}
private StoreState() {
}
public /* synthetic */ StoreState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: GuildInviteShareSheetViewModel.kt */
public static final class ViewState {
private final Channel channel;
private final long guildId;
private final boolean hasResults;
private final boolean hasSearchResults;
private final GuildInvite invite;
private final ModelInvite.Settings inviteSettings;
private final List<InviteSuggestionItemV2> inviteSuggestionItems;
private final String searchQuery;
private final Map<String, Set<Long>> sentInvites;
private final boolean showInviteSettings;
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: java.util.List<? extends com.discord.widgets.guilds.invite.InviteSuggestionItemV2> */
/* JADX DEBUG: Multi-variable search result rejected for r7v0, resolved type: java.util.Map<java.lang.String, ? extends java.util.Set<java.lang.Long>> */
/* JADX WARN: Multi-variable type inference failed */
public ViewState(GuildInvite guildInvite, ModelInvite.Settings settings, List<? extends InviteSuggestionItemV2> list, Channel channel, String str, Map<String, ? extends Set<Long>> map, boolean z2, long j) {
m.checkNotNullParameter(list, "inviteSuggestionItems");
m.checkNotNullParameter(str, "searchQuery");
m.checkNotNullParameter(map, "sentInvites");
this.invite = guildInvite;
this.inviteSettings = settings;
this.inviteSuggestionItems = list;
this.channel = channel;
this.searchQuery = str;
this.sentInvites = map;
this.showInviteSettings = z2;
this.guildId = j;
boolean z3 = true;
this.hasResults = !list.isEmpty();
this.hasSearchResults = (list.size() <= 1 || (list.get(0) instanceof InviteSuggestionItemV2.SearchNoResultsItem)) ? false : z3;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ ViewState(GuildInvite guildInvite, ModelInvite.Settings settings, List list, Channel channel, String str, Map map, boolean z2, long j, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(guildInvite, settings, list, channel, (i & 16) != 0 ? "" : str, map, z2, j);
}
public static /* synthetic */ ViewState copy$default(ViewState viewState, GuildInvite guildInvite, ModelInvite.Settings settings, List list, Channel channel, String str, Map map, boolean z2, long j, int i, Object obj) {
return viewState.copy((i & 1) != 0 ? viewState.invite : guildInvite, (i & 2) != 0 ? viewState.inviteSettings : settings, (i & 4) != 0 ? viewState.inviteSuggestionItems : list, (i & 8) != 0 ? viewState.channel : channel, (i & 16) != 0 ? viewState.searchQuery : str, (i & 32) != 0 ? viewState.sentInvites : map, (i & 64) != 0 ? viewState.showInviteSettings : z2, (i & 128) != 0 ? viewState.guildId : j);
}
public final GuildInvite component1() {
return this.invite;
}
public final ModelInvite.Settings component2() {
return this.inviteSettings;
}
public final List<InviteSuggestionItemV2> component3() {
return this.inviteSuggestionItems;
}
public final Channel component4() {
return this.channel;
}
public final String component5() {
return this.searchQuery;
}
public final Map<String, Set<Long>> component6() {
return this.sentInvites;
}
public final boolean component7() {
return this.showInviteSettings;
}
public final long component8() {
return this.guildId;
}
public final ViewState copy(GuildInvite guildInvite, ModelInvite.Settings settings, List<? extends InviteSuggestionItemV2> list, Channel channel, String str, Map<String, ? extends Set<Long>> map, boolean z2, long j) {
m.checkNotNullParameter(list, "inviteSuggestionItems");
m.checkNotNullParameter(str, "searchQuery");
m.checkNotNullParameter(map, "sentInvites");
return new ViewState(guildInvite, settings, list, channel, str, map, z2, j);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ViewState)) {
return false;
}
ViewState viewState = (ViewState) obj;
return m.areEqual(this.invite, viewState.invite) && m.areEqual(this.inviteSettings, viewState.inviteSettings) && m.areEqual(this.inviteSuggestionItems, viewState.inviteSuggestionItems) && m.areEqual(this.channel, viewState.channel) && m.areEqual(this.searchQuery, viewState.searchQuery) && m.areEqual(this.sentInvites, viewState.sentInvites) && this.showInviteSettings == viewState.showInviteSettings && this.guildId == viewState.guildId;
}
public final Channel getChannel() {
return this.channel;
}
public final long getGuildId() {
return this.guildId;
}
public final boolean getHasResults() {
return this.hasResults;
}
public final boolean getHasSearchResults() {
return this.hasSearchResults;
}
public final GuildInvite getInvite() {
return this.invite;
}
public final ModelInvite.Settings getInviteSettings() {
return this.inviteSettings;
}
public final List<InviteSuggestionItemV2> getInviteSuggestionItems() {
return this.inviteSuggestionItems;
}
public final String getSearchQuery() {
return this.searchQuery;
}
public final Map<String, Set<Long>> getSentInvites() {
return this.sentInvites;
}
public final boolean getShowInviteSettings() {
return this.showInviteSettings;
}
public int hashCode() {
GuildInvite guildInvite = this.invite;
int i = 0;
int hashCode = (guildInvite != null ? guildInvite.hashCode() : 0) * 31;
ModelInvite.Settings settings = this.inviteSettings;
int hashCode2 = (hashCode + (settings != null ? settings.hashCode() : 0)) * 31;
List<InviteSuggestionItemV2> list = this.inviteSuggestionItems;
int hashCode3 = (hashCode2 + (list != null ? list.hashCode() : 0)) * 31;
Channel channel = this.channel;
int hashCode4 = (hashCode3 + (channel != null ? channel.hashCode() : 0)) * 31;
String str = this.searchQuery;
int hashCode5 = (hashCode4 + (str != null ? str.hashCode() : 0)) * 31;
Map<String, Set<Long>> map = this.sentInvites;
if (map != null) {
i = map.hashCode();
}
int i2 = (hashCode5 + i) * 31;
boolean z2 = this.showInviteSettings;
if (z2) {
z2 = true;
}
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
return b.a(this.guildId) + ((i2 + i3) * 31);
}
public String toString() {
StringBuilder R = a.R("ViewState(invite=");
R.append(this.invite);
R.append(", inviteSettings=");
R.append(this.inviteSettings);
R.append(", inviteSuggestionItems=");
R.append(this.inviteSuggestionItems);
R.append(", channel=");
R.append(this.channel);
R.append(", searchQuery=");
R.append(this.searchQuery);
R.append(", sentInvites=");
R.append(this.sentInvites);
R.append(", showInviteSettings=");
R.append(this.showInviteSettings);
R.append(", guildId=");
return a.B(R, this.guildId, ")");
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public GuildInviteShareSheetViewModel(Long l, long j, StoreInviteSettings storeInviteSettings, StoreAnalytics storeAnalytics, StoreMessages storeMessages, TargetChannelSelector targetChannelSelector, Logger logger, Observable<StoreState> observable) {
super(null, 1, null);
m.checkNotNullParameter(storeInviteSettings, "storeInviteSettings");
m.checkNotNullParameter(storeAnalytics, "storeAnalytics");
m.checkNotNullParameter(storeMessages, "storeMessages");
m.checkNotNullParameter(targetChannelSelector, "targetChannelSelector");
m.checkNotNullParameter(logger, "logger");
m.checkNotNullParameter(observable, "storeStateObservable");
this.channelId = l;
this.guildId = j;
this.storeInviteSettings = storeInviteSettings;
this.storeAnalytics = storeAnalytics;
this.storeMessages = storeMessages;
this.targetChannelSelector = targetChannelSelector;
this.logger = logger;
BehaviorSubject<String> l0 = BehaviorSubject.l0("");
m.checkNotNullExpressionValue(l0, "BehaviorSubject.create(\"\")");
this.searchQuerySubject = l0;
this.searchQuery = "";
this.sentInvites = h0.emptyMap();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), GuildInviteShareSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
Observable<String> o = this.searchQuerySubject.o(250, TimeUnit.MILLISECONDS);
m.checkNotNullExpressionValue(o, "searchQuerySubject\n …0, TimeUnit.MILLISECONDS)");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(o, this, null, 2, null), GuildInviteShareSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass2(this), 62, (Object) null);
}
/* JADX WARNING: Illegal instructions before constructor call */
public /* synthetic */ GuildInviteShareSheetViewModel(Long l, long j, StoreInviteSettings storeInviteSettings, StoreAnalytics storeAnalytics, StoreMessages storeMessages, TargetChannelSelector targetChannelSelector, Logger logger, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(l, j, r6, r7, r8, r9, r10, r11);
Observable observable2;
StoreInviteSettings inviteSettings = (i & 4) != 0 ? StoreStream.Companion.getInviteSettings() : storeInviteSettings;
StoreAnalytics analytics = (i & 8) != 0 ? StoreStream.Companion.getAnalytics() : storeAnalytics;
StoreMessages messages = (i & 16) != 0 ? StoreStream.Companion.getMessages() : storeMessages;
TargetChannelSelector targetChannelSelector2 = (i & 32) != 0 ? new TargetChannelSelector() : targetChannelSelector;
AppLog appLog = (i & 64) != 0 ? AppLog.g : logger;
if ((i & 128) != 0) {
Companion companion = Companion;
InviteSuggestionsManager inviteSuggestionsManager = new InviteSuggestionsManager(null, null, null, null, null, 31, null);
StoreStream.Companion companion2 = StoreStream.Companion;
observable2 = Companion.access$observeStoreState(companion, j, inviteSuggestionsManager, companion2.getInviteSettings(), companion2.getUsers(), companion2.getChannels(), companion2.getGuilds(), companion2.getStageInstances());
} else {
observable2 = observable;
}
}
public static final /* synthetic */ StoreAnalytics access$getStoreAnalytics$p(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel) {
return guildInviteShareSheetViewModel.storeAnalytics;
}
public static final /* synthetic */ void access$handleInviteCreationFailure(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel) {
guildInviteShareSheetViewModel.handleInviteCreationFailure();
}
public static final /* synthetic */ void access$handleInviteCreationSuccess(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel, ModelInvite modelInvite) {
guildInviteShareSheetViewModel.handleInviteCreationSuccess(modelInvite);
}
public static final /* synthetic */ void access$handleStoreState(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel, StoreState storeState) {
guildInviteShareSheetViewModel.handleStoreState(storeState);
}
public static final /* synthetic */ void access$sendInviteToChannel(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel, long j) {
guildInviteShareSheetViewModel.sendInviteToChannel(j);
}
public static final /* synthetic */ void access$updateSearchQuery(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel, String str) {
guildInviteShareSheetViewModel.updateSearchQuery(str);
}
public static final /* synthetic */ void access$updateSentInvites(GuildInviteShareSheetViewModel guildInviteShareSheetViewModel, Map map) {
guildInviteShareSheetViewModel.updateSentInvites(map);
}
private final ViewState createViewState(String str, Map<String, ? extends Set<Long>> map, StoreState.Valid valid, GuildInvite guildInvite) {
String str2;
Long l;
List list;
Object obj;
boolean z2;
Collections.sort(new ArrayList(valid.getInvitableChannels().values()), ChannelUtils.h(Channel.Companion));
if (guildInvite == null || (str2 = guildInvite.toLink()) == null) {
str2 = BuildConfig.HOST_INVITE;
}
Object obj2 = map.get(str2);
if (obj2 == null) {
obj2 = n0.emptySet();
}
Set set = (Set) obj2;
List<InviteSuggestion> inviteSuggestions = valid.getInviteSuggestions();
if (!t.isBlank(str)) {
ArrayList arrayList = new ArrayList();
for (Object obj3 : inviteSuggestions) {
InviteSuggestion inviteSuggestion = (InviteSuggestion) obj3;
if (inviteSuggestion instanceof InviteSuggestion.ChannelItem) {
z2 = w.contains((CharSequence) ChannelUtils.c(((InviteSuggestion.ChannelItem) inviteSuggestion).getChannel()), (CharSequence) str, true);
} else if (inviteSuggestion instanceof InviteSuggestion.UserSuggestion) {
z2 = w.contains((CharSequence) ((InviteSuggestion.UserSuggestion) inviteSuggestion).getUser().getUsername(), (CharSequence) str, true);
} else {
throw new NoWhenBranchMatchedException();
}
if (z2) {
arrayList.add(obj3);
}
}
inviteSuggestions = arrayList;
}
List<Channel> dms = valid.getDms();
ArrayList arrayList2 = new ArrayList(d0.t.o.collectionSizeOrDefault(dms, 10));
Iterator<T> it = dms.iterator();
while (true) {
l = null;
if (!it.hasNext()) {
break;
}
Channel channel = (Channel) it.next();
User a = ChannelUtils.a(channel);
if (a != null) {
l = Long.valueOf(a.getId());
}
arrayList2.add(d0.o.to(l, Long.valueOf(channel.h())));
}
Map map2 = h0.toMap(arrayList2);
if ((!inviteSuggestions.isEmpty()) || t.isBlank(str)) {
list = new ArrayList(d0.t.o.collectionSizeOrDefault(inviteSuggestions, 10));
for (InviteSuggestion inviteSuggestion2 : inviteSuggestions) {
if (inviteSuggestion2 instanceof InviteSuggestion.ChannelItem) {
InviteSuggestion.ChannelItem channelItem = (InviteSuggestion.ChannelItem) inviteSuggestion2;
obj = new InviteSuggestionItemV2.ChannelItem(channelItem.getChannel(), set.contains(Long.valueOf(channelItem.getChannel().h())), str);
} else if (inviteSuggestion2 instanceof InviteSuggestion.UserSuggestion) {
InviteSuggestion.UserSuggestion userSuggestion = (InviteSuggestion.UserSuggestion) inviteSuggestion2;
obj = new InviteSuggestionItemV2.UserItem(userSuggestion.getUser(), u.contains(set, map2.get(Long.valueOf(userSuggestion.getUser().getId()))), str);
} else {
throw new NoWhenBranchMatchedException();
}
list.add(obj);
}
} else {
list = d0.t.m.listOf(InviteSuggestionItemV2.SearchNoResultsItem.INSTANCE);
}
boolean z3 = guildInvite != null ? !guildInvite.isStaticInvite() : true;
ModelInvite.Settings inviteSettings = valid.getInviteSettings();
Map<Long, Channel> invitableChannels = valid.getInvitableChannels();
if (guildInvite != null) {
l = guildInvite.getChannelId();
}
return new ViewState(guildInvite, inviteSettings, list, invitableChannels.get(l), str, map, z3, valid.getGuild().getId());
}
private final void generateInviteForChannel(long j) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(StoreInviteSettings.generateInvite$default(this.storeInviteSettings, j, null, 2, null), false, 1, null), this, null, 2, null), GuildInviteShareSheetViewModel.class, (Context) null, (Function1) null, new GuildInviteShareSheetViewModel$generateInviteForChannel$2(this), (Function0) null, (Function0) null, new GuildInviteShareSheetViewModel$generateInviteForChannel$1(this), 54, (Object) null);
}
@MainThread
private final void handleInviteCreationFailure() {
Guild guild;
String vanityUrlCode;
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null && (vanityUrlCode = (guild = valid.getGuild()).getVanityUrlCode()) != null) {
ModelInvite createForStaticUrl = ModelInvite.createForStaticUrl(vanityUrlCode, GuildUtilsKt.createApiGuild(guild));
GuildInvite.Companion companion = GuildInvite.Companion;
m.checkNotNullExpressionValue(createForStaticUrl, "vanityUrlInvite");
GuildInvite createFromModelInvite = companion.createFromModelInvite(createForStaticUrl);
this.invite = createFromModelInvite;
updateViewState(createViewState(this.searchQuery, this.sentInvites, valid, createFromModelInvite));
}
}
@MainThread
private final void handleInviteCreationSuccess(ModelInvite modelInvite) {
GuildInvite createFromModelInvite = GuildInvite.Companion.createFromModelInvite(modelInvite);
this.invite = createFromModelInvite;
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null) {
updateViewState(createViewState(this.searchQuery, this.sentInvites, valid, createFromModelInvite));
}
}
@MainThread
private final void handleStoreState(StoreState storeState) {
StoreState storeState2 = this.currentStoreState;
if (m.areEqual(storeState, StoreState.Invalid.INSTANCE)) {
Logger logger = this.logger;
StringBuilder R = a.R("invalid StoreState in ");
R.append(GuildInviteShareSheetViewModel.class.getSimpleName());
Logger.e$default(logger, R.toString(), null, null, 6, null);
return;
}
if (storeState instanceof StoreState.Valid) {
Channel channel = this.targetChannel;
StoreState.Valid valid = (StoreState.Valid) storeState;
Channel targetChannel = this.targetChannelSelector.getTargetChannel(valid.getInvitableChannels(), this.channelId);
Guild guild = valid.getGuild();
String vanityUrlCode = valid.getGuild().getVanityUrlCode();
StageInstance stageInstance = valid.getGuildStageInstances().get(this.channelId);
String d = stageInstance != null ? stageInstance.d() : null;
if (this.invite == null) {
boolean z2 = true;
boolean z3 = this.channelId == null;
if (storeState2 == null) {
if (!(vanityUrlCode == null || vanityUrlCode.length() == 0)) {
z2 = false;
}
if (!z2 && z3) {
ModelInvite createForStaticUrl = ModelInvite.createForStaticUrl(vanityUrlCode, GuildUtilsKt.createApiGuild(guild));
GuildInvite.Companion companion = GuildInvite.Companion;
m.checkNotNullExpressionValue(createForStaticUrl, "vanityUrlInvite");
this.invite = companion.createFromModelInvite(createForStaticUrl);
}
}
if (channel == null && targetChannel != null) {
generateInviteForChannel(targetChannel.h());
} else if (d != null) {
ModelInvite createForStaticUrl2 = ModelInvite.createForStaticUrl(d, GuildUtilsKt.createApiGuild(guild));
GuildInvite.Companion companion2 = GuildInvite.Companion;
m.checkNotNullExpressionValue(createForStaticUrl2, "stageInstanceInvite");
this.invite = companion2.createFromModelInvite(createForStaticUrl2);
}
}
this.targetChannel = targetChannel;
updateViewState(createViewState(this.searchQuery, this.sentInvites, valid, this.invite));
}
this.currentStoreState = storeState;
}
@MainThread
private final void sendInviteToChannel(long j) {
ViewState viewState;
GuildInvite guildInvite;
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null && (viewState = getViewState()) != null && (guildInvite = this.invite) != null) {
String link = guildInvite.toLink();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(StoreMessages.sendMessage$default(this.storeMessages, j, valid.getMe(), link, null, null, null, null, null, null, null, null, null, null, null, 16352, null), this, null, 2, null), GuildInviteShareSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new GuildInviteShareSheetViewModel$sendInviteToChannel$1(this, guildInvite, viewState, link), 62, (Object) null);
}
}
private final void sendInviteToUser(long j) {
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().createOrFetchDM(j), false, 1, null), this, null, 2, null), GuildInviteShareSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new GuildInviteShareSheetViewModel$sendInviteToUser$1(this), 62, (Object) null);
}
@MainThread
private final void updateSearchQuery(String str) {
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null && !m.areEqual(str, this.searchQuery)) {
this.searchQuery = str;
updateViewState(createViewState(str, this.sentInvites, valid, this.invite));
}
}
@MainThread
private final void updateSentInvites(Map<String, ? extends Set<Long>> map) {
this.sentInvites = map;
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null) {
updateViewState(createViewState(this.searchQuery, map, valid, this.invite));
}
}
public final long getGuildId() {
return this.guildId;
}
public final void onSearchTextChanged(String str) {
m.checkNotNullParameter(str, "searchQuery");
this.searchQuerySubject.onNext(str);
}
@MainThread
public final void sendInvite(InviteSuggestionItemV2 inviteSuggestionItemV2) {
m.checkNotNullParameter(inviteSuggestionItemV2, "item");
if (inviteSuggestionItemV2 instanceof InviteSuggestionItemV2.ChannelItem) {
sendInviteToChannel(((InviteSuggestionItemV2.ChannelItem) inviteSuggestionItemV2).getChannel().h());
} else if (inviteSuggestionItemV2 instanceof InviteSuggestionItemV2.UserItem) {
sendInviteToUser(((InviteSuggestionItemV2.UserItem) inviteSuggestionItemV2).getUser().getId());
}
}
@MainThread
public final void updateInvite(GuildInvite guildInvite) {
m.checkNotNullParameter(guildInvite, "invite");
this.invite = guildInvite;
ViewState viewState = getViewState();
if (viewState != null) {
StoreState storeState = this.currentStoreState;
if (!(storeState instanceof StoreState.Valid)) {
storeState = null;
}
StoreState.Valid valid = (StoreState.Valid) storeState;
if (valid != null) {
updateViewState(ViewState.copy$default(viewState, guildInvite, null, null, valid.getInvitableChannels().get(guildInvite.getChannelId()), null, null, false, 0, 246, null));
}
}
}
@MainThread
public void updateViewState(ViewState viewState) {
m.checkNotNullParameter(viewState, "viewState");
super.updateViewState((GuildInviteShareSheetViewModel) viewState);
if (viewState.getHasSearchResults() && !this.hasTrackedSuggestionsViewed) {
long guildId = viewState.getGuildId();
List<InviteSuggestionItemV2> inviteSuggestionItems = viewState.getInviteSuggestionItems();
StoreAnalytics storeAnalytics = this.storeAnalytics;
ArrayList<InviteSuggestionItemV2.ChannelItem> arrayList = new ArrayList();
for (Object obj : inviteSuggestionItems) {
if (obj instanceof InviteSuggestionItemV2.ChannelItem) {
arrayList.add(obj);
}
}
ArrayList arrayList2 = new ArrayList(d0.t.o.collectionSizeOrDefault(arrayList, 10));
for (InviteSuggestionItemV2.ChannelItem channelItem : arrayList) {
arrayList2.add(channelItem.getChannel());
}
ArrayList<InviteSuggestionItemV2.UserItem> arrayList3 = new ArrayList();
for (Object obj2 : inviteSuggestionItems) {
if (obj2 instanceof InviteSuggestionItemV2.UserItem) {
arrayList3.add(obj2);
}
}
ArrayList arrayList4 = new ArrayList(d0.t.o.collectionSizeOrDefault(arrayList3, 10));
for (InviteSuggestionItemV2.UserItem userItem : arrayList3) {
arrayList4.add(userItem.getUser());
}
storeAnalytics.inviteSuggestionOpened(guildId, arrayList2, arrayList4);
this.hasTrackedSuggestionsViewed = true;
}
}
}