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

414 lines
19 KiB
Java

package com.discord.stores;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.api.role.GuildRole;
import com.discord.api.stageinstance.StageInstance;
import com.discord.api.thread.AugmentedThreadMember;
import com.discord.api.thread.ThreadMemberUpdate;
import com.discord.api.thread.ThreadMembersUpdate;
import com.discord.models.guild.Guild;
import com.discord.models.member.GuildMember;
import com.discord.models.message.Message;
import com.discord.models.thread.dto.ModelThreadListSync;
import com.discord.stores.updates.ObservationDeck;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.persister.Persister;
import com.discord.utilities.search.network.state.SearchState;
import d0.d0.f;
import d0.t.g0;
import d0.t.h0;
import d0.t.n;
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.Pair;
import rx.Observable;
/* compiled from: StorePermissions.kt */
public final class StorePermissions extends StoreV2 {
private final ObservationDeck observationDeck;
private final Map<Long, Map<Long, Long>> permissionsForChannels = new HashMap();
private final Persister<Map<Long, Map<Long, Long>>> permissionsForChannelsCache = new Persister<>("STORE_CHANNEL_PERMISSIONS_BY_GUILD_V5", new HashMap());
private Map<Long, Long> permissionsForChannelsFlattenedSnapshot = new HashMap();
private Map<Long, ? extends Map<Long, Long>> permissionsForChannelsSnapshot = new HashMap();
private final Map<Long, Long> permissionsForGuilds = new HashMap();
private final Persister<Map<Long, Long>> permissionsForGuildsCache = new Persister<>("STORE_GUILD_PERMISSIONS_V5", new HashMap());
private Map<Long, Long> permissionsForGuildsSnapshot = new HashMap();
private final StoreChannels storeChannels;
private final StoreGuilds storeGuilds;
private final StoreStageInstances storeStageInstances;
private final StoreThreadsJoined storeThreadsJoined;
private final StoreUser storeUser;
public StorePermissions(StoreUser storeUser, StoreChannels storeChannels, StoreGuilds storeGuilds, StoreThreadsJoined storeThreadsJoined, StoreStageInstances storeStageInstances, ObservationDeck observationDeck) {
m.checkNotNullParameter(storeUser, "storeUser");
m.checkNotNullParameter(storeChannels, "storeChannels");
m.checkNotNullParameter(storeGuilds, "storeGuilds");
m.checkNotNullParameter(storeThreadsJoined, "storeThreadsJoined");
m.checkNotNullParameter(storeStageInstances, "storeStageInstances");
m.checkNotNullParameter(observationDeck, "observationDeck");
this.storeUser = storeUser;
this.storeChannels = storeChannels;
this.storeGuilds = storeGuilds;
this.storeThreadsJoined = storeThreadsJoined;
this.storeStageInstances = storeStageInstances;
this.observationDeck = observationDeck;
}
public static final /* synthetic */ Map access$getPermissionsForChannels$p(StorePermissions storePermissions) {
return storePermissions.permissionsForChannels;
}
public static final /* synthetic */ Map access$getPermissionsForChannelsFlattenedSnapshot$p(StorePermissions storePermissions) {
return storePermissions.permissionsForChannelsFlattenedSnapshot;
}
public static final /* synthetic */ Map access$getPermissionsForGuildsSnapshot$p(StorePermissions storePermissions) {
return storePermissions.permissionsForGuildsSnapshot;
}
public static final /* synthetic */ void access$setPermissionsForChannelsFlattenedSnapshot$p(StorePermissions storePermissions, Map map) {
storePermissions.permissionsForChannelsFlattenedSnapshot = map;
}
public static final /* synthetic */ void access$setPermissionsForGuildsSnapshot$p(StorePermissions storePermissions, Map map) {
storePermissions.permissionsForGuildsSnapshot = map;
}
@StoreThread
private final Map<Long, Long> computeChannelPermissions(long j, Iterable<Channel> iterable) {
Guild guild = this.storeGuilds.getGuildsInternal$app_productionBetaRelease().get(Long.valueOf(j));
if (guild == null) {
return h0.emptyMap();
}
Map<Long, GuildMember> map = this.storeGuilds.getGuildMembersComputedInternal$app_productionBetaRelease().get(Long.valueOf(j));
Map<Long, GuildRole> map2 = this.storeGuilds.getGuildRolesInternal$app_productionBetaRelease().get(Long.valueOf(j));
Map<Long, StageInstance> stageInstancesForGuildInternal = this.storeStageInstances.getStageInstancesForGuildInternal(j);
LinkedHashMap linkedHashMap = new LinkedHashMap(f.coerceAtLeast(g0.mapCapacity(o.collectionSizeOrDefault(iterable, 10)), 16));
for (Channel channel : iterable) {
boolean hasJoinedInternal = this.storeThreadsJoined.hasJoinedInternal(channel.h());
Pair pair = d0.o.to(Long.valueOf(channel.h()), Long.valueOf(AnimatableValueParser.s1(channel) ? 137438428927L : PermissionUtils.computePermissions(getMeId(), channel, this.storeChannels.getGuildChannelInternal$app_productionBetaRelease(channel.f(), channel.r()), guild.getOwnerId(), map != null ? map.get(Long.valueOf(getMeId())) : null, map2, stageInstancesForGuildInternal, hasJoinedInternal)));
linkedHashMap.put(pair.getFirst(), pair.getSecond());
}
return linkedHashMap;
}
private final long getMeId() {
return this.storeUser.getMeInternal$app_productionBetaRelease().getId();
}
@StoreThread
private final void recomputeAllPermissions() {
this.permissionsForGuilds.clear();
this.permissionsForChannels.clear();
Collection<Channel> values = this.storeChannels.getThreadsByIdInternal$app_productionBetaRelease().values();
LinkedHashMap linkedHashMap = new LinkedHashMap();
for (Object obj : values) {
Long valueOf = Long.valueOf(((Channel) obj).f());
Object obj2 = linkedHashMap.get(valueOf);
if (obj2 == null) {
obj2 = new ArrayList();
linkedHashMap.put(valueOf, obj2);
}
((List) obj2).add(obj);
}
Set<Long> keySet = this.storeChannels.getChannelsByGuildInternal$app_productionBetaRelease().keySet();
ArrayList<Number> arrayList = new ArrayList();
for (Object obj3 : keySet) {
if (((Number) obj3).longValue() != 0) {
arrayList.add(obj3);
}
}
for (Number number : arrayList) {
long longValue = number.longValue();
List list = (List) linkedHashMap.get(Long.valueOf(longValue));
if (list == null) {
list = n.emptyList();
}
updateGuildPermissions(longValue, list);
}
}
@StoreThread
private final void restoreFromCache() {
this.permissionsForGuilds.putAll(this.permissionsForGuildsCache.get());
this.permissionsForChannels.putAll(this.permissionsForChannelsCache.get());
}
@StoreThread
private final void updateChannelPermissions(Channel channel) {
if (getMeId() != 0) {
long f = channel.f();
Map<Long, Long> map = this.permissionsForChannels.get(Long.valueOf(f));
if (map == null) {
map = h0.emptyMap();
}
this.permissionsForChannels.put(Long.valueOf(f), h0.plus(map, computeChannelPermissions(f, d0.t.m.listOf(channel))));
markChanged();
}
}
@StoreThread
private final void updateGuildPermissions(long j, Collection<Channel> collection) {
Map<Long, Channel> map;
Guild guild;
if (getMeId() != 0 && (map = this.storeChannels.getChannelsByGuildInternal$app_productionBetaRelease().get(Long.valueOf(j))) != null && (guild = this.storeGuilds.getGuildsInternal$app_productionBetaRelease().get(Long.valueOf(j))) != null) {
Map<Long, GuildMember> map2 = this.storeGuilds.getGuildMembersComputedInternal$app_productionBetaRelease().get(Long.valueOf(j));
long computeNonThreadPermissions = PermissionUtils.computeNonThreadPermissions(getMeId(), j, guild.getOwnerId(), map2 != null ? map2.get(Long.valueOf(getMeId())) : null, this.storeGuilds.getGuildRolesInternal$app_productionBetaRelease().get(Long.valueOf(j)), null);
Long l = this.permissionsForGuilds.get(Long.valueOf(j));
if (l == null || l.longValue() != computeNonThreadPermissions) {
this.permissionsForGuilds.put(Long.valueOf(j), Long.valueOf(computeNonThreadPermissions));
markChanged();
}
Map<Long, Long> computeChannelPermissions = computeChannelPermissions(j, u.plus((Collection) map.values(), (Iterable) collection));
if (!m.areEqual(this.permissionsForChannels.get(Long.valueOf(j)), computeChannelPermissions)) {
this.permissionsForChannels.put(Long.valueOf(j), computeChannelPermissions);
markChanged();
}
}
}
public final Map<Long, Long> getGuildPermissions() {
return this.permissionsForGuildsSnapshot;
}
public final Map<Long, Long> getPermissionsByChannel() {
return this.permissionsForChannelsFlattenedSnapshot;
}
@StoreThread
public final Map<Long, Long> getPermissionsByChannelInternal$app_productionBetaRelease(long j) {
Map<Long, Long> map = this.permissionsForChannels.get(Long.valueOf(j));
return map != null ? map : h0.emptyMap();
}
@StoreThread
public final void handleChannelOrThreadCreateOrUpdate(Channel channel) {
m.checkNotNullParameter(channel, "channel");
updateChannelPermissions(channel);
}
@StoreThread
public final void handleChannelOrThreadDelete(Channel channel) {
m.checkNotNullParameter(channel, "channel");
long f = channel.f();
Map<Long, Long> map = this.permissionsForChannels.get(Long.valueOf(f));
if (map == null) {
map = h0.emptyMap();
}
this.permissionsForChannels.put(Long.valueOf(f), h0.minus(map, Long.valueOf(channel.h())));
markChanged();
}
@StoreThread
public final void handleConnectionOpen() {
recomputeAllPermissions();
markChanged();
}
@StoreThread
public final void handleGuildAdd(com.discord.api.guild.Guild guild) {
m.checkNotNullParameter(guild, "guild");
updateGuildPermissions(guild.o(), this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(guild.o()));
}
@StoreThread
public final void handleGuildMemberAdd(com.discord.api.guildmember.GuildMember guildMember) {
m.checkNotNullParameter(guildMember, "member");
if (getMeId() != 0 && guildMember.j().i() == getMeId()) {
updateGuildPermissions(guildMember.c(), this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(guildMember.c()));
}
}
@StoreThread
public final void handleGuildRemove(com.discord.api.guild.Guild guild) {
m.checkNotNullParameter(guild, "guild");
long o = guild.o();
this.permissionsForChannels.remove(Long.valueOf(o));
this.permissionsForGuilds.remove(Long.valueOf(o));
markChanged();
}
@StoreThread
public final void handleGuildRolesChanged(long j) {
updateGuildPermissions(j, this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(j));
}
@StoreThread
public final void handleMessagesLoaded(List<Message> list) {
m.checkNotNullParameter(list, "messages");
if (getMeId() != 0) {
ArrayList arrayList = new ArrayList();
for (Message message : list) {
Channel thread = message.getThread();
if (thread != null) {
arrayList.add(thread);
}
}
Channel channel = (Channel) u.firstOrNull((List<? extends Object>) arrayList);
Long valueOf = channel != null ? Long.valueOf(channel.f()) : null;
if (valueOf != null) {
updateGuildPermissions(valueOf.longValue(), this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(valueOf.longValue()));
}
}
}
/* JADX WARNING: Removed duplicated region for block: B:14:0x004e */
/* JADX WARNING: Removed duplicated region for block: B:17:? A[RETURN, SYNTHETIC] */
@StoreThread
public final void handleSearchFinish(SearchState searchState) {
Long l;
m.checkNotNullParameter(searchState, "searchState");
if (getMeId() != 0) {
List<Message> hits = searchState.getHits();
if (hits != null) {
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(hits, 10));
for (Message message : hits) {
arrayList.add(message.getThread());
}
Channel channel = (Channel) u.firstOrNull((List<? extends Object>) arrayList);
if (channel != null) {
l = Long.valueOf(channel.f());
if (l == null) {
updateGuildPermissions(l.longValue(), this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(l.longValue()));
return;
}
return;
}
}
l = null;
if (l == null) {
}
}
}
@StoreThread
public final void handleStageInstanceChange(StageInstance stageInstance) {
Channel channelInternal$app_productionBetaRelease;
m.checkNotNullParameter(stageInstance, "stageInstance");
if (getMeId() != 0 && (channelInternal$app_productionBetaRelease = this.storeChannels.getChannelInternal$app_productionBetaRelease(stageInstance.b(), stageInstance.a())) != null) {
updateChannelPermissions(channelInternal$app_productionBetaRelease);
}
}
@StoreThread
public final void handleThreadListSync(ModelThreadListSync modelThreadListSync) {
m.checkNotNullParameter(modelThreadListSync, "threadListSync");
if (getMeId() != 0) {
updateGuildPermissions(modelThreadListSync.getGuildId(), this.storeChannels.getThreadsForGuildInternal$app_productionBetaRelease(modelThreadListSync.getGuildId()));
}
}
@StoreThread
public final void handleThreadMemberUpdate(ThreadMemberUpdate threadMemberUpdate) {
m.checkNotNullParameter(threadMemberUpdate, "threadMemberUpdate");
Channel guildChannelInternal$app_productionBetaRelease = this.storeChannels.getGuildChannelInternal$app_productionBetaRelease(threadMemberUpdate.b(), threadMemberUpdate.c());
if (guildChannelInternal$app_productionBetaRelease != null) {
updateChannelPermissions(guildChannelInternal$app_productionBetaRelease);
}
}
@StoreThread
public final void handleThreadMembersUpdate(ThreadMembersUpdate threadMembersUpdate) {
Channel guildChannelInternal$app_productionBetaRelease;
Boolean bool;
boolean z2;
m.checkNotNullParameter(threadMembersUpdate, "threadMembersUpdate");
if (getMeId() != 0 && (guildChannelInternal$app_productionBetaRelease = this.storeChannels.getGuildChannelInternal$app_productionBetaRelease(threadMembersUpdate.b(), threadMembersUpdate.c())) != null) {
List<AugmentedThreadMember> a = threadMembersUpdate.a();
Boolean bool2 = null;
if (a != null) {
boolean z3 = true;
if (!a.isEmpty()) {
Iterator<T> it = a.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
if (((AugmentedThreadMember) it.next()).e() == getMeId()) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
break;
}
}
}
z3 = false;
bool = Boolean.valueOf(z3);
} else {
bool = null;
}
List<Long> d = threadMembersUpdate.d();
if (d != null) {
bool2 = Boolean.valueOf(d.contains(Long.valueOf(getMeId())));
}
Boolean bool3 = Boolean.TRUE;
if (m.areEqual(bool, bool3) || m.areEqual(bool2, bool3)) {
updateChannelPermissions(guildChannelInternal$app_productionBetaRelease);
}
}
}
@StoreThread
public final void init() {
restoreFromCache();
markChanged();
}
public final Observable<Map<Long, Map<Long, Long>>> observeAllPermissions() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StorePermissions$observeAllPermissions$1(this), 14, null);
}
public final Observable<Map<Long, Long>> observeChannelPermissionsForGuild(long j) {
Observable<Map<Long, Long>> r = observeAllPermissions().F(new StorePermissions$observeChannelPermissionsForGuild$1(j)).r();
m.checkNotNullExpressionValue(r, "observeAllPermissions()\n… .distinctUntilChanged()");
return r;
}
public final Observable<Map<Long, Long>> observePermissionsForAllChannels() {
Observable<Map<Long, Long>> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StorePermissions$observePermissionsForAllChannels$1(this), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck\n … .distinctUntilChanged()");
return r;
}
public final Observable<Long> observePermissionsForChannel(long j) {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StorePermissions$observePermissionsForChannel$1(this, j), 14, null);
}
public final Observable<Long> observePermissionsForGuild(long j) {
Observable<Long> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StorePermissions$observePermissionsForGuild$1(this, j), 14, null).r();
m.checkNotNullExpressionValue(r, "observationDeck\n … .distinctUntilChanged()");
return r;
}
@Override // com.discord.stores.StoreV2
@StoreThread
public void snapshotData() {
HashMap hashMap = new HashMap();
HashMap hashMap2 = new HashMap();
for (Map.Entry<Long, Map<Long, Long>> entry : this.permissionsForChannels.entrySet()) {
long longValue = entry.getKey().longValue();
Map<Long, Long> value = entry.getValue();
hashMap2.put(Long.valueOf(longValue), value);
hashMap.putAll(value);
}
this.permissionsForGuildsSnapshot = new HashMap(this.permissionsForGuilds);
this.permissionsForChannelsSnapshot = hashMap2;
this.permissionsForChannelsFlattenedSnapshot = hashMap;
this.permissionsForGuildsCache.set(this.permissionsForGuilds, true);
this.permissionsForChannelsCache.set(this.permissionsForChannels, true);
}
}