Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/04xxx/module_4943.js (118.4 MB)
476 lines
19 KiB
TypeScript
476 lines
19 KiB
TypeScript
// Module ID: 10196
|
|
// Function ID: 10197
|
|
// Name: MessageManager
|
|
// Dependencies: [32, 4774, 5496, 2049, 7524, 2045, 2067, 4773, 2099, 4580, 1078, 2052, 1095, 3, 5491, 10197, 4689, 8650, 7703, 10198, 510, 4585, 1105, 7526, 5110, 1119, 577, 7365, 2]
|
|
|
|
// Module 10196 (MessageManager)
|
|
import LoggerDefault from "Logger" /* 3 */;
|
|
import Storage3 from "Storage" /* 510 */;
|
|
import DispatcherDefault from "Dispatcher" /* 577 */;
|
|
import DurationsDefault from "Durations" /* 1095 */;
|
|
import router_utils from "router_utils" /* 1105 */;
|
|
import util from "util" /* 1119 */;
|
|
import matchPathCompat from "matchPathCompat" /* 4585 */;
|
|
import Client from "Client" /* 4689 */;
|
|
import AlertActionCreatorsDefault from "AlertActionCreators" /* 5110 */;
|
|
import ChannelMessagesDefault from "ChannelMessages" /* 5491 */;
|
|
import SidebarActionTypes from "SidebarActionTypes" /* 7526 */;
|
|
import MessageActionCreatorsDefault from "MessageActionCreators" /* 7703 */;
|
|
import AttachmentUrlUtilsAll from "AttachmentUrlUtils" /* 10197 */;
|
|
import getAdaptiveMessageLimit from "getAdaptiveMessageLimit" /* 10198 */;
|
|
import _slicedToArray from "module_32" /* 32 */;
|
|
import ChannelRTCStore from "ChannelRTCStore" /* 4774 */;
|
|
import GatewayConnectionStore from "GatewayConnectionStore" /* 5496 */;
|
|
import ChannelSectionStore from "ChannelSectionStore" /* 7524 */;
|
|
import ChannelStore from "ChannelStore" /* 2045 */;
|
|
import GuildStore from "GuildStore" /* 2067 */;
|
|
import ReadStateStore from "ReadStateStore" /* 4773 */;
|
|
import SelectedChannelStore from "SelectedChannelStore" /* 2099 */;
|
|
import SelectedGuildStore from "SelectedGuildStore" /* 4580 */;
|
|
import AutomaticLifecycleManager from "AutomaticLifecycleManager" /* 7365 */;
|
|
|
|
require = fn;
|
|
function fetchMessages(arg0) {
|
|
({ guildId, channelId, messageId, forceFetch, isPreload, skipLocalFetch, avoidInitialScroll, fetchKey } = arg0);
|
|
if (null != channelId) {
|
|
if (!isStaticChannelRoute(channelId)) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
let type;
|
|
if (channel != null) {
|
|
type = channel.type;
|
|
}
|
|
if (type !== constants.GUILD_STORE) {
|
|
let type1;
|
|
if (channel != null) {
|
|
type1 = channel.type;
|
|
}
|
|
if (null == type1) {
|
|
const orCreate = ChannelMessagesDefault.getOrCreate(channelId);
|
|
let orCreate1 = orCreate;
|
|
if (orCreate.some(AttachmentUrlUtilsAll.messageHasExpiredAttachmentUrl)) {
|
|
logger.log("Found expired attachment link, clearing messages");
|
|
tmp9(5491).clear(channelId);
|
|
const tmp9Result = tmp9(5491);
|
|
orCreate1 = tmp9(5491).getOrCreate(channelId);
|
|
const tmp9Result9 = tmp9(5491);
|
|
}
|
|
let obj7 = orCreate1;
|
|
if (tmp15) {
|
|
const obj = { jumpTargetId: null, jumped: false, jumpType: Client.JumpType.ANIMATED };
|
|
const mutation = orCreate1.mutate(obj);
|
|
tmp9(5491).commit(mutation);
|
|
obj7 = mutation;
|
|
const tmp9Result10 = tmp9(5491);
|
|
}
|
|
let obj10 = obj7;
|
|
if (tmp19) {
|
|
const mutation1 = obj7.mutate({ focusTargetId: null });
|
|
tmp9(5491).commit(mutation1);
|
|
obj10 = mutation1;
|
|
const tmp9Result11 = tmp9(5491);
|
|
}
|
|
if (isPreload) {
|
|
if (!GatewayConnectionStore.isConnected()) {
|
|
let flag = true;
|
|
}
|
|
let hasUnreadResult = tmp9(8650)(channelId);
|
|
if (hasUnreadResult) {
|
|
hasUnreadResult = ReadStateStore.hasUnread(channelId);
|
|
}
|
|
if (hasUnreadResult) {
|
|
flag = true;
|
|
}
|
|
if (flag) {
|
|
tmp9(5491).commit(obj10.mutate({ loadingMore: true }));
|
|
if (null == messageId) {
|
|
let isThreadResult;
|
|
if (channel != null) {
|
|
isThreadResult = channel.isThread();
|
|
}
|
|
if (isThreadResult) {
|
|
let flag2 = false;
|
|
if (!ReadStateStore.hasOpenedThread(channelId)) {
|
|
if (null == obj3) {
|
|
const Storage = Storage3.Storage;
|
|
obj3 = Storage.get(viewedThreadIds, {});
|
|
if (obj3 == null) {
|
|
obj3 = {};
|
|
}
|
|
}
|
|
flag2 = false;
|
|
if (!(channelId in obj3)) {
|
|
const _Date = Date;
|
|
obj3[channelId] = Date.now();
|
|
const _Date2 = Date;
|
|
for (const key10132 in obj3) {
|
|
if (obj3[key10132] >= tmp38) {
|
|
continue;
|
|
} else {
|
|
delete tmp[tmp2];
|
|
continue;
|
|
}
|
|
continue;
|
|
}
|
|
const Storage2 = Storage3.Storage;
|
|
const result = Storage2.set(viewedThreadIds, obj3);
|
|
flag2 = true;
|
|
}
|
|
}
|
|
if (flag2) {
|
|
const _HermesInternal2 = HermesInternal;
|
|
logger.log("Jumping to start of thread " + channel.id);
|
|
const obj4 = { channelId, limit: null, jump: null, isPreload: null, skipLocalFetch: null, avoidInitialScroll: null, fetchKey: null };
|
|
const tmp9Result13 = tmp9(7703);
|
|
obj4.limit = getAdaptiveMessageLimit.getMessageLimit("MessageManager.threadStart");
|
|
const obj5 = { messageId: channelId, flash: false };
|
|
obj4.jump = obj5;
|
|
obj4.isPreload = isPreload;
|
|
obj4.skipLocalFetch = skipLocalFetch;
|
|
obj4.avoidInitialScroll = avoidInitialScroll;
|
|
obj4.fetchKey = fetchKey;
|
|
return tmp9Result13.fetchMessages(obj4);
|
|
}
|
|
}
|
|
let isThreadResult1;
|
|
if (channel != null) {
|
|
isThreadResult1 = channel.isThread();
|
|
}
|
|
if (isThreadResult1) {
|
|
if (ReadStateStore.hasTrackedUnread(channel.id)) {
|
|
if (!obj10.ready) {
|
|
const trackedAckMessageId = obj16.getTrackedAckMessageId(channel.id);
|
|
const _HermesInternal = HermesInternal;
|
|
logger.log("Jumping to most recent message in thread " + channel.id + " - " + trackedAckMessageId);
|
|
const obj6 = { channelId, limit: null, jump: null, isPreload: null, skipLocalFetch: null, avoidInitialScroll: null, fetchKey: null };
|
|
const tmp9Result14 = tmp9(7703);
|
|
obj6.limit = getAdaptiveMessageLimit.getMessageLimit("MessageManager.threadUnread");
|
|
const obj8 = { messageId: trackedAckMessageId, flash: false, offset: 1 };
|
|
obj6.jump = obj8;
|
|
obj6.isPreload = isPreload;
|
|
obj6.skipLocalFetch = skipLocalFetch;
|
|
obj6.avoidInitialScroll = avoidInitialScroll;
|
|
obj6.fetchKey = fetchKey;
|
|
return tmp9Result14.fetchMessages(obj6);
|
|
}
|
|
}
|
|
obj16 = ReadStateStore;
|
|
}
|
|
const obj9 = { channelId, limit: null, isPreload: null, skipLocalFetch: null, jump: null, avoidInitialScroll: null, fetchKey: null };
|
|
const tmp9Result15 = tmp9(7703);
|
|
obj9.limit = getAdaptiveMessageLimit.getMessageLimit("MessageManager.initialFetch");
|
|
obj9.isPreload = isPreload;
|
|
obj9.skipLocalFetch = skipLocalFetch;
|
|
const obj11 = { jumpType: Client.JumpType.ANIMATED };
|
|
obj9.jump = obj11;
|
|
obj9.avoidInitialScroll = avoidInitialScroll;
|
|
obj9.fetchKey = fetchKey;
|
|
return tmp9Result15.fetchMessages(obj9);
|
|
} else {
|
|
const obj12 = { channelId, messageId, flash: true, isPreload, skipLocalFetch, jumpType: tmp3, avoidInitialScroll };
|
|
tmp9(7703).jumpToMessage(obj12);
|
|
const tmp9Result16 = tmp9(7703);
|
|
}
|
|
const tmp9Result12 = tmp9(5491);
|
|
}
|
|
}
|
|
if (!obj10.loadingMore) {
|
|
let tmp23 = null != guildId;
|
|
if (tmp23) {
|
|
tmp23 = null == GuildStore.getGuild(guildId);
|
|
}
|
|
flag = forceFetch;
|
|
if (!tmp23) {
|
|
flag = true;
|
|
}
|
|
}
|
|
flag = forceFetch;
|
|
if (null != messageId) {
|
|
flag = true;
|
|
}
|
|
tmp15 = null != orCreate1.jumpTargetId && null == messageId;
|
|
tmp19 = null != obj7.focusTargetId && null == messageId;
|
|
} else {
|
|
const GUILD_THREADS_ONLY = constants3.GUILD_THREADS_ONLY;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function handleConnectionOpen() {
|
|
const channelId = SelectedChannelStore.getChannelId();
|
|
if (null != channelId) {
|
|
const first = _slicedToArray(ChannelRTCStore.getOpenChatChannelIds(), 1)[0];
|
|
if (null != first) {
|
|
if (first !== channelId) {
|
|
const channel = ChannelStore.getChannel(first);
|
|
if (null != channel) {
|
|
const obj = { guildId: channel.getGuildId(), channelId: channel.id };
|
|
fetchMessages(obj);
|
|
}
|
|
}
|
|
}
|
|
const channel1 = ChannelStore.getChannel(channelId);
|
|
if (null != channel1) {
|
|
const id2 = channel1.id;
|
|
const obj7 = matchPathCompat;
|
|
const obj2 = { path: collapsedCategories.CHANNEL(":guild", ":channel", ":message"), exact: true };
|
|
const matchPathResult = obj7.matchPath(router_utils.getHistory().location.pathname, obj2);
|
|
let message;
|
|
if (matchPathResult != null) {
|
|
const params = matchPathResult.params;
|
|
if (params != null) {
|
|
message = params.message;
|
|
}
|
|
}
|
|
obj3 = { guildId: channel1.getGuildId(), channelId: channel1.id, messageId: message, avoidInitialScroll: null != message };
|
|
fetchMessages(obj3);
|
|
const id = channel1.id;
|
|
const guildId = channel1.getGuildId();
|
|
const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(id);
|
|
if (null != currentSidebarChannelId) {
|
|
const obj4 = { guildId, channelId: currentSidebarChannelId, messageId: obj5.getCurrentSidebarMessageId(id) };
|
|
tmp7(obj4);
|
|
}
|
|
obj5 = ChannelSectionStore;
|
|
tmp7 = fetchMessages;
|
|
}
|
|
}
|
|
}
|
|
function loadSelectedChannelIfNecessary() {
|
|
const channelId = SelectedChannelStore.getChannelId();
|
|
if (null != channelId) {
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
if (null != channel) {
|
|
if (isTextChannel(channel.type)) {
|
|
const orCreate = ChannelMessagesDefault.getOrCreate(channelId);
|
|
if (!tmp7) {
|
|
obj3 = { guildId: channel.getGuildId(), channelId: channel.id };
|
|
fetchMessages(obj3);
|
|
}
|
|
const id2 = channel.id;
|
|
const guildId = channel.getGuildId();
|
|
const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(id2);
|
|
if (null != currentSidebarChannelId) {
|
|
const obj5 = { guildId, channelId: currentSidebarChannelId, messageId: obj4.getCurrentSidebarMessageId(id2) };
|
|
fetchMessages(obj5);
|
|
}
|
|
obj4 = ChannelSectionStore;
|
|
tmp7 = orCreate.ready && orCreate.hasFetched;
|
|
} else {
|
|
const id = channel.id;
|
|
const guildId1 = channel.getGuildId();
|
|
const currentSidebarChannelId1 = ChannelSectionStore.getCurrentSidebarChannelId(id);
|
|
if (null != currentSidebarChannelId1) {
|
|
const obj6 = { guildId: guildId1, channelId: currentSidebarChannelId1, messageId: obj.getCurrentSidebarMessageId(id) };
|
|
fetchMessages(obj6);
|
|
}
|
|
obj = ChannelSectionStore;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function handleChannelSelect(skipMessageFetch) {
|
|
({ guildId, channelId } = skipMessageFetch);
|
|
if (skipMessageFetch.skipMessageFetch) {
|
|
return false;
|
|
} else {
|
|
const obj = { guildId, channelId, messageId: tmp, jumpType: tmp2 };
|
|
fetchMessages(obj);
|
|
const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId);
|
|
if (null != currentSidebarChannelId) {
|
|
obj3 = { guildId, channelId: currentSidebarChannelId, messageId: ChannelSectionStore.getCurrentSidebarMessageId(channelId) };
|
|
fetchMessages(obj3);
|
|
}
|
|
}
|
|
}
|
|
function handleVoiceChannelSelect(guildId) {
|
|
fetchMessages({ guildId: guildId.guildId, channelId: guildId.channelId });
|
|
}
|
|
function handleJumpToVoiceChannelMessage(guildId) {
|
|
fetchMessages({ guildId: guildId.guildId, channelId: guildId.channelId, messageId: guildId.messageId, jumpType: guildId.jumpType });
|
|
}
|
|
function handleChannelSectionStoreChange() {
|
|
const channelId = SelectedChannelStore.getChannelId();
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
if (null != guildId) {
|
|
if (null != channelId) {
|
|
const sidebarState = ChannelSectionStore.getSidebarState(channelId);
|
|
let type;
|
|
if (sidebarState != null) {
|
|
type = sidebarState.type;
|
|
}
|
|
if (!tmp6) {
|
|
const currentSidebarChannelId = obj2.getCurrentSidebarChannelId(channelId);
|
|
if (null != currentSidebarChannelId) {
|
|
const obj = { guildId, channelId: currentSidebarChannelId, messageId: obj2.getCurrentSidebarMessageId(channelId) };
|
|
fetchMessages(obj);
|
|
}
|
|
}
|
|
tmp6 = type === SidebarActionTypes.SidebarType.VIEW_CHANNEL && sidebarState.channelId === channelId;
|
|
}
|
|
}
|
|
}
|
|
function handleChannelPreload(context) {
|
|
({ guildId, channelId } = context);
|
|
if (context.context === closure_1_15) {
|
|
const obj = { guildId, channelId };
|
|
fetchMessages(obj);
|
|
const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId);
|
|
if (null != currentSidebarChannelId) {
|
|
obj3 = { guildId, channelId: currentSidebarChannelId, messageId: obj2.getCurrentSidebarMessageId(channelId) };
|
|
tmp(obj3);
|
|
}
|
|
obj2 = ChannelSectionStore;
|
|
tmp = fetchMessages;
|
|
}
|
|
}
|
|
function handleChannelCreate(channel) {
|
|
channel = channel.channel;
|
|
const guild_id = channel.guild_id;
|
|
let tmp = null != guild_id;
|
|
if (tmp) {
|
|
tmp = SelectedChannelStore.getChannelId(guild_id) === channel.id;
|
|
}
|
|
if (tmp) {
|
|
const obj = { guildId: guild_id, channelId: channel.id, messageId: channel.messageId };
|
|
fetchMessages(obj);
|
|
}
|
|
}
|
|
function handleMessageEditEnd(response) {
|
|
response = response.response;
|
|
if (null != response) {
|
|
if (null != response.body) {
|
|
if (response.body.code === constants2.CHANNEL_FOLLOWING_EDIT_RATE_LIMITED) {
|
|
const retry_after = response.body.retry_after;
|
|
if (null != retry_after) {
|
|
const obj2 = { title: null, body: null };
|
|
const intl = util.intl;
|
|
obj2.title = intl.string(util.t.Whhv4w);
|
|
const intl2 = util.intl;
|
|
obj3 = { retryAfterMinutes: null };
|
|
const _Math = Math;
|
|
obj3.retryAfterMinutes = Math.ceil(retry_after / 60);
|
|
obj2.body = intl2.formatToPlainString(util.t.qoxdQB, obj3);
|
|
AlertActionCreatorsDefault.show(obj2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function handleLoadMessagesSuccess(jump) {
|
|
({ channelId, isStale, isPreview } = jump);
|
|
if (isPreview === undefined) {
|
|
isPreview = false;
|
|
}
|
|
if (!isPreview) {
|
|
let num = closure_36[channelId];
|
|
if (num == null) {
|
|
num = 0;
|
|
}
|
|
const _Date = Date;
|
|
if (Date.now() - num >= closure_21) {
|
|
const _Date2 = Date;
|
|
tmp[channelId] = Date.now();
|
|
const channelId1 = SelectedChannelStore.getChannelId();
|
|
const currentSidebarChannelId = ChannelSectionStore.getCurrentSidebarChannelId(channelId1);
|
|
if (isStale) {
|
|
isStale = GatewayConnectionStore.isConnected();
|
|
}
|
|
if (isStale) {
|
|
isStale = channelId === channelId1 || channelId === currentSidebarChannelId;
|
|
const tmp6 = channelId === channelId1 || channelId === currentSidebarChannelId;
|
|
}
|
|
if (isStale) {
|
|
const obj2 = { channelId, limit: null, jump: null };
|
|
const obj = MessageActionCreatorsDefault;
|
|
obj2.limit = getAdaptiveMessageLimit.getMessageLimit("MessageManager.staleFetch");
|
|
obj2.jump = jump.jump;
|
|
const messages = obj.fetchMessages(obj2);
|
|
}
|
|
}
|
|
tmp = closure_36;
|
|
}
|
|
}
|
|
function handleUploadFail(arg0) {
|
|
({ messageId, reason } = arg0);
|
|
let tmp2 = null != messageId;
|
|
({ channelId, shouldSendNotification } = arg0);
|
|
if (tmp2) {
|
|
tmp2 = true !== tmp;
|
|
}
|
|
if (tmp2) {
|
|
const obj2 = { type: "MESSAGE_SEND_FAILED", channelId, messageId, reason: null, shouldNotify: null };
|
|
if (reason == null) {
|
|
reason = null;
|
|
}
|
|
obj2.reason = reason;
|
|
obj2.shouldNotify = false !== shouldSendNotification;
|
|
DispatcherDefault.dispatch(obj2);
|
|
}
|
|
}
|
|
function handleAppWillBecomeActive() {
|
|
const channelId = SelectedChannelStore.getChannelId();
|
|
if (null == channelId) {
|
|
return false;
|
|
} else {
|
|
const newLocalMessages = MessageActionCreatorsDefault.fetchNewLocalMessages(channelId, state);
|
|
}
|
|
}
|
|
const isTextChannel = fn(2049).isTextChannel;
|
|
const Constants = fn(1078);
|
|
({ MAX_MESSAGES_PER_CHANNEL: closure_14, CURRENT_APP_CONTEXT: closure_15, ChannelTypes: closure_16, AbortCodes: closure_17, Routes: closure_18, ChannelTypesSets: closure_19 } = Constants);
|
|
const isStaticChannelRoute = fn(2052).isStaticChannelRoute;
|
|
let closure_21 = 10 * DurationsDefault.Millis.SECOND;
|
|
const logger = new LoggerDefault("MessageManager");
|
|
let closure_25 = 90 * DurationsDefault.Millis.DAY;
|
|
const viewedThreadIds = "viewedThreadIds";
|
|
let closure_36 = {};
|
|
class MessageManager extends tmp4 {
|
|
constructor() {
|
|
applyArgumentsResult = HermesBuiltin.applyArguments(new.target, new.target);
|
|
applyArgumentsResult.fetchMessages = fetchMessages;
|
|
applyArgumentsResult.loadSelectedChannelIfNecessary = loadSelectedChannelIfNecessary;
|
|
map = new Map();
|
|
applyArgumentsResult.stores = map.set(closure_8, handleChannelSectionStoreChange);
|
|
obj1 = {
|
|
APP_STATE_UPDATE_WILL_BECOME_ACTIVE: handleAppWillBecomeActive,
|
|
OVERLAY_INITIALIZE: handleConnectionOpen,
|
|
CHANNEL_SELECT: handleChannelSelect,
|
|
VOICE_CHANNEL_SELECT: handleVoiceChannelSelect,
|
|
THREAD_CREATE: handleChannelCreate,
|
|
THREAD_LIST_SYNC() {
|
|
loadSelectedChannelIfNecessary();
|
|
},
|
|
CHANNEL_CREATE: handleChannelCreate,
|
|
CHANNEL_PRELOAD: handleChannelPreload,
|
|
GUILD_CREATE() {
|
|
loadSelectedChannelIfNecessary();
|
|
},
|
|
MESSAGE_END_EDIT: handleMessageEditEnd,
|
|
LOAD_MESSAGES_SUCCESS: handleLoadMessagesSuccess,
|
|
UPLOAD_FAIL: handleUploadFail,
|
|
CHANNEL_DELETE() {
|
|
loadSelectedChannelIfNecessary();
|
|
},
|
|
THREAD_DELETE() {
|
|
loadSelectedChannelIfNecessary();
|
|
},
|
|
CHANNEL_RTC_JUMP_TO_VOICE_CHANNEL_MESSAGE: handleJumpToVoiceChannelMessage
|
|
};
|
|
applyArgumentsResult.actions = obj1;
|
|
return applyArgumentsResult;
|
|
}
|
|
}
|
|
const prototype = MessageManager.prototype;
|
|
prototype["_initialize"] = function _initialize() {
|
|
const subscription = DispatcherDefault.subscribe("CONNECTION_OPEN", handleConnectionOpen);
|
|
};
|
|
prototype["_terminate"] = function _terminate() {
|
|
DispatcherDefault.unsubscribe("CONNECTION_OPEN", handleConnectionOpen);
|
|
};
|
|
const messageManager = new MessageManager();
|
|
const size = fn(2);
|
|
let result = size.fileFinishedImporting("modules/messages/MessageManager.tsx");
|
|
|
|
export default messageManager;
|