2021-06-27 20:44:35 +00:00
|
|
|
package com.discord.utilities.threads;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
|
|
import com.discord.api.channel.Channel;
|
2021-07-03 23:36:06 +00:00
|
|
|
import com.discord.api.guild.GuildFeature;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.api.thread.ThreadMetadata;
|
2021-07-03 23:36:06 +00:00
|
|
|
import com.discord.models.guild.Guild;
|
|
|
|
import com.discord.models.message.Message;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.models.user.User;
|
|
|
|
import com.discord.restapi.RestAPIParams;
|
|
|
|
import com.discord.stores.StoreThreadsActiveJoined;
|
|
|
|
import com.discord.stores.StoreThreadsJoined;
|
|
|
|
import com.discord.utilities.permissions.PermissionUtils;
|
|
|
|
import com.discord.utilities.rest.RestAPI;
|
|
|
|
import com.discord.utilities.time.Clock;
|
|
|
|
import com.discord.utilities.time.ClockFactory;
|
|
|
|
import com.discord.utilities.time.TimeUtils;
|
|
|
|
import com.discord.widgets.chat.list.CreateThreadsFeatureFlag;
|
|
|
|
import com.discord.widgets.chat.list.ViewThreadsFeatureFlag;
|
|
|
|
import d0.d0.f;
|
2021-07-03 23:36:06 +00:00
|
|
|
import d0.o;
|
2021-06-27 20:44:35 +00:00
|
|
|
import d0.t.g0;
|
|
|
|
import d0.t.h0;
|
|
|
|
import d0.t.n;
|
|
|
|
import d0.t.t;
|
2021-07-03 23:36:06 +00:00
|
|
|
import d0.t.u;
|
2021-06-27 20:44:35 +00:00
|
|
|
import d0.z.d.m;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2021-07-03 23:36:06 +00:00
|
|
|
import java.util.Set;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.SortedSet;
|
|
|
|
import rx.Observable;
|
|
|
|
/* compiled from: ThreadUtils.kt */
|
|
|
|
public final class ThreadUtils {
|
2021-07-03 23:36:06 +00:00
|
|
|
public static final int DEFAULT_AUTO_ARCHIVE_DURATION = 1440;
|
2021-06-27 20:44:35 +00:00
|
|
|
public static final ThreadUtils INSTANCE = new ThreadUtils();
|
|
|
|
public static final int MAX_DISPLAYED_THREAD_BROWSER_ICON_COUNT = 99;
|
|
|
|
public static final int MAX_THREAD_NAME_LENGTH = 30;
|
2021-07-03 23:36:06 +00:00
|
|
|
private static final List<Integer> THREAD_AUTO_ARCHIVE_DURATIONS;
|
|
|
|
private static final LinkedHashMap<Integer, Integer> THREAD_AUTO_ARCHIVE_DURATION_NAMES;
|
|
|
|
|
|
|
|
static {
|
|
|
|
LinkedHashMap<Integer, Integer> linkedMapOf = h0.linkedMapOf(o.to(60, 2131886778), o.to(1440, 2131886780), o.to(4320, 2131886781), o.to(10080, 2131886779));
|
|
|
|
THREAD_AUTO_ARCHIVE_DURATION_NAMES = linkedMapOf;
|
|
|
|
Set<Integer> keySet = linkedMapOf.keySet();
|
|
|
|
m.checkNotNullExpressionValue(keySet, "THREAD_AUTO_ARCHIVE_DURATION_NAMES.keys");
|
|
|
|
THREAD_AUTO_ARCHIVE_DURATIONS = u.toList(keySet);
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
private ThreadUtils() {
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public static /* synthetic */ Observable createThread$default(ThreadUtils threadUtils, long j, Long l, int i, String str, Integer num, int i2, Object obj) {
|
|
|
|
if ((i2 & 16) != 0) {
|
2021-06-27 20:44:35 +00:00
|
|
|
num = null;
|
|
|
|
}
|
2021-07-03 23:36:06 +00:00
|
|
|
return threadUtils.createThread(j, l, i, str, num);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static /* synthetic */ long getThreadAckMessageTimestamp$default(ThreadUtils threadUtils, Channel channel, Long l, Long l2, Clock clock, int i, Object obj) {
|
|
|
|
if ((i & 4) != 0) {
|
|
|
|
clock = ClockFactory.get();
|
|
|
|
}
|
|
|
|
return threadUtils.getThreadAckMessageTimestamp(channel, l, l2, clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Comparator<StoreThreadsActiveJoined.ActiveJoinedThread> getThreadTimestampComparator() {
|
|
|
|
return ThreadUtils$getThreadTimestampComparator$1.INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r10v0, resolved type: java.util.Map<java.lang.Long, ? extends java.util.Collection<com.discord.api.channel.Channel>> */
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
|
|
private final Map<Long, Collection<Channel>> prependSelectedThread(Map<Long, ? extends Collection<Channel>> map, Channel channel) {
|
|
|
|
boolean z2;
|
|
|
|
boolean z3;
|
2021-07-03 23:36:06 +00:00
|
|
|
Collection collection = (Collection) map.get(Long.valueOf(channel.r()));
|
2021-06-27 20:44:35 +00:00
|
|
|
if (collection == null) {
|
|
|
|
collection = n.emptyList();
|
|
|
|
}
|
|
|
|
if (!(collection instanceof Collection) || !collection.isEmpty()) {
|
|
|
|
Iterator it = collection.iterator();
|
|
|
|
while (true) {
|
|
|
|
if (!it.hasNext()) {
|
|
|
|
break;
|
|
|
|
}
|
2021-07-03 23:36:06 +00:00
|
|
|
if (((Channel) it.next()).h() == channel.h()) {
|
2021-06-27 20:44:35 +00:00
|
|
|
z3 = true;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
z3 = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (z3) {
|
|
|
|
z2 = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
z2 = false;
|
|
|
|
if (z2) {
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
Map<Long, Collection<Channel>> mutableMap = h0.toMutableMap(map);
|
2021-07-03 23:36:06 +00:00
|
|
|
Long valueOf = Long.valueOf(channel.r());
|
2021-06-27 20:44:35 +00:00
|
|
|
List mutableListOf = n.mutableListOf(channel);
|
|
|
|
mutableListOf.addAll(collection);
|
|
|
|
mutableMap.put(valueOf, mutableListOf);
|
|
|
|
return mutableMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Map<Long, Collection<Channel>> sortThreadsByJoinedDate(Map<Long, ? extends Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> map) {
|
|
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap(g0.mapCapacity(map.size()));
|
|
|
|
Iterator<T> it = map.entrySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Map.Entry entry = (Map.Entry) it.next();
|
|
|
|
Object key = entry.getKey();
|
|
|
|
SortedSet<StoreThreadsActiveJoined.ActiveJoinedThread> sortedSet = t.toSortedSet(((Map) entry.getValue()).values(), INSTANCE.getThreadTimestampComparator());
|
2021-07-03 23:36:06 +00:00
|
|
|
ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(sortedSet, 10));
|
2021-06-27 20:44:35 +00:00
|
|
|
for (StoreThreadsActiveJoined.ActiveJoinedThread activeJoinedThread : sortedSet) {
|
|
|
|
arrayList.add(activeJoinedThread.getChannel());
|
|
|
|
}
|
|
|
|
linkedHashMap.put(key, arrayList);
|
|
|
|
}
|
|
|
|
return linkedHashMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final String autoArchiveDurationName(Context context, int i) {
|
|
|
|
m.checkNotNullParameter(context, "context");
|
2021-07-03 23:36:06 +00:00
|
|
|
Integer num = THREAD_AUTO_ARCHIVE_DURATION_NAMES.get(Integer.valueOf(i));
|
|
|
|
if (num != null) {
|
|
|
|
m.checkNotNullExpressionValue(num, "it");
|
|
|
|
String string = context.getString(num.intValue());
|
|
|
|
if (string != null) {
|
|
|
|
return string;
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-07-03 23:36:06 +00:00
|
|
|
String quantityString = context.getResources().getQuantityString(2131755065, i / 60);
|
|
|
|
m.checkNotNullExpressionValue(quantityString, "context.resources.getQua…ours_hours, minutes / 60)");
|
|
|
|
return quantityString;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final boolean canCreatePrivateThread(Long l, Channel channel, Guild guild) {
|
|
|
|
if (guild == null || channel == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isThreadsEnabled(guild.getId()) && (PermissionUtils.INSTANCE.hasAccessWrite(channel, l) && PermissionUtils.can(68719476736L, l) && PermissionUtils.can(65536, l)) && (AnimatableValueParser.z1(channel) ^ true) && guild.hasFeature(GuildFeature.PRIVATE_THREADS);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final boolean canCreatePublicThread(Long l, Channel channel, Message message, Guild guild) {
|
|
|
|
if (guild == null || channel == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isThreadsEnabled(guild.getId()) && (PermissionUtils.INSTANCE.hasAccessWrite(channel, l) && PermissionUtils.can(34359738368L, l)) && ((message == null || !message.isSystemMessage()) && !AnimatableValueParser.z1(channel) && (message == null || !message.hasThread()));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final boolean canCreateThread(Long l, Channel channel, Message message, Guild guild) {
|
|
|
|
return canCreatePublicThread(l, channel, message, guild) || canCreatePrivateThread(l, channel, guild);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean canManageThread(User user, Channel channel, Long l) {
|
|
|
|
m.checkNotNullParameter(user, "user");
|
|
|
|
m.checkNotNullParameter(channel, "channel");
|
2021-07-03 23:36:06 +00:00
|
|
|
if (channel.q() != user.getId() || !PermissionUtils.INSTANCE.hasAccessWrite(channel, l)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
return PermissionUtils.can(17179869184L, l) && PermissionUtils.INSTANCE.hasAccess(channel, l);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean canUnarchiveThread(Channel channel, Long l) {
|
|
|
|
m.checkNotNullParameter(channel, "channel");
|
2021-07-03 23:36:06 +00:00
|
|
|
ThreadMetadata y2 = channel.y();
|
|
|
|
return m.areEqual(y2 != null ? Boolean.valueOf(y2.d()) : null, Boolean.TRUE) ? PermissionUtils.can(17179869184L, l) && PermissionUtils.INSTANCE.hasAccessWrite(channel, l) : PermissionUtils.INSTANCE.hasAccessWrite(channel, l);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean canViewAllPrivateThreads(Long l) {
|
|
|
|
return PermissionUtils.can(17179869184L, l) && PermissionUtils.can(65536, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean canViewAllPublicArchivedThreads(Channel channel, Long l) {
|
|
|
|
return channel != null && PermissionUtils.INSTANCE.hasAccess(channel, l) && PermissionUtils.can(65536, l);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final long computeThreadAutoArchiveTimeMs(Channel channel) {
|
|
|
|
String a;
|
|
|
|
m.checkNotNullParameter(channel, "channel");
|
2021-07-03 23:36:06 +00:00
|
|
|
long i = (channel.i() >>> 22) + 1420070400000L;
|
|
|
|
ThreadMetadata y2 = channel.y();
|
|
|
|
int c2 = (y2 != null ? y2.c() : 0) * 60 * 1000;
|
|
|
|
ThreadMetadata y3 = channel.y();
|
|
|
|
return Math.max(i, (y3 == null || (a = y3.a()) == null) ? 0 : TimeUtils.parseUTCDate(a)) + ((long) c2);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final int computeThreadNotificationSetting(StoreThreadsJoined.JoinedThread joinedThread, boolean z2) {
|
|
|
|
Integer valueOf = joinedThread != null ? Integer.valueOf(joinedThread.getFlags()) : null;
|
|
|
|
if (valueOf == null) {
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
if ((valueOf.intValue() & 2) == 0) {
|
|
|
|
if ((valueOf.intValue() & 4) == 0) {
|
|
|
|
if ((valueOf.intValue() & 8) != 0) {
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
if (!z2 && (valueOf.intValue() & 1) != 0) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final Observable<Channel> createThread(long j, Long l, int i, String str, Integer num) {
|
2021-06-27 20:44:35 +00:00
|
|
|
m.checkNotNullParameter(str, "name");
|
2021-07-03 23:36:06 +00:00
|
|
|
RestAPIParams.ThreadCreationSettings threadCreationSettings = new RestAPIParams.ThreadCreationSettings(str, i, num);
|
2021-06-27 20:44:35 +00:00
|
|
|
return l == null ? RestAPI.Companion.getApi().createThread(j, threadCreationSettings) : RestAPI.Companion.getApi().createThreadFromMessage(j, l.longValue(), threadCreationSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final String generateDefaultName(String str, String str2) {
|
|
|
|
m.checkNotNullParameter(str, "messageText");
|
|
|
|
String str3 = "";
|
|
|
|
if (d0.g0.t.isBlank(str)) {
|
|
|
|
str = str2 != null ? str2 : str3;
|
|
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
String substring = str.substring(0, f.coerceAtMost(30, str.length()));
|
|
|
|
m.checkNotNullExpressionValue(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
|
|
|
|
sb.append(substring);
|
|
|
|
if (str.length() > 30) {
|
|
|
|
str3 = "...";
|
|
|
|
}
|
|
|
|
sb.append(str3);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final List<Integer> getTHREAD_AUTO_ARCHIVE_DURATIONS() {
|
|
|
|
return THREAD_AUTO_ARCHIVE_DURATIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final LinkedHashMap<Integer, Integer> getTHREAD_AUTO_ARCHIVE_DURATION_NAMES() {
|
|
|
|
return THREAD_AUTO_ARCHIVE_DURATION_NAMES;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
public final long getThreadAckMessageTimestamp(Channel channel, Long l, Long l2, Clock clock) {
|
|
|
|
String a;
|
|
|
|
m.checkNotNullParameter(channel, "$this$getThreadAckMessageTimestamp");
|
|
|
|
m.checkNotNullParameter(clock, "clock");
|
|
|
|
long longValue = l != null ? l.longValue() : clock.currentTimeMillis();
|
|
|
|
long longValue2 = l2 != null ? l2.longValue() - ((long) 5000) : 0;
|
2021-07-03 23:36:06 +00:00
|
|
|
ThreadMetadata y2 = channel.y();
|
|
|
|
long max = Math.max(longValue2, (y2 == null || (a = y2.a()) == null) ? 0 : TimeUtils.parseUTCDate(a));
|
2021-06-27 20:44:35 +00:00
|
|
|
if (max == 0) {
|
2021-07-03 23:36:06 +00:00
|
|
|
max = TimeUtils.parseSnowflake(Long.valueOf(channel.h()));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
return Math.max(longValue, max);
|
|
|
|
}
|
|
|
|
|
2021-07-03 23:36:06 +00:00
|
|
|
public final boolean isThreadsEnabled(long j) {
|
|
|
|
return ViewThreadsFeatureFlag.Companion.getINSTANCE().isEnabled() && CreateThreadsFeatureFlag.Companion.getINSTANCE().isEnabled(j);
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
public final Map<Long, Collection<Channel>> sortThreadsForChannelList(Map<Long, ? extends Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread>> map, Channel channel) {
|
|
|
|
m.checkNotNullParameter(map, "threadsMap");
|
|
|
|
if (!ViewThreadsFeatureFlag.Companion.getINSTANCE().isEnabled()) {
|
|
|
|
return h0.emptyMap();
|
|
|
|
}
|
|
|
|
Map<Long, Collection<Channel>> sortThreadsByJoinedDate = sortThreadsByJoinedDate(map);
|
2021-07-03 23:36:06 +00:00
|
|
|
return (channel == null || !AnimatableValueParser.z1(channel)) ? sortThreadsByJoinedDate : prependSelectedThread(sortThreadsByJoinedDate, channel);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|