258 lines
14 KiB
Java
258 lines
14 KiB
Java
package com.discord.utilities.presence;
|
|
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.activity.Activity;
|
|
import com.discord.api.activity.ActivityAssets;
|
|
import com.discord.api.activity.ActivityEmoji;
|
|
import com.discord.api.activity.ActivityParty;
|
|
import com.discord.api.activity.ActivityPlatform;
|
|
import com.discord.api.activity.ActivityTimestamps;
|
|
import com.discord.api.activity.ActivityType;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.api.guild.GuildFeature;
|
|
import com.discord.api.stageinstance.StageInstance;
|
|
import com.discord.api.stageinstance.StageInstancePrivacyLevel;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreThread;
|
|
import com.discord.utilities.platform.Platform;
|
|
import com.discord.utilities.time.ClockFactory;
|
|
import com.discord.widgets.chat.input.MentionUtilsKt;
|
|
import com.discord.widgets.stage.StageRoles;
|
|
import d0.d0.f;
|
|
import d0.g0.a;
|
|
import d0.g0.t;
|
|
import d0.g0.w;
|
|
import d0.o;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import kotlin.Pair;
|
|
/* compiled from: ActivityUtils.kt */
|
|
public final class ActivityUtilsKt {
|
|
private static final long STAGE_PRESENCE_APPLICATION_ID = 834488117758001152L;
|
|
private static final long STAGE_PRESENCE_FLAG_GUILD_IS_PARTNERED = 2;
|
|
private static final long STAGE_PRESENCE_FLAG_GUILD_IS_VERIFIED = 4;
|
|
private static final long STAGE_PRESENCE_FLAG_USER_IS_SPEAKER = 1;
|
|
private static final String STAGE_PRESENCE_PARTY_PREFIX = "stage:";
|
|
private static final long XBOX_APPLICATION_ID = 438122941302046720L;
|
|
|
|
public static final Activity createCustomStatusActivity(String str, ActivityEmoji activityEmoji, long j) {
|
|
return new Activity("Custom Status", ActivityType.CUSTOM_STATUS, null, j, null, null, null, str, activityEmoji, null, null, null, null, null, null, null, null, null);
|
|
}
|
|
|
|
public static final Activity createPlayingActivity(String str, long j) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
return new Activity(str, ActivityType.PLAYING, null, j, null, null, null, null, null, null, null, null, null, null, null, ActivityPlatform.ANDROID, null, null);
|
|
}
|
|
|
|
public static final Activity createSpotifyListeningActivity(long j, String str, String str2, String str3, String str4, String str5, String str6, long j2, long j3, String str7) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
ActivityType activityType = ActivityType.LISTENING;
|
|
ActivityAssets activityAssets = new ActivityAssets(str5, str4, null, null);
|
|
return new Activity(str, activityType, null, j, new ActivityTimestamps(String.valueOf(j2), String.valueOf(j3)), null, str2, str6, null, new ActivityParty(str7, null), activityAssets, 48, str3, null, null, null, null, null);
|
|
}
|
|
|
|
@StoreThread
|
|
public static final Activity createStageChannelListeningActivity() {
|
|
Guild guild;
|
|
int i;
|
|
String str;
|
|
ActivityTimestamps o;
|
|
Collection<StageRoles> values;
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
long selectedVoiceChannelId = companion.getVoiceChannelSelected().getSelectedVoiceChannelId();
|
|
Channel channel = companion.getChannels().getChannel(selectedVoiceChannelId);
|
|
if (channel == null || !AnimatableValueParser.x1(channel)) {
|
|
return null;
|
|
}
|
|
Map<Long, StageRoles> channelRolesInternal = companion.getStageChannels().getChannelRolesInternal(selectedVoiceChannelId);
|
|
StageRoles r1 = companion.getStageChannels().m11getMyRolesInternalvisDeB4(selectedVoiceChannelId);
|
|
StageInstance stageInstanceForChannelInternal = companion.getStageInstances().getStageInstanceForChannelInternal(channel.h());
|
|
if (!(stageInstanceForChannelInternal == null || (guild = companion.getGuilds().getGuild(channel.f())) == null)) {
|
|
String r12 = m15packStageChannelPartyIdhLOU_GE(channel, guild, r1, stageInstanceForChannelInternal);
|
|
if (channelRolesInternal == null || (values = channelRolesInternal.values()) == null) {
|
|
i = 0;
|
|
} else {
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Object obj : values) {
|
|
if (StageRoles.m26isSpeakerimpl(((StageRoles) obj).m28unboximpl())) {
|
|
arrayList.add(obj);
|
|
}
|
|
}
|
|
i = arrayList.size();
|
|
}
|
|
int size = channelRolesInternal != null ? channelRolesInternal.size() : 0;
|
|
StoreStream.Companion companion2 = StoreStream.Companion;
|
|
Activity applicationActivity = companion2.getPresences().getApplicationActivity(companion2.getUsers().getMe().getId(), STAGE_PRESENCE_APPLICATION_ID);
|
|
StageCallRichPresencePartyData unpackStageChannelParty = unpackStageChannelParty(applicationActivity);
|
|
if (!(unpackStageChannelParty != null && unpackStageChannelParty.getGuildId() == guild.getId() && unpackStageChannelParty.getChannelId() == channel.h())) {
|
|
applicationActivity = null;
|
|
}
|
|
if (applicationActivity == null || (o = applicationActivity.o()) == null || (str = String.valueOf(o.c())) == null) {
|
|
str = String.valueOf(ClockFactory.get().currentTimeMillis());
|
|
}
|
|
if (stageInstanceForChannelInternal.e() != StageInstancePrivacyLevel.PUBLIC) {
|
|
return null;
|
|
}
|
|
return new Activity(stageInstanceForChannelInternal.f(), ActivityType.LISTENING, null, ClockFactory.get().currentTimeMillis(), new ActivityTimestamps(str, null), Long.valueOf((long) STAGE_PRESENCE_APPLICATION_ID), null, null, null, new ActivityParty(r12, n.listOf((Object[]) new Integer[]{Integer.valueOf(i), Integer.valueOf(size)})), new ActivityAssets(null, null, guild.getIcon(), guild.getName()), null, null, null, null, null, null, null);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static final ActivityPlatform getGamePlatform(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$gamePlatform");
|
|
if (!isGameActivity(activity)) {
|
|
return null;
|
|
}
|
|
if (isXboxActivity(activity)) {
|
|
return ActivityPlatform.XBOX;
|
|
}
|
|
ActivityPlatform j = activity.j();
|
|
return j != null ? j : ActivityPlatform.DESKTOP;
|
|
}
|
|
|
|
public static final StageCallRichPresencePartyData getStageChannelRichPresencePartyData(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$stageChannelRichPresencePartyData");
|
|
return unpackStageChannelParty(activity);
|
|
}
|
|
|
|
private static /* synthetic */ void getXBOX_APPLICATION_ID$annotations() {
|
|
}
|
|
|
|
public static final boolean hasFlag(Activity activity, int i) {
|
|
m.checkNotNullParameter(activity, "$this$hasFlag");
|
|
Integer g = activity.g();
|
|
return ((g != null ? g.intValue() : 0) & i) == i;
|
|
}
|
|
|
|
public static final boolean isCurrentPlatform(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isCurrentPlatform");
|
|
ActivityPlatform j = activity.j();
|
|
ActivityPlatform activityPlatform = ActivityPlatform.ANDROID;
|
|
if (j == activityPlatform) {
|
|
return true;
|
|
}
|
|
List<ActivityPlatform> m = activity.m();
|
|
return m != null && m.contains(activityPlatform);
|
|
}
|
|
|
|
public static final boolean isCustomStatus(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isCustomStatus");
|
|
return activity.p() == ActivityType.CUSTOM_STATUS;
|
|
}
|
|
|
|
public static final boolean isGameActivity(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isGameActivity");
|
|
return activity.p() == ActivityType.PLAYING;
|
|
}
|
|
|
|
public static final boolean isGamePlatform(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isGamePlatform");
|
|
return isXboxActivity(activity) || (activity.j() != null && activity.j() == ActivityPlatform.SAMSUNG);
|
|
}
|
|
|
|
public static final boolean isRichPresence(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isRichPresence");
|
|
if (!isCustomStatus(activity)) {
|
|
if (activity.b() != null || activity.i() != null) {
|
|
return true;
|
|
}
|
|
String l = activity.l();
|
|
if (!(l == null || l.length() == 0)) {
|
|
return true;
|
|
}
|
|
String e = activity.e();
|
|
if (!(e == null || e.length() == 0)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static final boolean isSpotifyActivity(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isSpotifyActivity");
|
|
return t.equals(activity.h(), Platform.SPOTIFY.getProperName(), true);
|
|
}
|
|
|
|
public static final boolean isStageChannelActivity(Activity activity) {
|
|
Long a;
|
|
m.checkNotNullParameter(activity, "$this$isStageChannelActivity");
|
|
return activity.p() == ActivityType.LISTENING && (a = activity.a()) != null && a.longValue() == STAGE_PRESENCE_APPLICATION_ID;
|
|
}
|
|
|
|
public static final boolean isStreaming(Activity activity) {
|
|
m.checkNotNullParameter(activity, "$this$isStreaming");
|
|
return activity.p() == ActivityType.STREAMING;
|
|
}
|
|
|
|
public static final boolean isXboxActivity(Activity activity) {
|
|
Long a;
|
|
m.checkNotNullParameter(activity, "$this$isXboxActivity");
|
|
return (activity.j() != null && activity.j() == ActivityPlatform.XBOX) || !(activity.a() == null || (a = activity.a()) == null || a.longValue() != XBOX_APPLICATION_ID);
|
|
}
|
|
|
|
/* renamed from: packStageChannelPartyId-hLOU_GE reason: not valid java name */
|
|
private static final String m15packStageChannelPartyIdhLOU_GE(Channel channel, Guild guild, StageRoles stageRoles, StageInstance stageInstance) {
|
|
String l = Long.toString((stageRoles == null || !StageRoles.m26isSpeakerimpl(stageRoles.m28unboximpl())) ? guild.hasFeature(GuildFeature.PARTNERED) ? 2 : guild.hasFeature(GuildFeature.VERIFIED) ? 4 : 0 : 1, a.checkRadix(16));
|
|
m.checkNotNullExpressionValue(l, "java.lang.Long.toString(this, checkRadix(radix))");
|
|
StringBuilder L = c.d.b.a.a.L(STAGE_PRESENCE_PARTY_PREFIX);
|
|
L.append(channel.f());
|
|
L.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
L.append(channel.h());
|
|
L.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
L.append(l);
|
|
L.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
L.append(stageInstance.c());
|
|
return L.toString();
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:22:0x0036 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:23:0x0043 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:29:0x00c5 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:30:0x00c8 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:33:0x00d1 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:34:0x00d3 A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:37:0x00db A[Catch:{ Exception -> 0x00e7 }] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:38:0x00de A[Catch:{ Exception -> 0x00e7 }] */
|
|
private static final StageCallRichPresencePartyData unpackStageChannelParty(Activity activity) {
|
|
ActivityParty i;
|
|
String a;
|
|
boolean z2;
|
|
if (activity == null || (i = activity.i()) == null || (a = i.a()) == null || !t.startsWith$default(a, STAGE_PRESENCE_PARTY_PREFIX, false, 2, null)) {
|
|
return null;
|
|
}
|
|
try {
|
|
ActivityParty i2 = activity.i();
|
|
List<Integer> b = i2 != null ? i2.b() : null;
|
|
if (b != null) {
|
|
if (!b.isEmpty()) {
|
|
z2 = false;
|
|
Pair pair = !z2 ? o.to(0, 0) : b.size() != 2 ? o.to(0, 0) : o.to(b.get(0), b.get(1));
|
|
int intValue = ((Number) pair.component1()).intValue();
|
|
int coerceAtLeast = f.coerceAtLeast(0, ((Number) pair.component2()).intValue() - intValue);
|
|
List split$default = w.split$default((CharSequence) a, new char[]{MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR}, false, 0, 6, (Object) null);
|
|
long parseLong = Long.parseLong((String) split$default.get(3), a.checkRadix(16));
|
|
return new StageCallRichPresencePartyData(Long.parseLong((String) split$default.get(4)), Long.parseLong((String) split$default.get(2)), (1 & parseLong) == 0, Long.parseLong((String) split$default.get(1)), (2 & parseLong) == 0, (4 & parseLong) == 0, intValue, coerceAtLeast);
|
|
}
|
|
}
|
|
z2 = true;
|
|
if (!z2) {
|
|
}
|
|
int intValue = ((Number) pair.component1()).intValue();
|
|
int coerceAtLeast = f.coerceAtLeast(0, ((Number) pair.component2()).intValue() - intValue);
|
|
List split$default = w.split$default((CharSequence) a, new char[]{MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR}, false, 0, 6, (Object) null);
|
|
long parseLong = Long.parseLong((String) split$default.get(3), a.checkRadix(16));
|
|
return new StageCallRichPresencePartyData(Long.parseLong((String) split$default.get(4)), Long.parseLong((String) split$default.get(2)), (1 & parseLong) == 0, Long.parseLong((String) split$default.get(1)), (2 & parseLong) == 0, (4 & parseLong) == 0, intValue, coerceAtLeast);
|
|
} catch (Exception unused) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|