205 lines
11 KiB
Java
205 lines
11 KiB
Java
package com.discord.widgets.chat.input.autocomplete.sources;
|
|
|
|
import c.d.b.a.a;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.api.channel.ChannelRecipientNick;
|
|
import com.discord.api.channel.ChannelUtils;
|
|
import com.discord.api.permission.Permission;
|
|
import com.discord.api.role.GuildRole;
|
|
import com.discord.models.member.GuildMember;
|
|
import com.discord.models.presence.Presence;
|
|
import com.discord.models.user.User;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StoreGuilds;
|
|
import com.discord.stores.StorePermissions;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.stores.StoreUserPresence;
|
|
import com.discord.utilities.collections.ShallowPartitionCollection;
|
|
import com.discord.utilities.permissions.PermissionUtils;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$1;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt$filterNull$2;
|
|
import com.discord.widgets.chat.input.autocomplete.Autocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.AutocompletableComparator;
|
|
import com.discord.widgets.chat.input.autocomplete.GlobalRoleAutocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.LeadingIdentifier;
|
|
import com.discord.widgets.chat.input.autocomplete.RoleAutocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.UserAutocompletable;
|
|
import d0.o;
|
|
import d0.t.g0;
|
|
import d0.t.h0;
|
|
import d0.z.d.m;
|
|
import j0.l.e.j;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.TreeSet;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
/* compiled from: UserMentionableSource.kt */
|
|
public final class UserAutocompletableSource {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final int PARTITION_HUGE_GUILD_SIZE = 3000;
|
|
private static final int PARTITION_IDEAL_PARTITION_SIZE = 100;
|
|
private final StoreChannels storeChannels;
|
|
private final StoreGuilds storeGuilds;
|
|
private final StorePermissions storePermissions;
|
|
private final StoreUserPresence storePresences;
|
|
private final StoreUser storeUsers;
|
|
|
|
/* compiled from: UserMentionableSource.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public UserAutocompletableSource(StoreUser storeUser, StoreGuilds storeGuilds, StoreUserPresence storeUserPresence, StorePermissions storePermissions, StoreChannels storeChannels) {
|
|
m.checkNotNullParameter(storeUser, "storeUsers");
|
|
m.checkNotNullParameter(storeGuilds, "storeGuilds");
|
|
m.checkNotNullParameter(storeUserPresence, "storePresences");
|
|
m.checkNotNullParameter(storePermissions, "storePermissions");
|
|
m.checkNotNullParameter(storeChannels, "storeChannels");
|
|
this.storeUsers = storeUser;
|
|
this.storeGuilds = storeGuilds;
|
|
this.storePresences = storeUserPresence;
|
|
this.storePermissions = storePermissions;
|
|
this.storeChannels = storeChannels;
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$createAutocompletablesForDmUsers(UserAutocompletableSource userAutocompletableSource, Map map, Map map2, List list) {
|
|
return userAutocompletableSource.createAutocompletablesForDmUsers(map, map2, list);
|
|
}
|
|
|
|
public static final /* synthetic */ Map access$createAutocompletablesForUsers(UserAutocompletableSource userAutocompletableSource, long j, Channel channel, Channel channel2, long j2, Map map, Map map2, Map map3, Map map4, Long l) {
|
|
return userAutocompletableSource.createAutocompletablesForUsers(j, channel, channel2, j2, map, map2, map3, map4, l);
|
|
}
|
|
|
|
private final Map<LeadingIdentifier, TreeSet<Autocompletable>> createAutocompletablesForDmUsers(Map<Long, ? extends User> map, Map<Long, Presence> map2, List<ChannelRecipientNick> list) {
|
|
ChannelRecipientNick channelRecipientNick;
|
|
TreeSet treeSet = new TreeSet(new AutocompletableComparator());
|
|
for (User user : map.values()) {
|
|
String str = null;
|
|
if (list != null) {
|
|
int size = list.size();
|
|
channelRecipientNick = null;
|
|
for (int i = 0; i < size; i++) {
|
|
if (list.get(i).a() == user.getId()) {
|
|
channelRecipientNick = list.get(i);
|
|
}
|
|
}
|
|
} else {
|
|
channelRecipientNick = null;
|
|
}
|
|
if (channelRecipientNick != null) {
|
|
str = channelRecipientNick.c();
|
|
}
|
|
treeSet.add(new UserAutocompletable(user, null, str, (Presence) a.e(user, map2), false, 16, null));
|
|
}
|
|
return g0.mapOf(o.to(LeadingIdentifier.MENTION, treeSet));
|
|
}
|
|
|
|
private final Map<LeadingIdentifier, TreeSet<Autocompletable>> createAutocompletablesForUsers(long j, Channel channel, Channel channel2, long j2, Map<Long, GuildRole> map, Map<Long, GuildMember> map2, Map<Long, ? extends User> map3, Map<Long, Presence> map4, Long l) {
|
|
Collection collection;
|
|
boolean z2;
|
|
boolean can;
|
|
if (map2.size() > 3000) {
|
|
int size = map2.size() / 100;
|
|
collection = ShallowPartitionCollection.Companion.withArrayListPartions(size, new UserAutocompletableSource$createAutocompletablesForUsers$mentions$1(size));
|
|
} else {
|
|
collection = new ArrayList(map2.size());
|
|
}
|
|
boolean canEveryone = PermissionUtils.canEveryone(Permission.VIEW_CHANNEL, channel, channel2, map);
|
|
for (Map.Entry<Long, GuildMember> entry : map2.entrySet()) {
|
|
long longValue = entry.getKey().longValue();
|
|
GuildMember value = entry.getValue();
|
|
if (canEveryone || (can = PermissionUtils.can(Permission.VIEW_CHANNEL, Long.valueOf(PermissionUtils.computePermissions(longValue, channel, channel2, j2, value, map, null, true))))) {
|
|
User user = (User) map3.get(Long.valueOf(longValue));
|
|
if (user != null) {
|
|
collection.add(new UserAutocompletable(user, value, value.getNick(), map4.get(Long.valueOf(longValue)), false, 16, null));
|
|
}
|
|
} else {
|
|
User user2 = (User) map3.get(Long.valueOf(longValue));
|
|
if (user2 != null) {
|
|
collection.add(new UserAutocompletable(user2, value, value.getNick(), map4.get(Long.valueOf(longValue)), can));
|
|
}
|
|
}
|
|
}
|
|
if (map2.get(Long.valueOf(j)) != null) {
|
|
z2 = PermissionUtils.can(Permission.MENTION_EVERYONE, l);
|
|
if (z2) {
|
|
GlobalRoleAutocompletable.Companion companion = GlobalRoleAutocompletable.Companion;
|
|
collection.add(companion.getHere());
|
|
collection.add(companion.getEveryone());
|
|
}
|
|
} else {
|
|
z2 = false;
|
|
}
|
|
for (GuildRole guildRole : map.values()) {
|
|
if (guildRole.getId() != channel.f()) {
|
|
collection.add(new RoleAutocompletable(guildRole, guildRole.f() || z2));
|
|
}
|
|
}
|
|
TreeSet treeSet = new TreeSet(new AutocompletableComparator());
|
|
treeSet.addAll(collection);
|
|
return g0.mapOf(o.to(LeadingIdentifier.MENTION, treeSet));
|
|
}
|
|
|
|
public final StoreChannels getStoreChannels() {
|
|
return this.storeChannels;
|
|
}
|
|
|
|
public final StoreGuilds getStoreGuilds() {
|
|
return this.storeGuilds;
|
|
}
|
|
|
|
public final StorePermissions getStorePermissions() {
|
|
return this.storePermissions;
|
|
}
|
|
|
|
public final StoreUserPresence getStorePresences() {
|
|
return this.storePresences;
|
|
}
|
|
|
|
public final StoreUser getStoreUsers() {
|
|
return this.storeUsers;
|
|
}
|
|
|
|
public final Observable<Map<LeadingIdentifier, TreeSet<Autocompletable>>> observeUserAutocompletables(Channel channel) {
|
|
Observable observable;
|
|
m.checkNotNullParameter(channel, "channel");
|
|
long f = channel.f();
|
|
if (UserMentionableSourceKt.access$isTextOrVoiceChannel(channel)) {
|
|
Observable computationLatest = ObservableExtensionsKt.computationLatest(this.storeUsers.observeMeId());
|
|
Observable<R> F = this.storeGuilds.observeGuild(f).x(ObservableExtensionsKt$filterNull$1.INSTANCE).F(ObservableExtensionsKt$filterNull$2.INSTANCE);
|
|
m.checkNotNullExpressionValue(F, "filter { it != null }.map { it!! }");
|
|
Observable q = F.F(UserAutocompletableSource$observeUserAutocompletables$1.INSTANCE).q();
|
|
m.checkNotNullExpressionValue(q, "storeGuilds.observeGuild… }.distinctUntilChanged()");
|
|
Observable computationLatest2 = ObservableExtensionsKt.computationLatest(q);
|
|
Observable computationLatest3 = ObservableExtensionsKt.computationLatest(this.storeGuilds.observeRoles(f));
|
|
Observable<Map<Long, GuildMember>> observeComputed = this.storeGuilds.observeComputed(f);
|
|
TimeUnit timeUnit = TimeUnit.SECONDS;
|
|
Observable computationLatest4 = ObservableExtensionsKt.computationLatest(ObservableExtensionsKt.leadingEdgeThrottle(observeComputed, 5, timeUnit));
|
|
Observable computationLatest5 = ObservableExtensionsKt.computationLatest(this.storeUsers.observeAllUsers());
|
|
Observable computationLatest6 = ObservableExtensionsKt.computationLatest(ObservableExtensionsKt.leadingEdgeThrottle(this.storePresences.observeAllPresences(), 10, timeUnit));
|
|
Observable<Long> q2 = this.storePermissions.observePermissionsForChannel(channel.h()).q();
|
|
m.checkNotNullExpressionValue(q2, "storePermissions.observe…d).distinctUntilChanged()");
|
|
Observable computationLatest7 = ObservableExtensionsKt.computationLatest(q2);
|
|
Observable<Channel> q3 = this.storeChannels.observeChannel(channel.r()).q();
|
|
m.checkNotNullExpressionValue(q3, "storeChannels.observeCha…d).distinctUntilChanged()");
|
|
observable = Observable.d(computationLatest, computationLatest2, computationLatest3, computationLatest4, computationLatest5, computationLatest6, computationLatest7, ObservableExtensionsKt.computationLatest(q3), new UserAutocompletableSource$observeUserAutocompletables$2(this, channel));
|
|
} else {
|
|
observable = UserMentionableSourceKt.access$isDmOrGroupDm(channel) ? Observable.j(Observable.A(ChannelUtils.g(channel)).F(UserAutocompletableSource$observeUserAutocompletables$3.INSTANCE).f0(), this.storeUsers.observeMeId(), UserAutocompletableSource$observeUserAutocompletables$4.INSTANCE).Y(new UserAutocompletableSource$observeUserAutocompletables$5(this, channel)) : new j(h0.emptyMap());
|
|
}
|
|
m.checkNotNullExpressionValue(observable, "when {\n // Guild Ch…vable.just(mapOf())\n }");
|
|
Observable<Map<LeadingIdentifier, TreeSet<Autocompletable>>> q4 = ObservableExtensionsKt.computationLatest(observable).q();
|
|
m.checkNotNullExpressionValue(q4, "when {\n // Guild Ch… .distinctUntilChanged()");
|
|
return q4;
|
|
}
|
|
}
|