decord/source/modules/multi_account/MultiAccountStore.tsx

194 lines
6.4 KiB
TypeScript
Raw Normal View History

// Module ID: 12542
// Function ID: 12543
// Name: MultiAccountStore
// Dependencies: [12543, 12544, 1099, 12545, 504, 573, 2]
2026-07-20 16:05:17 +00:00
// Module 12542 (MultiAccountStore)
import initializeDefault from "initialize" /* 504 */;
import DispatcherDefault from "Dispatcher" /* 573 */;
import TokenManagerAll from "TokenManager" /* 1099 */;
import Constants from "Constants" /* 12543 */;
import isStaffFromRawUserDefault from "isStaffFromRawUser" /* 12544 */;
import DragAndDropUtils from "DragAndDropUtils" /* 12545 */;
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
const MAX_ACCOUNTS = Constants.MAX_ACCOUNTS;
const MultiAccountTokenStatus = { INVALID: 0, [0]: "INVALID", VALIDATING: 1, [1]: "VALIDATING", VALID: 2, [2]: "VALID" };
let users = [];
2026-08-24 06:08:38 +00:00
const PersistedStore = initializeDefault.PersistedStore;
2026-07-29 08:29:29 +00:00
class MultiAccountStore extends PersistedStore {
}
const prototype = MultiAccountStore.prototype;
prototype["initialize"] = function initialize(users) {
if (null != users) {
users = users.users;
if (users == null) {
users = [];
}
closure_8 = users;
canUseMultiAccountMobile = users.canUseMultiAccountMobile;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
};
prototype["getCanUseMultiAccountMobile"] = function getCanUseMultiAccountMobile() {
return canUseMultiAccountMobile;
2026-07-29 08:29:29 +00:00
};
prototype["getState"] = function getState() {
return { users, canUseMultiAccountMobile };
2026-07-29 08:29:29 +00:00
};
prototype["getUsers"] = function getUsers() {
return closure_8;
};
prototype["getValidUsers"] = function getValidUsers() {
return users.filter((tokenStatus) => tokenStatus.tokenStatus !== constants.INVALID);
2026-07-29 08:29:29 +00:00
};
prototype["getHasLoggedInAccounts"] = function getHasLoggedInAccounts() {
return users.length > 0;
2026-07-29 08:29:29 +00:00
};
prototype["getIsValidatingUsers"] = function getIsValidatingUsers() {
return users.some((tokenStatus) => tokenStatus.tokenStatus === constants.VALIDATING);
2026-07-29 08:29:29 +00:00
};
Object.defineProperty(prototype, "canUseMultiAccountNotifications", {
get: function canUseMultiAccountNotifications() {
return this.getCanUseMultiAccountMobile();
},
set: undefined
});
MultiAccountStore.displayName = "MultiAccountStore";
MultiAccountStore.persistKey = "MultiAccountStore";
const items = [
2026-07-20 16:05:17 +00:00
(users) => {
if (null != users) {
users = users.users;
2026-07-29 08:29:29 +00:00
if (users == null) {
2026-07-20 16:05:17 +00:00
users = [];
}
const obj2 = { users, canUseMultiAccountMobile: false };
let obj = obj2;
2026-07-20 16:05:17 +00:00
} else {
obj = { users: [], canUseMultiAccountMobile: false };
2026-07-20 16:05:17 +00:00
}
return obj;
}
];
2026-07-29 08:29:29 +00:00
MultiAccountStore.migrations = items;
const multiAccountStore = new MultiAccountStore(DispatcherDefault, {
2026-07-20 16:05:17 +00:00
CONNECTION_OPEN: function handleConnectionOpen(user) {
user = user.user;
2026-07-29 08:29:29 +00:00
let id = user.id;
let tmp = !c5;
if (!c5) {
tmp = isStaffFromRawUserDefault(user);
2026-07-20 16:05:17 +00:00
}
if (tmp) {
2026-07-29 08:29:29 +00:00
c5 = true;
2026-07-20 16:05:17 +00:00
}
const substr = users.slice();
2026-07-20 16:05:17 +00:00
const findIndexResult = substr.findIndex((id) => id.id === user.id);
if (findIndexResult > -1) {
users[findIndexResult].avatar = user.avatar;
users[findIndexResult].username = user.username;
users[findIndexResult].discriminator = user.discriminator;
users[findIndexResult].tokenStatus = obj.VALID;
users = substr;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
obj = { id: null, avatar: null, username: null, discriminator: null, tokenStatus: null, pushSyncToken: null };
({ id: obj.id, avatar: obj.avatar, username: obj.username, discriminator: obj.discriminator } = user);
obj.tokenStatus = obj.VALID;
2026-07-23 10:11:24 +00:00
substr.push(obj);
users = substr;
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
if (substr.length > MAX_ACCOUNTS) {
const item = users.splice(tmp12).forEach((id) => {
2026-07-29 08:29:29 +00:00
id = id.id;
closure_8 = closure_8.filter((id) => id.id !== id);
TokenManagerAll.removeToken(id);
2026-07-20 16:05:17 +00:00
});
const spliceResult = users.splice(tmp12);
2026-07-20 16:05:17 +00:00
}
},
LOGOUT: function handleLogout(isSwitchingAccount) {
if (!isSwitchingAccount.isSwitchingAccount) {
users = users.filter((id) => id.id !== closure_1_4);
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
c4 = null;
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_VALIDATE_TOKEN_REQUEST(userId) {
2026-07-29 08:29:29 +00:00
userId = userId.userId;
const substr = users.slice();
2026-07-29 08:29:29 +00:00
const found = substr.find((id) => id.id === userId);
if (null != found) {
found.tokenStatus = obj.VALIDATING;
users = substr;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_VALIDATE_TOKEN_SUCCESS(userId) {
2026-07-29 08:29:29 +00:00
userId = userId.userId;
const substr = users.slice();
2026-07-29 08:29:29 +00:00
const found = substr.find((id) => id.id === userId);
if (null != found) {
found.tokenStatus = obj.VALID;
users = substr;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_VALIDATE_TOKEN_FAILURE(userId) {
2026-07-29 08:29:29 +00:00
userId = userId.userId;
const substr = users.slice();
2026-07-29 08:29:29 +00:00
const found = substr.find((id) => id.id === userId);
if (null != found) {
found.tokenStatus = obj.INVALID;
users = substr;
2026-07-29 08:29:29 +00:00
}
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_REMOVE_ACCOUNT(userId) {
2026-07-29 08:29:29 +00:00
userId = userId.userId;
users = users.filter((id) => id.id !== id);
TokenManagerAll.removeToken(userId);
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_MOVE_ACCOUNT: function handleMoveAccount(arg0) {
({ from, to } = arg0);
closure_8 = DragAndDropUtils.moveItemFromTo(closure_8, from, to);
2026-07-20 16:05:17 +00:00
},
CURRENT_USER_UPDATE: function handleCurrentUserUpdate(user) {
user = user.user;
const substr = users.slice();
2026-07-20 16:05:17 +00:00
const found = substr.find((id) => id.id === user.id);
if (null != found) {
({ avatar: tmp.avatar, username: tmp.username, discriminator: tmp.discriminator } = user);
users = substr;
2026-07-20 16:05:17 +00:00
}
},
MULTI_ACCOUNT_UPDATE_PUSH_SYNC_TOKEN: function handleUpdatePushSyncToken(arg0) {
2026-07-23 10:11:24 +00:00
({ userId: require, pushSyncToken: importDefault } = arg0);
users = users.map((id) => {
2026-07-23 10:11:24 +00:00
let tmp = id;
if (id.id === require) {
const obj = {};
2026-07-23 10:11:24 +00:00
const merged = Object.assign(id);
obj.pushSyncToken = pushSyncToken;
2026-07-23 10:11:24 +00:00
tmp = obj;
}
return tmp;
});
2026-07-20 16:05:17 +00:00
},
MULTI_ACCOUNT_INVALIDATE_PUSH_SYNC_TOKENS: function handleInvalidatePushSyncTokens(invalidPushSyncTokens) {
2026-07-23 10:11:24 +00:00
invalidPushSyncTokens = invalidPushSyncTokens.invalidPushSyncTokens;
users = users.map((pushSyncToken) => {
2026-07-23 10:11:24 +00:00
let tmp = pushSyncToken;
if (null != pushSyncToken.pushSyncToken) {
tmp = pushSyncToken;
if (invalidPushSyncTokens.includes(pushSyncToken.pushSyncToken)) {
const obj = {};
2026-07-23 10:11:24 +00:00
const merged = Object.assign(pushSyncToken);
2026-07-29 08:29:29 +00:00
obj.pushSyncToken = null;
2026-07-23 10:11:24 +00:00
tmp = obj;
}
}
return tmp;
});
2026-07-20 16:05:17 +00:00
}
});
const result = size.fileFinishedImporting("modules/multi_account/MultiAccountStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default multiAccountStore;
export { MultiAccountTokenStatus };