Files
discord-decomp/modules/friend_groups/FriendGroupsStore.tsx
T
2026-11-01 12:12:55 +02:00

155 lines
4.2 KiB
TypeScript

// Metro module 12755 (f12756).
import UserAffinitiesV2Store from "../user_affinities/UserAffinitiesV2Store";
import ConsentStore from "../../stores/ConsentStore";
import RelationshipStore from "../../stores/RelationshipStore";
import UserStore from "../../stores/UserStore";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
const groups = [];
let isInitialized2 = false;
class FriendGroupsStore extends Module589.PersistedStore {
static displayName = "FriendGroupsStore";
static persistKey = "FriendGroupsStoreV2";
initialize(a0) {
this.waitFor(ConsentStore, RelationshipStore, UserAffinitiesV2Store, UserStore);
if (a0 != null) {
let groups2 = a0.groups;
if (groups2 == null) {
groups2 = [];
}
groups = groups2;
let isInitialized3 = a0.isInitialized;
if (isInitialized3 == null) {
isInitialized3 = false;
}
isInitialized2 = isInitialized3;
}
}
getGroups() {
return groups;
}
getGroup(c20188_0) {
let r7 = groups.find((group) => group.id === c20188_0);
if (r7 == null) {
r7 = null;
}
return r7;
}
getGroupIds() {
return groups.map((group) => group.id);
}
getUserGroups(c20189_0) {
return groups.filter((group) => group.userIds.includes(c20189_0));
}
isGroupEmpty(a0) {
const group = this.getGroup(a0);
return group == null || group.userIds.length === 0;
}
isInitialized() {
return isInitialized2;
}
getState() {
return {
groups,
isInitialized: isInitialized2
};
}
}
const friendGroupsStore = new FriendGroupsStore(Dispatcher, {
POST_CONNECTION_OPEN: function handleInitializeFriendGroups() {
if (!isInitialized2 && !(groups.length > 0)) {
groups = [];
isInitialized2 = true;
return void 0;
}
return false;
},
CREATE_FRIEND_GROUP: function handleCreateFriendGroup({ groupId, name }) {
const r10 = groups.some((group) => group.id === groupId);
let r0 = !r10;
if (!r10) {
groups.push({
id: groupId,
name,
userIds: []
});
r0 = true;
}
return r0;
},
UPDATE_FRIEND_GROUP: function handleUpdateFriendGroup({ groupId: groupId2, name }) {
const r13 = groups.findIndex((group) => group.id === groupId2);
let r1 = r13 !== -1;
if (r1) {
groups[r13] = {
...groups[r13],
name
};
r1 = true;
}
return r1;
},
DELETE_FRIEND_GROUP: function handleDeleteFriendGroup({ groupId: groupId3 }) {
const length = groups.length;
groups = groups.filter((group) => group.id !== groupId3);
return groups.length !== length;
},
REORDER_FRIEND_GROUPS: function handleReorderFriendGroups({ groupIds }) {
const r1 = [];
const map = new Map(groups.map((group) => [group.id, group]));
for (const item of groupIds) {
const r33 = map.get(item);
if (r33 != null) {
r1.push(r33);
}
}
let r42 = r1.length === groups.length;
if (r42) {
groups = r1;
r42 = true;
}
return r42;
},
ADD_USERS_TO_GROUP: function handleAddUsersToGroup({ groupId: groupId4, userIds }) {
let c20193_1;
c20193_1 = void 0;
const r17 = groups.findIndex((group) => group.id === groupId4);
if (r17 === -1) {
return false;
}
const r19 = groups[r17];
c20193_1 = new Set(r19.userIds);
const r25 = userIds.filter((userId) => !c20193_1.has(userId));
let r28 = r25.length !== 0;
if (r28) {
groups[r17] = {
...r19,
userIds: [...r19.userIds, ...r25]
};
r28 = true;
}
return r28;
},
REMOVE_USERS_FROM_GROUP: function handleRemoveUsersFromGroup({ groupId: groupId5, userIds }) {
let c20194_1;
c20194_1 = void 0;
const r15 = groups.findIndex((group) => group.id === groupId5);
if (r15 === -1) {
return false;
}
const r17 = groups[r15];
c20194_1 = new Set(userIds);
const userIds2 = r17.userIds.filter((userId) => !c20194_1.has(userId));
let r29 = userIds2.length !== r17.userIds.length;
if (r29) {
groups[r15] = {
...r17,
userIds: userIds2
};
r29 = true;
}
return r29;
}
});
export default friendGroupsStore;