discord-jadx/app/src/main/java/com/discord/stores/StoreNotifications.java

228 lines
11 KiB
Java

package com.discord.stores;
import android.app.Application;
import android.content.Context;
import c.a.d.q;
import c.a.e.d;
import c.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.api.presence.ClientStatus;
import com.discord.models.guild.Guild;
import com.discord.models.message.Message;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreStream;
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;
private final Persister<NotificationClient.SettingsV2> notificationSettings = new Persister<>("STORE_NOTIFICATIONS_SETTINGS_V2", new NotificationClient.SettingsV2(false, false, false, false, false, false, null, null, null, 511, null));
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;
Observable j = Observable.j(Observable.h(settings, companion.getAuthentication().getAuthedToken$app_productionBetaRelease(), 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);
m.checkNotNullExpressionValue(j, "Observable\n .comb… isBackgrounded\n }");
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);
}
private final void displayPopup(Message message, Channel channel) {
Context context;
if ((message.getId() >>> 22) + 1420070400000L + 10000 > this.clock.currentTimeMillis() && (context = this.context) != null) {
NoticePopupChannel noticePopupChannel = NoticePopupChannel.INSTANCE;
StringBuilder L = a.L("{InAppNotif}#");
L.append(message.getChannelId());
noticePopupChannel.enqueue(context, L.toString(), message, new StoreNotifications$displayPopup$1(channel, message));
}
}
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)) {
ObservableExtensionsKt.computationBuffered(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().userCreateDevice(new RestAPIParams.UserDevices(this.pushToken)), false, 1, null)).k(q.a.g(null, new StoreNotifications$tryTokenPersist$1(this), null));
}
}
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) {
c.q.a.k.a.G(c.q.a.k.a.a(j0.a), null, null, new StoreNotifications$handleChannelSelected$1(j, null), 3, null);
}
/* JADX WARNING: Removed duplicated region for block: B:29:0x00ce */
/* JADX WARNING: Removed duplicated region for block: B:41:? A[RETURN, SYNTHETIC] */
@StoreThread
public final void handleMessageCreate(com.discord.api.message.Message message) {
Channel channel;
m.checkNotNullParameter(message, "message");
if (this.notificationSettings.get().isEnabledInApp() && this.stream.getPresences$app_productionBetaRelease().getLocalPresence$app_productionBetaRelease().getStatus() != ClientStatus.DND) {
Map<Long, Integer> relationships = this.stream.getUserRelationships$app_productionBetaRelease().getRelationships();
LinkedHashMap linkedHashMap = new LinkedHashMap();
for (Map.Entry<Long, Integer> entry : relationships.entrySet()) {
if (entry.getValue().intValue() == 2) {
linkedHashMap.put(entry.getKey(), entry.getValue());
}
}
if (message.g() != this.stream.getChannelsSelected$app_productionBetaRelease().getId()) {
Map<Long, Map<Long, Channel>> channelsByGuildInternal$app_productionBetaRelease = this.stream.getChannels$app_productionBetaRelease().getChannelsByGuildInternal$app_productionBetaRelease();
Long m = message.m();
Map<Long, Channel> map = channelsByGuildInternal$app_productionBetaRelease.get(Long.valueOf(m != null ? m.longValue() : 0));
Channel channel2 = this.stream.getChannels$app_productionBetaRelease().getThreadsByIdInternal$app_productionBetaRelease().get(Long.valueOf(message.g()));
if (channel2 == null) {
if (map != null) {
channel2 = map.get(Long.valueOf(message.g()));
} else {
channel = null;
if (channel == null) {
if (NotificationTextUtils.INSTANCE.shouldNotifyInAppPopup(this.stream.getUsers$app_productionBetaRelease().getMeInternal$app_productionBetaRelease(), message, channel, linkedHashMap, map != null ? map.get(Long.valueOf(channel.r())) : null, (Guild) a.c(channel, this.stream.getGuilds$app_productionBetaRelease().getGuildsInternal$app_productionBetaRelease()), this.stream.getGuilds$app_productionBetaRelease().getGuildMembersComputedInternal$app_productionBetaRelease(), this.stream.getGuildSettings$app_productionBetaRelease().getGuildSettingsInternal$app_productionBetaRelease(), this.stream.getThreadsJoined$app_productionBetaRelease().getAllJoinedThreadsInternal$app_productionBetaRelease())) {
displayPopup(new Message(message), channel);
return;
}
return;
}
return;
}
}
channel = channel2;
if (channel == null) {
}
}
}
}
public final void handlePreLogout() {
Persister.set$default(this.notificationSettings, new NotificationClient.SettingsV2(false, false, false, false, false, false, null, null, null, 511, null), false, 2, null);
}
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));
}
}