202 lines
12 KiB
Java
202 lines
12 KiB
Java
package com.discord.stores;
|
|
|
|
import android.content.Context;
|
|
import c.a.d.c0;
|
|
import c.a.d.d0;
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.models.application.Unread;
|
|
import com.discord.models.domain.ModelNotificationSettings;
|
|
import com.discord.stores.StoreMessageAck;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreThreadsActiveJoined;
|
|
import com.discord.utilities.message.MessageUtils;
|
|
import com.discord.utilities.permissions.PermissionUtils;
|
|
import com.discord.utilities.persister.Persister;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.rx.ObservableWithLeadingEdgeThrottle;
|
|
import com.discord.utilities.time.Clock;
|
|
import d0.z.d.m;
|
|
import java.util.HashSet;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.Pair;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import rx.Observable;
|
|
import rx.subjects.BehaviorSubject;
|
|
import rx.subjects.SerializedSubject;
|
|
/* compiled from: StoreReadStates.kt */
|
|
public final class StoreReadStates extends Store {
|
|
private final Clock clock;
|
|
private final SerializedSubject<Boolean, Boolean> markAsRead = new SerializedSubject<>(BehaviorSubject.l0(Boolean.FALSE));
|
|
private final SerializedSubject<Set<Long>, Set<Long>> unreadChannelIds = new SerializedSubject<>(BehaviorSubject.l0(new HashSet()));
|
|
private final SerializedSubject<Set<Long>, Set<Long>> unreadGuildIds = new SerializedSubject<>(BehaviorSubject.l0(new HashSet()));
|
|
private final Persister<Unread> unreadMessageMarker = new Persister<>("UNREAD_MESSAGE_MARKER_V3", new Unread(null, 0, 3, null));
|
|
|
|
public StoreReadStates(Clock clock) {
|
|
m.checkNotNullParameter(clock, "clock");
|
|
this.clock = clock;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$clearMarker(StoreReadStates storeReadStates) {
|
|
storeReadStates.clearMarker();
|
|
}
|
|
|
|
public static final /* synthetic */ Pair access$computeUnreadIds(StoreReadStates storeReadStates, Map map, Map map2, Map map3, Map map4, Map map5, Map map6, Map map7) {
|
|
return storeReadStates.computeUnreadIds(map, map2, map3, map4, map5, map6, map7);
|
|
}
|
|
|
|
public static final /* synthetic */ SerializedSubject access$getMarkAsRead$p(StoreReadStates storeReadStates) {
|
|
return storeReadStates.markAsRead;
|
|
}
|
|
|
|
public static final /* synthetic */ SerializedSubject access$getUnreadChannelIds$p(StoreReadStates storeReadStates) {
|
|
return storeReadStates.unreadChannelIds;
|
|
}
|
|
|
|
public static final /* synthetic */ SerializedSubject access$getUnreadGuildIds$p(StoreReadStates storeReadStates) {
|
|
return storeReadStates.unreadGuildIds;
|
|
}
|
|
|
|
public static final /* synthetic */ Persister access$getUnreadMessageMarker$p(StoreReadStates storeReadStates) {
|
|
return storeReadStates.unreadMessageMarker;
|
|
}
|
|
|
|
private final void clearMarker() {
|
|
Observable Z = this.unreadMessageMarker.getObservable().F(StoreReadStates$clearMarker$1.INSTANCE).Z(1);
|
|
m.checkNotNullExpressionValue(Z, "unreadMessageMarker\n …ount() }\n .take(1)");
|
|
ObservableExtensionsKt.appSubscribe$default(Z, (Context) null, "unreadMessageMarker", (Function1) null, new StoreReadStates$clearMarker$2(this), (Function1) null, (Function0) null, (Function0) null, 117, (Object) null);
|
|
}
|
|
|
|
private final void computeUnreadChannelIds() {
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
Observable<Map<Long, Long>> observePermissionsForAllChannels = companion.getPermissions().observePermissionsForAllChannels();
|
|
Observable<Map<Long, Channel>> observeGuildAndPrivateChannels = companion.getChannels().observeGuildAndPrivateChannels();
|
|
Observable<Map<Long, Long>> observeJoinedAt = companion.getGuilds().observeJoinedAt();
|
|
Observable<Map<Long, ModelNotificationSettings>> observeGuildSettings = companion.getUserGuildSettings().observeGuildSettings();
|
|
Observable<Map<Long, StoreMessageAck.Ack>> observeAll = companion.getMessageAck().observeAll();
|
|
Observable<Map<Long, Long>> observeRecentMessageIds = companion.getMessagesMostRecent().observeRecentMessageIds();
|
|
TimeUnit timeUnit = TimeUnit.SECONDS;
|
|
Observable combineLatest = ObservableWithLeadingEdgeThrottle.combineLatest(observePermissionsForAllChannels, observeGuildAndPrivateChannels, observeJoinedAt, observeGuildSettings, observeAll, ObservableExtensionsKt.leadingEdgeThrottle(observeRecentMessageIds, 3, timeUnit), companion.getThreadsActiveJoined().observeAllActiveJoinedThreadsById(), new StoreReadStates$sam$rx_functions_Func7$0(new StoreReadStates$computeUnreadChannelIds$1(this)), 1, timeUnit);
|
|
m.checkNotNullExpressionValue(combineLatest, "ObservableWithLeadingEdg…imeUnit.SECONDS\n )");
|
|
Observable r = ObservableExtensionsKt.computationLatest(combineLatest).r();
|
|
m.checkNotNullExpressionValue(r, "ObservableWithLeadingEdg… .distinctUntilChanged()");
|
|
ObservableExtensionsKt.appSubscribe$default(r, (Context) null, "computeUnreadChannelIds", (Function1) null, new StoreReadStates$computeUnreadChannelIds$2(this), (Function1) null, (Function0) null, (Function0) null, 117, (Object) null);
|
|
}
|
|
|
|
private final Pair<Set<Long>, Set<Long>> computeUnreadIds(Map<Long, Long> map, Map<Long, Channel> map2, Map<Long, Long> map3, Map<Long, ? extends ModelNotificationSettings> map4, Map<Long, StoreMessageAck.Ack> map5, Map<Long, Long> map6, Map<Long, StoreThreadsActiveJoined.ActiveJoinedThread> map7) {
|
|
long j;
|
|
HashSet hashSet = new HashSet();
|
|
HashSet hashSet2 = new HashSet();
|
|
for (Map.Entry<Long, Long> entry : map6.entrySet()) {
|
|
long longValue = entry.getKey().longValue();
|
|
long longValue2 = entry.getValue().longValue();
|
|
StoreThreadsActiveJoined.ActiveJoinedThread activeJoinedThread = map7.get(Long.valueOf(longValue));
|
|
Channel channel = map2.get(Long.valueOf(longValue));
|
|
if (channel == null) {
|
|
StoreThreadsActiveJoined.ActiveJoinedThread activeJoinedThread2 = map7.get(Long.valueOf(longValue));
|
|
channel = activeJoinedThread2 != null ? activeJoinedThread2.getChannel() : null;
|
|
}
|
|
if (channel != null && !AnimatableValueParser.s1(channel) && (!AnimatableValueParser.z1(channel) || activeJoinedThread != null)) {
|
|
if (PermissionUtils.INSTANCE.hasAccess(channel, map.get(Long.valueOf(longValue))) && !isChannelMuted(channel, map4)) {
|
|
StoreMessageAck.Ack ack = map5.get(Long.valueOf(longValue));
|
|
if (ack != null || !AnimatableValueParser.z1(channel)) {
|
|
if (ack != null) {
|
|
j = ack.getMessageId();
|
|
} else {
|
|
Long l = (Long) a.c(channel, map3);
|
|
j = ((l != null ? l.longValue() : this.clock.currentTimeMillis()) - 1420070400000L) << 22;
|
|
}
|
|
if (MessageUtils.isNewer(Long.valueOf(j), Long.valueOf(longValue2))) {
|
|
hashSet.add(Long.valueOf(longValue));
|
|
Channel channel2 = map2.get(Long.valueOf(channel.r()));
|
|
boolean isChannelMuted = isChannelMuted(channel2, map4);
|
|
if (!isChannelMuted && AnimatableValueParser.z1(channel) && channel2 != null) {
|
|
isChannelMuted = isChannelMuted(map2.get(Long.valueOf(channel2.r())), map4);
|
|
}
|
|
if (!isChannelMuted) {
|
|
hashSet2.add(Long.valueOf(channel.f()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return new Pair<>(hashSet, hashSet2);
|
|
}
|
|
|
|
private final void computeUnreadMarker() {
|
|
StoreReadStates$computeUnreadMarker$1 storeReadStates$computeUnreadMarker$1 = StoreReadStates$computeUnreadMarker$1.INSTANCE;
|
|
Observable<Long> observeId = StoreStream.Companion.getChannelsSelected().observeId();
|
|
StoreReadStates$computeUnreadMarker$2 storeReadStates$computeUnreadMarker$2 = StoreReadStates$computeUnreadMarker$2.INSTANCE;
|
|
Unread.Marker marker = new Unread.Marker();
|
|
StoreReadStates$computeUnreadMarker$3 storeReadStates$computeUnreadMarker$3 = StoreReadStates$computeUnreadMarker$3.INSTANCE;
|
|
m.checkNotNullParameter(storeReadStates$computeUnreadMarker$2, "observableCondition");
|
|
m.checkNotNullParameter(storeReadStates$computeUnreadMarker$3, "defaultObservableFunc");
|
|
d0 d0Var = new d0(marker);
|
|
m.checkNotNullParameter(storeReadStates$computeUnreadMarker$2, "observableCondition");
|
|
m.checkNotNullParameter(d0Var, "switchedObservableFunc");
|
|
m.checkNotNullParameter(storeReadStates$computeUnreadMarker$3, "defaultObservableFunc");
|
|
Observable Y = observeId.k(new c0(storeReadStates$computeUnreadMarker$2, d0Var, storeReadStates$computeUnreadMarker$3)).Y(new StoreReadStates$computeUnreadMarker$4(this));
|
|
m.checkNotNullExpressionValue(Y, "getChannelsSelected()\n …clearMarker() }\n }");
|
|
ObservableExtensionsKt.appSubscribe$default(Y, (Context) null, "unreadMessageMarker", (Function1) null, new StoreReadStates$computeUnreadMarker$5(this), (Function1) null, (Function0) null, (Function0) null, 117, (Object) null);
|
|
}
|
|
|
|
private final boolean isChannelMuted(Channel channel, Map<Long, ? extends ModelNotificationSettings> map) {
|
|
if (channel == null) {
|
|
return false;
|
|
}
|
|
long h = channel.h();
|
|
ModelNotificationSettings modelNotificationSettings = (ModelNotificationSettings) a.c(channel, map);
|
|
ModelNotificationSettings.ChannelOverride channelOverride = modelNotificationSettings != null ? modelNotificationSettings.getChannelOverride(h) : null;
|
|
return channelOverride != null && channelOverride.isMuted();
|
|
}
|
|
|
|
public final Observable<Boolean> getIsUnread(long j) {
|
|
Observable<Boolean> r = getUnreadGuildIds().F(new StoreReadStates$getIsUnread$1(j)).r();
|
|
m.checkNotNullExpressionValue(r, "getUnreadGuildIds()\n … .distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
|
|
public final Observable<Set<Long>> getUnreadChannelIds() {
|
|
return this.unreadChannelIds;
|
|
}
|
|
|
|
public final Observable<Set<Long>> getUnreadGuildIds() {
|
|
return this.unreadGuildIds;
|
|
}
|
|
|
|
public final Observable<Unread> getUnreadMarker(long j) {
|
|
Observable<Unread> r = getUnreadMarkerForSelectedChannel().x(new StoreReadStates$getUnreadMarker$1(j)).r();
|
|
m.checkNotNullExpressionValue(r, "unreadMarkerForSelectedC… .distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
|
|
public final Observable<Unread> getUnreadMarkerForSelectedChannel() {
|
|
Observable<Unread> r = ObservableExtensionsKt.computationLatest(this.unreadMessageMarker.getObservable()).r();
|
|
m.checkNotNullExpressionValue(r, "unreadMessageMarker\n … .distinctUntilChanged()");
|
|
return r;
|
|
}
|
|
|
|
@Override // com.discord.stores.Store
|
|
public void init(Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
super.init(context);
|
|
computeUnreadChannelIds();
|
|
computeUnreadMarker();
|
|
}
|
|
|
|
public final void markAsRead(Long l) {
|
|
if (l != null) {
|
|
SerializedSubject<Boolean, Boolean> serializedSubject = this.markAsRead;
|
|
serializedSubject.j.onNext(Boolean.TRUE);
|
|
SerializedSubject<Boolean, Boolean> serializedSubject2 = this.markAsRead;
|
|
serializedSubject2.j.onNext(Boolean.FALSE);
|
|
StoreStream.Companion.getMessageAck().ack(l.longValue(), false, false);
|
|
}
|
|
}
|
|
}
|