Files
discord-decomp/sources/modules/guilds_bar/GuildsTree.tsx
T
2026-07-27 16:20:00 +03:00

299 lines
14 KiB
TypeScript

/* Metro module 4898; source: modules/guilds_bar/GuildsTree.tsx; dependencies: [6, 7, 44, 22, 2] */
function _fun43159(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#43159, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:6, offset: 0x0114bc33, size: 209 bytes, params: 8, frame: 19
const env0_0 = require;
const randomFolderId = function() {
var Math = global.Math;
var Math2 = global.Math;
return Math.floor(4294967296 * Math2.random());
};
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(6) /* metro dependency 6 */;
const env0_4 = importDefault(7) /* metro dependency 7 */;
const value = _fun43161();
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/guilds_bar/GuildsTree.tsx');
exports.GuildsNodeType = {ROOT: 'root', FOLDER: 'folder', GUILD: 'guild'};
exports.GuildsTree = value;
exports.createGuildNode = createGuildNode;
exports.createFolderNode = createFolderNode;
}
function _fun43161() { // fn#43161, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:268, offset: 0x0114bd37, size: 381 bytes, params: 1, frame: 15
return env0_4(GuildsTree, [{key: 'getSnapshot', value: value_43163}, {key: 'loadSnapshot', value: value_43166},
{key: 'moveNextTo', value: value_43169}, {key: 'moveInto', value: function(a0, a1) {
var r3;
var r5;
var property;
var value = a2;
r3 = !(value !== undefined) || value;
this._pluckNode(a0);
value = 0;
r5 = r3 ? a1.children.length : value;
property = a1.children;
var items = [];
arraySpread(items, property, value, value);
a1.children = items;
a1.children.splice(r5, value, a0);
a0.parentId = a1.id;
property = this.version;
this.version = typeof property === 'bigint' ? property + 1n : +property + 1;
return this;
}}, {key: 'addNode', value: value_43171}, {key: 'removeNode', value: value_43172}, {key: 'replaceNode',
value: value_43173}, {key: 'cloneNode', value: value_43174}, {key: 'convertToFolder', value: value_43175},
{key: 'allNodes', value: function() {
var Object = global.Object;
return Object.values(this.nodes);
}}, {key: 'getNode', value: function(a0) {
return this.nodes[a0];
}}, {key: 'getRoots', value: function() {
return this.root.children;
}}, {key: 'size', get: function() {
return this.allNodes().length;
}}, {key: 'sortedGuildNodes', value: function() {
var closure = _fun43181;
var env0_0 = closure;
return closure(this.root);
}}, {key: '_pluckNode', value: value_43183}]);
}
function createGuildNode(a0, a1) { // fn#43185, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:4048, offset: 0x0114c74e, size: 51 bytes, params: 3, frame: 2
const GUILD = env0_5.GUILD;
return {type: GUILD, id: a0, parentId: a1, children: [], unavailable: false};
}
function createFolderNode(a0, a1, a2) { // fn#43186, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:4162, offset: 0x0114c781, size: 127 bytes, params: 4, frame: 8
const value = a2;
const FOLDER = env0_5.FOLDER;
const folderName = a0.folderName;
const value3 = undefined;
return {type: FOLDER, id: a0.folderId, parentId: a1, name: folderName ?? value3, color: a0.folderColor ?? value3,
expanded: value ?? (a0.expanded ?? a0.expanded != null), children: []};
}
function GuildsTree() { // fn#43162, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:289, offset: 0x0114beb4, size: 73 bytes, params: 1, frame: 14
env1_3(this, GuildsTree);
const ROOT = env1_5.ROOT;
this.root = {type: ROOT, children: []};
this.nodes = {};
this.version = 0;
}
function value_43163() { // fn#43163, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:423, offset: 0x0114befd, size: 141 bytes, params: 1, frame: 25
var r15;
var propertyName;
var nodes2;
var property;
var object4;
var children;
var map;
const object5 = {};
for (propertyName in this.nodes) {
nodes2 = this.nodes;
property = nodes2[propertyName];
object4 = {};
copyDataProperties(object4, property, r15);
object4['children'] = undefined;
children = property.children;
map = children.map;
object4['childrenIds'] = Reflect.apply(map, children, [function(a0) {
return a0.id;
}]);
object5[propertyName] = object4;
r15 = children;
}
const object6 = {};
object6.rootChildrenIds = this.root.children.map(function(a0) {
return a0.id;
});
object6.nodes = object5;
return object6;
}
function value_43166({nodes, rootChildrenIds}) { // fn#43166, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:648, offset: 0x0114bf8a, size: 157 bytes, params: 2, frame: 21
var r6;
var propertyName;
var propertyName2;
var nodes2;
var property;
var childrenIds;
this.nodes = nodes;
for (propertyName in this.nodes) {
nodes2 = this.nodes;
property = nodes2[propertyName];
if (!('childrenIds' in property)) {
r6 = propertyName2;
continue;
}
childrenIds = property.childrenIds;
property.children = childrenIds.map(_fun43167);
delete property.childrenIds;
r6 = propertyName2;
}
this.root.children = rootChildrenIds.map(_fun43168);
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
}
function value_43169(a0, a1) { // fn#43169, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:917, offset: 0x0114c03d, size: 353 bytes, params: 3, frame: 29
let value = a2;
const r4 = value !== undefined ? value : false;
this._pluckNode(a0);
const r1 = a1.parentId != null ? this.nodes[a1.parentId] : this.root;
let children = r1.children;
value = children.indexOf(a1);
const defaultImport = importDefault(44) /* metro dependency 44 */;
const type = a0.type;
const FOLDER = env1_5.FOLDER;
defaultImport(!(type === FOLDER && r1.type === env1_5.FOLDER),
'[GUILDS TREE] Tried moving a folder (' + a0.id + ') inside of another folder (' + r1.id + ')');
const defaultImport2 = defaultImport;
const value6 = 0;
defaultImport2(value >= value6,
'[GUILDS TREE] target node (' + a1.id + ') did not exist within its specified parent (' + a1.parentId + ')');
const r3 = r4 ? 1 : value6;
children = r1.children;
const items2 = [];
arraySpread(items2, children, value6, ')');
r1.children = items2;
r1.children.splice(value + r3, value6, a0);
a0.parentId = r1.id;
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
return this;
}
function value_43171(a0) { // fn#43171, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:1594, offset: 0x0114c214, size: 231 bytes, params: 2, frame: 22
let value = a1;
const value2 = a2;
const r3 = value !== undefined ? value : this.root;
const r2 = !(value2 !== undefined) || value2;
value = environment.__proto__;
const defaultImport = importDefault(44) /* metro dependency 44 */;
const type = a0.type;
const ROOT = env1_5.ROOT;
defaultImport(type !== ROOT, '[GUILDS TREE] Tried adding another root node into the tree');
defaultImport(a0.id != null, '[GUILDS TREE] Tried adding a node without an id');
defaultImport(this.nodes[a0.id] == null, '[GUILDS TREE] Tried adding a node that already exists (' + a0.id + ')');
this.nodes[a0.id] = a0;
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
return this.moveInto(a0, r3, r2);
}
function value_43172(a0) { // fn#43172, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:1965, offset: 0x0114c2fb, size: 134 bytes, params: 2, frame: 18
const value = environment.__proto__;
(importDefault(44) /* metro dependency 44 */)(a0 !== this.root,
'[GUILDS TREE] Tried removing the root node from the tree');
(importDefault(44) /* metro dependency 44 */)(a0.id != null, '[GUILDS TREE] Tried removing a node without an id');
this._pluckNode(a0);
a0.parentId = undefined;
delete this.nodes[a0.id];
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
return this;
}
function value_43173(a0, a1) { // fn#43173, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:2246, offset: 0x0114c381, size: 321 bytes, params: 3, frame: 26
const value = environment.__proto__;
(importDefault(44) /* metro dependency 44 */)(a0.id != null, '[GUILDS TREE] Tried replacing a node without an id');
(importDefault(44) /* metro dependency 44 */)(a1.id != null,
'[GUILDS TREE] Tried replacing a node with one that does not have an id');
const r4 = a0.parentId != null ? this.nodes[a0.parentId] : this.root;
let children = r4.children;
const value2 = children.indexOf(a0);
(importDefault(44) /* metro dependency 44 */)(value2 >= 0,
'[GUILDS TREE] existing node (' + a0.id + ') did not exist within its specified parent (' + a0.parentId + ')');
children = r4.children;
const items2 = [];
arraySpread(items2, children, 0, ')');
r4.children = items2;
r4.children.splice(value2, 1, a1);
a1.parentId = r4.id;
a0.parentId = undefined;
delete this.nodes[a0.id];
this.nodes[a1.id] = a1;
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
return this;
}
function value_43174(a0) { // fn#43174, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:2799, offset: 0x0114c4c2, size: 41 bytes, params: 2, frame: 11
const value = environment.__proto__;
return (require(22) /* metro dependency 22 */).clone(a0);
}
function value_43175(a0) { // fn#43175, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:2866, offset: 0x0114c4eb, size: 150 bytes, params: 2, frame: 18
var r1;
var value4;
const value2 = randomFolderId();
if (this.getNode(value2) == null) {
r1 = value2;
} else {
while (true) {
value4 = randomFolderId();
getNode = this.getNode;
if (Reflect.apply(getNode, this, [value4]) == null) {
r1 = value4;
break;
}
}
}
const object2 = {};
const FOLDER = env1_5.FOLDER;
object2.type = FOLDER;
object2.id = r1;
object2.expanded = false;
object2.children = [];
this.replaceNode(a0, object2);
this.removeNode(a0);
this.addNode(a0, object2, false);
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
return object2;
}
function value_43180() { // fn#43180, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:3360, offset: 0x0114c5d4, size: 29 bytes, params: 1, frame: 11
return collectChildren(this.root);
}
function value_43183(a0) { // fn#43183, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:3539, offset: 0x0114c65d, size: 241 bytes, params: 2, frame: 29
var environment;
const env0_0 = a0;
const r4 = a0.parentId != null ? this.nodes[a0.parentId] : this.root;
const value = environment.__proto__;
(importDefault(44) /* metro dependency 44 */)(r4 != null,
'[GUILDS TREE] source node (' + a0.id + ') had a parent id (' + a0.parentId + ") which doesn't exist in the tree");
const children = r4.children;
(importDefault(44) /* metro dependency 44 */)(children != null,
'[GUILDS TREE] source node (' + a0.id + ') had a parent id (' + a0.parentId + ') which contains no children');
r4.children = children.filter(_fun43184);
a0.parentId = undefined;
const version = this.version;
this.version = typeof version === 'bigint' ? version + 1n : +version + 1;
}
function _fun43167(a0) { // fn#43167, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:774, offset: 0x0114c027, size: 22 bytes, params: 2, frame: 2
return env0_0.nodes[a0];
}
function collectChildren(a0) { // fn#43181, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:5076:3378, owner: value_43180.collectChildren, offset: 0x0114c5f1, size: 89 bytes, params: 2, frame: 12
var environment;
var r0;
const type = a0.type;
let value = environment.__proto__.__proto__;
const GUILD = env2_5.GUILD;
if (type === GUILD) {
r0 = [a0];
} else if (a0.children == null) {
r0 = [];
} else {
value = a0.children.map(function(a0) {
return collectChildren(a0);
});
value = value.flat();
r0 = value;
}
return r0;
}