package com.discord.stores; import android.content.Context; import androidx.annotation.MainThread; import androidx.fragment.app.FragmentActivity; import com.discord.app.AppComponent; import com.discord.app.AppLog; import com.discord.utilities.logging.Logger; import com.discord.utilities.persister.Persister; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.time.Clock; import com.discord.utilities.time.ClockFactory; import com.discord.widgets.home.WidgetHome; import com.discord.widgets.voice.fullscreen.WidgetCallFullscreen; import d0.e0.c; import d0.g; import d0.g0.w; import d0.t.n; import d0.t.u; import d0.u.a; import d0.z.d.a0; import d0.z.d.m; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.concurrent.TimeUnit; import kotlin.Lazy; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; import rx.subjects.BehaviorSubject; /* compiled from: StoreNotices.kt */ public final class StoreNotices extends Store { public static final Companion Companion = new Companion(null); public static final String IN_APP_NOTICE_TAG = "InAppNotif"; public static final String NOTICE_POPUP_TAG = "Popup"; public static final int PRIORITY_HIGH = 0; public static final int PRIORITY_INAPP_NOTIFICATION = 1; public static final int PRIORITY_PASSIVE_NOTICE = 10; public static final int PRIORITY_USER_SURVEY = 5; public static final long PROCESS_PERIOD_MS = 30000; public static final long PROCESS_THROTTLE_MS = 50; private final Clock clock; private final Lazy firstUseTimestamp$delegate; private HashMap lastShownTimes = new HashMap<>(); private final BehaviorSubject noticePublisher; private final PriorityQueue noticeQueue = new PriorityQueue<>(11, a.compareBy(StoreNotices$noticeQueue$1.INSTANCE, StoreNotices$noticeQueue$2.INSTANCE, StoreNotices$noticeQueue$3.INSTANCE)); private final Persister> noticesSeenCache = new Persister<>("NOTICES_SHOWN_V2", new HashMap()); private long pollRateMs = 30000; private final BehaviorSubject processTrigger; private final StoreStream stream; /* compiled from: StoreNotices.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: StoreNotices.kt */ public static final class Dialog { private final Map metadata; private final Type type; /* compiled from: StoreNotices.kt */ public enum Type { REQUEST_RATING_MODAL, DELETE_CONNECTION_MODAL; public static /* synthetic */ PassiveNotice buildPassiveNotice$default(Type type, int i, long j, long j2, boolean z2, int i2, Object obj) { if ((i2 & 1) != 0) { i = 10; } if ((i2 & 2) != 0) { j = 31536000000L; } if ((i2 & 4) != 0) { j2 = 21600000; } return type.buildPassiveNotice(i, j, j2, (i2 & 8) != 0 ? false : z2); } public final PassiveNotice buildPassiveNotice(int i, long j, long j2, boolean z2) { return new PassiveNotice(name(), i, z2, j, j2, new StoreNotices$Dialog$Type$buildPassiveNotice$1(this)); } } public Dialog(Type type, Map map) { m.checkNotNullParameter(type, "type"); this.type = type; this.metadata = map; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ Dialog(Type type, Map map, int i, DefaultConstructorMarker defaultConstructorMarker) { this(type, (i & 2) != 0 ? null : map); } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreNotices$Dialog */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Dialog copy$default(Dialog dialog, Type type, Map map, int i, Object obj) { if ((i & 1) != 0) { type = dialog.type; } if ((i & 2) != 0) { map = dialog.metadata; } return dialog.copy(type, map); } public final Type component1() { return this.type; } public final Map component2() { return this.metadata; } public final Dialog copy(Type type, Map map) { m.checkNotNullParameter(type, "type"); return new Dialog(type, map); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Dialog)) { return false; } Dialog dialog = (Dialog) obj; return m.areEqual(this.type, dialog.type) && m.areEqual(this.metadata, dialog.metadata); } public final Map getMetadata() { return this.metadata; } public final Type getType() { return this.type; } public int hashCode() { Type type = this.type; int i = 0; int hashCode = (type != null ? type.hashCode() : 0) * 31; Map map = this.metadata; if (map != null) { i = map.hashCode(); } return hashCode + i; } public String toString() { StringBuilder L = c.d.b.a.a.L("Dialog(type="); L.append(this.type); L.append(", metadata="); return c.d.b.a.a.F(L, this.metadata, ")"); } } /* compiled from: StoreNotices.kt */ public static class Notice { private final Clock clock; private final long delayPeriodMs; private boolean hasShown; private final String name; private final boolean persist; private final int priority; private final long requestedShowTimestamp; private final Function1 show; private final long sinceLastPeriodMs; private final List> validScreens; /* JADX DEBUG: Multi-variable search result rejected for r8v0, resolved type: java.util.List> */ /* JADX DEBUG: Multi-variable search result rejected for r13v0, resolved type: kotlin.jvm.functions.Function1 */ /* JADX WARN: Multi-variable type inference failed */ public Notice(String str, Clock clock, long j, int i, boolean z2, List> list, long j2, long j3, Function1 function1) { m.checkNotNullParameter(str, "name"); m.checkNotNullParameter(clock, "clock"); m.checkNotNullParameter(function1, "show"); this.name = str; this.clock = clock; this.requestedShowTimestamp = j; this.priority = i; this.persist = z2; this.validScreens = list; this.delayPeriodMs = j2; this.sinceLastPeriodMs = j3; this.show = function1; } /* JADX WARNING: Illegal instructions before constructor call */ public /* synthetic */ Notice(String str, Clock clock, long j, int i, boolean z2, List list, long j2, long j3, Function1 function1, int i2, DefaultConstructorMarker defaultConstructorMarker) { this(str, r4, (i2 & 4) != 0 ? r4.currentTimeMillis() : j, (i2 & 8) != 0 ? 10 : i, (i2 & 16) != 0 ? false : z2, (i2 & 32) != 0 ? n.listOf((Object[]) new c[]{a0.getOrCreateKotlinClass(WidgetHome.class), a0.getOrCreateKotlinClass(WidgetCallFullscreen.class)}) : list, (i2 & 64) != 0 ? 15000 : j2, (i2 & 128) != 0 ? 31536000000L : j3, function1); Clock clock2 = (i2 & 2) != 0 ? ClockFactory.get() : clock; } public static /* synthetic */ void getHasShown$annotations() { } public boolean canShow(Long l) { return l == null || this.clock.currentTimeMillis() - l.longValue() > this.sinceLastPeriodMs; } public final Clock getClock() { return this.clock; } public final long getDelayPeriodMs() { return this.delayPeriodMs; } public final boolean getHasShown() { return this.hasShown; } public final String getName() { return this.name; } public final boolean getPersist() { return this.persist; } public final int getPriority() { return this.priority; } public final long getRequestedShowTimestamp() { return this.requestedShowTimestamp; } public final Function1 getShow() { return this.show; } public final long getSinceLastPeriodMs() { return this.sinceLastPeriodMs; } public final List> getValidScreens() { return this.validScreens; } public final boolean isInAppNotification() { return w.contains((CharSequence) this.name, (CharSequence) "InAppNotif", true); } public final boolean isPopup() { return w.contains((CharSequence) this.name, (CharSequence) "Popup", true); } public final void setHasShown(boolean z2) { this.hasShown = z2; } public boolean shouldShow(Map map) { m.checkNotNullParameter(map, "lastShownTimes"); Long l = map.get(Integer.valueOf(this.priority)); return this.delayPeriodMs < this.clock.currentTimeMillis() - (l != null ? l.longValue() : 0); } @MainThread public final boolean show(FragmentActivity fragmentActivity) { m.checkNotNullParameter(fragmentActivity, "activity"); if (this.hasShown || fragmentActivity.isFinishing()) { return false; } Boolean invoke = this.show.invoke(fragmentActivity); this.hasShown = invoke.booleanValue(); return invoke.booleanValue(); } public String toString() { StringBuilder L = c.d.b.a.a.L("Notice<"); L.append(this.name); L.append(">(pri="); L.append(this.priority); L.append(", ts="); L.append(this.requestedShowTimestamp); L.append(')'); return L.toString(); } } /* compiled from: StoreNotices.kt */ public static class PassiveNotice extends Notice { /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public PassiveNotice(String str, int i, boolean z2, long j, long j2, Function1 function1) { super(str, null, 0, i, z2, null, j2, j, function1, 38, null); m.checkNotNullParameter(str, "name"); m.checkNotNullParameter(function1, "show"); } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ PassiveNotice(String str, int i, boolean z2, long j, long j2, Function1 function1, int i2, DefaultConstructorMarker defaultConstructorMarker) { this(str, i, (i2 & 4) != 0 ? false : z2, (i2 & 8) != 0 ? 31536000000L : j, (i2 & 16) != 0 ? 21600000 : j2, function1); } @Override // com.discord.stores.StoreNotices.Notice public boolean shouldShow(Map map) { m.checkNotNullParameter(map, "lastShownTimes"); LinkedHashMap linkedHashMap = new LinkedHashMap(); Iterator> it = map.entrySet().iterator(); while (true) { boolean z2 = true; if (!it.hasNext()) { break; } Map.Entry next = it.next(); if (next.getKey().intValue() > getPriority()) { z2 = false; } if (z2) { linkedHashMap.put(next.getKey(), next.getValue()); } } Long l = (Long) u.maxOrNull((Iterable) linkedHashMap.values()); return getDelayPeriodMs() < getClock().currentTimeMillis() - (l != null ? l.longValue() : 0); } } public StoreNotices(Clock clock, StoreStream storeStream) { m.checkNotNullParameter(clock, "clock"); m.checkNotNullParameter(storeStream, "stream"); this.clock = clock; this.stream = storeStream; BehaviorSubject k0 = BehaviorSubject.k0(); m.checkNotNullExpressionValue(k0, "BehaviorSubject.create()"); this.processTrigger = k0; BehaviorSubject l0 = BehaviorSubject.l0(null); m.checkNotNullExpressionValue(l0, "BehaviorSubject.create(null as Notice?)"); this.noticePublisher = l0; this.firstUseTimestamp$delegate = g.lazy(new StoreNotices$firstUseTimestamp$2(this)); } public static final /* synthetic */ Clock access$getClock$p(StoreNotices storeNotices) { return storeNotices.clock; } public static final /* synthetic */ PriorityQueue access$getNoticeQueue$p(StoreNotices storeNotices) { return storeNotices.noticeQueue; } public static final /* synthetic */ long access$getPollRateMs$p(StoreNotices storeNotices) { return storeNotices.pollRateMs; } public static final /* synthetic */ void access$processNextNotice(StoreNotices storeNotices) { storeNotices.processNextNotice(); } public static final /* synthetic */ void access$setPollRateMs$p(StoreNotices storeNotices, long j) { storeNotices.setPollRateMs(j); } public static /* synthetic */ void markSeen$default(StoreNotices storeNotices, String str, long j, int i, Object obj) { if ((i & 2) != 0) { j = storeNotices.clock.currentTimeMillis(); } storeNotices.markSeen(str, j); } private final synchronized void processNextNotice() { Object obj; Iterator it = this.noticeQueue.iterator(); while (true) { if (!it.hasNext()) { obj = null; break; } obj = it.next(); if (((Notice) obj).shouldShow(this.lastShownTimes)) { break; } } this.noticePublisher.onNext((Notice) obj); } private final void setPollRateMs(long j) { this.pollRateMs = Math.max(500L, j); } public final synchronized void clearSeen(String str) { m.checkNotNullParameter(str, "noticeName"); Persister.getAndSet$default(this.noticesSeenCache, false, new StoreNotices$clearSeen$1(str), 1, null); } public final long getFirstUseTimestamp() { return ((Number) this.firstUseTimestamp$delegate.getValue()).longValue(); } public final Observable getNotices() { Observable r = this.noticePublisher.r(); m.checkNotNullExpressionValue(r, "noticePublisher.distinctUntilChanged()"); return r; } public final StoreStream getStream() { return this.stream; } @Override // com.discord.stores.Store public void init(Context context) { m.checkNotNullParameter(context, "context"); super.init(context); AppLog appLog = AppLog.g; Logger.d$default(appLog, "Notices init", null, 2, null); Logger.d$default(appLog, "Notices prev seen: " + this.noticesSeenCache.get().entrySet(), null, 2, null); Observable o = this.processTrigger.Y(new StoreNotices$init$1(this)).o(50, TimeUnit.MILLISECONDS); m.checkNotNullExpressionValue(o, "processTrigger\n .…S, TimeUnit.MILLISECONDS)"); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.computationLatest(o), StoreNotices.class, (Context) null, (Function1) null, new StoreNotices$init$3(this), (Function0) null, (Function0) null, new StoreNotices$init$2(this), 54, (Object) null); } public final void markDialogSeen(String str) { m.checkNotNullParameter(str, "noticeDialogType"); try { markSeen(Dialog.Type.valueOf(str)); } catch (IllegalArgumentException unused) { markSeen$default(this, str, 0, 2, null); } } public final synchronized void markInAppSeen() { PriorityQueue priorityQueue = this.noticeQueue; ArrayList arrayList = new ArrayList(); for (Object obj : priorityQueue) { if (w.contains$default((CharSequence) ((Notice) obj).getName(), (CharSequence) "InAppNotif", false, 2, (Object) null)) { arrayList.add(obj); } } for (Notice notice : arrayList) { markSeen$default(this, notice.getName(), 0, 2, null); } } public final void markSeen(Dialog.Type type) { m.checkNotNullParameter(type, "type"); markSeen$default(this, type.name(), 0, 2, null); } public final synchronized void markSeen(String str, long j) { Object obj; Object obj2; m.checkNotNullParameter(str, "noticeName"); AppLog.i("Notice seen: " + str + " @ " + j); Iterator it = this.noticeQueue.iterator(); while (true) { if (!it.hasNext()) { obj = null; break; } obj = it.next(); if (m.areEqual(((Notice) obj).getName(), str)) { break; } } Notice notice = (Notice) obj; if (notice != null) { this.noticeQueue.remove(notice); if (notice.getDelayPeriodMs() <= this.pollRateMs) { Iterator it2 = this.noticeQueue.iterator(); if (!it2.hasNext()) { obj2 = null; } else { obj2 = it2.next(); if (it2.hasNext()) { long delayPeriodMs = ((Notice) obj2).getDelayPeriodMs(); do { Object next = it2.next(); long delayPeriodMs2 = ((Notice) next).getDelayPeriodMs(); if (delayPeriodMs > delayPeriodMs2) { obj2 = next; delayPeriodMs = delayPeriodMs2; } } while (it2.hasNext()); } } Notice notice2 = (Notice) obj2; setPollRateMs(notice2 != null ? notice2.getDelayPeriodMs() : 30000); } this.lastShownTimes.put(Integer.valueOf(notice.getPriority()), Long.valueOf(j)); if (notice.getPersist()) { HashMap hashMap = this.noticesSeenCache.get(); hashMap.put(notice.getName(), Long.valueOf(j)); this.noticesSeenCache.set(hashMap, true); Logger.v$default(AppLog.g, "Notice seen saved: " + str + " @ " + j, null, 2, null); } this.noticePublisher.onNext(null); } this.processTrigger.onNext(Unit.a); } public final Observable> observeNoticesSeen() { return this.noticesSeenCache.getObservable(); } public final synchronized void requestToShow(Notice notice) { m.checkNotNullParameter(notice, "notice"); if (notice.canShow(this.noticesSeenCache.get().get(notice.getName()))) { PriorityQueue priorityQueue = this.noticeQueue; boolean z2 = true; if (!(priorityQueue instanceof Collection) || !priorityQueue.isEmpty()) { Iterator it = priorityQueue.iterator(); while (true) { if (it.hasNext()) { if (m.areEqual(((Notice) it.next()).getName(), notice.getName())) { z2 = false; break; } } else { break; } } } if (z2) { this.noticeQueue.add(notice); AppLog.i("Notice Request: " + notice.getName()); AppLog appLog = AppLog.g; Logger.d$default(appLog, "Notice queues: " + this.noticeQueue, null, 2, null); long delayPeriodMs = notice.getDelayPeriodMs(); if (delayPeriodMs < this.pollRateMs) { setPollRateMs(delayPeriodMs); } this.processTrigger.onNext(Unit.a); } } } }