discord-jadx/app/src/main/java/com/discord/stores/StoreThreadMessages.java

405 lines
16 KiB
Java

package com.discord.stores;
import a0.a.a.b;
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.models.domain.ModelMessageDelete;
import com.discord.models.domain.ModelPayload;
import com.discord.models.message.Message;
import com.discord.models.thread.dto.ModelThreadListSync;
import com.discord.stores.StoreMessagesLoader;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
import d0.d0.f;
import d0.t.h0;
import d0.t.r;
import d0.z.d.m;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: StoreThreadMessages.kt */
public final class StoreThreadMessages extends StoreV2 {
public static final Companion Companion = new Companion(null);
public static final int MAX_THREAD_MESSAGE_COUNT = 50;
private final ObservationDeck observationDeck;
private final StoreChannels storeChannels;
private final StoreMessages storeMessages;
private final Map<Long, ThreadState> threads;
private Map<Long, ThreadState> threadsSnapshot;
/* compiled from: StoreThreadMessages.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: StoreThreadMessages.kt */
public static final class ThreadState {
private int count;
private final long guildId;
private Message mostRecentMessage;
private final long parentId;
private final long threadId;
public ThreadState(long j, long j2, long j3, int i, Message message) {
this.threadId = j;
this.guildId = j2;
this.parentId = j3;
this.count = i;
this.mostRecentMessage = message;
}
public static /* synthetic */ ThreadState copy$default(ThreadState threadState, long j, long j2, long j3, int i, Message message, int i2, Object obj) {
return threadState.copy((i2 & 1) != 0 ? threadState.threadId : j, (i2 & 2) != 0 ? threadState.guildId : j2, (i2 & 4) != 0 ? threadState.parentId : j3, (i2 & 8) != 0 ? threadState.count : i, (i2 & 16) != 0 ? threadState.mostRecentMessage : message);
}
public final long component1() {
return this.threadId;
}
public final long component2() {
return this.guildId;
}
public final long component3() {
return this.parentId;
}
public final int component4() {
return this.count;
}
public final Message component5() {
return this.mostRecentMessage;
}
public final ThreadState copy(long j, long j2, long j3, int i, Message message) {
return new ThreadState(j, j2, j3, i, message);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ThreadState)) {
return false;
}
ThreadState threadState = (ThreadState) obj;
return this.threadId == threadState.threadId && this.guildId == threadState.guildId && this.parentId == threadState.parentId && this.count == threadState.count && m.areEqual(this.mostRecentMessage, threadState.mostRecentMessage);
}
public final int getCount() {
return this.count;
}
public final long getGuildId() {
return this.guildId;
}
public final Message getMostRecentMessage() {
return this.mostRecentMessage;
}
public final long getParentId() {
return this.parentId;
}
public final long getThreadId() {
return this.threadId;
}
public int hashCode() {
int a = (((b.a(this.parentId) + ((b.a(this.guildId) + (b.a(this.threadId) * 31)) * 31)) * 31) + this.count) * 31;
Message message = this.mostRecentMessage;
return a + (message != null ? message.hashCode() : 0);
}
public final void setCount(int i) {
this.count = i;
}
public final void setMostRecentMessage(Message message) {
this.mostRecentMessage = message;
}
public String toString() {
StringBuilder K = a.K("ThreadState(threadId=");
K.append(this.threadId);
K.append(", guildId=");
K.append(this.guildId);
K.append(", parentId=");
K.append(this.parentId);
K.append(", count=");
K.append(this.count);
K.append(", mostRecentMessage=");
K.append(this.mostRecentMessage);
K.append(")");
return K.toString();
}
}
public StoreThreadMessages(StoreMessages storeMessages, StoreChannels storeChannels, ObservationDeck observationDeck) {
m.checkNotNullParameter(storeMessages, "storeMessages");
m.checkNotNullParameter(storeChannels, "storeChannels");
m.checkNotNullParameter(observationDeck, "observationDeck");
this.storeMessages = storeMessages;
this.storeChannels = storeChannels;
this.observationDeck = observationDeck;
this.threads = new HashMap();
this.threadsSnapshot = h0.emptyMap();
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreThreadMessages(StoreMessages storeMessages, StoreChannels storeChannels, ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(storeMessages, storeChannels, (i & 4) != 0 ? ObservationDeckProvider.get() : observationDeck);
}
public static final /* synthetic */ Map access$getThreadsSnapshot$p(StoreThreadMessages storeThreadMessages) {
return storeThreadMessages.threadsSnapshot;
}
public static final /* synthetic */ void access$setThreadsSnapshot$p(StoreThreadMessages storeThreadMessages, Map map) {
storeThreadMessages.threadsSnapshot = map;
}
@StoreThread
private final void deleteForGuild(long j) {
if (r.removeAll(this.threads.values(), new StoreThreadMessages$deleteForGuild$removed$1(j))) {
markChanged();
}
}
@StoreThread
private final void deleteForParentChannel(long j) {
if (r.removeAll(this.threads.values(), new StoreThreadMessages$deleteForParentChannel$removed$1(j))) {
markChanged();
}
}
@StoreThread
private final ThreadState getOrAddState(Channel channel) {
ThreadState threadState = (ThreadState) a.o0(channel, this.threads);
if (threadState == null) {
long h = channel.h();
long f = channel.f();
long r = channel.r();
Integer l = channel.l();
threadState = new ThreadState(h, f, r, l != null ? l.intValue() : 0, null);
this.threads.put(Long.valueOf(channel.h()), threadState);
markChanged();
}
return threadState;
}
@StoreThread
private final void updateFromGuild(Guild guild) {
List<Channel> K = guild.K();
if (K != null) {
for (Channel channel : K) {
updateFromThread(channel);
}
}
}
@StoreThread
private final void updateFromThread(Channel channel) {
ThreadState orAddState = getOrAddState(channel);
Integer l = channel.l();
if (l != null) {
this.threads.put(Long.valueOf(channel.h()), ThreadState.copy$default(orAddState, 0, 0, 0, l.intValue(), null, 23, null));
markChanged();
}
if (channel.i() != 0) {
Message mostRecentMessage = orAddState.getMostRecentMessage();
if (mostRecentMessage == null || mostRecentMessage.getId() != channel.i()) {
this.threads.put(Long.valueOf(channel.h()), ThreadState.copy$default(orAddState, 0, 0, 0, 0, null, 15, null));
markChanged();
}
}
}
public final Integer getThreadMessageCount(long j) {
ThreadState threadState = this.threadsSnapshot.get(Long.valueOf(j));
if (threadState != null) {
return Integer.valueOf(threadState.getCount());
}
return null;
}
@StoreThread
public final void handleChannelDelete(Channel channel) {
m.checkNotNullParameter(channel, "channel");
deleteForParentChannel(channel.h());
}
@StoreThread
public final void handleConnectionOpen(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
List<Guild> guilds = modelPayload.getGuilds();
m.checkNotNullExpressionValue(guilds, "payload.guilds");
for (Guild guild : guilds) {
updateFromGuild(guild);
}
}
@StoreThread
public final void handleGuildCreate(Guild guild) {
m.checkNotNullParameter(guild, "guild");
updateFromGuild(guild);
}
@StoreThread
public final void handleGuildDelete(long j) {
deleteForGuild(j);
}
@StoreThread
public final void handleMessageCreate(com.discord.api.message.Message message) {
m.checkNotNullParameter(message, "message");
Channel channel = this.storeChannels.getChannel(message.g());
if (channel != null && AnimatableValueParser.A1(channel)) {
ThreadState orAddState = getOrAddState(channel);
this.threads.put(Long.valueOf(channel.h()), ThreadState.copy$default(orAddState, 0, 0, 0, f.coerceAtMost(orAddState.getCount() + 1, 50), new Message(message), 7, null));
markChanged();
}
}
@StoreThread
public final void handleMessageDelete(ModelMessageDelete modelMessageDelete) {
Message mostRecentMessage;
m.checkNotNullParameter(modelMessageDelete, "messageDeleteBulk");
ThreadState threadState = this.threads.get(Long.valueOf(modelMessageDelete.getChannelId()));
Long valueOf = (threadState == null || (mostRecentMessage = threadState.getMostRecentMessage()) == null) ? null : Long.valueOf(mostRecentMessage.getId());
if (valueOf != null) {
valueOf.longValue();
for (Long l : modelMessageDelete.getMessageIds()) {
if (!(!m.areEqual(valueOf, l))) {
this.threads.put(Long.valueOf(modelMessageDelete.getChannelId()), ThreadState.copy$default(threadState, 0, 0, 0, 0, null, 15, null));
markChanged();
return;
}
}
}
}
@StoreThread
public final void handleMessageUpdate(com.discord.api.message.Message message) {
Message mostRecentMessage;
m.checkNotNullParameter(message, "message");
ThreadState threadState = this.threads.get(Long.valueOf(message.g()));
if (threadState != null && (mostRecentMessage = threadState.getMostRecentMessage()) != null && mostRecentMessage.getId() == message.o()) {
this.threads.put(Long.valueOf(message.g()), ThreadState.copy$default(threadState, 0, 0, 0, 0, this.storeMessages.getMessage(message.g(), message.o()), 15, null));
markChanged();
}
}
@StoreThread
public final void handleMessagesLoaded(StoreMessagesLoader.ChannelChunk channelChunk) {
Channel channel;
boolean z2;
Channel channel2;
m.checkNotNullParameter(channelChunk, "chunk");
boolean z3 = false;
boolean z4 = false;
for (Message message : channelChunk.getMessages()) {
if (message.hasThread() && !this.threads.containsKey(Long.valueOf(message.getId())) && (channel2 = this.storeChannels.getThreadsByIdInternal$app_productionBetaRelease().get(Long.valueOf(message.getId()))) != null) {
updateFromThread(channel2);
z4 = true;
}
}
if (z4) {
markChanged();
}
if (channelChunk.isPresent() && (channel = this.storeChannels.getThreadsByIdInternal$app_productionBetaRelease().get(Long.valueOf(channelChunk.getChannelId()))) != null && AnimatableValueParser.A1(channel)) {
ThreadState orAddState = getOrAddState(channel);
if (channelChunk.getMessages().isEmpty()) {
this.threads.put(Long.valueOf(channel.h()), ThreadState.copy$default(orAddState, 0, 0, 0, 0, null, 7, null));
} else {
Message message2 = this.storeMessages.getMessage(channelChunk.getChannelId(), channelChunk.getMessages().get(0).getId());
int size = channelChunk.getMessages().size();
List<Message> messages = channelChunk.getMessages();
if (!(messages instanceof Collection) || !messages.isEmpty()) {
Iterator<T> it = messages.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
Integer type = ((Message) it.next()).getType();
if (type != null && type.intValue() == 21) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
z3 = true;
break;
}
}
}
if (z3) {
size--;
}
Integer type2 = message2 != null ? message2.getType() : null;
this.threads.put(Long.valueOf(channel.h()), ThreadState.copy$default(orAddState, 0, 0, 0, f.coerceAtMost(size, 50), (type2 != null && type2.intValue() == 21) ? null : message2, 7, null));
}
markChanged();
}
}
@StoreThread
public final void handleThreadCreateOrUpdate(Channel channel) {
m.checkNotNullParameter(channel, "thread");
updateFromThread(channel);
}
@StoreThread
public final void handleThreadDelete(Channel channel) {
m.checkNotNullParameter(channel, "channel");
if (this.threads.containsKey(Long.valueOf(channel.h()))) {
this.threads.remove(Long.valueOf(channel.h()));
markChanged();
}
}
@StoreThread
public final void handleThreadListSync(ModelThreadListSync modelThreadListSync) {
m.checkNotNullParameter(modelThreadListSync, "threadListSync");
for (Channel channel : modelThreadListSync.getThreads()) {
updateFromThread(channel);
}
List<com.discord.api.message.Message> mostRecentMessages = modelThreadListSync.getMostRecentMessages();
if (mostRecentMessages != null) {
for (com.discord.api.message.Message message : mostRecentMessages) {
ThreadState threadState = this.threads.get(Long.valueOf(message.g()));
if (threadState != null) {
this.threads.put(Long.valueOf(message.g()), ThreadState.copy$default(threadState, 0, 0, 0, 0, new Message(message), 15, null));
}
}
}
}
public final Observable<Map<Long, ThreadState>> observeThreadCountAndLatestMessage() {
Observable<Map<Long, ThreadState>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreThreadMessages$observeThreadCountAndLatestMessage$1(this), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck.connectR… }.distinctUntilChanged()");
return r;
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData() {
this.threadsSnapshot = new HashMap(this.threads);
}
}