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

151 lines
6.8 KiB
Java

package com.discord.stores;
import com.discord.api.friendsuggestions.AllowedInSuggestionsType;
import com.discord.models.domain.ModelConnectedAccount;
import com.discord.models.experiments.domain.Experiment;
import com.discord.models.user.MeUser;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreNotices;
import com.discord.utilities.contacts.ContactsFetcher;
import com.discord.utilities.persister.Persister;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.time.Clock;
import com.discord.utilities.time.ClockFactory;
import com.discord.utilities.user.UserUtils;
import d0.t.g0;
import d0.t.o;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import kotlin.Pair;
/* compiled from: StoreContactSync.kt */
public final class StoreContactSync extends StoreV2 {
private final Clock clock;
private final StoreUserConnections connectionsStore;
private ContactsFetcher contactsFetcher;
private final HashMap<String, Boolean> dismissState = new HashMap<>();
private final Persister<Map<String, Boolean>> dismissStateCache = new Persister<>("CONTACT_SYNC_DISMISS_STATE", new HashMap());
private final Dispatcher dispatcher;
private final StoreExperiments experimentsStore;
private final StoreNotices noticesStore;
private final RestAPI restAPI;
private boolean shouldTryUploadContacts;
private final Persister<Long> uploadTimestampCache = new Persister<>("CONTACT_SYNC_LAST_UPLOAD_TIME", 0L);
private final StoreUser usersStore;
public StoreContactSync(Dispatcher dispatcher, RestAPI restAPI, Clock clock, StoreUserConnections storeUserConnections, StoreUser storeUser, StoreExperiments storeExperiments, StoreNotices storeNotices) {
m.checkNotNullParameter(dispatcher, "dispatcher");
m.checkNotNullParameter(restAPI, "restAPI");
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(storeUserConnections, "connectionsStore");
m.checkNotNullParameter(storeUser, "usersStore");
m.checkNotNullParameter(storeExperiments, "experimentsStore");
m.checkNotNullParameter(storeNotices, "noticesStore");
this.dispatcher = dispatcher;
this.restAPI = restAPI;
this.clock = clock;
this.connectionsStore = storeUserConnections;
this.usersStore = storeUser;
this.experimentsStore = storeExperiments;
this.noticesStore = storeNotices;
}
private final StoreNotices.Notice createContactSyncNotice() {
return new StoreNotices.Notice("CONTACT_SYNC_UPSELL", null, 1336, 0, true, null, 0, 0, StoreContactSync$createContactSyncNotice$1.INSTANCE, 226, null);
}
public final void backgroundUploadContacts() {
ContactsFetcher contactsFetcher = this.contactsFetcher;
if (contactsFetcher == null) {
m.throwUninitializedPropertyAccessException("contactsFetcher");
}
Set<String> fetchContacts = contactsFetcher.fetchContacts();
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(fetchContacts, 10));
for (String str : fetchContacts) {
arrayList.add(new RestAPIParams.ContactEntry(str, str, g0.mapOf(new Pair("number", str))));
}
this.restAPI.uploadContacts(new RestAPIParams.UploadContacts(arrayList, true, AllowedInSuggestionsType.ANYONE_WITH_CONTACT_INFO));
setContactSyncUploadTimestamp(this.clock.currentTimeMillis());
}
public final void clearDismissStates() {
this.dismissState.clear();
this.dismissStateCache.clear(true);
markChanged();
}
public final void dismissFriendsListUpsell() {
this.dismissState.put("CONTACT_SYNC_DISMISS_FRIENDS_UPSELL", Boolean.TRUE);
this.dismissStateCache.set(this.dismissState, true);
markChanged();
}
public final void dismissUpsell() {
this.dismissState.put("CONTACT_SYNC_DISMISS_UPSELL", Boolean.TRUE);
this.dismissStateCache.set(this.dismissState, true);
markChanged();
}
public final boolean getFriendsListUpsellDismissed() {
return m.areEqual(this.dismissState.get("CONTACT_SYNC_DISMISS_FRIENDS_UPSELL"), Boolean.TRUE);
}
@StoreThread
public final void handleConnectionOpen() {
this.dispatcher.schedule(new StoreContactSync$handleConnectionOpen$1(this));
}
@StoreThread
public final void handlePostConnectionOpen() {
ModelConnectedAccount modelConnectedAccount;
MeUser me2 = this.usersStore.getMe();
List<ModelConnectedAccount> connectedAccounts = this.connectionsStore.getConnectedAccounts();
ListIterator<ModelConnectedAccount> listIterator = connectedAccounts.listIterator(connectedAccounts.size());
while (true) {
if (!listIterator.hasPrevious()) {
modelConnectedAccount = null;
break;
}
modelConnectedAccount = listIterator.previous();
if (m.areEqual(modelConnectedAccount.getType(), "contacts")) {
break;
}
}
ModelConnectedAccount modelConnectedAccount2 = modelConnectedAccount;
Boolean bool = this.dismissState.get("CONTACT_SYNC_DISMISS_UPSELL");
boolean z2 = false;
Experiment userExperiment = this.experimentsStore.getUserExperiment("2021-04_contact_sync_android_main", modelConnectedAccount2 == null);
if (userExperiment != null && userExperiment.getBucket() == 1 && modelConnectedAccount2 == null) {
UserUtils userUtils = UserUtils.INSTANCE;
if (userUtils.getHasPhone(me2) && (!m.areEqual(bool, Boolean.TRUE)) && userUtils.getAgeMs(me2, ClockFactory.get()) > 604800000) {
z2 = true;
}
}
Experiment userExperiment2 = this.experimentsStore.getUserExperiment("2021-04_contact_sync_android_existing_user_phone_prompt", z2);
if (z2 && userExperiment2 != null && userExperiment2.getBucket() == 1) {
this.noticesStore.requestToShow(createContactSyncNotice());
}
if (this.shouldTryUploadContacts) {
backgroundUploadContacts();
}
}
public final void init(ContactsFetcher contactsFetcher) {
m.checkNotNullParameter(contactsFetcher, "fetcher");
this.contactsFetcher = contactsFetcher;
this.dismissState.putAll(this.dismissStateCache.get());
this.shouldTryUploadContacts = this.clock.currentTimeMillis() - this.uploadTimestampCache.get().longValue() > 86400000;
markChanged();
}
public final void setContactSyncUploadTimestamp(long j) {
this.shouldTryUploadContacts = this.clock.currentTimeMillis() - j > 86400000;
this.uploadTimestampCache.set(Long.valueOf(j), true);
markChanged();
}
}