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

361 lines
18 KiB
Java

package com.discord.stores;
import android.content.Context;
import c.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.models.domain.ModelMuteConfig;
import com.discord.models.domain.ModelNotificationSettings;
import com.discord.models.domain.ModelPayload;
import com.discord.models.guild.Guild;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.updates.ObservationDeck;
import com.discord.stores.updates.ObservationDeckProvider;
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 d0.t.h0;
import d0.t.n0;
import d0.t.u;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.Subscription;
import rx.subjects.PublishSubject;
/* compiled from: StoreUserGuildSettings.kt */
public final class StoreUserGuildSettings extends StoreV2 {
private final StoreAnalytics analytics;
private final Clock clock;
private final Dispatcher dispatcher;
private final PublishSubject<Event> eventSubject;
private final Map<Long, ModelNotificationSettings> guildSettings;
private final Persister<Map<Long, ModelNotificationSettings>> guildSettingsCache;
private Map<Long, ? extends ModelNotificationSettings> guildSettingsSnapshot;
private final HashSet<Long> guildsToHideMutedChannelsIn;
private final Persister<Set<Long>> guildsToHideMutedChannelsInCache;
private Set<Long> guildsToHideMutedChannelsInSnapshot;
private final ObservationDeck observationDeck;
private Subscription recomputeSettingsSubscription;
private final RestAPI restApi;
private final StoreChannels storeChannels;
/* compiled from: StoreUserGuildSettings.kt */
public static abstract class Event {
/* compiled from: StoreUserGuildSettings.kt */
public static final class SettingsUpdated extends Event {
private final SettingsUpdateType type;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public SettingsUpdated(SettingsUpdateType settingsUpdateType) {
super(null);
m.checkNotNullParameter(settingsUpdateType, "type");
this.type = settingsUpdateType;
}
public static /* synthetic */ SettingsUpdated copy$default(SettingsUpdated settingsUpdated, SettingsUpdateType settingsUpdateType, int i, Object obj) {
if ((i & 1) != 0) {
settingsUpdateType = settingsUpdated.type;
}
return settingsUpdated.copy(settingsUpdateType);
}
public final SettingsUpdateType component1() {
return this.type;
}
public final SettingsUpdated copy(SettingsUpdateType settingsUpdateType) {
m.checkNotNullParameter(settingsUpdateType, "type");
return new SettingsUpdated(settingsUpdateType);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof SettingsUpdated) && m.areEqual(this.type, ((SettingsUpdated) obj).type);
}
return true;
}
public final SettingsUpdateType getType() {
return this.type;
}
public int hashCode() {
SettingsUpdateType settingsUpdateType = this.type;
if (settingsUpdateType != null) {
return settingsUpdateType.hashCode();
}
return 0;
}
public String toString() {
StringBuilder L = a.L("SettingsUpdated(type=");
L.append(this.type);
L.append(")");
return L.toString();
}
}
private Event() {
}
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: StoreUserGuildSettings.kt */
public enum SettingsUpdateType {
GUILD,
CHANNEL,
CATEGORY
}
public StoreUserGuildSettings(Dispatcher dispatcher, Clock clock, StoreAnalytics storeAnalytics, StoreChannels storeChannels, ObservationDeck observationDeck, RestAPI restAPI) {
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(storeAnalytics, "analytics");
m.checkNotNullParameter(storeChannels, "storeChannels");
m.checkNotNullParameter(observationDeck, "observationDeck");
m.checkNotNullParameter(restAPI, "restApi");
this.dispatcher = dispatcher;
this.clock = clock;
this.analytics = storeAnalytics;
this.storeChannels = storeChannels;
this.observationDeck = observationDeck;
this.restApi = restAPI;
this.guildSettings = new HashMap();
this.guildsToHideMutedChannelsIn = new HashSet<>();
this.guildSettingsSnapshot = h0.emptyMap();
this.guildsToHideMutedChannelsInSnapshot = n0.emptySet();
this.guildSettingsCache = new Persister<>("STORE_SETTINGS_USER_GUILD_V5", new HashMap());
this.guildsToHideMutedChannelsInCache = new Persister<>("STORE_SHOW_HIDE_MUTED_CHANNELS_V2", new HashSet());
this.eventSubject = PublishSubject.k0();
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreUserGuildSettings(Dispatcher dispatcher, Clock clock, StoreAnalytics storeAnalytics, StoreChannels storeChannels, ObservationDeck observationDeck, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(dispatcher, clock, storeAnalytics, storeChannels, (i & 16) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 32) != 0 ? RestAPI.Companion.getApi() : restAPI);
}
public static final /* synthetic */ StoreAnalytics access$getAnalytics$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.analytics;
}
public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.dispatcher;
}
public static final /* synthetic */ PublishSubject access$getEventSubject$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.eventSubject;
}
public static final /* synthetic */ HashSet access$getGuildsToHideMutedChannelsIn$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.guildsToHideMutedChannelsIn;
}
public static final /* synthetic */ Subscription access$getRecomputeSettingsSubscription$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.recomputeSettingsSubscription;
}
public static final /* synthetic */ StoreChannels access$getStoreChannels$p(StoreUserGuildSettings storeUserGuildSettings) {
return storeUserGuildSettings.storeChannels;
}
public static final /* synthetic */ void access$recomputeMuteConfigs(StoreUserGuildSettings storeUserGuildSettings) {
storeUserGuildSettings.recomputeMuteConfigs();
}
public static final /* synthetic */ void access$setRecomputeSettingsSubscription$p(StoreUserGuildSettings storeUserGuildSettings, Subscription subscription) {
storeUserGuildSettings.recomputeSettingsSubscription = subscription;
}
public static final /* synthetic */ void access$updateUserGuildSettings(StoreUserGuildSettings storeUserGuildSettings, Context context, long j, RestAPIParams.UserGuildSettings userGuildSettings, SettingsUpdateType settingsUpdateType) {
storeUserGuildSettings.updateUserGuildSettings(context, j, userGuildSettings, settingsUpdateType);
}
@StoreThread
private final void handleGuildSettings(List<? extends ModelNotificationSettings> list) {
Subscription subscription = this.recomputeSettingsSubscription;
if (subscription != null) {
subscription.unsubscribe();
}
for (ModelNotificationSettings modelNotificationSettings : list) {
ModelNotificationSettings copyAndRecomputeTransientFields = modelNotificationSettings.copyAndRecomputeTransientFields(this.clock);
Map<Long, ModelNotificationSettings> map = this.guildSettings;
m.checkNotNullExpressionValue(copyAndRecomputeTransientFields, "computedSettings");
if (!m.areEqual(copyAndRecomputeTransientFields, map.get(Long.valueOf(copyAndRecomputeTransientFields.getGuildId())))) {
this.guildSettings.put(Long.valueOf(copyAndRecomputeTransientFields.getGuildId()), copyAndRecomputeTransientFields);
markChanged();
}
}
long j = Long.MAX_VALUE;
for (ModelNotificationSettings modelNotificationSettings2 : this.guildSettings.values()) {
j = Math.min(j, modelNotificationSettings2.getNextMuteEndTimeMs(this.clock));
}
if (j < Long.MAX_VALUE) {
Observable<Long> e02 = Observable.e0(j - this.clock.currentTimeMillis(), TimeUnit.MILLISECONDS, this.dispatcher.getScheduler());
m.checkNotNullExpressionValue(e02, "Observable.timer(\n …patcher.scheduler\n )");
ObservableExtensionsKt.appSubscribe$default(e02, StoreUserGuildSettings.class, (Context) null, new StoreUserGuildSettings$handleGuildSettings$1(this), (Function1) null, (Function0) null, (Function0) null, new StoreUserGuildSettings$handleGuildSettings$2(this), 58, (Object) null);
}
}
@StoreThread
private final void recomputeMuteConfigs() {
handleGuildSettingUpdated$app_productionBetaRelease(new ArrayList(this.guildSettings.values()));
}
public static /* synthetic */ void setChannelMuted$default(StoreUserGuildSettings storeUserGuildSettings, Context context, long j, boolean z2, ModelMuteConfig modelMuteConfig, int i, Object obj) {
if ((i & 8) != 0) {
modelMuteConfig = null;
}
storeUserGuildSettings.setChannelMuted(context, j, z2, modelMuteConfig);
}
public static /* synthetic */ void setGuildMuted$default(StoreUserGuildSettings storeUserGuildSettings, Context context, long j, boolean z2, ModelMuteConfig modelMuteConfig, int i, Object obj) {
if ((i & 8) != 0) {
modelMuteConfig = null;
}
storeUserGuildSettings.setGuildMuted(context, j, z2, modelMuteConfig);
}
public static /* synthetic */ void setGuildToggles$default(StoreUserGuildSettings storeUserGuildSettings, Context context, Guild guild, Boolean bool, Boolean bool2, Boolean bool3, Boolean bool4, int i, Object obj) {
storeUserGuildSettings.setGuildToggles(context, guild, (i & 4) != 0 ? null : bool, (i & 8) != 0 ? null : bool2, (i & 16) != 0 ? null : bool3, (i & 32) != 0 ? null : bool4);
}
private final void updateUserGuildSettings(Context context, long j, RestAPIParams.UserGuildSettings userGuildSettings, SettingsUpdateType settingsUpdateType) {
Set<Long> keySet;
Map<Long, RestAPIParams.UserGuildSettings.ChannelOverride> channelOverrides = userGuildSettings.getChannelOverrides();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(ObservableExtensionsKt.restSubscribeOn$default(this.restApi.updateUserGuildSettings(j, userGuildSettings), false, 1, null)), StoreUserGuildSettings.class, context, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new StoreUserGuildSettings$updateUserGuildSettings$1(this, (channelOverrides == null || (keySet = channelOverrides.keySet()) == null) ? null : (Long) u.firstOrNull(keySet), settingsUpdateType), 60, (Object) null);
}
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.Map<java.lang.Long, ? extends com.discord.models.domain.ModelNotificationSettings>, java.util.Map<java.lang.Long, com.discord.models.domain.ModelNotificationSettings> */
public final Map<Long, ModelNotificationSettings> getGuildSettings() {
return this.guildSettingsSnapshot;
}
@StoreThread
public final Map<Long, ModelNotificationSettings> getGuildSettingsInternal$app_productionBetaRelease() {
return this.guildSettings;
}
public final Set<Long> getGuildsToHideMutedChannelsIn() {
return this.guildsToHideMutedChannelsInSnapshot;
}
@StoreThread
public final void handleConnectionOpen$app_productionBetaRelease(ModelPayload modelPayload) {
m.checkNotNullParameter(modelPayload, "payload");
ModelPayload.VersionedUserGuildSettings userGuildSettings = modelPayload.getUserGuildSettings();
m.checkNotNullExpressionValue(userGuildSettings, "payload.userGuildSettings");
if (!userGuildSettings.isPartial()) {
this.guildSettings.clear();
}
ModelPayload.VersionedUserGuildSettings userGuildSettings2 = modelPayload.getUserGuildSettings();
m.checkNotNullExpressionValue(userGuildSettings2, "payload.userGuildSettings");
List<ModelNotificationSettings> entries = userGuildSettings2.getEntries();
m.checkNotNullExpressionValue(entries, "payload.userGuildSettings.entries");
handleGuildSettings(entries);
markChanged();
}
@StoreThread
public final void handleGuildSettingUpdated$app_productionBetaRelease(List<? extends ModelNotificationSettings> list) {
m.checkNotNullParameter(list, "guildSettingsList");
handleGuildSettings(list);
}
@Override // com.discord.stores.Store
public void init(Context context) {
m.checkNotNullParameter(context, "context");
super.init(context);
this.guildsToHideMutedChannelsIn.addAll(this.guildsToHideMutedChannelsInCache.get());
this.guildSettings.putAll(this.guildSettingsCache.get());
markChanged();
}
public final Observable<Event> observeEvents() {
PublishSubject<Event> publishSubject = this.eventSubject;
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
return publishSubject;
}
public final Observable<Map<Long, ModelNotificationSettings>> observeGuildSettings() {
return ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserGuildSettings$observeGuildSettings$1(this), 14, null);
}
public final Observable<ModelNotificationSettings> observeGuildSettings(long j) {
Observable<ModelNotificationSettings> r = observeGuildSettings().F(new StoreUserGuildSettings$observeGuildSettings$2(j)).r();
m.checkNotNullExpressionValue(r, "observeGuildSettings()\n … .distinctUntilChanged()");
return r;
}
public final Observable<Boolean> observeHideMutedChannels(long j) {
Observable<Boolean> r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreUserGuildSettings$observeHideMutedChannels$1(this), 14, null).F(new StoreUserGuildSettings$observeHideMutedChannels$2(j)).r();
m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()");
return r;
}
public final Observable<List<Long>> observeMutedGuildIds() {
Observable<List<Long>> r = observeGuildSettings().F(StoreUserGuildSettings$observeMutedGuildIds$1.INSTANCE).r();
m.checkNotNullExpressionValue(r, "observeGuildSettings()\n … .distinctUntilChanged()");
return r;
}
public final void setChannelFrequency(Context context, Channel channel, int i) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(channel, "channel");
updateUserGuildSettings(context, channel.f(), new RestAPIParams.UserGuildSettings(channel.h(), new RestAPIParams.UserGuildSettings.ChannelOverride(Integer.valueOf(i))), SettingsUpdateType.CHANNEL);
}
public final void setChannelMuted(Context context, long j, boolean z2, ModelMuteConfig modelMuteConfig) {
m.checkNotNullParameter(context, "context");
this.dispatcher.schedule(new StoreUserGuildSettings$setChannelMuted$1(this, j, context, z2, modelMuteConfig));
}
public final void setChannelNotificationsDefault(Context context, Channel channel) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(channel, "channel");
updateUserGuildSettings(context, channel.f(), new RestAPIParams.UserGuildSettings(channel.h(), new RestAPIParams.UserGuildSettings.ChannelOverride(Boolean.FALSE, null, Integer.valueOf(ModelNotificationSettings.FREQUENCY_UNSET))), SettingsUpdateType.CHANNEL);
}
public final void setGuildFrequency(Context context, Guild guild, int i) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(guild, "guild");
updateUserGuildSettings(context, guild.getId(), new RestAPIParams.UserGuildSettings(null, null, null, null, null, Integer.valueOf(i), null, 95, null), SettingsUpdateType.GUILD);
}
public final void setGuildMuted(Context context, long j, boolean z2, ModelMuteConfig modelMuteConfig) {
m.checkNotNullParameter(context, "context");
updateUserGuildSettings(context, j, new RestAPIParams.UserGuildSettings(null, null, Boolean.valueOf(z2), modelMuteConfig, null, null, null, 115, null), SettingsUpdateType.GUILD);
}
public final void setGuildToggles(Context context, Guild guild, Boolean bool, Boolean bool2, Boolean bool3, Boolean bool4) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(guild, "guild");
updateUserGuildSettings(context, guild.getId(), new RestAPIParams.UserGuildSettings(bool, bool2, bool3, null, bool4, null, null, 104, null), SettingsUpdateType.GUILD);
}
public final void setHideMutedChannels(long j, boolean z2) {
this.dispatcher.schedule(new StoreUserGuildSettings$setHideMutedChannels$1(this, z2, j));
}
@Override // com.discord.stores.StoreV2
public void snapshotData() {
super.snapshotData();
this.guildSettingsSnapshot = new HashMap(this.guildSettings);
Persister.set$default(this.guildSettingsCache, this.guildSettings, false, 2, null);
this.guildsToHideMutedChannelsInSnapshot = new HashSet(this.guildsToHideMutedChannelsIn);
this.guildsToHideMutedChannelsInCache.set(this.guildsToHideMutedChannelsIn, true);
}
}