package com.discord.stores; import c.d.b.a.a; import com.airbnb.lottie.parser.AnimatableValueParser; import com.discord.api.channel.Channel; import com.discord.api.guild.Guild; import com.discord.api.guildmember.GuildMember; import com.discord.api.thread.ThreadMembersUpdate; import com.discord.api.user.User; import com.discord.api.utcdatetime.UtcDateTime; import com.discord.models.domain.ModelMessageDelete; import com.discord.models.domain.ModelNotificationSettings; import com.discord.models.domain.ModelPayload; import com.discord.models.domain.ModelReadState; import com.discord.models.domain.ModelUserRelationship; import com.discord.models.message.Message; import com.discord.models.thread.dto.ModelThreadListSync; import com.discord.stores.StoreMessageAck; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import com.discord.utilities.permissions.PermissionUtils; import com.discord.utilities.persister.Persister; import d0.t.h0; import d0.t.o; import d0.t.r; import d0.t.u; import d0.z.d.m; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreMentions.kt */ public final class StoreMentions extends StoreV2 { private final HashMap channelGuildIds; private final Persister> countsCache; private final Map countsEmpty; private Map countsSnapshot; private final HashMap mentionedMessages; private long myId; private final HashMap> myRoleIds; private final ObservationDeck observationDeck; private final HashSet privateChannels; private long selectedChannelId; private final ArrayList serverInitReadStates; private final StoreChannels storeChannels; private final StoreMessageAck storeMessageAck; private final StorePermissions storePermissions; private final StoreUserGuildSettings storeUserGuildSettings; private final StoreUserRelationships storeUserRelationships; public StoreMentions(StoreUserRelationships storeUserRelationships, StorePermissions storePermissions, StoreMessageAck storeMessageAck, StoreUserGuildSettings storeUserGuildSettings, StoreChannels storeChannels, ObservationDeck observationDeck) { m.checkNotNullParameter(storeUserRelationships, "storeUserRelationships"); m.checkNotNullParameter(storePermissions, "storePermissions"); m.checkNotNullParameter(storeMessageAck, "storeMessageAck"); m.checkNotNullParameter(storeUserGuildSettings, "storeUserGuildSettings"); m.checkNotNullParameter(storeChannels, "storeChannels"); m.checkNotNullParameter(observationDeck, "observationDeck"); this.storeUserRelationships = storeUserRelationships; this.storePermissions = storePermissions; this.storeMessageAck = storeMessageAck; this.storeUserGuildSettings = storeUserGuildSettings; this.storeChannels = storeChannels; this.observationDeck = observationDeck; HashMap hashMap = new HashMap(); this.countsEmpty = hashMap; this.countsCache = new Persister<>("CHANNEL_MENTION_COUNTS_V6", hashMap); this.countsSnapshot = h0.emptyMap(); this.serverInitReadStates = new ArrayList<>(); this.mentionedMessages = new HashMap<>(); this.privateChannels = new HashSet<>(); this.myRoleIds = new HashMap<>(); this.channelGuildIds = new HashMap<>(); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreMentions(StoreUserRelationships storeUserRelationships, StorePermissions storePermissions, StoreMessageAck storeMessageAck, StoreUserGuildSettings storeUserGuildSettings, StoreChannels storeChannels, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) { this(storeUserRelationships, storePermissions, storeMessageAck, storeUserGuildSettings, storeChannels, (i & 32) != 0 ? ObservationDeckProvider.get() : observationDeck); } public static final /* synthetic */ StoreChannels access$getStoreChannels$p(StoreMentions storeMentions) { return storeMentions.storeChannels; } @StoreThread private final Map computeMentionCounts() { StoreMessageAck.Ack ack; if (this.serverInitReadStates.isEmpty() && this.mentionedMessages.isEmpty()) { return this.countsEmpty; } HashMap hashMap = new HashMap(); Map allInternal = this.storeMessageAck.getAllInternal(); Iterator it = this.serverInitReadStates.iterator(); while (it.hasNext()) { ModelReadState next = it.next(); long component1 = next.component1(); long component2 = next.component2(); int component3 = next.component3(); if (component3 >= 1 && isMentionableChannel(component1) && (ack = allInternal.get(Long.valueOf(component1))) != null && ack.component1() <= component2) { Long valueOf = Long.valueOf(component1); Integer num = (Integer) hashMap.get(Long.valueOf(component1)); if (num == null) { num = 0; } hashMap.put(valueOf, Integer.valueOf(num.intValue() + component3)); } } for (Message message : this.mentionedMessages.values()) { long channelId = message.getChannelId(); User author = message.getAuthor(); if (!ModelUserRelationship.isType(this.storeUserRelationships.getRelationships().get(author != null ? Long.valueOf(author.i()) : null), 2) && isMentionableChannel(channelId)) { StoreMessageAck.Ack ack2 = allInternal.get(Long.valueOf(channelId)); if (ack2 == null || ack2.component1() < message.getId()) { Long valueOf2 = Long.valueOf(channelId); Integer num2 = (Integer) hashMap.get(Long.valueOf(channelId)); if (num2 == null) { num2 = 0; } hashMap.put(valueOf2, Integer.valueOf(num2.intValue() + 1)); } } } return hashMap; } /* JADX WARNING: Removed duplicated region for block: B:36:0x008f A[RETURN] */ @StoreThread private final boolean hasMention(long j, User user, UtcDateTime utcDateTime, List list, List list2, Boolean bool) { List list3; boolean z2; boolean z3; ModelNotificationSettings modelNotificationSettings; ModelNotificationSettings.ChannelOverride channelOverride; Long l = this.channelGuildIds.get(Long.valueOf(j)); if (l == null) { l = 0L; } m.checkNotNullExpressionValue(l, "channelGuildIds[channelId] ?: 0"); long longValue = l.longValue(); if (user == null || user.i() != this.myId) { if ((utcDateTime != null ? utcDateTime.f() : 0) <= 0) { Map guildSettingsInternal$app_productionBetaRelease = this.storeUserGuildSettings.getGuildSettingsInternal$app_productionBetaRelease(); if (this.privateChannels.contains(Long.valueOf(j)) && ((modelNotificationSettings = guildSettingsInternal$app_productionBetaRelease.get(0L)) == null || (channelOverride = modelNotificationSettings.getChannelOverride(j)) == null || !channelOverride.isMuted())) { return true; } if (list != null) { if (!list.isEmpty()) { Iterator it = list.iterator(); while (true) { if (!it.hasNext()) { break; } if (((User) it.next()).i() == this.myId) { z3 = true; continue; } else { z3 = false; continue; } if (z3) { z2 = true; break; } } if (z2) { return true; } } z2 = false; if (z2) { } } ModelNotificationSettings modelNotificationSettings2 = guildSettingsInternal$app_productionBetaRelease.get(Long.valueOf(longValue)); if (!((modelNotificationSettings2 != null && modelNotificationSettings2.isSuppressRoles()) || (list3 = this.myRoleIds.get(Long.valueOf(longValue))) == null || list2 == null)) { Iterator it2 = list2.iterator(); if (it2.hasNext()) { return list3.contains(Long.valueOf(((Number) it2.next()).longValue())); } } if (!m.areEqual(bool, Boolean.TRUE)) { return false; } ModelNotificationSettings modelNotificationSettings3 = guildSettingsInternal$app_productionBetaRelease.get(Long.valueOf(longValue)); return modelNotificationSettings3 == null || !modelNotificationSettings3.isSuppressEveryone(); } } return false; } @StoreThread private final boolean hasMention(com.discord.api.message.Message message) { return hasMention(message.g(), message.e(), message.j(), message.t(), message.s(), message.r()); } @StoreThread private final boolean hasMention(Message message) { return hasMention(message.getChannelId(), message.getAuthor(), message.getEditedTimestamp(), message.getMentions(), message.getMentionRoles(), message.getMentionEveryone()); } @StoreThread private final boolean isMentionableChannel(long j) { StoreMessageAck.Ack ack = this.storeMessageAck.getAllInternal().get(Long.valueOf(j)); boolean isLockedAck = ack != null ? ack.isLockedAck() : false; if (j == this.selectedChannelId && !isLockedAck) { return false; } return this.privateChannels.contains(Long.valueOf(j)) || PermissionUtils.can(1024, this.storePermissions.getPermissionsByChannel().get(Long.valueOf(j))); } @StoreThread private final void removeAllMessagesForChannel(long j) { HashMap hashMap = this.mentionedMessages; LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry entry : hashMap.entrySet()) { if (entry.getValue().getChannelId() == j) { linkedHashMap.put(entry.getKey(), entry.getValue()); } } for (Number number : linkedHashMap.keySet()) { this.mentionedMessages.remove(Long.valueOf(number.longValue())); markChanged(); } } public final Map getMentionCounts() { return this.countsSnapshot; } @StoreThread public final void handleChannelOrThreadCreateOrUpdate(Channel channel) { m.checkNotNullParameter(channel, "channel"); this.channelGuildIds.put(Long.valueOf(channel.h()), Long.valueOf(channel.f())); if (AnimatableValueParser.s1(channel) && !AnimatableValueParser.p1(channel)) { this.privateChannels.add(Long.valueOf(channel.h())); } } @StoreThread public final void handleChannelOrThreadDelete(Channel channel) { m.checkNotNullParameter(channel, "channel"); this.channelGuildIds.remove(Long.valueOf(channel.h())); this.privateChannels.remove(Long.valueOf(channel.h())); removeAllMessagesForChannel(channel.h()); } @StoreThread public final void handleChannelSelected(long j) { this.selectedChannelId = j; markChanged(); } @StoreThread public final void handleConnectionOpen(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "payload"); this.privateChannels.clear(); this.mentionedMessages.clear(); this.channelGuildIds.clear(); this.myRoleIds.clear(); this.myId = modelPayload.getMe().i(); for (Guild guild : modelPayload.getGuilds()) { m.checkNotNullExpressionValue(guild, "guild"); handleGuildAdd(guild); } HashSet hashSet = this.privateChannels; List privateChannels = modelPayload.getPrivateChannels(); ArrayList S = a.S(privateChannels, "payload.privateChannels"); for (Object obj : privateChannels) { Channel channel = (Channel) obj; m.checkNotNullExpressionValue(channel, "it"); if (!AnimatableValueParser.p1(channel)) { S.add(obj); } } ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(S, 10)); for (Channel channel2 : S) { arrayList.add(Long.valueOf(channel2.h())); } hashSet.addAll(arrayList); ModelPayload.VersionedReadStates readState = modelPayload.getReadState(); m.checkNotNullExpressionValue(readState, "payload.readState"); if (!readState.isPartial()) { this.serverInitReadStates.clear(); } else { ModelPayload.VersionedReadStates readState2 = modelPayload.getReadState(); m.checkNotNullExpressionValue(readState2, "payload.readState"); List entries = readState2.getEntries(); m.checkNotNullExpressionValue(entries, "payload.readState.entries"); ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(entries, 10)); for (ModelReadState modelReadState : entries) { arrayList2.add(Long.valueOf(modelReadState.getChannelId())); } r.removeAll((List) this.serverInitReadStates, (Function1) new StoreMentions$handleConnectionOpen$3(u.toHashSet(arrayList2))); } ArrayList arrayList3 = this.serverInitReadStates; ModelPayload.VersionedReadStates readState3 = modelPayload.getReadState(); m.checkNotNullExpressionValue(readState3, "payload.readState"); List entries2 = readState3.getEntries(); m.checkNotNullExpressionValue(entries2, "payload.readState.entries"); ArrayList arrayList4 = new ArrayList(); for (Object obj2 : entries2) { if (((ModelReadState) obj2).isMentioned()) { arrayList4.add(obj2); } } arrayList3.addAll(arrayList4); r.removeAll((List) this.serverInitReadStates, (Function1) new StoreMentions$handleConnectionOpen$5(this)); markChanged(); } @StoreThread public final void handleGuildAdd(Guild guild) { Object obj; boolean z2; m.checkNotNullParameter(guild, "guild"); List s2 = guild.s(); if (s2 != null) { Iterator it = s2.iterator(); while (true) { if (!it.hasNext()) { obj = null; break; } obj = it.next(); if (((GuildMember) obj).j().i() == this.myId) { z2 = true; continue; } else { z2 = false; continue; } if (z2) { break; } } GuildMember guildMember = (GuildMember) obj; if (guildMember != null) { this.myRoleIds.put(Long.valueOf(guild.o()), guildMember.i()); } } List g = guild.g(); if (g != null) { for (Channel channel : g) { this.channelGuildIds.put(Long.valueOf(channel.h()), Long.valueOf(guild.o())); } } List K = guild.K(); if (K != null) { for (Channel channel2 : K) { this.channelGuildIds.put(Long.valueOf(channel2.h()), Long.valueOf(guild.o())); } } } @StoreThread public final void handleGuildMemberAdd(GuildMember guildMember) { m.checkNotNullParameter(guildMember, "member"); long i = guildMember.j().i(); if (i == this.myId) { this.myRoleIds.put(Long.valueOf(i), guildMember.i()); } } @StoreThread public final void handleMessageAck(ModelReadState modelReadState) { m.checkNotNullParameter(modelReadState, "readState"); r.removeAll((List) this.serverInitReadStates, (Function1) new StoreMentions$handleMessageAck$1(modelReadState)); this.serverInitReadStates.add(modelReadState); markChanged(); } @StoreThread public final void handleMessageCreateOrUpdate(com.discord.api.message.Message message) { m.checkNotNullParameter(message, "message"); if (hasMention(message)) { this.mentionedMessages.put(Long.valueOf(message.o()), new Message(message)); markChanged(); } } @StoreThread public final void handleMessageDeleted(ModelMessageDelete modelMessageDelete) { m.checkNotNullParameter(modelMessageDelete, "messageDeleteBulk"); if (this.privateChannels.contains(Long.valueOf(modelMessageDelete.getChannelId()))) { List messageIds = modelMessageDelete.getMessageIds(); m.checkNotNullExpressionValue(messageIds, "messageDeleteBulk.messageIds"); for (Long l : messageIds) { HashMap hashMap = this.mentionedMessages; m.checkNotNullExpressionValue(l, "it"); hashMap.remove(l); } markChanged(); } } @StoreThread public final void handleThreadListSync(ModelThreadListSync modelThreadListSync) { m.checkNotNullParameter(modelThreadListSync, "payload"); for (Channel channel : modelThreadListSync.getThreads()) { this.channelGuildIds.put(Long.valueOf(channel.h()), Long.valueOf(modelThreadListSync.getGuildId())); } } @StoreThread public final void handleThreadMembersUpdate(ThreadMembersUpdate threadMembersUpdate) { m.checkNotNullParameter(threadMembersUpdate, "payload"); List d = threadMembersUpdate.d(); if (d != null && d.contains(Long.valueOf(this.myId))) { removeAllMessagesForChannel(threadMembersUpdate.c()); } } public final Observable> observeMentionCounts() { Observable> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreMentions$observeMentionCounts$1(this), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()"); return r; } public final Observable observeTotalMentions() { Observable F = observeMentionCounts().F(StoreMentions$observeTotalMentions$1.INSTANCE); m.checkNotNullExpressionValue(F, "observeMentionCounts()\n … .map { it.values.sum() }"); return F; } @StoreThread public final int processMarkUnread$app_productionBetaRelease(long j, List list) { m.checkNotNullParameter(list, "messagesAfter"); int i = 0; for (Message message : list) { if (!this.mentionedMessages.containsKey(Long.valueOf(message.getId())) && hasMention(message)) { this.mentionedMessages.put(Long.valueOf(message.getId()), message); i++; } } r.removeAll((List) this.serverInitReadStates, (Function1) new StoreMentions$processMarkUnread$1(j)); markChanged(); return i; } @Override // com.discord.stores.StoreV2 @StoreThread public void snapshotData() { super.snapshotData(); Map computeMentionCounts = computeMentionCounts(); Persister.set$default(this.countsCache, computeMentionCounts, false, 2, null); this.countsSnapshot = computeMentionCounts; } }