369 lines
14 KiB
Java
369 lines
14 KiB
Java
package com.discord.stores;
|
|
|
|
import c.d.b.a.a;
|
|
import com.discord.api.message.MessageReference;
|
|
import com.discord.models.domain.ModelMessage;
|
|
import com.discord.models.domain.ModelMessageDelete;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import d0.d0.f;
|
|
import d0.t.g0;
|
|
import d0.t.h0;
|
|
import d0.t.m0;
|
|
import d0.t.n0;
|
|
import d0.t.o;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public final class StoreMessageReplies extends StoreV2 {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final Map<Long, MessageState> NO_RESULTS = h0.emptyMap();
|
|
private final HashMap<Long, Set<Long>> channelMap;
|
|
private final Dispatcher dispatcher;
|
|
private final ObservationDeck observationDeck;
|
|
private Map<Long, ? extends Map<Long, ? extends MessageState>> repliedChannelMessagesCacheSnapshot;
|
|
private final MessageCache<Long, MessageState> repliedMessagesCache;
|
|
private Map<Long, ? extends MessageState> repliedMessagesCacheSnapshot;
|
|
private final StoreMessages storeMessages;
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static final class MessageCache<K, V> extends LinkedHashMap<K, V> {
|
|
@Override // java.util.LinkedHashMap, java.util.AbstractMap, java.util.Map, java.util.HashMap
|
|
public final /* bridge */ Set<Map.Entry<K, V>> entrySet() {
|
|
return getEntries();
|
|
}
|
|
|
|
public /* bridge */ Set getEntries() {
|
|
return super.entrySet();
|
|
}
|
|
|
|
public /* bridge */ Set getKeys() {
|
|
return super.keySet();
|
|
}
|
|
|
|
public /* bridge */ int getSize() {
|
|
return super.size();
|
|
}
|
|
|
|
public /* bridge */ Collection getValues() {
|
|
return super.values();
|
|
}
|
|
|
|
@Override // java.util.LinkedHashMap, java.util.AbstractMap, java.util.Map, java.util.HashMap
|
|
public final /* bridge */ Set<K> keySet() {
|
|
return getKeys();
|
|
}
|
|
|
|
@Override // java.util.LinkedHashMap
|
|
public boolean removeEldestEntry(Map.Entry<K, V> entry) {
|
|
return size() > 1000;
|
|
}
|
|
|
|
@Override // java.util.AbstractMap, java.util.Map, java.util.HashMap
|
|
public final /* bridge */ int size() {
|
|
return getSize();
|
|
}
|
|
|
|
@Override // java.util.LinkedHashMap, java.util.AbstractMap, java.util.Map, java.util.HashMap
|
|
public final /* bridge */ Collection<V> values() {
|
|
return getValues();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static abstract class MessageState {
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static final class Deleted extends MessageState {
|
|
public static final Deleted INSTANCE = new Deleted();
|
|
|
|
private Deleted() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static final class Loaded extends MessageState {
|
|
private final ModelMessage modelMessage;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Loaded(ModelMessage modelMessage) {
|
|
super(null);
|
|
m.checkNotNullParameter(modelMessage, "modelMessage");
|
|
this.modelMessage = modelMessage;
|
|
}
|
|
|
|
public static /* synthetic */ Loaded copy$default(Loaded loaded, ModelMessage modelMessage, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
modelMessage = loaded.modelMessage;
|
|
}
|
|
return loaded.copy(modelMessage);
|
|
}
|
|
|
|
public final ModelMessage component1() {
|
|
return this.modelMessage;
|
|
}
|
|
|
|
public final Loaded copy(ModelMessage modelMessage) {
|
|
m.checkNotNullParameter(modelMessage, "modelMessage");
|
|
return new Loaded(modelMessage);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Loaded) && m.areEqual(this.modelMessage, ((Loaded) obj).modelMessage);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final ModelMessage getModelMessage() {
|
|
return this.modelMessage;
|
|
}
|
|
|
|
public int hashCode() {
|
|
ModelMessage modelMessage = this.modelMessage;
|
|
if (modelMessage != null) {
|
|
return modelMessage.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Loaded(modelMessage=");
|
|
L.append(this.modelMessage);
|
|
L.append(")");
|
|
return L.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: StoreMessageReplies.kt */
|
|
public static final class Unloaded extends MessageState {
|
|
public static final Unloaded INSTANCE = new Unloaded();
|
|
|
|
private Unloaded() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private MessageState() {
|
|
}
|
|
|
|
public /* synthetic */ MessageState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public StoreMessageReplies(Dispatcher dispatcher, StoreMessages storeMessages, ObservationDeck observationDeck) {
|
|
m.checkNotNullParameter(dispatcher, "dispatcher");
|
|
m.checkNotNullParameter(storeMessages, "storeMessages");
|
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
|
this.dispatcher = dispatcher;
|
|
this.storeMessages = storeMessages;
|
|
this.observationDeck = observationDeck;
|
|
this.repliedMessagesCache = new MessageCache<>();
|
|
this.channelMap = new HashMap<>();
|
|
this.repliedChannelMessagesCacheSnapshot = h0.emptyMap();
|
|
this.repliedMessagesCacheSnapshot = h0.emptyMap();
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ StoreMessageReplies(Dispatcher dispatcher, StoreMessages storeMessages, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(dispatcher, storeMessages, (i & 4) != 0 ? ObservationDeckProvider.get() : observationDeck);
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$getCachedChannelMessages(StoreMessageReplies storeMessageReplies, long j) {
|
|
return storeMessageReplies.getCachedChannelMessages(j);
|
|
}
|
|
|
|
@StoreThread
|
|
private final boolean deleteMessage(long j, long j2) {
|
|
if (!this.repliedMessagesCache.containsKey(Long.valueOf(j))) {
|
|
return false;
|
|
}
|
|
updateCache(j, j2, MessageState.Deleted.INSTANCE);
|
|
return true;
|
|
}
|
|
|
|
private final Map<Long, MessageState> getCachedChannelMessages(long j) {
|
|
Map<Long, MessageState> map = (Map) this.repliedChannelMessagesCacheSnapshot.get(Long.valueOf(j));
|
|
return map != null ? map : NO_RESULTS;
|
|
}
|
|
|
|
@StoreThread
|
|
private final boolean processMessage(ModelMessage modelMessage) {
|
|
boolean z2;
|
|
if (this.repliedMessagesCache.containsKey(Long.valueOf(modelMessage.getId()))) {
|
|
updateCache(modelMessage.getId(), modelMessage.getChannelId(), new MessageState.Loaded(modelMessage));
|
|
z2 = true;
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
if (!modelMessage.isEmbeddedMessageType()) {
|
|
return z2;
|
|
}
|
|
MessageReference messageReference = modelMessage.getMessageReference();
|
|
if (messageReference == null) {
|
|
return z2;
|
|
}
|
|
m.checkNotNullExpressionValue(messageReference, "message.messageReference ?: return updated");
|
|
ModelMessage referencedMessage = modelMessage.getReferencedMessage();
|
|
Long a = messageReference.a();
|
|
Long c2 = messageReference.c();
|
|
if (referencedMessage != null) {
|
|
processReferencedMessage(referencedMessage);
|
|
return true;
|
|
} else if (a == null || c2 == null) {
|
|
return true;
|
|
} else {
|
|
ModelMessage message = this.storeMessages.getMessage(a.longValue(), c2.longValue());
|
|
if (message != null) {
|
|
processReferencedMessage(message);
|
|
return true;
|
|
}
|
|
updateCache(c2.longValue(), a.longValue(), MessageState.Unloaded.INSTANCE);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private final void processReferencedMessage(ModelMessage modelMessage) {
|
|
updateCache(modelMessage.getId(), modelMessage.getChannelId(), new MessageState.Loaded(modelMessage));
|
|
if (modelMessage.getType() == 19) {
|
|
processMessage(modelMessage);
|
|
}
|
|
}
|
|
|
|
private final void snapShotAllMessages() {
|
|
this.repliedMessagesCacheSnapshot = new HashMap(this.repliedMessagesCache);
|
|
}
|
|
|
|
@StoreThread
|
|
private final void snapShotChannelMessages() {
|
|
HashMap<Long, Set<Long>> hashMap = this.channelMap;
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap(g0.mapCapacity(hashMap.size()));
|
|
Iterator<T> it = hashMap.entrySet().iterator();
|
|
while (it.hasNext()) {
|
|
Map.Entry entry = (Map.Entry) it.next();
|
|
Object key = entry.getKey();
|
|
Set set = (Set) entry.getValue();
|
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap(f.coerceAtLeast(g0.mapCapacity(o.collectionSizeOrDefault(set, 10)), 16));
|
|
for (Object obj : set) {
|
|
Object obj2 = (MessageState) this.repliedMessagesCache.get(Long.valueOf(((Number) obj).longValue()));
|
|
if (obj2 == null) {
|
|
obj2 = MessageState.Unloaded.INSTANCE;
|
|
}
|
|
linkedHashMap2.put(obj, obj2);
|
|
}
|
|
linkedHashMap.put(key, linkedHashMap2);
|
|
}
|
|
this.repliedChannelMessagesCacheSnapshot = linkedHashMap;
|
|
}
|
|
|
|
@StoreThread
|
|
private final void updateCache(long j, long j2, MessageState messageState) {
|
|
this.repliedMessagesCache.put(Long.valueOf(j), messageState);
|
|
HashMap<Long, Set<Long>> hashMap = this.channelMap;
|
|
Long valueOf = Long.valueOf(j2);
|
|
Set of = m0.setOf(Long.valueOf(j));
|
|
Set<Long> set = this.channelMap.get(Long.valueOf(j2));
|
|
if (set == null) {
|
|
set = n0.emptySet();
|
|
}
|
|
hashMap.put(valueOf, u.union(of, set));
|
|
}
|
|
|
|
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends com.discord.stores.StoreMessageReplies$MessageState>, java.util.Map<java.lang.Long, com.discord.stores.StoreMessageReplies$MessageState> */
|
|
public final Map<Long, MessageState> getAllMessageReferences() {
|
|
return this.repliedMessagesCacheSnapshot;
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleLoadMessages(Collection<? extends ModelMessage> collection) {
|
|
m.checkNotNullParameter(collection, "messages");
|
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(collection, 10));
|
|
for (ModelMessage modelMessage : collection) {
|
|
arrayList.add(Boolean.valueOf(processMessage(modelMessage)));
|
|
}
|
|
if (arrayList.contains(Boolean.TRUE)) {
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleMessageCreate(ModelMessage modelMessage) {
|
|
m.checkNotNullParameter(modelMessage, "message");
|
|
if (processMessage(modelMessage)) {
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleMessageDelete(ModelMessageDelete modelMessageDelete) {
|
|
boolean z2;
|
|
m.checkNotNullParameter(modelMessageDelete, "messageDeleteBulk");
|
|
List<Long> messageIds = modelMessageDelete.getMessageIds();
|
|
m.checkNotNullExpressionValue(messageIds, "messageDeleteBulk.messageIds");
|
|
Iterator<T> it = messageIds.iterator();
|
|
loop0:
|
|
while (true) {
|
|
z2 = false;
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break loop0;
|
|
}
|
|
Long l = (Long) it.next();
|
|
m.checkNotNullExpressionValue(l, "messageId");
|
|
if (deleteMessage(l.longValue(), modelMessageDelete.getChannelId()) || z2) {
|
|
z2 = true;
|
|
}
|
|
}
|
|
}
|
|
if (z2) {
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
@StoreThread
|
|
public final void handleMessageUpdate(ModelMessage modelMessage) {
|
|
MessageState messageState;
|
|
m.checkNotNullParameter(modelMessage, "message");
|
|
if (this.repliedMessagesCache.containsKey(Long.valueOf(modelMessage.getId())) && (messageState = this.repliedMessagesCache.get(Long.valueOf(modelMessage.getId()))) != null && (messageState instanceof MessageState.Loaded)) {
|
|
ModelMessage modelMessage2 = new ModelMessage(((MessageState.Loaded) messageState).getModelMessage(), modelMessage);
|
|
updateCache(modelMessage2.getId(), modelMessage2.getChannelId(), new MessageState.Loaded(modelMessage2));
|
|
markChanged();
|
|
}
|
|
}
|
|
|
|
public final Observable<Map<Long, MessageState>> observeMessageReferencesForChannel(long j) {
|
|
Observable<Map<Long, MessageState>> s2 = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreMessageReplies$observeMessageReferencesForChannel$1(this, j), 14, null).s();
|
|
m.checkNotNullExpressionValue(s2, "observationDeck\n … .distinctUntilChanged()");
|
|
return s2;
|
|
}
|
|
|
|
@Override // com.discord.stores.StoreV2
|
|
public void snapshotData() {
|
|
super.snapshotData();
|
|
snapShotChannelMessages();
|
|
snapShotAllMessages();
|
|
}
|
|
}
|