NekoX/TMessagesProj/src/main/java/org/telegram/messenger/UserConfig.java

529 lines
24 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2013-10-25 17:19:00 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.messenger;
2013-11-04 13:31:01 +01:00
import android.content.Context;
import android.content.SharedPreferences;
2018-07-30 04:07:02 +02:00
import android.os.SystemClock;
2013-12-20 20:25:49 +01:00
import android.util.Base64;
2013-11-04 13:31:01 +01:00
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.SerializedData;
import org.telegram.tgnet.TLRPC;
2013-10-25 17:19:00 +02:00
2022-08-12 17:23:51 +02:00
import java.util.ArrayList;
2020-03-30 14:00:09 +02:00
import java.util.Arrays;
2022-08-12 17:23:51 +02:00
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
2013-10-25 17:19:00 +02:00
2019-07-18 15:01:39 +02:00
public class UserConfig extends BaseController {
2015-05-21 23:27:27 +02:00
2018-07-30 04:07:02 +02:00
public static int selectedAccount;
2022-06-21 04:51:00 +02:00
public final static int MAX_ACCOUNT_DEFAULT_COUNT = 3;
public final static int MAX_ACCOUNT_COUNT = 4;
2018-07-30 04:07:02 +02:00
private final Object sync = new Object();
private boolean configLoaded;
private TLRPC.User currentUser;
public boolean registeredForPush;
public int lastSendMessageId = -210000;
public int lastBroadcastId = -1;
public int contactsSavedCount;
2021-09-20 07:54:41 +02:00
public long clientUserId;
2018-07-30 04:07:02 +02:00
public int lastContactsSyncTime;
public int lastHintsSyncTime;
public boolean draftsLoaded;
public boolean unreadDialogsLoaded = true;
public TLRPC.TL_account_tmpPassword tmpPassword;
public int ratingLoadTime;
public int botRatingLoadTime;
public boolean contactsReimported;
2019-05-14 14:08:05 +02:00
public boolean hasValidDialogLoadIds;
2018-07-30 04:07:02 +02:00
public int migrateOffsetId = -1;
public int migrateOffsetDate = -1;
2021-09-20 07:54:41 +02:00
public long migrateOffsetUserId = -1;
public long migrateOffsetChatId = -1;
public long migrateOffsetChannelId = -1;
2018-07-30 04:07:02 +02:00
public long migrateOffsetAccess = -1;
2020-03-30 14:00:09 +02:00
public boolean filtersLoaded;
2019-05-14 14:08:05 +02:00
2020-02-13 19:26:53 +01:00
public int sharingMyLocationUntil;
public int lastMyLocationShareTime;
2018-07-30 04:07:02 +02:00
public boolean notificationsSettingsLoaded;
2019-01-23 18:03:33 +01:00
public boolean notificationsSignUpSettingsLoaded;
2018-07-30 04:07:02 +02:00
public boolean syncContacts = true;
public boolean suggestContacts = true;
public boolean hasSecureData;
public int loginTime;
public TLRPC.TL_help_termsOfService unacceptedTermsOfService;
2019-03-03 21:40:48 +01:00
public long autoDownloadConfigLoadTime;
2018-07-30 04:07:02 +02:00
2022-08-12 17:23:51 +02:00
public List<String> awaitBillingProductIds = new ArrayList<>();
public TLRPC.InputStorePaymentPurpose billingPaymentPurpose;
public String premiumGiftsStickerPack;
2022-09-16 20:48:21 +02:00
public String genericAnimationsStickerPack;
2022-08-12 17:23:51 +02:00
public long lastUpdatedPremiumGiftsStickerPack;
2022-09-16 20:48:21 +02:00
public long lastUpdatedGenericAnimations;
2022-08-12 17:23:51 +02:00
2018-07-30 04:07:02 +02:00
public volatile byte[] savedPasswordHash;
public volatile byte[] savedSaltedPassword;
public volatile long savedPasswordTime;
private static volatile UserConfig[] Instance = new UserConfig[UserConfig.MAX_ACCOUNT_COUNT];
public static UserConfig getInstance(int num) {
UserConfig localInstance = Instance[num];
if (localInstance == null) {
synchronized (UserConfig.class) {
localInstance = Instance[num];
if (localInstance == null) {
Instance[num] = localInstance = new UserConfig(num);
}
}
}
return localInstance;
}
public static int getActivatedAccountsCount() {
int count = 0;
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
2019-07-18 15:01:39 +02:00
if (AccountInstance.getInstance(a).getUserConfig().isClientActivated()) {
2018-07-30 04:07:02 +02:00
count++;
}
}
return count;
}
public UserConfig(int instance) {
2019-07-18 15:01:39 +02:00
super(instance);
2018-07-30 04:07:02 +02:00
}
2022-06-21 04:51:00 +02:00
public static boolean hasPremiumOnAccounts() {
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
if (AccountInstance.getInstance(a).getUserConfig().isClientActivated() && AccountInstance.getInstance(a).getUserConfig().getUserConfig().isPremium()) {
return true;
}
}
return false;
}
public static int getMaxAccountCount() {
return hasPremiumOnAccounts() ? 5 : 3;
}
2018-07-30 04:07:02 +02:00
public int getNewMessageId() {
2013-10-25 17:19:00 +02:00
int id;
synchronized (sync) {
id = lastSendMessageId;
lastSendMessageId--;
}
return id;
}
2018-07-30 04:07:02 +02:00
public void saveConfig(boolean withFile) {
2021-07-15 16:24:57 +02:00
NotificationCenter.getInstance(currentAccount).doOnIdle(() -> {
synchronized (sync) {
try {
SharedPreferences.Editor editor = getPreferences().edit();
if (currentAccount == 0) {
editor.putInt("selectedAccount", selectedAccount);
}
editor.putBoolean("registeredForPush", registeredForPush);
editor.putInt("lastSendMessageId", lastSendMessageId);
editor.putInt("contactsSavedCount", contactsSavedCount);
editor.putInt("lastBroadcastId", lastBroadcastId);
editor.putInt("lastContactsSyncTime", lastContactsSyncTime);
editor.putInt("lastHintsSyncTime", lastHintsSyncTime);
editor.putBoolean("draftsLoaded", draftsLoaded);
editor.putBoolean("unreadDialogsLoaded", unreadDialogsLoaded);
editor.putInt("ratingLoadTime", ratingLoadTime);
editor.putInt("botRatingLoadTime", botRatingLoadTime);
editor.putBoolean("contactsReimported", contactsReimported);
editor.putInt("loginTime", loginTime);
editor.putBoolean("syncContacts", syncContacts);
editor.putBoolean("suggestContacts", suggestContacts);
editor.putBoolean("hasSecureData", hasSecureData);
editor.putBoolean("notificationsSettingsLoaded3", notificationsSettingsLoaded);
editor.putBoolean("notificationsSignUpSettingsLoaded", notificationsSignUpSettingsLoaded);
editor.putLong("autoDownloadConfigLoadTime", autoDownloadConfigLoadTime);
editor.putBoolean("hasValidDialogLoadIds", hasValidDialogLoadIds);
editor.putInt("sharingMyLocationUntil", sharingMyLocationUntil);
editor.putInt("lastMyLocationShareTime", lastMyLocationShareTime);
editor.putBoolean("filtersLoaded", filtersLoaded);
2022-08-12 17:23:51 +02:00
editor.putStringSet("awaitBillingProductIds", new HashSet<>(awaitBillingProductIds));
if (billingPaymentPurpose != null) {
SerializedData data = new SerializedData(billingPaymentPurpose.getObjectSize());
billingPaymentPurpose.serializeToStream(data);
editor.putString("billingPaymentPurpose", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
data.cleanup();
} else {
editor.remove("billingPaymentPurpose");
}
editor.putString("premiumGiftsStickerPack", premiumGiftsStickerPack);
editor.putLong("lastUpdatedPremiumGiftsStickerPack", lastUpdatedPremiumGiftsStickerPack);
2018-07-30 04:07:02 +02:00
2022-09-16 20:48:21 +02:00
editor.putString("genericAnimationsStickerPack", genericAnimationsStickerPack);
editor.putLong("lastUpdatedGenericAnimations", lastUpdatedGenericAnimations);
2021-07-15 16:24:57 +02:00
editor.putInt("6migrateOffsetId", migrateOffsetId);
if (migrateOffsetId != -1) {
editor.putInt("6migrateOffsetDate", migrateOffsetDate);
2021-09-20 07:54:41 +02:00
editor.putLong("6migrateOffsetUserId", migrateOffsetUserId);
editor.putLong("6migrateOffsetChatId", migrateOffsetChatId);
editor.putLong("6migrateOffsetChannelId", migrateOffsetChannelId);
2021-07-15 16:24:57 +02:00
editor.putLong("6migrateOffsetAccess", migrateOffsetAccess);
2018-07-30 04:07:02 +02:00
}
2021-07-15 16:24:57 +02:00
if (unacceptedTermsOfService != null) {
try {
SerializedData data = new SerializedData(unacceptedTermsOfService.getObjectSize());
unacceptedTermsOfService.serializeToStream(data);
editor.putString("terms", Base64.encodeToString(data.toByteArray(), Base64.DEFAULT));
data.cleanup();
} catch (Exception ignore) {
}
} else {
editor.remove("terms");
}
2018-07-30 04:07:02 +02:00
2021-07-15 16:24:57 +02:00
SharedConfig.saveConfig();
2015-11-26 22:04:02 +01:00
2021-07-15 16:24:57 +02:00
if (tmpPassword != null) {
2013-12-20 20:25:49 +01:00
SerializedData data = new SerializedData();
2021-07-15 16:24:57 +02:00
tmpPassword.serializeToStream(data);
2017-03-31 01:58:05 +02:00
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
2021-07-15 16:24:57 +02:00
editor.putString("tmpPassword", string);
2015-02-27 20:57:58 +01:00
data.cleanup();
2021-07-15 16:24:57 +02:00
} else {
editor.remove("tmpPassword");
2013-11-04 13:31:01 +01:00
}
2015-05-21 23:27:27 +02:00
2021-07-15 16:24:57 +02:00
if (currentUser != null) {
if (withFile) {
SerializedData data = new SerializedData();
currentUser.serializeToStream(data);
String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT);
editor.putString("user", string);
data.cleanup();
}
} else {
editor.remove("user");
}
editor.commit();
} catch (Exception e) {
FileLog.e(e);
2013-10-25 17:19:00 +02:00
}
}
2021-07-15 16:24:57 +02:00
});
2013-10-25 17:19:00 +02:00
}
2021-04-09 15:17:32 +02:00
public static boolean isValidAccount(int num) {
return num >= 0 && num < UserConfig.MAX_ACCOUNT_COUNT && getInstance(num).isClientActivated();
}
2018-07-30 04:07:02 +02:00
public boolean isClientActivated() {
2014-06-13 12:42:21 +02:00
synchronized (sync) {
return currentUser != null;
}
}
2021-09-20 07:54:41 +02:00
public long getClientUserId() {
2014-06-13 12:42:21 +02:00
synchronized (sync) {
return currentUser != null ? currentUser.id : 0;
}
}
2018-07-30 04:07:02 +02:00
public String getClientPhone() {
synchronized (sync) {
return currentUser != null && currentUser.phone != null ? currentUser.phone : "";
}
}
public TLRPC.User getCurrentUser() {
2014-06-13 12:42:21 +02:00
synchronized (sync) {
return currentUser;
}
}
2018-07-30 04:07:02 +02:00
public void setCurrentUser(TLRPC.User user) {
2014-06-13 12:42:21 +02:00
synchronized (sync) {
2022-06-21 04:51:00 +02:00
TLRPC.User oldUser = currentUser;
2014-06-13 12:42:21 +02:00
currentUser = user;
2018-07-30 04:07:02 +02:00
clientUserId = user.id;
2022-09-21 16:20:30 +02:00
checkPremiumSelf(oldUser, user);
2022-06-21 04:51:00 +02:00
}
}
2022-09-21 16:20:30 +02:00
private void checkPremiumSelf(TLRPC.User oldUser, TLRPC.User newUser) {
2022-06-21 04:51:00 +02:00
if (oldUser == null || (newUser != null && oldUser.premium != newUser.premium)) {
AndroidUtilities.runOnUIThread(() -> {
getMessagesController().updatePremium(newUser.premium);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.currentUserPremiumStatusChanged);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.premiumStatusChangedGlobal);
getMediaDataController().loadPremiumPromo(false);
2022-09-21 16:20:30 +02:00
getMediaDataController().loadReactions(false, true);
2022-06-21 04:51:00 +02:00
});
2014-06-13 12:42:21 +02:00
}
}
2018-07-30 04:07:02 +02:00
public void loadConfig() {
2013-10-25 17:19:00 +02:00
synchronized (sync) {
2017-12-08 18:35:59 +01:00
if (configLoaded) {
return;
}
2019-05-14 14:08:05 +02:00
SharedPreferences preferences = getPreferences();
2018-07-30 04:07:02 +02:00
if (currentAccount == 0) {
selectedAccount = preferences.getInt("selectedAccount", 0);
}
registeredForPush = preferences.getBoolean("registeredForPush", false);
lastSendMessageId = preferences.getInt("lastSendMessageId", -210000);
contactsSavedCount = preferences.getInt("contactsSavedCount", 0);
lastBroadcastId = preferences.getInt("lastBroadcastId", -1);
lastContactsSyncTime = preferences.getInt("lastContactsSyncTime", (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60);
lastHintsSyncTime = preferences.getInt("lastHintsSyncTime", (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60);
draftsLoaded = preferences.getBoolean("draftsLoaded", false);
unreadDialogsLoaded = preferences.getBoolean("unreadDialogsLoaded", false);
contactsReimported = preferences.getBoolean("contactsReimported", false);
ratingLoadTime = preferences.getInt("ratingLoadTime", 0);
botRatingLoadTime = preferences.getInt("botRatingLoadTime", 0);
loginTime = preferences.getInt("loginTime", currentAccount);
syncContacts = preferences.getBoolean("syncContacts", true);
suggestContacts = preferences.getBoolean("suggestContacts", true);
hasSecureData = preferences.getBoolean("hasSecureData", false);
2019-01-23 18:03:33 +01:00
notificationsSettingsLoaded = preferences.getBoolean("notificationsSettingsLoaded3", false);
notificationsSignUpSettingsLoaded = preferences.getBoolean("notificationsSignUpSettingsLoaded", false);
2019-03-03 21:40:48 +01:00
autoDownloadConfigLoadTime = preferences.getLong("autoDownloadConfigLoadTime", 0);
2019-05-14 14:08:05 +02:00
hasValidDialogLoadIds = preferences.contains("2dialogsLoadOffsetId") || preferences.getBoolean("hasValidDialogLoadIds", false);
2020-02-13 19:26:53 +01:00
sharingMyLocationUntil = preferences.getInt("sharingMyLocationUntil", 0);
lastMyLocationShareTime = preferences.getInt("lastMyLocationShareTime", 0);
2020-03-30 14:00:09 +02:00
filtersLoaded = preferences.getBoolean("filtersLoaded", false);
2022-08-12 17:23:51 +02:00
awaitBillingProductIds = new ArrayList<>(preferences.getStringSet("awaitBillingProductIds", Collections.emptySet()));
if (preferences.contains("billingPaymentPurpose")) {
String purpose = preferences.getString("billingPaymentPurpose", null);
if (purpose != null) {
byte[] arr = Base64.decode(purpose, Base64.DEFAULT);
if (arr != null) {
SerializedData data = new SerializedData();
billingPaymentPurpose = TLRPC.InputStorePaymentPurpose.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
}
premiumGiftsStickerPack = preferences.getString("premiumGiftsStickerPack", null);
lastUpdatedPremiumGiftsStickerPack = preferences.getLong("lastUpdatedPremiumGiftsStickerPack", 0);
2018-07-30 04:07:02 +02:00
2022-09-16 20:48:21 +02:00
genericAnimationsStickerPack = preferences.getString("genericAnimationsStickerPack", null);
lastUpdatedGenericAnimations = preferences.getLong("lastUpdatedGenericAnimations", 0);
2018-07-30 04:07:02 +02:00
try {
String terms = preferences.getString("terms", null);
if (terms != null) {
byte[] arr = Base64.decode(terms, Base64.DEFAULT);
if (arr != null) {
SerializedData data = new SerializedData(arr);
unacceptedTermsOfService = TLRPC.TL_help_termsOfService.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
} catch (Exception e) {
FileLog.e(e);
}
2019-05-14 14:08:05 +02:00
migrateOffsetId = preferences.getInt("6migrateOffsetId", 0);
2018-07-30 04:07:02 +02:00
if (migrateOffsetId != -1) {
2019-05-14 14:08:05 +02:00
migrateOffsetDate = preferences.getInt("6migrateOffsetDate", 0);
2021-09-20 07:54:41 +02:00
migrateOffsetUserId = AndroidUtilities.getPrefIntOrLong(preferences, "6migrateOffsetUserId", 0);
migrateOffsetChatId = AndroidUtilities.getPrefIntOrLong(preferences, "6migrateOffsetChatId", 0);
migrateOffsetChannelId = AndroidUtilities.getPrefIntOrLong(preferences, "6migrateOffsetChannelId", 0);
2019-05-14 14:08:05 +02:00
migrateOffsetAccess = preferences.getLong("6migrateOffsetAccess", 0);
2018-07-30 04:07:02 +02:00
}
2017-03-31 01:58:05 +02:00
2018-07-30 04:07:02 +02:00
String string = preferences.getString("tmpPassword", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
tmpPassword = TLRPC.TL_account_tmpPassword.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
2015-05-21 23:27:27 +02:00
}
2018-07-30 04:07:02 +02:00
}
2017-03-31 01:58:05 +02:00
2018-07-30 04:07:02 +02:00
string = preferences.getString("user", null);
if (string != null) {
byte[] bytes = Base64.decode(string, Base64.DEFAULT);
if (bytes != null) {
SerializedData data = new SerializedData(bytes);
currentUser = TLRPC.User.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
2017-03-31 01:58:05 +02:00
}
2015-05-21 23:27:27 +02:00
}
2018-07-30 04:07:02 +02:00
if (currentUser != null) {
2022-09-21 16:20:30 +02:00
checkPremiumSelf(null, currentUser);
2018-07-30 04:07:02 +02:00
clientUserId = currentUser.id;
}
2017-12-08 18:35:59 +01:00
configLoaded = true;
2015-05-21 23:27:27 +02:00
}
}
2020-02-14 18:15:39 +01:00
public boolean isConfigLoaded() {
return configLoaded;
}
2018-07-30 04:07:02 +02:00
public void savePassword(byte[] hash, byte[] salted) {
savedPasswordTime = SystemClock.elapsedRealtime();
savedPasswordHash = hash;
savedSaltedPassword = salted;
}
public void checkSavedPassword() {
if (savedSaltedPassword == null && savedPasswordHash == null || Math.abs(SystemClock.elapsedRealtime() - savedPasswordTime) < 30 * 60 * 1000) {
return;
}
resetSavedPassword();
}
public void resetSavedPassword() {
savedPasswordTime = 0;
if (savedPasswordHash != null) {
2020-03-30 14:00:09 +02:00
Arrays.fill(savedPasswordHash, (byte) 0);
2018-07-30 04:07:02 +02:00
savedPasswordHash = null;
}
if (savedSaltedPassword != null) {
2020-03-30 14:00:09 +02:00
Arrays.fill(savedSaltedPassword, (byte) 0);
2018-07-30 04:07:02 +02:00
savedSaltedPassword = null;
2013-10-25 17:19:00 +02:00
}
}
2019-05-14 14:08:05 +02:00
private SharedPreferences getPreferences() {
if (currentAccount == 0) {
return ApplicationLoader.applicationContext.getSharedPreferences("userconfing", Context.MODE_PRIVATE);
} else {
return ApplicationLoader.applicationContext.getSharedPreferences("userconfig" + currentAccount, Context.MODE_PRIVATE);
}
}
2018-07-30 04:07:02 +02:00
public void clearConfig() {
2022-03-11 17:49:54 +01:00
getPreferences().edit().clear().apply();
2019-05-14 14:08:05 +02:00
2020-02-13 19:26:53 +01:00
sharingMyLocationUntil = 0;
lastMyLocationShareTime = 0;
2013-10-25 17:19:00 +02:00
currentUser = null;
2018-07-30 04:07:02 +02:00
clientUserId = 0;
2013-10-25 17:19:00 +02:00
registeredForPush = false;
2017-12-08 18:35:59 +01:00
contactsSavedCount = 0;
2013-12-20 20:25:49 +01:00
lastSendMessageId = -210000;
lastBroadcastId = -1;
2018-07-30 04:07:02 +02:00
notificationsSettingsLoaded = false;
2019-01-23 18:03:33 +01:00
notificationsSignUpSettingsLoaded = false;
2015-11-26 22:04:02 +01:00
migrateOffsetId = -1;
migrateOffsetDate = -1;
migrateOffsetUserId = -1;
migrateOffsetChatId = -1;
migrateOffsetChannelId = -1;
migrateOffsetAccess = -1;
2017-12-08 18:35:59 +01:00
ratingLoadTime = 0;
botRatingLoadTime = 0;
2019-12-31 14:08:08 +01:00
draftsLoaded = false;
2017-12-08 18:35:59 +01:00
contactsReimported = true;
2018-07-30 04:07:02 +02:00
syncContacts = true;
suggestContacts = true;
unreadDialogsLoaded = true;
2019-05-14 14:08:05 +02:00
hasValidDialogLoadIds = true;
2018-07-30 04:07:02 +02:00
unacceptedTermsOfService = null;
2020-03-30 14:00:09 +02:00
filtersLoaded = false;
2018-07-30 04:07:02 +02:00
hasSecureData = false;
loginTime = (int) (System.currentTimeMillis() / 1000);
2015-08-13 11:23:31 +02:00
lastContactsSyncTime = (int) (System.currentTimeMillis() / 1000) - 23 * 60 * 60;
2016-05-25 23:49:47 +02:00
lastHintsSyncTime = (int) (System.currentTimeMillis() / 1000) - 25 * 60 * 60;
2018-07-30 04:07:02 +02:00
resetSavedPassword();
boolean hasActivated = false;
for (int a = 0; a < MAX_ACCOUNT_COUNT; a++) {
2019-07-18 15:01:39 +02:00
if (AccountInstance.getInstance(a).getUserConfig().isClientActivated()) {
2018-07-30 04:07:02 +02:00
hasActivated = true;
break;
}
}
if (!hasActivated) {
SharedConfig.clearConfig();
}
2013-11-04 13:31:01 +01:00
saveConfig(true);
2013-10-25 17:19:00 +02:00
}
2019-05-14 14:08:05 +02:00
public boolean isPinnedDialogsLoaded(int folderId) {
return getPreferences().getBoolean("2pinnedDialogsLoaded" + folderId, false);
}
public void setPinnedDialogsLoaded(int folderId, boolean loaded) {
getPreferences().edit().putBoolean("2pinnedDialogsLoaded" + folderId, loaded).commit();
}
public static final int i_dialogsLoadOffsetId = 0;
public static final int i_dialogsLoadOffsetDate = 1;
public static final int i_dialogsLoadOffsetUserId = 2;
public static final int i_dialogsLoadOffsetChatId = 3;
public static final int i_dialogsLoadOffsetChannelId = 4;
2021-09-20 07:54:41 +02:00
public static final int i_dialogsLoadOffsetAccess = 5;
2019-05-14 14:08:05 +02:00
public int getTotalDialogsCount(int folderId) {
return getPreferences().getInt("2totalDialogsLoadCount" + (folderId == 0 ? "" : folderId), 0);
}
public void setTotalDialogsCount(int folderId, int totalDialogsLoadCount) {
getPreferences().edit().putInt("2totalDialogsLoadCount" + (folderId == 0 ? "" : folderId), totalDialogsLoadCount).commit();
}
2021-09-20 07:54:41 +02:00
public long[] getDialogLoadOffsets(int folderId) {
2019-05-14 14:08:05 +02:00
SharedPreferences preferences = getPreferences();
int dialogsLoadOffsetId = preferences.getInt("2dialogsLoadOffsetId" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
int dialogsLoadOffsetDate = preferences.getInt("2dialogsLoadOffsetDate" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
2021-09-20 07:54:41 +02:00
long dialogsLoadOffsetUserId = AndroidUtilities.getPrefIntOrLong(preferences, "2dialogsLoadOffsetUserId" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
long dialogsLoadOffsetChatId = AndroidUtilities.getPrefIntOrLong(preferences, "2dialogsLoadOffsetChatId" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
long dialogsLoadOffsetChannelId = AndroidUtilities.getPrefIntOrLong(preferences, "2dialogsLoadOffsetChannelId" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
2019-05-14 14:08:05 +02:00
long dialogsLoadOffsetAccess = preferences.getLong("2dialogsLoadOffsetAccess" + (folderId == 0 ? "" : folderId), hasValidDialogLoadIds ? 0 : -1);
2021-09-20 07:54:41 +02:00
return new long[]{dialogsLoadOffsetId, dialogsLoadOffsetDate, dialogsLoadOffsetUserId, dialogsLoadOffsetChatId, dialogsLoadOffsetChannelId, dialogsLoadOffsetAccess};
2019-05-14 14:08:05 +02:00
}
2021-09-20 07:54:41 +02:00
public void setDialogsLoadOffset(int folderId, int dialogsLoadOffsetId, int dialogsLoadOffsetDate, long dialogsLoadOffsetUserId, long dialogsLoadOffsetChatId, long dialogsLoadOffsetChannelId, long dialogsLoadOffsetAccess) {
2019-05-14 14:08:05 +02:00
SharedPreferences.Editor editor = getPreferences().edit();
editor.putInt("2dialogsLoadOffsetId" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetId);
editor.putInt("2dialogsLoadOffsetDate" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetDate);
2021-09-20 07:54:41 +02:00
editor.putLong("2dialogsLoadOffsetUserId" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetUserId);
editor.putLong("2dialogsLoadOffsetChatId" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetChatId);
editor.putLong("2dialogsLoadOffsetChannelId" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetChannelId);
2019-05-14 14:08:05 +02:00
editor.putLong("2dialogsLoadOffsetAccess" + (folderId == 0 ? "" : folderId), dialogsLoadOffsetAccess);
editor.putBoolean("hasValidDialogLoadIds", true);
editor.commit();
}
2022-06-21 04:51:00 +02:00
public boolean isPremium() {
if (currentUser == null) {
return false;
}
return currentUser.premium;
}
2022-09-16 20:48:21 +02:00
public Long getEmojiStatus() {
if (currentUser == null) {
return null;
}
if (currentUser.emoji_status instanceof TLRPC.TL_emojiStatusUntil && ((TLRPC.TL_emojiStatusUntil) currentUser.emoji_status).until > (int) (System.currentTimeMillis() / 1000)) {
return ((TLRPC.TL_emojiStatusUntil) currentUser.emoji_status).document_id;
}
if (currentUser.emoji_status instanceof TLRPC.TL_emojiStatus) {
return ((TLRPC.TL_emojiStatus) currentUser.emoji_status).document_id;
}
return null;
}
2013-10-25 17:19:00 +02:00
}