// Module ID: 10238 // Function ID: 10239 // Name: MessageManager // Dependencies: [32, 4804, 5526, 2045, 7554, 2041, 2063, 4803, 2095, 4609, 1074, 2048, 1091, 3, 5521, 10239, 4718, 8677, 7730, 10240, 510, 4614, 1101, 7556, 5140, 1115, 573, 7395, 2] // Module 10238 (MessageManager) import LoggerDefault from "Logger" /* 3 */; import Storage3 from "Storage" /* 510 */; import DispatcherDefault from "Dispatcher" /* 573 */; import DurationsDefault from "Durations" /* 1091 */; import router_utils from "router_utils" /* 1101 */; import util from "util" /* 1115 */; import matchPathCompat from "matchPathCompat" /* 4614 */; import Client from "Client" /* 4718 */; import AlertActionCreatorsDefault from "AlertActionCreators" /* 5140 */; import ChannelMessagesDefault from "ChannelMessages" /* 5521 */; import SidebarActionTypes from "SidebarActionTypes" /* 7556 */; import MessageActionCreatorsDefault from "MessageActionCreators" /* 7730 */; import AttachmentUrlUtilsAll from "AttachmentUrlUtils" /* 10239 */; import getAdaptiveMessageLimit from "getAdaptiveMessageLimit" /* 10240 */; import _slicedToArray from "module_32" /* 32 */; import ChannelRTCStore from "ChannelRTCStore" /* 4804 */; import GatewayConnectionStore from "GatewayConnectionStore" /* 5526 */; import ChannelSectionStore from "ChannelSectionStore" /* 7554 */; import ChannelStore from "ChannelStore" /* 2041 */; import GuildStore from "GuildStore" /* 2063 */; import ReadStateStore from "ReadStateStore" /* 4803 */; import SelectedChannelStore from "SelectedChannelStore" /* 2095 */; import SelectedGuildStore from "SelectedGuildStore" /* 4609 */; import AutomaticLifecycleManager from "AutomaticLifecycleManager" /* 7395 */; 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(5521).clear(channelId); const tmp9Result = tmp9(5521); orCreate1 = tmp9(5521).getOrCreate(channelId); const tmp9Result9 = tmp9(5521); } let obj7 = orCreate1; if (tmp15) { const obj = { jumpTargetId: null, jumped: false, jumpType: Client.JumpType.ANIMATED }; const mutation = orCreate1.mutate(obj); tmp9(5521).commit(mutation); obj7 = mutation; const tmp9Result10 = tmp9(5521); } let obj10 = obj7; if (tmp19) { const mutation1 = obj7.mutate({ focusTargetId: null }); tmp9(5521).commit(mutation1); obj10 = mutation1; const tmp9Result11 = tmp9(5521); } if (isPreload) { if (!GatewayConnectionStore.isConnected()) { let flag = true; } let hasUnreadResult = tmp9(8677)(channelId); if (hasUnreadResult) { hasUnreadResult = ReadStateStore.hasUnread(channelId); } if (hasUnreadResult) { flag = true; } if (flag) { tmp9(5521).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(7730); 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(7730); 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(7730); 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(7730).jumpToMessage(obj12); const tmp9Result16 = tmp9(7730); } const tmp9Result12 = tmp9(5521); } } 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 === __initData) { 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, closure_1_14); } } const isTextChannel = fn(2045).isTextChannel; const Constants = fn(1074); ({ 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(2048).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;