273 lines
7.5 KiB
TypeScript
273 lines
7.5 KiB
TypeScript
// Module ID: 5681
|
|
// Function ID: 48793
|
|
// Name: _shouldRequestFirstMessage
|
|
// Dependencies: [5, 6, 7, 1348, 5682, 5656, 5686, 653, 22, 21, 566, 507, 686, 2]
|
|
// Exports: preloadForumThreads, useFirstForumPostMessage, useMostRecentForumMessage
|
|
|
|
// Module 5681 (_shouldRequestFirstMessage)
|
|
import _isNativeReflectConstruct from "_isNativeReflectConstruct";
|
|
import closure_4 from "_isNativeReflectConstruct";
|
|
import ME from "ME";
|
|
import closure_6 from "_isNativeReflectConstruct";
|
|
import { computeThreadIdsSnapshot } from "_isNativeReflectConstruct";
|
|
import closure_8 from "_isNativeReflectConstruct";
|
|
import closure_9 from "_isNativeReflectConstruct";
|
|
import { Endpoints } from "ME";
|
|
|
|
const require = arg1;
|
|
function _shouldRequestFirstMessage(loaded, firstMessage) {
|
|
let tmp = !loaded;
|
|
if (tmp) {
|
|
tmp = null == firstMessage;
|
|
}
|
|
return tmp;
|
|
}
|
|
function loadMultipleForumPostData(stateFromStores, arr) {
|
|
let closure_0 = stateFromStores;
|
|
let c1 = false;
|
|
const item = arr.forEach((arg0) => {
|
|
const message = outer1_8.getMessage(arg0);
|
|
if (outer1_14(message.loaded, message.firstMessage)) {
|
|
outer1_12.request(stateFromStores.id, arg0);
|
|
let c1 = true;
|
|
}
|
|
});
|
|
let tmp2 = c1;
|
|
if (c1) {
|
|
tmp2 = null == timeout;
|
|
}
|
|
if (tmp2) {
|
|
const _setTimeout = setTimeout;
|
|
timeout = setTimeout(loadForumPostData, 0);
|
|
}
|
|
}
|
|
function loadForumPostData() {
|
|
return _loadForumPostData(...arguments);
|
|
}
|
|
async function _loadForumPostData() {
|
|
if (outer2_12.hasNext()) {
|
|
yield outer2_18(outer2_12.next());
|
|
do {
|
|
let tmp4 = outer2_12;
|
|
} while (outer2_12.hasNext());
|
|
}
|
|
const outer2_13 = null;
|
|
}
|
|
function loadForumPostDataForChannelId() {
|
|
return _loadForumPostDataForChannelId(...arguments);
|
|
}
|
|
async function _loadForumPostDataForChannelId(arg0, arg1) {
|
|
const nextBatch = outer2_12.getNextBatch(arg0, 10);
|
|
if (0 === nextBatch.length) {
|
|
outer2_12.finishRequesting(tmp, nextBatch);
|
|
} else {
|
|
const channel = outer2_6.getChannel(tmp);
|
|
let guild_id;
|
|
if (null != channel) {
|
|
guild_id = channel.guild_id;
|
|
}
|
|
if (null == guild_id) {
|
|
outer2_12.finishRequesting(tmp, nextBatch);
|
|
} else {
|
|
const HTTP = outer2_0(outer2_2[11]).HTTP;
|
|
let obj = { url: outer2_10.FORUM_POSTS(tmp) };
|
|
obj = { thread_ids: nextBatch };
|
|
obj.body = obj;
|
|
obj.rejectWithError = true;
|
|
obj = outer2_1(outer2_2[12]);
|
|
const obj1 = { type: "LOAD_FORUM_POSTS", guildId: guild_id, threads: yield HTTP.post(obj).body.threads };
|
|
obj.dispatch(obj1);
|
|
outer2_12.finishRequesting(tmp, nextBatch);
|
|
}
|
|
}
|
|
}
|
|
let closure_11 = (() => {
|
|
class DefaultDict {
|
|
constructor(arg0) {
|
|
tmp = outer1_4(this, DefaultDict);
|
|
this._set = {};
|
|
this._defaultValueFunc = arg0;
|
|
return;
|
|
}
|
|
}
|
|
let obj = {
|
|
key: "get",
|
|
value(arg0) {
|
|
const self = this;
|
|
const _set = this._set;
|
|
if (!_set.hasOwnProperty(arg0)) {
|
|
self._set[arg0] = self._defaultValueFunc();
|
|
}
|
|
return self._set[arg0];
|
|
}
|
|
};
|
|
const items = [obj, , , ];
|
|
obj = {
|
|
key: "delete",
|
|
value(arg0) {
|
|
delete tmp2[tmp];
|
|
}
|
|
};
|
|
items[1] = obj;
|
|
obj = {
|
|
key: "hasNext",
|
|
value() {
|
|
return !outer1_1(outer1_2[8]).isEmpty(this._set);
|
|
}
|
|
};
|
|
items[2] = obj;
|
|
items[3] = {
|
|
key: "next",
|
|
value() {
|
|
return outer1_1(outer1_2[9]).keys(this._set)[0];
|
|
}
|
|
};
|
|
return callback2(DefaultDict, items);
|
|
})();
|
|
let tmp2 = (() => {
|
|
class RequestQueue {
|
|
constructor() {
|
|
tmp = outer1_4(this, RequestQueue);
|
|
tmp2 = new outer1_11(() => new Set());
|
|
this.requested = tmp2;
|
|
return;
|
|
}
|
|
}
|
|
let obj = {
|
|
key: "request",
|
|
value(arg0, arg1) {
|
|
const requested = this.requested;
|
|
const value = requested.get(arg0);
|
|
value.add(arg1);
|
|
}
|
|
};
|
|
const items = [obj, , , , , , , ];
|
|
obj = {
|
|
key: "hasRequested",
|
|
value(arg0, arg1) {
|
|
const requested = this.requested;
|
|
const value = requested.get(arg0);
|
|
return value.has(arg1);
|
|
}
|
|
};
|
|
items[1] = obj;
|
|
obj = {
|
|
key: "finishRequesting",
|
|
value(arg0, arr) {
|
|
const requested = this.requested;
|
|
let closure_0 = requested.get(arg0);
|
|
const item = arr.forEach((arg0) => set.delete(arg0));
|
|
outer1_12.compact(arg0);
|
|
}
|
|
};
|
|
items[2] = obj;
|
|
items[3] = {
|
|
key: "getRequested",
|
|
value(arg0) {
|
|
const requested = this.requested;
|
|
return requested.get(arg0);
|
|
}
|
|
};
|
|
items[4] = {
|
|
key: "getNextBatch",
|
|
value(arg0, arg1) {
|
|
const requested = this.requested;
|
|
return Array.from(requested.get(arg0)).slice(0, arg1);
|
|
}
|
|
};
|
|
items[5] = {
|
|
key: "hasNext",
|
|
value() {
|
|
const requested = this.requested;
|
|
return requested.hasNext();
|
|
}
|
|
};
|
|
items[6] = {
|
|
key: "next",
|
|
value() {
|
|
return this.requested.next();
|
|
}
|
|
};
|
|
items[7] = {
|
|
key: "compact",
|
|
value(arg0) {
|
|
const requested = this.requested;
|
|
if (0 === requested.get(arg0).size) {
|
|
const requested2 = this.requested;
|
|
requested2.delete(arg0);
|
|
}
|
|
}
|
|
};
|
|
return callback2(RequestQueue, items);
|
|
})();
|
|
tmp2 = new tmp2();
|
|
let closure_12 = tmp2;
|
|
let c13 = null;
|
|
const result = require("_defineProperties").fileFinishedImporting("modules/forums/ForumPostDataLoader.tsx");
|
|
|
|
export const BATCH_SIZE = 10;
|
|
export const useFirstForumPostMessage = function useFirstForumPostMessage(stateFromStores, arg1) {
|
|
let firstMessage;
|
|
let loaded;
|
|
let obj = arg1;
|
|
const _require = stateFromStores;
|
|
if (arg1 === undefined) {
|
|
obj = {};
|
|
}
|
|
let flag = obj.enabled;
|
|
if (flag === undefined) {
|
|
flag = true;
|
|
}
|
|
let flag2 = obj.allowArchived;
|
|
if (flag2 === undefined) {
|
|
flag2 = false;
|
|
}
|
|
const items = [closure_8];
|
|
const stateFromStoresObject = _require(566).useStateFromStoresObject(items, () => outer1_8.getMessage(stateFromStores.id));
|
|
({ loaded, firstMessage } = stateFromStoresObject);
|
|
const obj2 = _require(566);
|
|
const items1 = [closure_6];
|
|
stateFromStores = _require(566).useStateFromStores(items1, () => outer1_6.getChannel(stateFromStores.parent_id));
|
|
let tmp3 = flag;
|
|
if (flag) {
|
|
tmp3 = null != stateFromStores;
|
|
}
|
|
if (tmp3) {
|
|
tmp3 = _shouldRequestFirstMessage(loaded, firstMessage);
|
|
}
|
|
if (tmp3) {
|
|
if (flag2) {
|
|
const items2 = [stateFromStores.id];
|
|
loadMultipleForumPostData(stateFromStores, items2);
|
|
} else {
|
|
(function preloadForumPostDataFrom(stateFromStores, id) {
|
|
let closure_0 = stateFromStores;
|
|
let closure_1 = id;
|
|
if (!outer1_12.hasRequested(stateFromStores.id, id)) {
|
|
const arr = outer1_7(stateFromStores.id);
|
|
const findIndexResult = arr.findIndex((arg0) => arg0 === closure_1);
|
|
const substr = arr.slice(findIndexResult, findIndexResult + 5);
|
|
outer1_15(stateFromStores, substr.filter((arg0) => !outer2_12.hasRequested(stateFromStores.id, arg0)));
|
|
}
|
|
})(stateFromStores, stateFromStores.id);
|
|
}
|
|
}
|
|
obj = { loaded };
|
|
let tmp9 = null;
|
|
if (flag) {
|
|
tmp9 = firstMessage;
|
|
}
|
|
obj.firstMessage = tmp9;
|
|
return obj;
|
|
};
|
|
export const useMostRecentForumMessage = function useMostRecentForumMessage(arg0, arg1) {
|
|
const _require = arg1;
|
|
let obj = _require(566);
|
|
const items = [closure_9];
|
|
const stateFromStoresObject = obj.useStateFromStoresObject(items, () => outer1_9.getMessageState(id.id));
|
|
obj = { loaded: stateFromStoresObject.loaded, mostRecentMessage: stateFromStoresObject.message };
|
|
return obj;
|
|
};
|
|
export const preloadForumThreads = function preloadForumThreads(channel) {
|
|
loadMultipleForumPostData(channel, computeThreadIdsSnapshot(channel.id).slice(0, 10));
|
|
};
|