decord/alpha/source/modules/scheduled_messages/ScheduledMessageUtils.tsx
github-actions c6aa9eb120 chore: update source for alpha 349.3
Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/05xxx/module_5030.js (118.4 MB)
2026-10-01 06:55:13 +00:00

330 lines
14 KiB
TypeScript

// Module ID: 7439
// Function ID: 7440
// Name: ScheduledMessageUtils
// Dependencies: [32, 4498, 1372, 1074, 1374, 7440, 3, 38, 1435, 7270, 1385, 1241, 504, 4450, 1115, 11, 1970, 5067, 7441, 1370, 2]
// Exports: canSendScheduledMessagesInChannel, canUseScheduledMessages, convertServerScheduledMessageCreateArgs, convertServerScheduledMessageSend, getDefaultScheduledTime, getEarliestScheduledTime, getLatestScheduledTime, getMessageForState, getPresetScheduledTimes, getScheduledMessagesLimit, getScheduledTimeError, parseContentAndFlagsForSilentMessage, trackScheduledMessageTimePickerOpened, unparseContentAndFlagsForSilentMessage, useCanSendScheduledMessagesInChannel, useCanUseScheduledMessages, useScheduledMessagesLimit
// Module 7439 (ScheduledMessageUtils)
import LoggerDefault from "Logger" /* 3 */;
import _modDef38 from "module_38" /* 38 */;
import util from "util" /* 1115 */;
import AnalyticsUtilsDefault from "AnalyticsUtils" /* 1241 */;
import FlagUtils from "FlagUtils" /* 1385 */;
import PremiumTypeUtils from "PremiumTypeUtils" /* 1970 */;
import _modDef4450 from "module_4450" /* 4450 */;
import MessageRecordUtils from "MessageRecordUtils" /* 5067 */;
import parseContentForSuppressNotifications from "parseContentForSuppressNotifications" /* 7270 */;
import ScheduledMessageTypes from "ScheduledMessageTypes" /* 7441 */;
import _slicedToArray from "module_32" /* 32 */;
import PermissionStore from "PermissionStore" /* 4498 */;
import UserStore from "UserStore" /* 1372 */;
const require = globalThis.__r;
const parseContentForSuppressNotificationsDefault = parseContentForSuppressNotifications;
require = fn;
const Constants = fn(1074);
({ AnalyticEvents: metroRequire, MessageFlags: closure_7, Permissions: closure_8 } = Constants);
const PremiumTypes = fn(1374).PremiumTypes;
const ScheduledMessagesConstants = fn(7440);
({ MAX_SCHEDULE_TIME_AFTER_CREATION_SECONDS: c10, MAX_SCHEDULE_TIME_INTO_FUTURE_SECONDS: closure_11, MAX_SCHEDULED_MESSAGES_PER_USER: closure_12, MIN_SCHEDULE_TIME_INTO_FUTURE_SECONDS: map1 } = ScheduledMessagesConstants);
class ScheduledMessagesConfig {
constructor(arg0, arg1) {
merged = Object.assign({ enabled: false, limit: 0 });
tmp2 = closure_1(closure_2[7])(null != fn.limit, "Config is missing scheduled message limit");
merged.enabled = global;
merged.limit = fn.limit;
return merged;
}
}
const ApexExperiment = fn(1435);
let obj2 = { name: "2026-08-scheduled-messages", kind: "user", defaultConfig: null, variations: null };
let merged = Object.assign({ enabled: false, limit: 0 });
_modDef38(true, "Config is missing scheduled message limit");
merged.enabled = false;
merged.limit = 0;
obj2.defaultConfig = merged;
let obj3 = {
1: null,
2: (arg0) => {
const parsed = JSON.parse(arg0);
if (typeof ScheduledMessagesConfig === "function") {
const merged = Object.assign({ enabled: false, limit: 0 });
_modDef38(null != parsed.limit, "Config is missing scheduled message limit");
merged.enabled = true;
merged.limit = parsed.limit;
return merged;
} else {
throw new TypeError("Trying to call a non-function");
}
}
};
obj3[2] = (arg0) => {
const parsed = JSON.parse(arg0);
if (typeof ScheduledMessagesConfig === "function") {
const merged = Object.assign({ enabled: false, limit: 0 });
_modDef38(null != parsed.limit, "Config is missing scheduled message limit");
merged.enabled = true;
merged.limit = parsed.limit;
return merged;
} else {
throw new TypeError("Trying to call a non-function");
}
};
obj2.variations = obj3;
let closure_15 = ApexExperiment.createApexExperiment(obj2);
const size = fn(2);
let result = size.fileFinishedImporting("modules/scheduled_messages/ScheduledMessageUtils.tsx");
export const scheduledMessageLogger = new LoggerDefault("Scheduled Messages");
export const parseContentAndFlagsForSilentMessage = function parseContentAndFlagsForSilentMessage(arg0) {
({ content, flags } = arg0);
const tmp2 = _slicedToArray(parseContentForSuppressNotificationsDefault(content), 2);
const items = [, ];
if (tmp2[0]) {
items[0] = tmp2[1];
if (flags == null) {
flags = 0;
}
items[1] = FlagUtils.addFlag(flags, constants2.SUPPRESS_NOTIFICATIONS);
let tmp4 = items;
} else {
items[0] = content;
let num = flags;
if (flags == null) {
num = 0;
}
items[1] = num;
tmp4 = items;
}
return tmp4;
};
export const unparseContentAndFlagsForSilentMessage = function unparseContentAndFlagsForSilentMessage(createArgs) {
({ content, flags } = createArgs);
if (flags == null) {
flags = 0;
}
let combined = content;
if (obj.hasFlag(flags, constants2.SUPPRESS_NOTIFICATIONS)) {
const _HermesInternal = HermesInternal;
combined = "" + parseContentForSuppressNotifications.SILENT_SENTINEL + " " + content;
}
return combined;
};
export const trackScheduledMessageTimePickerOpened = function trackScheduledMessageTimePickerOpened(arg0) {
({ entryPoint, isEditing, channelId } = arg0);
AnalyticsUtilsDefault.track(constants.SCHEDULED_MESSAGE_TIME_PICKER_OPENED, { entry_point: entryPoint, is_editing: isEditing, channel_id: channelId });
};
export const useCanUseScheduledMessages = function useCanUseScheduledMessages() {
return closure_15.useConfig({ location: "useCanUseScheduledMessages" }).enabled;
};
export const useCanSendScheduledMessagesInChannel = function useCanSendScheduledMessagesInChannel(channel) {
_require = channel;
let enabled = closure_15.useConfig({ location: "useCanUseScheduledMessages" }).enabled;
const items = [PermissionStore];
if (enabled) {
enabled = obj.useStateFromStores(items, () => {
let tmp = null != closure_0;
if (tmp) {
let canResult = obj.isPrivate();
if (!canResult) {
canResult = PermissionStore.can(constants3.SEND_MESSAGES, obj);
}
tmp = canResult;
}
return tmp;
});
}
return enabled;
};
export const canUseScheduledMessages = function canUseScheduledMessages(location) {
return closure_15.getConfig({ location }).enabled;
};
export const canSendScheduledMessagesInChannel = function canSendScheduledMessagesInChannel(isPrivate, location) {
let enabled = closure_15.getConfig({ location }).enabled;
if (enabled) {
let canResult = isPrivate.isPrivate();
if (!canResult) {
canResult = PermissionStore.can(constants3.SEND_MESSAGES, isPrivate);
}
enabled = canResult;
}
return enabled;
};
export const getPresetScheduledTimes = function getPresetScheduledTimes() {
const addResult = _modDef4450().add(map1, "seconds");
const obj = _modDef4450();
const obj2 = _modDef4450();
const result = _modDef4450().startOf("day").set("hours", 9);
const startOfResult = _modDef4450().startOf("day");
const obj5 = _modDef4450();
const result1 = _modDef4450().startOf("day").set("hours", 13);
const obj3 = { label: null, value: null };
const startOfResult1 = _modDef4450().startOf("day");
const intl = util.intl;
const string = intl.string;
const t = util.t;
if (isAfterResult) {
obj3.label = string(t["qINKo/"]);
obj3.value = result;
let tmp6 = tmp5;
let tmp7 = obj3;
} else {
obj3.label = string(t.tjIn9i);
obj3.value = result.add(1, "day");
tmp6 = tmp5;
tmp7 = obj3;
}
const items = [tmp7, , ];
const obj4 = { label: null, value: null };
isAfterResult = result.isAfter(addResult);
const intl2 = tmp6(1115).intl;
const string2 = intl2.string;
const t2 = tmp6(1115).t;
if (isAfterResult1) {
obj4.label = string2(t2.qT6LjY);
obj4.value = result1;
let tmp9 = obj4;
} else {
obj4.label = string2(t2.EMRZyS);
obj4.value = result1.add(1, "day");
tmp9 = obj4;
}
items[1] = tmp9;
const obj6 = { label: null, value: null };
const intl3 = tmp6(1115).intl;
obj6.label = intl3.string(tmp6(1115).t["+P5MmK"]);
isAfterResult1 = result1.isAfter(addResult);
const obj11 = _modDef4450();
const startOfResult2 = _modDef4450().startOf("isoWeek");
obj6.value = _modDef4450().startOf("isoWeek").add(1, "week").set("hours", 9);
items[2] = obj6;
return items;
};
export const getDefaultScheduledTime = function getDefaultScheduledTime() {
const obj = _modDef4450();
const addResult = _modDef4450().startOf("hour").add(1, "hour");
const startOfResult = _modDef4450().startOf("hour");
let addResult1 = addResult;
if (addResult.isBefore(obj4.add(map1, "seconds"))) {
addResult1 = addResult.add(1, "hour");
}
return addResult1;
};
export const getScheduledTimeError = function getScheduledTimeError(isBefore, arg1) {
if (isBefore.isBefore(obj.add(map1, "seconds"))) {
const intl2 = util.intl;
let stringResult = intl2.string(util.t["w/fgvh"]);
} else {
const addResult = tmp(4450)().add(closure_1_11, "seconds");
let minResult = addResult;
if (null != arg1) {
const tmpResult = tmp(4450);
const tmpResult3 = tmp(11);
const tmpResultResult = tmpResult(tmp(11).extractTimestamp(arg1));
minResult = tmp(4450).min(addResult, tmpResultResult.add(closure_1_10, "seconds"));
const tmpResult4 = tmp(4450);
}
stringResult = null;
if (isBefore.isAfter(minResult)) {
const intl = util.intl;
stringResult = intl.string(util.t.Nt0tz7);
}
const obj2 = tmp(4450)();
}
return stringResult;
};
export const getEarliestScheduledTime = function getEarliestScheduledTime() {
return _modDef4450().add(map1, "seconds");
};
export const getLatestScheduledTime = function getLatestScheduledTime(arg0) {
const addResult = _modDef4450().add(closure_1_11, "seconds");
if (null == arg0) {
return addResult;
} else {
const tmpResult = tmp(4450);
const tmpResult3 = tmp(11);
const tmpResultResult = tmpResult(tmp(11).extractTimestamp(arg0));
return tmp(4450).min(addResult, tmpResultResult.add(closure_1_10, "seconds"));
}
const obj = _modDef4450();
};
export const getScheduledMessagesLimit = function getScheduledMessagesLimit(ScheduledMessagesCreateRoadblock) {
const obj2 = { location: ScheduledMessagesCreateRoadblock };
const config = closure_15.getConfig(obj2);
if (config.enabled) {
if (isPremiumResult) {
const obj3 = { limit, isUpgradable: false };
} else {
const obj4 = { limit: config.limit, isUpgradable: true };
}
} else {
return { limit: 0, isUpgradable: false };
}
};
export const useScheduledMessagesLimit = function useScheduledMessagesLimit(ScheduledMessagesMobileModal) {
const config = closure_15.useConfig({ location: ScheduledMessagesMobileModal });
const items = [UserStore];
if (config.enabled) {
if (obj2.useStateFromStores(items, () => require("PremiumTypeUtils").isPremium(currentUser.getCurrentUser(), TIER_2.TIER_2))) {
const obj3 = { limit, isUpgradable: false };
} else {
const obj4 = { limit: config.limit, isUpgradable: true };
}
} else {
return { limit: 0, isUpgradable: false };
}
};
export const convertServerScheduledMessageSend = function convertServerScheduledMessageSend(body) {
const obj = { userId: body.user_id, scheduledMessageId: body.scheduled_message_id, sendAtTimestamp: body.send_at_timestamp, createArgs: null, state: body.state, attachmentUploads: null, record: null };
const create_args = body.create_args;
obj.createArgs = { channelId: create_args.channel_id, content: create_args.content, type: create_args.type, flags: create_args.flags, messageReference: create_args.message_reference };
let attachment_uploads = body.attachment_uploads;
if (attachment_uploads == null) {
attachment_uploads = [];
}
obj.attachmentUploads = attachment_uploads.map((filename) => ({ filename: filename.filename, uploadedFilename: filename.uploaded_filename, description: filename.description, title: filename.title }));
const obj3 = {};
const merged = Object.assign(body.message_preview);
obj3.timestamp = body.send_at_timestamp;
obj.record = MessageRecordUtils.createMessageRecord(obj3);
return obj;
};
export const getMessageForState = function getMessageForState(state) {
if (ScheduledMessageTypes.ScheduledMessageSendState.SCHEDULED === state) {
const obj = { isError: false, stateMessage: null };
const intl6 = tmp(1115).intl;
obj.stateMessage = intl6.string(tmp(1115).t.Fn6Odn);
return obj;
} else if (tmp(7441).ScheduledMessageSendState.ERROR_CHANNEL_NOT_FOUND === state) {
const obj2 = { isError: true, stateMessage: null };
const intl5 = tmp(1115).intl;
obj2.stateMessage = intl5.string(tmp(1115).t.v5O2dK);
return obj2;
} else if (tmp(7441).ScheduledMessageSendState.ERROR_USER_NOT_FOUND === state) {
const obj3 = { isError: true, stateMessage: null };
const intl4 = tmp(1115).intl;
obj3.stateMessage = intl4.string(tmp(1115).t.j8uIfG);
return obj3;
} else if (tmp(7441).ScheduledMessageSendState.ERROR_USER_CANNOT_USE_SCHEDULED_MESSAGES === state) {
const obj4 = { isError: true, stateMessage: null };
const intl3 = tmp(1115).intl;
obj4.stateMessage = intl3.string(tmp(1115).t["w6zHX/"]);
return obj4;
} else if (tmp(7441).ScheduledMessageSendState.ERROR_SEND_FAILED === state) {
const obj5 = { isError: true, stateMessage: null };
const intl2 = tmp(1115).intl;
obj5.stateMessage = intl2.string(tmp(1115).t.pflV7z);
return obj5;
} else if (tmp(7441).ScheduledMessageSendState.ERROR_SCHEDULED_MESSAGES_DISABLED === state) {
const obj6 = { isError: true, stateMessage: null };
const intl = tmp(1115).intl;
obj6.stateMessage = intl.string(tmp(1115).t.j8uIfG);
return obj6;
} else {
tmp(1370).assertNever(state);
}
};
export const convertServerScheduledMessageCreateArgs = function convertServerScheduledMessageCreateArgs(channelId) {
return { channelId: channelId.channel_id, content: channelId.content, type: channelId.type, flags: channelId.flags, messageReference: channelId.message_reference };
};