discord-jadx/app/src/main/java/com/discord/widgets/settings/MuteSettingsSheetViewModel....

740 lines
28 KiB
Java

package com.discord.widgets.settings;
import a0.a.a.b;
import android.content.Context;
import androidx.annotation.MainThread;
import c.d.b.a.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.api.channel.Channel;
import com.discord.app.AppViewModel;
import com.discord.models.domain.ModelMuteConfig;
import com.discord.models.domain.ModelNotificationSettings;
import com.discord.models.guild.Guild;
import com.discord.stores.StoreChannels;
import com.discord.stores.StoreGuilds;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUserGuildSettings;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.time.Clock;
import com.discord.utilities.time.ClockFactory;
import com.discord.utilities.time.TimeUtils;
import com.discord.widgets.chat.input.MentionUtilsKt;
import d0.z.d.m;
import d0.z.d.o;
import java.util.Iterator;
import java.util.List;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.subjects.PublishSubject;
/* compiled from: MuteSettingsSheetViewModel.kt */
public final class MuteSettingsSheetViewModel extends AppViewModel<ViewState> {
public static final Companion Companion = new Companion(null);
public static final long MUTE_DURATION_ALWAYS = 0;
private final long channelId;
private final Clock clock;
private final Config config;
private final PublishSubject<Event> eventSubject;
private final long guildId;
private final Observable<StoreState> storeStateObservable;
private final StoreUserGuildSettings storeUserGuildSettings;
/* compiled from: MuteSettingsSheetViewModel.kt */
/* renamed from: com.discord.widgets.settings.MuteSettingsSheetViewModel$1 reason: invalid class name */
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
public final /* synthetic */ MuteSettingsSheetViewModel this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AnonymousClass1(MuteSettingsSheetViewModel muteSettingsSheetViewModel) {
super(1);
this.this$0 = muteSettingsSheetViewModel;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
invoke(storeState);
return Unit.a;
}
public final void invoke(StoreState storeState) {
m.checkNotNullParameter(storeState, "storeState");
MuteSettingsSheetViewModel.access$handleStoreState(this.this$0, storeState);
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Observable access$observeStoreState(Companion companion, long j, long j2, StoreGuilds storeGuilds, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings) {
return companion.observeStoreState(j, j2, storeGuilds, storeChannels, storeUserGuildSettings);
}
private final Observable<StoreState> observeStoreState(long j, long j2, StoreGuilds storeGuilds, StoreChannels storeChannels, StoreUserGuildSettings storeUserGuildSettings) {
Observable<StoreState> i = Observable.i(storeGuilds.observeGuild(j), storeChannels.observeChannel(j2), storeUserGuildSettings.observeGuildSettings(), MuteSettingsSheetViewModel$Companion$observeStoreState$1.INSTANCE);
m.checkNotNullExpressionValue(i, "Observable.combineLatest…d ?: 0]\n )\n }");
return i;
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static abstract class Config {
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Channel extends Config {
private final long channelId;
public Channel(long j) {
super(null);
this.channelId = j;
}
public static /* synthetic */ Channel copy$default(Channel channel, long j, int i, Object obj) {
if ((i & 1) != 0) {
j = channel.channelId;
}
return channel.copy(j);
}
public final long component1() {
return this.channelId;
}
public final Channel copy(long j) {
return new Channel(j);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Channel) && this.channelId == ((Channel) obj).channelId;
}
return true;
}
public final long getChannelId() {
return this.channelId;
}
public int hashCode() {
return b.a(this.channelId);
}
public String toString() {
return a.A(a.P("Channel(channelId="), this.channelId, ")");
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Guild extends Config {
private final long guildId;
public Guild(long j) {
super(null);
this.guildId = j;
}
public static /* synthetic */ Guild copy$default(Guild guild, long j, int i, Object obj) {
if ((i & 1) != 0) {
j = guild.guildId;
}
return guild.copy(j);
}
public final long component1() {
return this.guildId;
}
public final Guild copy(long j) {
return new Guild(j);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Guild) && this.guildId == ((Guild) obj).guildId;
}
return true;
}
public final long getGuildId() {
return this.guildId;
}
public int hashCode() {
return b.a(this.guildId);
}
public String toString() {
return a.A(a.P("Guild(guildId="), this.guildId, ")");
}
}
private Config() {
}
public /* synthetic */ Config(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static abstract class Event {
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Dismiss extends Event {
public static final Dismiss INSTANCE = new Dismiss();
private Dismiss() {
super(null);
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class NavigateToChannelSettings extends Event {
private final long channelId;
public NavigateToChannelSettings(long j) {
super(null);
this.channelId = j;
}
public static /* synthetic */ NavigateToChannelSettings copy$default(NavigateToChannelSettings navigateToChannelSettings, long j, int i, Object obj) {
if ((i & 1) != 0) {
j = navigateToChannelSettings.channelId;
}
return navigateToChannelSettings.copy(j);
}
public final long component1() {
return this.channelId;
}
public final NavigateToChannelSettings copy(long j) {
return new NavigateToChannelSettings(j);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof NavigateToChannelSettings) && this.channelId == ((NavigateToChannelSettings) obj).channelId;
}
return true;
}
public final long getChannelId() {
return this.channelId;
}
public int hashCode() {
return b.a(this.channelId);
}
public String toString() {
return a.A(a.P("NavigateToChannelSettings(channelId="), this.channelId, ")");
}
}
private Event() {
}
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public enum SettingsType {
GUILD,
DM,
GROUP_DM,
GUILD_CHANNEL,
CATEGORY,
UNKNOWN
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class StoreState {
private final Channel channel;
private final Guild guild;
private final ModelNotificationSettings guildNotificationSettings;
public StoreState(Guild guild, Channel channel, ModelNotificationSettings modelNotificationSettings) {
this.guild = guild;
this.channel = channel;
this.guildNotificationSettings = modelNotificationSettings;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ StoreState(Guild guild, Channel channel, ModelNotificationSettings modelNotificationSettings, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(guild, channel, (i & 4) != 0 ? null : modelNotificationSettings);
}
public static /* synthetic */ StoreState copy$default(StoreState storeState, Guild guild, Channel channel, ModelNotificationSettings modelNotificationSettings, int i, Object obj) {
if ((i & 1) != 0) {
guild = storeState.guild;
}
if ((i & 2) != 0) {
channel = storeState.channel;
}
if ((i & 4) != 0) {
modelNotificationSettings = storeState.guildNotificationSettings;
}
return storeState.copy(guild, channel, modelNotificationSettings);
}
public final Guild component1() {
return this.guild;
}
public final Channel component2() {
return this.channel;
}
public final ModelNotificationSettings component3() {
return this.guildNotificationSettings;
}
public final StoreState copy(Guild guild, Channel channel, ModelNotificationSettings modelNotificationSettings) {
return new StoreState(guild, channel, modelNotificationSettings);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StoreState)) {
return false;
}
StoreState storeState = (StoreState) obj;
return m.areEqual(this.guild, storeState.guild) && m.areEqual(this.channel, storeState.channel) && m.areEqual(this.guildNotificationSettings, storeState.guildNotificationSettings);
}
public final Channel getChannel() {
return this.channel;
}
public final Guild getGuild() {
return this.guild;
}
public final ModelNotificationSettings getGuildNotificationSettings() {
return this.guildNotificationSettings;
}
public int hashCode() {
Guild guild = this.guild;
int i = 0;
int hashCode = (guild != null ? guild.hashCode() : 0) * 31;
Channel channel = this.channel;
int hashCode2 = (hashCode + (channel != null ? channel.hashCode() : 0)) * 31;
ModelNotificationSettings modelNotificationSettings = this.guildNotificationSettings;
if (modelNotificationSettings != null) {
i = modelNotificationSettings.hashCode();
}
return hashCode2 + i;
}
public String toString() {
StringBuilder P = a.P("StoreState(guild=");
P.append(this.guild);
P.append(", channel=");
P.append(this.channel);
P.append(", guildNotificationSettings=");
P.append(this.guildNotificationSettings);
P.append(")");
return P.toString();
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static abstract class ViewState {
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Failure extends ViewState {
public static final Failure INSTANCE = new Failure();
private Failure() {
super(null);
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Loaded extends ViewState {
private final boolean isChannelMuted;
private final boolean isGuildMuted;
private final String muteEndTime;
private final int notificationOverride;
private final SettingsType settingsType;
private final String subtitle;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public Loaded(SettingsType settingsType, String str, boolean z2, boolean z3, String str2, int i) {
super(null);
m.checkNotNullParameter(settingsType, "settingsType");
m.checkNotNullParameter(str, "subtitle");
this.settingsType = settingsType;
this.subtitle = str;
this.isChannelMuted = z2;
this.isGuildMuted = z3;
this.muteEndTime = str2;
this.notificationOverride = i;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ Loaded(SettingsType settingsType, String str, boolean z2, boolean z3, String str2, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(settingsType, str, (i2 & 4) != 0 ? false : z2, (i2 & 8) != 0 ? false : z3, (i2 & 16) != 0 ? null : str2, (i2 & 32) != 0 ? ModelNotificationSettings.FREQUENCY_UNSET : i);
}
public static /* synthetic */ Loaded copy$default(Loaded loaded, SettingsType settingsType, String str, boolean z2, boolean z3, String str2, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
settingsType = loaded.settingsType;
}
if ((i2 & 2) != 0) {
str = loaded.subtitle;
}
if ((i2 & 4) != 0) {
z2 = loaded.isChannelMuted;
}
if ((i2 & 8) != 0) {
z3 = loaded.isGuildMuted;
}
if ((i2 & 16) != 0) {
str2 = loaded.muteEndTime;
}
if ((i2 & 32) != 0) {
i = loaded.notificationOverride;
}
return loaded.copy(settingsType, str, z2, z3, str2, i);
}
public final SettingsType component1() {
return this.settingsType;
}
public final String component2() {
return this.subtitle;
}
public final boolean component3() {
return this.isChannelMuted;
}
public final boolean component4() {
return this.isGuildMuted;
}
public final String component5() {
return this.muteEndTime;
}
public final int component6() {
return this.notificationOverride;
}
public final Loaded copy(SettingsType settingsType, String str, boolean z2, boolean z3, String str2, int i) {
m.checkNotNullParameter(settingsType, "settingsType");
m.checkNotNullParameter(str, "subtitle");
return new Loaded(settingsType, str, z2, z3, str2, i);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Loaded)) {
return false;
}
Loaded loaded = (Loaded) obj;
return m.areEqual(this.settingsType, loaded.settingsType) && m.areEqual(this.subtitle, loaded.subtitle) && this.isChannelMuted == loaded.isChannelMuted && this.isGuildMuted == loaded.isGuildMuted && m.areEqual(this.muteEndTime, loaded.muteEndTime) && this.notificationOverride == loaded.notificationOverride;
}
public final String getMuteEndTime() {
return this.muteEndTime;
}
public final int getNotificationOverride() {
return this.notificationOverride;
}
public final SettingsType getSettingsType() {
return this.settingsType;
}
public final String getSubtitle() {
return this.subtitle;
}
public int hashCode() {
SettingsType settingsType = this.settingsType;
int i = 0;
int hashCode = (settingsType != null ? settingsType.hashCode() : 0) * 31;
String str = this.subtitle;
int hashCode2 = (hashCode + (str != null ? str.hashCode() : 0)) * 31;
boolean z2 = this.isChannelMuted;
int i2 = 1;
if (z2) {
z2 = true;
}
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
int i6 = (hashCode2 + i3) * 31;
boolean z3 = this.isGuildMuted;
if (!z3) {
i2 = z3 ? 1 : 0;
}
int i7 = (i6 + i2) * 31;
String str2 = this.muteEndTime;
if (str2 != null) {
i = str2.hashCode();
}
return ((i7 + i) * 31) + this.notificationOverride;
}
public final boolean isChannelMuted() {
return this.isChannelMuted;
}
public final boolean isGuildMuted() {
return this.isGuildMuted;
}
public String toString() {
StringBuilder P = a.P("Loaded(settingsType=");
P.append(this.settingsType);
P.append(", subtitle=");
P.append(this.subtitle);
P.append(", isChannelMuted=");
P.append(this.isChannelMuted);
P.append(", isGuildMuted=");
P.append(this.isGuildMuted);
P.append(", muteEndTime=");
P.append(this.muteEndTime);
P.append(", notificationOverride=");
return a.z(P, this.notificationOverride, ")");
}
}
/* compiled from: MuteSettingsSheetViewModel.kt */
public static final class Uninitialized extends ViewState {
public static final Uninitialized INSTANCE = new Uninitialized();
private Uninitialized() {
super(null);
}
}
private ViewState() {
}
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
SettingsType.values();
int[] iArr = new int[6];
$EnumSwitchMapping$0 = iArr;
iArr[SettingsType.GUILD.ordinal()] = 1;
iArr[SettingsType.GUILD_CHANNEL.ordinal()] = 2;
iArr[SettingsType.DM.ordinal()] = 3;
iArr[SettingsType.GROUP_DM.ordinal()] = 4;
iArr[SettingsType.CATEGORY.ordinal()] = 5;
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public MuteSettingsSheetViewModel(long j, long j2, Observable<StoreState> observable, StoreUserGuildSettings storeUserGuildSettings, Clock clock) {
super(ViewState.Uninitialized.INSTANCE);
m.checkNotNullParameter(observable, "storeStateObservable");
m.checkNotNullParameter(storeUserGuildSettings, "storeUserGuildSettings");
m.checkNotNullParameter(clock, "clock");
this.guildId = j;
this.channelId = j2;
this.storeStateObservable = observable;
this.storeUserGuildSettings = storeUserGuildSettings;
this.clock = clock;
this.config = j != 0 ? new Config.Guild(j) : new Config.Channel(j2);
this.eventSubject = PublishSubject.j0();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), MuteSettingsSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
}
/* JADX WARNING: Illegal instructions before constructor call */
public /* synthetic */ MuteSettingsSheetViewModel(long j, long j2, Observable observable, StoreUserGuildSettings storeUserGuildSettings, Clock clock, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(j, j2, r6, (i & 8) != 0 ? StoreStream.Companion.getUserGuildSettings() : storeUserGuildSettings, (i & 16) != 0 ? ClockFactory.get() : clock);
Observable observable2;
if ((i & 4) != 0) {
Companion companion = Companion;
StoreStream.Companion companion2 = StoreStream.Companion;
observable2 = Companion.access$observeStoreState(companion, j, j2, companion2.getGuilds(), companion2.getChannels(), companion2.getUserGuildSettings());
} else {
observable2 = observable;
}
}
public static final /* synthetic */ void access$handleStoreState(MuteSettingsSheetViewModel muteSettingsSheetViewModel, StoreState storeState) {
muteSettingsSheetViewModel.handleStoreState(storeState);
}
@MainThread
private final void emitDismissEvent() {
PublishSubject<Event> publishSubject = this.eventSubject;
publishSubject.j.onNext(Event.Dismiss.INSTANCE);
}
/* JADX WARNING: Removed duplicated region for block: B:72:0x00b6 A[EDGE_INSN: B:72:0x00b6->B:48:0x00b6 ?: BREAK , SYNTHETIC] */
@MainThread
private final void handleStoreState(StoreState storeState) {
String str;
ModelNotificationSettings.ChannelOverride channelOverride;
ModelNotificationSettings guildNotificationSettings;
List<ModelNotificationSettings.ChannelOverride> channelOverrides;
Object obj;
boolean z2;
Guild guild = storeState.getGuild();
Channel channel = storeState.getChannel();
SettingsType settingsType = guild != null ? SettingsType.GUILD : channel != null ? AnimatableValueParser.h1(channel) ? SettingsType.DM : AnimatableValueParser.k1(channel) ? SettingsType.GROUP_DM : AnimatableValueParser.f1(channel) ? SettingsType.CATEGORY : SettingsType.GUILD_CHANNEL : SettingsType.UNKNOWN;
if (settingsType == SettingsType.UNKNOWN) {
updateViewState(ViewState.Failure.INSTANCE);
return;
}
int ordinal = settingsType.ordinal();
if (ordinal != 0) {
if (!(ordinal == 1 || ordinal == 2)) {
if (ordinal == 3) {
StringBuilder sb = new StringBuilder();
sb.append(MentionUtilsKt.CHANNELS_CHAR);
m.checkNotNull(channel);
sb.append(AnimatableValueParser.y0(channel));
str = sb.toString();
} else if (ordinal != 4) {
str = "";
}
}
m.checkNotNull(channel);
str = AnimatableValueParser.y0(channel);
} else {
m.checkNotNull(guild);
str = guild.getName();
}
ModelNotificationSettings guildNotificationSettings2 = storeState.getGuildNotificationSettings();
boolean z3 = false;
if (guildNotificationSettings2 == null || (channelOverrides = guildNotificationSettings2.getChannelOverrides()) == null) {
channelOverride = null;
} else {
Iterator<T> it = channelOverrides.iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
}
obj = it.next();
ModelNotificationSettings.ChannelOverride channelOverride2 = (ModelNotificationSettings.ChannelOverride) obj;
Channel channel2 = storeState.getChannel();
if (channel2 != null) {
long h = channel2.h();
m.checkNotNullExpressionValue(channelOverride2, "channelOverride");
if (h == channelOverride2.getChannelId()) {
z2 = true;
continue;
if (z2) {
break;
}
}
}
z2 = false;
continue;
if (z2) {
}
}
channelOverride = (ModelNotificationSettings.ChannelOverride) obj;
}
boolean z4 = channel != null && !AnimatableValueParser.t1(channel) && (guildNotificationSettings = storeState.getGuildNotificationSettings()) != null && guildNotificationSettings.isMuted();
if (channelOverride != null && channelOverride.isMuted()) {
z3 = true;
}
updateViewState(new ViewState.Loaded(settingsType, str, z3, z4, channelOverride != null ? channelOverride.getMuteEndTime() : null, channelOverride != null ? channelOverride.getMessageNotifications() : ModelNotificationSettings.FREQUENCY_UNSET));
}
@MainThread
public final void emitNotificationSettingsEvent(long j) {
PublishSubject<Event> publishSubject = this.eventSubject;
publishSubject.j.onNext(new Event.NavigateToChannelSettings(j));
}
public final long getChannelId() {
return this.channelId;
}
public final Clock getClock() {
return this.clock;
}
public final Config getConfig() {
return this.config;
}
public final long getGuildId() {
return this.guildId;
}
public final Observable<StoreState> getStoreStateObservable() {
return this.storeStateObservable;
}
public final StoreUserGuildSettings getStoreUserGuildSettings() {
return this.storeUserGuildSettings;
}
public final Observable<Event> observeEvents() {
PublishSubject<Event> publishSubject = this.eventSubject;
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
return publishSubject;
}
@MainThread
public final void onChannelSettingsSelected() {
Config config = this.config;
if (config instanceof Config.Channel) {
emitNotificationSettingsEvent(((Config.Channel) config).getChannelId());
}
}
@MainThread
public final void selectMuteDurationMs(long j, Context context) {
m.checkNotNullParameter(context, "appContext");
ModelMuteConfig modelMuteConfig = null;
if (j != 0) {
modelMuteConfig = new ModelMuteConfig(TimeUtils.toUTCDateTime$default(Long.valueOf(this.clock.currentTimeMillis() + j), null, 2, null));
}
Config config = this.config;
if (config instanceof Config.Guild) {
this.storeUserGuildSettings.setGuildMuted(context, ((Config.Guild) config).getGuildId(), true, modelMuteConfig);
} else if (config instanceof Config.Channel) {
this.storeUserGuildSettings.setChannelMuted(context, ((Config.Channel) config).getChannelId(), true, modelMuteConfig);
}
emitDismissEvent();
}
@MainThread
public final void unmute(Context context) {
m.checkNotNullParameter(context, "appContext");
Config config = this.config;
if (config instanceof Config.Channel) {
this.storeUserGuildSettings.setChannelMuted(context, ((Config.Channel) config).getChannelId(), false, null);
emitDismissEvent();
}
}
}