package com.discord.stores; import a0.a.a.b; import android.content.Context; import c.d.b.a.a; import com.discord.api.user.NsfwAllowance; import com.discord.stores.updates.ObservationDeck; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.search.history.MGPreferenceSearchHistoryCache; import com.discord.utilities.search.history.SearchHistoryCache; import com.discord.utilities.search.network.SearchFetcher; import com.discord.utilities.search.query.node.QueryNode; import com.discord.utilities.search.strings.SearchStringProvider; import com.discord.utilities.search.suggestion.SearchSuggestionEngine; import d0.z.d.m; import java.util.Collection; import java.util.List; import kotlin.NoWhenBranchMatchedException; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import rx.Observable; import rx.Subscription; import rx.subjects.BehaviorSubject; import rx.subjects.SerializedSubject; /* compiled from: StoreSearch.kt */ public final class StoreSearch { private final Dispatcher dispatcher; private final SerializedSubject displayStateSubject; private final SearchHistoryCache historyCache; private SearchTarget searchTarget; private final SerializedSubject searchTargetSubject; private final StoreGuildsNsfw storeGuildsNsfw; private final StoreSearchData storeSearchData; private final StoreSearchInput storeSearchInput; private final StoreSearchQuery storeSearchQuery; private final StoreUser storeUser; private final StoreStream stream; private Subscription subscription; /* compiled from: StoreSearch.kt */ public enum DisplayState { SUGGESTIONS, RESULTS } /* compiled from: StoreSearch.kt */ public static final class SearchTarget { /* renamed from: id reason: collision with root package name */ private final long f2105id; private final Type type; /* compiled from: StoreSearch.kt */ public enum Type { GUILD, CHANNEL } public SearchTarget(Type type, long j) { m.checkNotNullParameter(type, "type"); this.type = type; this.f2105id = j; } public static /* synthetic */ SearchTarget copy$default(SearchTarget searchTarget, Type type, long j, int i, Object obj) { if ((i & 1) != 0) { type = searchTarget.type; } if ((i & 2) != 0) { j = searchTarget.f2105id; } return searchTarget.copy(type, j); } public final Type component1() { return this.type; } public final long component2() { return this.f2105id; } public final SearchTarget copy(Type type, long j) { m.checkNotNullParameter(type, "type"); return new SearchTarget(type, j); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof SearchTarget)) { return false; } SearchTarget searchTarget = (SearchTarget) obj; return m.areEqual(this.type, searchTarget.type) && this.f2105id == searchTarget.f2105id; } public final long getId() { return this.f2105id; } public final Type getType() { return this.type; } public int hashCode() { Type type = this.type; return b.a(this.f2105id) + ((type != null ? type.hashCode() : 0) * 31); } public String toString() { StringBuilder L = a.L("SearchTarget(type="); L.append(this.type); L.append(", id="); return a.A(L, this.f2105id, ")"); } } public final /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; static { SearchTarget.Type.values(); int[] iArr = new int[2]; $EnumSwitchMapping$0 = iArr; iArr[SearchTarget.Type.GUILD.ordinal()] = 1; iArr[SearchTarget.Type.CHANNEL.ordinal()] = 2; } } public StoreSearch(StoreSearchData storeSearchData, StoreSearchInput storeSearchInput, StoreSearchQuery storeSearchQuery, StoreStream storeStream, Dispatcher dispatcher, StoreGuildsNsfw storeGuildsNsfw, StoreUser storeUser, SearchHistoryCache searchHistoryCache) { m.checkNotNullParameter(storeSearchData, "storeSearchData"); m.checkNotNullParameter(storeSearchInput, "storeSearchInput"); m.checkNotNullParameter(storeSearchQuery, "storeSearchQuery"); m.checkNotNullParameter(storeStream, "stream"); m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(storeGuildsNsfw, "storeGuildsNsfw"); m.checkNotNullParameter(storeUser, "storeUser"); m.checkNotNullParameter(searchHistoryCache, "historyCache"); this.storeSearchData = storeSearchData; this.storeSearchInput = storeSearchInput; this.storeSearchQuery = storeSearchQuery; this.stream = storeStream; this.dispatcher = dispatcher; this.storeGuildsNsfw = storeGuildsNsfw; this.storeUser = storeUser; this.historyCache = searchHistoryCache; this.displayStateSubject = new SerializedSubject<>(BehaviorSubject.l0(DisplayState.SUGGESTIONS)); this.searchTargetSubject = new SerializedSubject<>(BehaviorSubject.k0()); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public StoreSearch(StoreStream storeStream, Dispatcher dispatcher, StoreGuildsNsfw storeGuildsNsfw, StoreUser storeUser, ObservationDeck observationDeck, StoreChannels storeChannels, StoreGuilds storeGuilds) { this(new StoreSearchData(observationDeck, storeChannels, storeUser, storeGuilds), new StoreSearchInput(), new StoreSearchQuery(new SearchFetcher()), storeStream, dispatcher, storeGuildsNsfw, storeUser, new MGPreferenceSearchHistoryCache()); m.checkNotNullParameter(storeStream, "stream"); m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(storeGuildsNsfw, "storeGuildsNsfw"); m.checkNotNullParameter(storeUser, "storeUser"); m.checkNotNullParameter(observationDeck, "observationDeck"); m.checkNotNullParameter(storeChannels, "storeChannels"); m.checkNotNullParameter(storeGuilds, "storeGuilds"); } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreSearch storeSearch) { return storeSearch.dispatcher; } public static final /* synthetic */ SearchHistoryCache access$getHistoryCache$p(StoreSearch storeSearch) { return storeSearch.historyCache; } public static final /* synthetic */ StoreStream access$getStream$p(StoreSearch storeSearch) { return storeSearch.stream; } public static final /* synthetic */ void access$handleSubscription(StoreSearch storeSearch, Subscription subscription) { storeSearch.handleSubscription(subscription); } public static final /* synthetic */ void access$onStateChanged(StoreSearch storeSearch, DisplayState displayState) { storeSearch.onStateChanged(displayState); } private final synchronized void handleSubscription(Subscription subscription) { Subscription subscription2 = this.subscription; if (subscription2 != null) { subscription2.unsubscribe(); } this.subscription = subscription; } private final boolean includeNsfw(SearchTarget searchTarget) { if (this.storeUser.getMe().getNsfwAllowance() == NsfwAllowance.DISALLOWED) { return false; } int ordinal = searchTarget.getType().ordinal(); if (ordinal == 0) { return this.storeGuildsNsfw.isGuildNsfwGateAgreed(searchTarget.getId()); } if (ordinal == 1) { return true; } throw new NoWhenBranchMatchedException(); } private final synchronized void init(SearchTarget searchTarget, SearchStringProvider searchStringProvider) { if (!m.areEqual(this.searchTarget, searchTarget)) { updateTarget(searchTarget); this.storeSearchData.init(searchTarget); this.storeSearchInput.init(searchStringProvider); Observable H = Observable.H(this.storeSearchQuery.getState().x(StoreSearch$init$1.INSTANCE).F(StoreSearch$init$2.INSTANCE), this.storeSearchInput.getCurrentParsedInput().F(StoreSearch$init$3.INSTANCE)); m.checkNotNullExpressionValue(H, "Observable\n .merg…splayState.SUGGESTIONS })"); ObservableExtensionsKt.appSubscribe$default(H, getClass(), (Context) null, new StoreSearch$init$4(this), (Function1) null, (Function0) null, (Function0) null, new StoreSearch$init$5(this), 58, (Object) null); ObservableExtensionsKt.appSubscribe$default(this.storeSearchQuery.getState(), getClass(), (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreSearch$init$6(this), 62, (Object) null); } } private final void onStateChanged(DisplayState displayState) { this.displayStateSubject.j.onNext(displayState); } private final synchronized void updateTarget(SearchTarget searchTarget) { this.searchTarget = searchTarget; this.searchTargetSubject.j.onNext(searchTarget); } public final synchronized void clear() { updateTarget(null); handleSubscription(null); onStateChanged(DisplayState.SUGGESTIONS); this.storeSearchQuery.clear(); this.storeSearchInput.clear(); this.storeSearchData.clear(); } public final void clearHistory() { SearchHistoryCache searchHistoryCache = this.historyCache; SearchTarget searchTarget = this.searchTarget; if (searchTarget != null) { searchHistoryCache.clear(searchTarget); } } public final Observable getDisplayState() { Observable r = ObservableExtensionsKt.computationLatest(this.displayStateSubject).r(); m.checkNotNullExpressionValue(r, "displayStateSubject\n … .distinctUntilChanged()"); return r; } public final Observable>> getHistory() { Observable Y = this.searchTargetSubject.Y(new StoreSearch$getHistory$1(this)); m.checkNotNullExpressionValue(Y, "searchTargetSubject\n …())\n }\n }"); return Y; } public final StoreSearchData getStoreSearchData() { return this.storeSearchData; } public final StoreSearchInput getStoreSearchInput() { return this.storeSearchInput; } public final StoreSearchQuery getStoreSearchQuery() { return this.storeSearchQuery; } public final void initForChannel(long j, SearchStringProvider searchStringProvider) { m.checkNotNullParameter(searchStringProvider, "searchStringProvider"); init(new SearchTarget(SearchTarget.Type.CHANNEL, j), searchStringProvider); SearchSuggestionEngine.INSTANCE.setTargetGuildId(null); } public final void initForGuild(long j, SearchStringProvider searchStringProvider) { m.checkNotNullParameter(searchStringProvider, "searchStringProvider"); init(new SearchTarget(SearchTarget.Type.GUILD, j), searchStringProvider); SearchSuggestionEngine.INSTANCE.setTargetGuildId(Long.valueOf(j)); } public final void loadInitial(String str, SearchStringProvider searchStringProvider) { m.checkNotNullParameter(str, "queryString"); m.checkNotNullParameter(searchStringProvider, "searchStringProvider"); SearchTarget searchTarget = this.searchTarget; if (searchTarget != null) { this.storeSearchQuery.parseAndQuery(this, searchTarget, str, searchStringProvider, includeNsfw(searchTarget)); } } public final void loadMore(long j) { SearchTarget searchTarget = this.searchTarget; if (searchTarget != null) { this.storeSearchQuery.loadMore(searchTarget, j); } } public final void persistQuery$app_productionBetaRelease(SearchTarget searchTarget, List list) { m.checkNotNullParameter(searchTarget, "searchTarget"); m.checkNotNullParameter(list, "query"); this.historyCache.persistQuery(searchTarget, list); } }