352 lines
14 KiB
Java
352 lines
14 KiB
Java
|
package com.discord.stores;
|
||
|
|
||
|
import a0.a.a.b;
|
||
|
import c.d.b.a.a;
|
||
|
import com.discord.api.channel.Channel;
|
||
|
import com.discord.api.emoji.GuildEmojisUpdate;
|
||
|
import com.discord.api.guild.Guild;
|
||
|
import com.discord.api.guildhash.GuildHash;
|
||
|
import com.discord.api.guildhash.GuildHashes;
|
||
|
import com.discord.api.message.Message;
|
||
|
import com.discord.api.sticker.GuildStickersUpdate;
|
||
|
import com.discord.gateway.io.OutgoingPayload;
|
||
|
import com.discord.models.domain.ModelNotificationSettings;
|
||
|
import com.discord.models.domain.ModelPayload;
|
||
|
import com.discord.models.domain.ModelReadState;
|
||
|
import com.discord.stores.updates.ObservationDeck;
|
||
|
import com.discord.stores.updates.ObservationDeckProvider;
|
||
|
import com.discord.utilities.guildhash.GuildHashUtilsKt;
|
||
|
import d0.t.g0;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.LinkedHashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
import rx.Observable;
|
||
|
/* compiled from: StoreClientDataState.kt */
|
||
|
public final class StoreClientDataState extends StoreV2 {
|
||
|
private ClientDataState clientDataStateSnapshot;
|
||
|
private Map<Long, GuildHashes> guildHashes;
|
||
|
private long highestLastMessageId;
|
||
|
private final ObservationDeck observationDeck;
|
||
|
private int readStateVersion;
|
||
|
private int userGuildSettingsVersion;
|
||
|
|
||
|
/* compiled from: StoreClientDataState.kt */
|
||
|
public static final class ClientDataState {
|
||
|
private final Map<Long, GuildHashes> guildHashes;
|
||
|
private final long highestLastMessageId;
|
||
|
private final int readStateVersion;
|
||
|
private final int userGuildSettingsVersion;
|
||
|
|
||
|
public ClientDataState() {
|
||
|
this(null, 0, 0, 0, 15, null);
|
||
|
}
|
||
|
|
||
|
public ClientDataState(Map<Long, GuildHashes> map, long j, int i, int i2) {
|
||
|
m.checkNotNullParameter(map, "guildHashes");
|
||
|
this.guildHashes = map;
|
||
|
this.highestLastMessageId = j;
|
||
|
this.readStateVersion = i;
|
||
|
this.userGuildSettingsVersion = i2;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
||
|
public /* synthetic */ ClientDataState(Map map, long j, int i, int i2, int i3, DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this((i3 & 1) != 0 ? new HashMap() : map, (i3 & 2) != 0 ? 0 : j, (i3 & 4) != 0 ? -1 : i, (i3 & 8) != 0 ? -1 : i2);
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.discord.stores.StoreClientDataState$ClientDataState */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
public static /* synthetic */ ClientDataState copy$default(ClientDataState clientDataState, Map map, long j, int i, int i2, int i3, Object obj) {
|
||
|
if ((i3 & 1) != 0) {
|
||
|
map = clientDataState.guildHashes;
|
||
|
}
|
||
|
if ((i3 & 2) != 0) {
|
||
|
j = clientDataState.highestLastMessageId;
|
||
|
}
|
||
|
if ((i3 & 4) != 0) {
|
||
|
i = clientDataState.readStateVersion;
|
||
|
}
|
||
|
if ((i3 & 8) != 0) {
|
||
|
i2 = clientDataState.userGuildSettingsVersion;
|
||
|
}
|
||
|
return clientDataState.copy(map, j, i, i2);
|
||
|
}
|
||
|
|
||
|
private final String[] toArray(GuildHashes guildHashes) {
|
||
|
GuildHash b = guildHashes.b();
|
||
|
String a = b != null ? b.a() : null;
|
||
|
GuildHash a2 = guildHashes.a();
|
||
|
String a3 = a2 != null ? a2.a() : null;
|
||
|
GuildHash c2 = guildHashes.c();
|
||
|
String a4 = c2 != null ? c2.a() : null;
|
||
|
if (a == null || a3 == null || a4 == null) {
|
||
|
return null;
|
||
|
}
|
||
|
return new String[]{a, a3, a4};
|
||
|
}
|
||
|
|
||
|
public final Map<Long, GuildHashes> component1() {
|
||
|
return this.guildHashes;
|
||
|
}
|
||
|
|
||
|
public final long component2() {
|
||
|
return this.highestLastMessageId;
|
||
|
}
|
||
|
|
||
|
public final int component3() {
|
||
|
return this.readStateVersion;
|
||
|
}
|
||
|
|
||
|
public final int component4() {
|
||
|
return this.userGuildSettingsVersion;
|
||
|
}
|
||
|
|
||
|
public final ClientDataState copy(Map<Long, GuildHashes> map, long j, int i, int i2) {
|
||
|
m.checkNotNullParameter(map, "guildHashes");
|
||
|
return new ClientDataState(map, j, i, i2);
|
||
|
}
|
||
|
|
||
|
public boolean equals(Object obj) {
|
||
|
if (this == obj) {
|
||
|
return true;
|
||
|
}
|
||
|
if (!(obj instanceof ClientDataState)) {
|
||
|
return false;
|
||
|
}
|
||
|
ClientDataState clientDataState = (ClientDataState) obj;
|
||
|
return m.areEqual(this.guildHashes, clientDataState.guildHashes) && this.highestLastMessageId == clientDataState.highestLastMessageId && this.readStateVersion == clientDataState.readStateVersion && this.userGuildSettingsVersion == clientDataState.userGuildSettingsVersion;
|
||
|
}
|
||
|
|
||
|
public final Map<Long, GuildHashes> getGuildHashes() {
|
||
|
return this.guildHashes;
|
||
|
}
|
||
|
|
||
|
public final long getHighestLastMessageId() {
|
||
|
return this.highestLastMessageId;
|
||
|
}
|
||
|
|
||
|
public final int getReadStateVersion() {
|
||
|
return this.readStateVersion;
|
||
|
}
|
||
|
|
||
|
public final int getUserGuildSettingsVersion() {
|
||
|
return this.userGuildSettingsVersion;
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
Map<Long, GuildHashes> map = this.guildHashes;
|
||
|
return ((((b.a(this.highestLastMessageId) + ((map != null ? map.hashCode() : 0) * 31)) * 31) + this.readStateVersion) * 31) + this.userGuildSettingsVersion;
|
||
|
}
|
||
|
|
||
|
public final OutgoingPayload.IdentifyClientState toIdentifyData() {
|
||
|
Map<Long, GuildHashes> map = this.guildHashes;
|
||
|
LinkedHashMap linkedHashMap = new LinkedHashMap(g0.mapCapacity(map.size()));
|
||
|
Iterator<T> it = map.entrySet().iterator();
|
||
|
while (it.hasNext()) {
|
||
|
Map.Entry entry = (Map.Entry) it.next();
|
||
|
linkedHashMap.put(entry.getKey(), toArray((GuildHashes) entry.getValue()));
|
||
|
}
|
||
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap();
|
||
|
for (Map.Entry entry2 : linkedHashMap.entrySet()) {
|
||
|
if (entry2.getValue() != null) {
|
||
|
linkedHashMap2.put(entry2.getKey(), entry2.getValue());
|
||
|
}
|
||
|
}
|
||
|
LinkedHashMap linkedHashMap3 = new LinkedHashMap(g0.mapCapacity(linkedHashMap2.size()));
|
||
|
for (Map.Entry entry3 : linkedHashMap2.entrySet()) {
|
||
|
Object key = entry3.getKey();
|
||
|
Object value = entry3.getValue();
|
||
|
m.checkNotNull(value);
|
||
|
linkedHashMap3.put(key, (String[]) value);
|
||
|
}
|
||
|
return new OutgoingPayload.IdentifyClientState(linkedHashMap3, this.highestLastMessageId, this.readStateVersion, this.userGuildSettingsVersion);
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
StringBuilder K = a.K("ClientDataState(guildHashes=");
|
||
|
K.append(this.guildHashes);
|
||
|
K.append(", highestLastMessageId=");
|
||
|
K.append(this.highestLastMessageId);
|
||
|
K.append(", readStateVersion=");
|
||
|
K.append(this.readStateVersion);
|
||
|
K.append(", userGuildSettingsVersion=");
|
||
|
return a.w(K, this.userGuildSettingsVersion, ")");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public StoreClientDataState() {
|
||
|
this(null, 1, null);
|
||
|
}
|
||
|
|
||
|
public StoreClientDataState(ObservationDeck observationDeck) {
|
||
|
m.checkNotNullParameter(observationDeck, "observationDeck");
|
||
|
this.observationDeck = observationDeck;
|
||
|
this.guildHashes = new HashMap();
|
||
|
this.readStateVersion = -1;
|
||
|
this.userGuildSettingsVersion = -1;
|
||
|
this.clientDataStateSnapshot = new ClientDataState(null, 0, 0, 0, 15, null);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
||
|
public /* synthetic */ StoreClientDataState(ObservationDeck observationDeck, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this((i & 1) != 0 ? ObservationDeckProvider.get() : observationDeck);
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ ClientDataState access$getClientDataStateSnapshot$p(StoreClientDataState storeClientDataState) {
|
||
|
return storeClientDataState.clientDataStateSnapshot;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$setClientDataStateSnapshot$p(StoreClientDataState storeClientDataState, ClientDataState clientDataState) {
|
||
|
storeClientDataState.clientDataStateSnapshot = clientDataState;
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
private final void updateGuildHash(Guild guild) {
|
||
|
GuildHashes m;
|
||
|
if (guild.L() || (m = guild.m()) == null || !GuildHashUtilsKt.isSupported(m)) {
|
||
|
this.guildHashes.remove(Long.valueOf(guild.o()));
|
||
|
return;
|
||
|
}
|
||
|
Map<Long, GuildHashes> map = this.guildHashes;
|
||
|
Long valueOf = Long.valueOf(guild.o());
|
||
|
GuildHashes m2 = guild.m();
|
||
|
m.checkNotNull(m2);
|
||
|
map.put(valueOf, m2);
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
private final void updateHighestLastMessageId(long j) {
|
||
|
if (j > this.highestLastMessageId) {
|
||
|
this.highestLastMessageId = j;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void clear() {
|
||
|
this.guildHashes.clear();
|
||
|
this.highestLastMessageId = 0;
|
||
|
this.readStateVersion = 0;
|
||
|
this.userGuildSettingsVersion = -1;
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleChannelCreateOrUpdateOrDelete(Channel channel) {
|
||
|
m.checkNotNullParameter(channel, "channel");
|
||
|
GuildHashes e = channel.e();
|
||
|
if (e != null && GuildHashUtilsKt.isSupported(e)) {
|
||
|
Map<Long, GuildHashes> map = this.guildHashes;
|
||
|
Long valueOf = Long.valueOf(channel.f());
|
||
|
GuildHashes e2 = channel.e();
|
||
|
m.checkNotNull(e2);
|
||
|
map.put(valueOf, e2);
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleConnectionOpen(ModelPayload modelPayload) {
|
||
|
m.checkNotNullParameter(modelPayload, "payload");
|
||
|
clear();
|
||
|
for (Guild guild : modelPayload.getGuilds()) {
|
||
|
m.checkNotNullExpressionValue(guild, "guild");
|
||
|
updateGuildHash(guild);
|
||
|
List<Channel> g = guild.g();
|
||
|
if (g != null) {
|
||
|
for (Channel channel : g) {
|
||
|
updateHighestLastMessageId(channel.i());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for (Channel channel2 : modelPayload.getPrivateChannels()) {
|
||
|
updateHighestLastMessageId(channel2.i());
|
||
|
}
|
||
|
ModelPayload.VersionedReadStates readState = modelPayload.getReadState();
|
||
|
m.checkNotNullExpressionValue(readState, "payload.readState");
|
||
|
this.readStateVersion = readState.getVersion();
|
||
|
ModelPayload.VersionedUserGuildSettings userGuildSettings = modelPayload.getUserGuildSettings();
|
||
|
m.checkNotNullExpressionValue(userGuildSettings, "payload.userGuildSettings");
|
||
|
this.userGuildSettingsVersion = userGuildSettings.getVersion();
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleEmojiUpdate(GuildEmojisUpdate guildEmojisUpdate) {
|
||
|
m.checkNotNullParameter(guildEmojisUpdate, "payload");
|
||
|
if (GuildHashUtilsKt.isSupported(guildEmojisUpdate.b())) {
|
||
|
this.guildHashes.put(Long.valueOf(guildEmojisUpdate.c()), guildEmojisUpdate.b());
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleGuildAdd(Guild guild) {
|
||
|
m.checkNotNullParameter(guild, "guild");
|
||
|
updateGuildHash(guild);
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleGuildRemove(Guild guild) {
|
||
|
m.checkNotNullParameter(guild, "guild");
|
||
|
this.guildHashes.remove(Long.valueOf(guild.o()));
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleGuildSettingUpdated(ModelNotificationSettings modelNotificationSettings) {
|
||
|
m.checkNotNullParameter(modelNotificationSettings, "userGuildSettings");
|
||
|
if (modelNotificationSettings.getVersion() > this.userGuildSettingsVersion) {
|
||
|
this.userGuildSettingsVersion = modelNotificationSettings.getVersion();
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleMessageAck(ModelReadState modelReadState) {
|
||
|
m.checkNotNullParameter(modelReadState, "readState");
|
||
|
if (modelReadState.getVersion() > this.readStateVersion) {
|
||
|
this.readStateVersion = modelReadState.getVersion();
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleMessageCreate(Message message) {
|
||
|
m.checkNotNullParameter(message, "message");
|
||
|
updateHighestLastMessageId(message.o());
|
||
|
markChanged();
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleRoleAddOrRemove(long j, GuildHashes guildHashes) {
|
||
|
if (guildHashes != null && GuildHashUtilsKt.isSupported(guildHashes)) {
|
||
|
this.guildHashes.put(Long.valueOf(j), guildHashes);
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@StoreThread
|
||
|
public final void handleStickersUpdate(GuildStickersUpdate guildStickersUpdate) {
|
||
|
m.checkNotNullParameter(guildStickersUpdate, "payload");
|
||
|
if (GuildHashUtilsKt.isSupported(guildStickersUpdate.a())) {
|
||
|
this.guildHashes.put(Long.valueOf(guildStickersUpdate.b()), guildStickersUpdate.a());
|
||
|
markChanged();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final Observable<ClientDataState> observeClientState() {
|
||
|
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreClientDataState$observeClientState$1(this), 14, null);
|
||
|
}
|
||
|
|
||
|
@Override // com.discord.stores.StoreV2
|
||
|
public void snapshotData() {
|
||
|
super.snapshotData();
|
||
|
this.clientDataStateSnapshot = new ClientDataState(this.guildHashes, this.highestLastMessageId, this.readStateVersion, this.userGuildSettingsVersion);
|
||
|
}
|
||
|
}
|