2021-06-27 20:44:35 +00:00
|
|
|
package com.discord.stores;
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
import android.content.Context;
|
2021-08-09 22:50:01 +00:00
|
|
|
import androidx.core.app.FrameMetricsAggregator;
|
2021-08-24 17:45:16 +00:00
|
|
|
import c.a.d.o;
|
|
|
|
import c.a.e.d;
|
2021-06-27 20:44:35 +00:00
|
|
|
import c.d.b.a.a;
|
|
|
|
import com.discord.api.channel.Channel;
|
|
|
|
import com.discord.api.presence.ClientStatus;
|
|
|
|
import com.discord.models.guild.Guild;
|
2021-07-13 20:48:29 +00:00
|
|
|
import com.discord.models.message.Message;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.restapi.RestAPIParams;
|
|
|
|
import com.discord.stores.StoreStream;
|
2021-08-09 22:50:01 +00:00
|
|
|
import com.discord.utilities.SnowflakeUtils;
|
2021-06-27 20:44:35 +00:00
|
|
|
import com.discord.utilities.analytics.AnalyticsTracker;
|
|
|
|
import com.discord.utilities.fcm.NotificationClient;
|
|
|
|
import com.discord.utilities.persister.Persister;
|
|
|
|
import com.discord.utilities.rest.RestAPI;
|
|
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
|
|
import com.discord.utilities.time.Clock;
|
|
|
|
import com.discord.widgets.notice.NoticePopupChannel;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import kotlin.jvm.functions.Function0;
|
|
|
|
import kotlin.jvm.functions.Function1;
|
|
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
|
|
import rx.Observable;
|
|
|
|
import s.a.j0;
|
|
|
|
/* compiled from: StoreNotifications.kt */
|
|
|
|
public final class StoreNotifications extends Store {
|
|
|
|
public static final Companion Companion = new Companion(null);
|
|
|
|
private static final long INAPP_MESSAGE_WINDOW_MS = 10000;
|
|
|
|
private String authToken;
|
|
|
|
private final Clock clock;
|
|
|
|
private Context context;
|
2021-08-09 22:50:01 +00:00
|
|
|
private final Persister<NotificationClient.SettingsV2> notificationSettings = new Persister<>("STORE_NOTIFICATIONS_SETTINGS_V2", new NotificationClient.SettingsV2(false, false, false, false, false, false, null, null, null, FrameMetricsAggregator.EVERY_DURATION, null));
|
2021-06-27 20:44:35 +00:00
|
|
|
private String pushToken;
|
|
|
|
private String pushTokenPersisted;
|
|
|
|
private final StoreStream stream;
|
|
|
|
|
|
|
|
/* compiled from: StoreNotifications.kt */
|
|
|
|
public static final class Companion {
|
|
|
|
private Companion() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
|
|
this();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public StoreNotifications(Clock clock, StoreStream storeStream) {
|
|
|
|
m.checkNotNullParameter(clock, "clock");
|
|
|
|
m.checkNotNullParameter(storeStream, "stream");
|
|
|
|
this.clock = clock;
|
|
|
|
this.stream = storeStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ Context access$getContext$p(StoreNotifications storeNotifications) {
|
|
|
|
return storeNotifications.context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ String access$getPushToken$p(StoreNotifications storeNotifications) {
|
|
|
|
return storeNotifications.pushToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$handleRegistrationToken(StoreNotifications storeNotifications, String str) {
|
|
|
|
storeNotifications.handleRegistrationToken(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$handleRegistrationTokenPersisted(StoreNotifications storeNotifications, String str) {
|
|
|
|
storeNotifications.handleRegistrationTokenPersisted(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$setContext$p(StoreNotifications storeNotifications, Context context) {
|
|
|
|
storeNotifications.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$setPushToken$p(StoreNotifications storeNotifications, String str) {
|
|
|
|
storeNotifications.pushToken = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void configureContextSetter(Application application) {
|
|
|
|
application.registerActivityLifecycleCallbacks(new StoreNotifications$configureContextSetter$1(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void configureNotificationClient() {
|
|
|
|
NotificationClient.INSTANCE.setRegistrationIdReceived(new StoreNotifications$configureNotificationClient$1(this));
|
|
|
|
Observable<NotificationClient.SettingsV2> settings = getSettings();
|
|
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
2021-07-13 20:48:29 +00:00
|
|
|
Observable j = Observable.j(Observable.h(settings, companion.getAuthentication().getAuthedToken$app_productionGoogleRelease(), companion.getUserSettingsSystem().observeSettings(false), ObservableExtensionsKt.leadingEdgeThrottle(companion.getPermissions().observePermissionsForAllChannels(), 1, TimeUnit.SECONDS).F(StoreNotifications$configureNotificationClient$completedSettings$1.INSTANCE), StoreNotifications$configureNotificationClient$completedSettings$2.INSTANCE).r(), d.d.a(), StoreNotifications$configureNotificationClient$2.INSTANCE);
|
2021-06-27 20:44:35 +00:00
|
|
|
m.checkNotNullExpressionValue(j, "Observable\n .comb… isBackgrounded\n }");
|
2021-07-13 20:48:29 +00:00
|
|
|
Observable r = ObservableExtensionsKt.computationBuffered(j).r();
|
|
|
|
m.checkNotNullExpressionValue(r, "Observable\n .comb… .distinctUntilChanged()");
|
|
|
|
ObservableExtensionsKt.appSubscribe$default(r, (Context) null, "nsClient", (Function1) null, StoreNotifications$configureNotificationClient$3.INSTANCE, (Function1) null, (Function0) null, (Function0) null, 117, (Object) null);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 21:07:36 +00:00
|
|
|
private final void displayPopup(Message message, Channel channel) {
|
2021-06-27 20:44:35 +00:00
|
|
|
Context context;
|
2021-08-09 22:50:01 +00:00
|
|
|
if ((message.getId() >>> 22) + SnowflakeUtils.DISCORD_EPOCH + 10000 > this.clock.currentTimeMillis() && (context = this.context) != null) {
|
2021-06-27 20:44:35 +00:00
|
|
|
NoticePopupChannel noticePopupChannel = NoticePopupChannel.INSTANCE;
|
2021-10-14 23:16:01 +00:00
|
|
|
StringBuilder O = a.O("{InAppNotif}#");
|
|
|
|
O.append(message.getChannelId());
|
|
|
|
noticePopupChannel.enqueue(context, O.toString(), message, new StoreNotifications$displayPopup$1(channel, message));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final synchronized void handleRegistrationToken(String str) {
|
|
|
|
this.pushToken = str;
|
|
|
|
tryTokenPersist();
|
|
|
|
}
|
|
|
|
|
|
|
|
private final synchronized void handleRegistrationTokenPersisted(String str) {
|
|
|
|
this.pushTokenPersisted = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static /* synthetic */ void setEnabledInApp$default(StoreNotifications storeNotifications, boolean z2, boolean z3, int i, Object obj) {
|
|
|
|
if ((i & 2) != 0) {
|
|
|
|
z3 = true;
|
|
|
|
}
|
|
|
|
storeNotifications.setEnabledInApp(z2, z3);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final void tryTokenPersist() {
|
|
|
|
String str = this.authToken;
|
|
|
|
if (str == null) {
|
|
|
|
this.pushTokenPersisted = null;
|
|
|
|
}
|
|
|
|
if (str != null && !m.areEqual(this.pushToken, this.pushTokenPersisted)) {
|
2021-08-24 17:45:16 +00:00
|
|
|
ObservableExtensionsKt.computationBuffered(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().userCreateDevice(new RestAPIParams.UserDevices(this.pushToken)), false, 1, null)).k(o.a.g(null, new StoreNotifications$tryTokenPersist$1(this), null));
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final synchronized String getPushToken() {
|
|
|
|
return this.pushToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final Observable<NotificationClient.SettingsV2> getSettings() {
|
|
|
|
return ObservableExtensionsKt.computationBuffered(this.notificationSettings.getObservable());
|
|
|
|
}
|
|
|
|
|
|
|
|
public final synchronized void handleAuthToken(String str) {
|
|
|
|
this.authToken = str;
|
|
|
|
tryTokenPersist();
|
|
|
|
}
|
|
|
|
|
|
|
|
@StoreThread
|
|
|
|
public final void handleChannelSelected(long j) {
|
2021-10-05 20:14:30 +00:00
|
|
|
c.q.a.k.a.H(c.q.a.k.a.a(j0.a), null, null, new StoreNotifications$handleChannelSelected$1(j, null), 3, null);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-09 21:07:36 +00:00
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:29:0x00ce */
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:41:? A[RETURN, SYNTHETIC] */
|
2021-06-27 20:44:35 +00:00
|
|
|
@StoreThread
|
2021-07-13 20:48:29 +00:00
|
|
|
public final void handleMessageCreate(com.discord.api.message.Message message) {
|
2021-06-27 20:44:35 +00:00
|
|
|
Channel channel;
|
2021-07-09 21:07:36 +00:00
|
|
|
m.checkNotNullParameter(message, "message");
|
2021-06-27 22:10:28 +00:00
|
|
|
if (this.notificationSettings.get().isEnabledInApp() && this.stream.getPresences$app_productionGoogleRelease().getLocalPresence$app_productionGoogleRelease().getStatus() != ClientStatus.DND) {
|
|
|
|
Map<Long, Integer> relationships = this.stream.getUserRelationships$app_productionGoogleRelease().getRelationships();
|
2021-06-27 20:44:35 +00:00
|
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
|
|
for (Map.Entry<Long, Integer> entry : relationships.entrySet()) {
|
|
|
|
if (entry.getValue().intValue() == 2) {
|
|
|
|
linkedHashMap.put(entry.getKey(), entry.getValue());
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 20:48:29 +00:00
|
|
|
if (message.g() != this.stream.getChannelsSelected$app_productionGoogleRelease().getId()) {
|
2021-06-27 22:10:28 +00:00
|
|
|
Map<Long, Map<Long, Channel>> channelsByGuildInternal$app_productionGoogleRelease = this.stream.getChannels$app_productionGoogleRelease().getChannelsByGuildInternal$app_productionGoogleRelease();
|
2021-07-13 20:48:29 +00:00
|
|
|
Long m = message.m();
|
|
|
|
Map<Long, Channel> map = channelsByGuildInternal$app_productionGoogleRelease.get(Long.valueOf(m != null ? m.longValue() : 0));
|
|
|
|
Channel channel2 = this.stream.getChannels$app_productionGoogleRelease().getThreadsByIdInternal$app_productionGoogleRelease().get(Long.valueOf(message.g()));
|
2021-06-27 20:44:35 +00:00
|
|
|
if (channel2 == null) {
|
|
|
|
if (map != null) {
|
2021-07-13 20:48:29 +00:00
|
|
|
channel2 = map.get(Long.valueOf(message.g()));
|
2021-06-27 20:44:35 +00:00
|
|
|
} else {
|
|
|
|
channel = null;
|
|
|
|
if (channel == null) {
|
2021-10-14 23:16:01 +00:00
|
|
|
if (NotificationTextUtils.INSTANCE.shouldNotifyInAppPopup(this.stream.getUsers$app_productionGoogleRelease().getMeInternal$app_productionGoogleRelease(), message, channel, linkedHashMap, map != null ? map.get(Long.valueOf(channel.r())) : null, (Guild) a.s0(channel, this.stream.getGuilds$app_productionGoogleRelease().getGuildsInternal$app_productionGoogleRelease()), this.stream.getGuilds$app_productionGoogleRelease().getGuildMembersComputedInternal$app_productionGoogleRelease(), this.stream.getGuildSettings$app_productionGoogleRelease().getGuildSettingsInternal$app_productionGoogleRelease(), this.stream.getThreadsJoined$app_productionGoogleRelease().getAllJoinedThreadsInternal$app_productionGoogleRelease())) {
|
2021-07-13 20:48:29 +00:00
|
|
|
displayPopup(new Message(message), channel);
|
2021-06-27 20:44:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
channel = channel2;
|
|
|
|
if (channel == null) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void handlePreLogout() {
|
2021-08-09 22:50:01 +00:00
|
|
|
Persister.set$default(this.notificationSettings, new NotificationClient.SettingsV2(false, false, false, false, false, false, null, null, null, FrameMetricsAggregator.EVERY_DURATION, null), false, 2, null);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final void init(Application application) {
|
|
|
|
m.checkNotNullParameter(application, "application");
|
|
|
|
super.init((Context) application);
|
|
|
|
configureContextSetter(application);
|
|
|
|
configureNotificationClient();
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setEnabled(boolean z2) {
|
|
|
|
this.notificationSettings.getAndSet(true, new StoreNotifications$setEnabled$1(z2));
|
|
|
|
AnalyticsTracker.INSTANCE.updateNotifications(z2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setEnabledInApp(boolean z2, boolean z3) {
|
|
|
|
NotificationClient.SettingsV2 andSet = this.notificationSettings.getAndSet(true, new StoreNotifications$setEnabledInApp$oldValue$1(z2));
|
|
|
|
if (z3 && andSet.isEnabledInApp() != z2) {
|
|
|
|
AnalyticsTracker.INSTANCE.updateNotificationsInApp(z2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setNotificationLightDisabled(boolean z2) {
|
|
|
|
this.notificationSettings.getAndSet(true, new StoreNotifications$setNotificationLightDisabled$1(z2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setNotificationSoundDisabled(boolean z2) {
|
|
|
|
this.notificationSettings.getAndSet(true, new StoreNotifications$setNotificationSoundDisabled$1(z2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setNotificationsVibrateDisabled(boolean z2) {
|
|
|
|
this.notificationSettings.getAndSet(true, new StoreNotifications$setNotificationsVibrateDisabled$1(z2));
|
|
|
|
}
|
|
|
|
}
|