package com.discord.stores; import com.discord.api.friendsuggestions.FriendSuggestionDelete; import com.discord.api.friendsuggestions.FriendSuggestionReason; import com.discord.models.domain.ModelPayload; import com.discord.models.friendsuggestions.FriendSuggestion; import com.discord.models.user.CoreUser; import com.discord.utilities.friendsuggestions.FriendSuggestionsFetcher; import d0.t.h0; import d0.t.u; import d0.z.d.m; import java.util.HashMap; import java.util.List; import java.util.Map; /* compiled from: StoreFriendSuggestions.kt */ public final class StoreFriendSuggestions extends StoreV2 { private final FriendSuggestionsFetcher friendSuggestionsFetcher; private final Map suggestions = new HashMap(); private Map suggestionsSnapshot = h0.emptyMap(); public StoreFriendSuggestions(FriendSuggestionsFetcher friendSuggestionsFetcher) { m.checkNotNullParameter(friendSuggestionsFetcher, "friendSuggestionsFetcher"); this.friendSuggestionsFetcher = friendSuggestionsFetcher; } private final FriendSuggestion convertApiFriendSuggestion(com.discord.api.friendsuggestions.FriendSuggestion friendSuggestion) { CoreUser coreUser = new CoreUser(friendSuggestion.b()); FriendSuggestionReason friendSuggestionReason = (FriendSuggestionReason) u.firstOrNull((List) friendSuggestion.a()); return new FriendSuggestion(coreUser, friendSuggestionReason != null ? friendSuggestionReason.a() : null); } public final Map getFriendSuggestions() { return this.suggestionsSnapshot; } public final FriendSuggestionsFetcher getFriendSuggestionsFetcher() { return this.friendSuggestionsFetcher; } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "readyPayload"); this.suggestions.clear(); if (modelPayload.getFriendSuggestionCount() > 0) { this.friendSuggestionsFetcher.maybeFetch(); } markChanged(); } @StoreThread public final void handleFriendSuggestionCreate(com.discord.api.friendsuggestions.FriendSuggestion friendSuggestion) { m.checkNotNullParameter(friendSuggestion, "friendSuggestionCreate"); CoreUser coreUser = new CoreUser(friendSuggestion.b()); FriendSuggestionReason friendSuggestionReason = (FriendSuggestionReason) u.firstOrNull((List) friendSuggestion.a()); FriendSuggestion friendSuggestion2 = new FriendSuggestion(coreUser, friendSuggestionReason != null ? friendSuggestionReason.a() : null); this.suggestions.put(Long.valueOf(friendSuggestion2.getUser().getId()), friendSuggestion2); markChanged(); } @StoreThread public final void handleFriendSuggestionDelete(FriendSuggestionDelete friendSuggestionDelete) { m.checkNotNullParameter(friendSuggestionDelete, "friendSuggestionDelete"); if (this.suggestions.remove(Long.valueOf(friendSuggestionDelete.a())) != null) { markChanged(); } } @StoreThread public final void handleFriendSuggestionsLoadFailure() { this.suggestions.clear(); markChanged(); } @StoreThread public final void handleFriendSuggestionsLoaded(List list) { m.checkNotNullParameter(list, "loadedSuggestions"); this.suggestions.clear(); Map map = this.suggestions; for (com.discord.api.friendsuggestions.FriendSuggestion friendSuggestion : list) { map.put(Long.valueOf(friendSuggestion.b().i()), convertApiFriendSuggestion(friendSuggestion)); } markChanged(); } @Override // com.discord.stores.StoreV2 public void snapshotData() { super.snapshotData(); this.suggestionsSnapshot = new HashMap(this.suggestions); } }