discord-jadx/app/src/main/java/com/discord/api/channel/ChannelUtils.java

360 lines
13 KiB
Java

package com.discord.api.channel;
import android.content.Context;
import com.discord.R;
import com.discord.api.channel.Channel;
import com.discord.api.guild.GuildFeature;
import com.discord.api.permission.Permission;
import com.discord.api.permission.PermissionOverwrite;
import com.discord.api.role.GuildRole;
import com.discord.api.thread.ThreadMetadata;
import com.discord.api.user.User;
import com.discord.models.guild.Guild;
import com.discord.models.presence.Presence;
import com.discord.models.user.CoreUser;
import com.discord.utilities.PermissionOverwriteUtilsKt;
import com.discord.utilities.guilds.GuildUtilsKt;
import com.discord.utilities.guilds.RoleUtils;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.user.UserUtils;
import d0.t.n;
import d0.t.o;
import d0.t.u;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* compiled from: ChannelUtils.kt */
public final class ChannelUtils {
private static final long HQ_DIRECTORY_CHANNEL_ID = 883060064561299456L;
public static final boolean A(Channel channel) {
User user;
m.checkNotNullParameter(channel, "$this$isSystemDM");
if (channel.A() == 1) {
List<User> w = channel.w();
if (m.areEqual((w == null || (user = (User) u.firstOrNull(w)) == null) ? null : user.p(), Boolean.TRUE)) {
return true;
}
}
return false;
}
public static final boolean B(Channel channel) {
m.checkNotNullParameter(channel, "$this$isTextChannel");
return x(channel) || s(channel);
}
public static final boolean C(Channel channel) {
m.checkNotNullParameter(channel, "$this$isThread");
return channel.A() == 10 || channel.A() == 11 || channel.A() == 12;
}
public static final boolean D(Channel channel) {
m.checkNotNullParameter(channel, "$this$isThreaded");
return channel.A() == 0 || channel.A() == 5 || channel.A() == 15;
}
public static final boolean E(Channel channel) {
m.checkNotNullParameter(channel, "$this$isVoiceChannel");
return channel.A() == 2;
}
public static final boolean F(Channel channel) {
m.checkNotNullParameter(channel, "$this$shouldPlayJoinLeaveSounds");
return E(channel) || x(channel);
}
public static final com.discord.models.user.User a(Channel channel) {
List<User> w;
List<User> w2;
User user;
m.checkNotNullParameter(channel, "$this$getDMRecipient");
if (!m(channel) || (w = channel.w()) == null || w.size() != 1 || (w2 = channel.w()) == null || (user = (User) u.first((List<? extends Object>) w2)) == null) {
return null;
}
return new CoreUser(user);
}
public static final Integer b(Channel channel) {
m.checkNotNullParameter(channel, "$this$getDeletedMessage");
if (k(channel)) {
return Integer.valueOf((int) R.string.category_has_been_deleted);
}
if (C(channel)) {
return Integer.valueOf((int) R.string.thread_has_been_deleted);
}
if (x(channel)) {
return null;
}
return Integer.valueOf((int) R.string.channel_has_been_deleted);
}
public static final String c(Channel channel) {
String str;
m.checkNotNullParameter(channel, "$this$getDisplayName");
if (x(channel)) {
String m = channel.m();
if (m == null || m.length() == 0) {
List<User> w = channel.w();
str = w != null ? u.joinToString$default(w, null, null, null, 0, null, ChannelUtils$getDisplayName$1.INSTANCE, 31, null) : null;
if (str == null) {
return "";
}
return str;
}
}
str = channel.m();
if (str == null) {
return "";
}
return str;
}
public static final String d(Channel channel, Context context, boolean z2) {
m.checkNotNullParameter(channel, "$this$getDisplayNameOrDefault");
m.checkNotNullParameter(context, "context");
String c2 = c(channel);
boolean z3 = false;
if (r(channel) || i(channel)) {
if (c2.length() == 0) {
z3 = true;
}
if (z3) {
String string = context.getString(R.string.invalid_text_channel);
m.checkNotNullExpressionValue(string, "context.getString(R.string.invalid_text_channel)");
return string;
} else if (z2) {
StringBuilder sb = new StringBuilder();
m.checkNotNullParameter(Channel.Companion, "$this$DISPLAY_PREFIX_GUILD");
sb.append("#");
sb.append(c2);
return sb.toString();
}
} else if (t(channel)) {
if (c2.length() == 0) {
z3 = true;
}
if (z3) {
String string2 = context.getString(R.string.invalid_voice_channel);
m.checkNotNullExpressionValue(string2, "context.getString(R.string.invalid_voice_channel)");
return string2;
}
} else if (p(channel)) {
if (c2.length() == 0) {
z3 = true;
}
if (z3) {
String string3 = context.getString(R.string.unnamed);
m.checkNotNullExpressionValue(string3, "context.getString(R.string.unnamed)");
return string3;
}
} else if (m(channel)) {
if (c2.length() == 0) {
z3 = true;
}
if (z3) {
String string4 = context.getString(R.string.direct_message);
m.checkNotNullExpressionValue(string4, "context.getString(R.string.direct_message)");
return string4;
} else if (z2) {
StringBuilder sb2 = new StringBuilder();
m.checkNotNullParameter(Channel.Companion, "$this$DISPLAY_PREFIX_DM");
sb2.append("@");
sb2.append(c2);
return sb2.toString();
}
}
return c2;
}
public static /* synthetic */ String e(Channel channel, Context context, boolean z2, int i) {
if ((i & 2) != 0) {
z2 = true;
}
return d(channel, context, z2);
}
public static final PermissionOverwrite f(Channel channel, long j) {
boolean z2;
m.checkNotNullParameter(channel, "$this$getPermissionOverwriteForId");
List<PermissionOverwrite> s2 = channel.s();
Object obj = null;
if (s2 == null) {
return null;
}
Iterator<T> it = s2.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
Object next = it.next();
if (((PermissionOverwrite) next).e() == j) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
obj = next;
break;
}
}
return (PermissionOverwrite) obj;
}
public static final List<com.discord.models.user.User> g(Channel channel) {
m.checkNotNullParameter(channel, "$this$getRecipients");
List<User> w = channel.w();
if (w == null) {
return n.emptyList();
}
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(w, 10));
for (User user : w) {
arrayList.add(new CoreUser(user));
}
return arrayList;
}
public static final Comparator<Channel> h(Channel.Companion companion) {
m.checkNotNullParameter(companion, "$this$getSortByNameAndType");
return new ChannelUtils$getSortByNameAndType$1(companion);
}
public static final boolean i(Channel channel) {
m.checkNotNullParameter(channel, "$this$isAnnouncementChannel");
return channel.A() == 5;
}
public static final boolean j(Channel channel) {
m.checkNotNullParameter(channel, "$this$isArchivedThread");
ThreadMetadata y2 = channel.y();
return y2 != null && y2.b();
}
public static final boolean k(Channel channel) {
m.checkNotNullParameter(channel, "$this$isCategory");
return channel.A() == 4;
}
public static final boolean l(int i) {
return i == 0 || i == 5 || i == 10 || i == 11 || i == 12 || i == 14 || i == 15;
}
public static final boolean m(Channel channel) {
m.checkNotNullParameter(channel, "$this$isDM");
return channel.A() == 1;
}
public static final boolean n(Channel channel, Presence presence) {
m.checkNotNullParameter(channel, "$this$isDMStatusVisible");
com.discord.models.user.User a = a(channel);
return m(channel) && !A(channel) && (a != null ? UserUtils.INSTANCE.isStatusVisible(a, presence, true) : false);
}
public static final boolean o(Channel channel) {
m.checkNotNullParameter(channel, "$this$isDirectory");
return channel.A() == 14;
}
public static final boolean p(Channel channel) {
m.checkNotNullParameter(channel, "$this$isGroup");
return channel.A() == 3;
}
public static final boolean q(Channel channel, Guild guild, GuildRole guildRole, Map<Long, GuildRole> map) {
Object obj;
boolean z2;
m.checkNotNullParameter(channel, "$this$isGuildRoleSubscriptionChannel");
if (guild != null && guild.hasFeature(GuildFeature.ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE)) {
List<PermissionOverwrite> s2 = channel.s();
if (s2 == null) {
s2 = n.emptyList();
}
for (PermissionOverwrite permissionOverwrite : s2) {
GuildRole guildRole2 = GuildUtilsKt.getGuildRole(Long.valueOf(permissionOverwrite.e()));
if (guildRole2 != null && RoleUtils.isSubscriptionRolePurchasableOrHasSubscribers(guildRole2) && PermissionOverwriteUtilsKt.grantsAccessTo(permissionOverwrite, channel)) {
return true;
}
}
boolean isFullyGatedGuildRoleSubscriptionGuild = GuildUtilsKt.isFullyGatedGuildRoleSubscriptionGuild(guild, guildRole);
Iterator<T> it = s2.iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
}
obj = it.next();
if (((PermissionOverwrite) obj).e() == guild.getId()) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
break;
}
}
PermissionOverwrite permissionOverwrite2 = (PermissionOverwrite) obj;
boolean deniesAccessTo = permissionOverwrite2 != null ? PermissionOverwriteUtilsKt.deniesAccessTo(permissionOverwrite2, channel) : false;
if (map != null && !deniesAccessTo && isFullyGatedGuildRoleSubscriptionGuild) {
for (GuildRole guildRole3 : map.values()) {
if (RoleUtils.isSubscriptionRolePurchasableOrHasSubscribers(guildRole3) && PermissionUtils.INSTANCE.canRole(Permission.VIEW_CHANNEL, guildRole3, null)) {
return true;
}
}
}
}
return false;
}
public static final boolean r(Channel channel) {
m.checkNotNullParameter(channel, "$this$isGuildTextChannel");
return channel.A() == 0 || channel.A() == 15;
}
public static final boolean s(Channel channel) {
m.checkNotNullParameter(channel, "$this$isGuildTextyChannel");
return l(channel.A());
}
public static final boolean t(Channel channel) {
m.checkNotNullParameter(channel, "$this$isGuildVocalChannel");
return channel.A() == 2 || channel.A() == 13;
}
public static final boolean u(Channel channel) {
m.checkNotNullParameter(channel, "$this$isHQDirectoryChannel");
return channel.h() == HQ_DIRECTORY_CHANNEL_ID;
}
public static final boolean v(Channel channel) {
m.checkNotNullParameter(channel, "$this$isManaged");
return channel.b() != 0;
}
public static final boolean w(Channel channel) {
m.checkNotNullParameter(channel, "$this$isMultiUserDM");
return channel.A() == 3;
}
public static final boolean x(Channel channel) {
m.checkNotNullParameter(channel, "$this$isPrivate");
return channel.A() == 1 || channel.A() == 3;
}
public static final boolean y(Channel channel) {
m.checkNotNullParameter(channel, "$this$isPrivateThread");
return channel.A() == 12;
}
public static final boolean z(Channel channel) {
m.checkNotNullParameter(channel, "$this$isStageVoiceChannel");
return channel.A() == 13;
}
}