281 lines
9.8 KiB
TypeScript
281 lines
9.8 KiB
TypeScript
// Module ID: 8406
|
|
// Function ID: 8407
|
|
// Name: AnnouncementMessageUtils
|
|
// Dependencies: [4520, 1985, 5121, 5040, 8407, 5112, 8408, 1126, 1371, 2]
|
|
// Exports: getPollExpiryLabel, getPosterUrl, toAnnouncementMessages
|
|
|
|
// Module 8406 (AnnouncementMessageUtils)
|
|
import URLUtilsDefault from "URLUtils" /* 1371 */;
|
|
import MessageRecord from "MessageRecord" /* 4520 */;
|
|
import useFormattedExpirationLabel from "useFormattedExpirationLabel" /* 8408 */;
|
|
import size from "module_2" /* 2 */;
|
|
|
|
let reactions;
|
|
|
|
const isMessageComponentsV2 = MessageRecord.isMessageComponentsV2;
|
|
const re4 = /^#{1,3}\s+(.+)$/;
|
|
const re5 = /^https?:\/\/\S+$/;
|
|
let result = size.fileFinishedImporting("modules/game_profile/AnnouncementMessageUtils.tsx");
|
|
|
|
export const toAnnouncementMessages = function toAnnouncementMessages(messages) {
|
|
let regex;
|
|
return messages.map((reactions) => {
|
|
let body;
|
|
let color;
|
|
let embeds;
|
|
let embeds2;
|
|
let embeds3;
|
|
let found4;
|
|
let found5;
|
|
let found6;
|
|
let joined;
|
|
let obj11;
|
|
let obj13;
|
|
let obj3;
|
|
let obj9;
|
|
let result;
|
|
let str10;
|
|
let str11;
|
|
let title;
|
|
let url;
|
|
const tmp2 = found5(found6[4]);
|
|
let obj = found4(found6[5]);
|
|
const tmp2Result = tmp2(obj.createMessageRecord(reactions));
|
|
const content = tmp2Result.content;
|
|
if (closure_3(tmp2Result)) {
|
|
const components = tmp2Result.components;
|
|
const found = components.filter((type) => type.type === found4(found6[1]).ComponentType.TEXT_DISPLAY);
|
|
const mapped = found.map((content) => content.content);
|
|
joined = mapped.join("\n");
|
|
} else {
|
|
const content1 = tmp2Result.content;
|
|
if (0 === content1.length) {
|
|
const first = tmp2Result.embeds[0];
|
|
let tmp9 = null;
|
|
if (null != first) {
|
|
const items = [];
|
|
if (null != first.rawTitle) {
|
|
const _HermesInternal = HermesInternal;
|
|
items.push("# " + first.rawTitle);
|
|
}
|
|
if (null != first.rawDescription) {
|
|
items.push(first.rawDescription);
|
|
}
|
|
let joined1 = null;
|
|
if (items.length > 0) {
|
|
joined1 = items.join("\n");
|
|
}
|
|
tmp9 = joined1;
|
|
}
|
|
if (tmp9 == null) {
|
|
tmp9 = content1;
|
|
}
|
|
joined = tmp9;
|
|
} else {
|
|
joined = content1;
|
|
}
|
|
}
|
|
if (closure_3(tmp2Result)) {
|
|
const components1 = tmp2Result.components;
|
|
const found1 = components1.find((type) => type.type === found4(found6[1]).ComponentType.MEDIA_GALLERY);
|
|
let media;
|
|
if (found1 != null) {
|
|
const first1 = found1.items[0];
|
|
if (first1 != null) {
|
|
media = first1.media;
|
|
}
|
|
}
|
|
if (null != media) {
|
|
let obj5;
|
|
const tmp3Result = found4(found6[2]);
|
|
const unfurledMediaItemType = tmp3Result.getUnfurledMediaItemType(media);
|
|
if ("INVALID" !== unfurledMediaItemType) {
|
|
const obj2 = { type: unfurledMediaItemType, sourceMetadata: obj3 };
|
|
const merged = Object.assign(media);
|
|
result = obj2;
|
|
obj3 = { message: tmp2Result };
|
|
}
|
|
const index = joined.indexOf("\n");
|
|
let str9 = joined;
|
|
if (-1 !== index) {
|
|
str9 = joined.slice(0, index);
|
|
}
|
|
const match = str9.match(closure_4);
|
|
if (null != match) {
|
|
const obj4 = { title: str10.trim(), body: str11 };
|
|
str11 = "";
|
|
str10 = match[1];
|
|
if (-1 !== index) {
|
|
const substr = joined.slice(index + 1);
|
|
str11 = substr.trimStart();
|
|
}
|
|
obj5 = obj4;
|
|
} else {
|
|
obj5 = { body: joined };
|
|
}
|
|
reactions = reactions.reactions;
|
|
let num5;
|
|
({ title, body } = obj5);
|
|
if (reactions != null) {
|
|
num5 = reactions.reduce((acc, count) => acc + count.count, 0);
|
|
}
|
|
if (num5 == null) {
|
|
num5 = 0;
|
|
}
|
|
let tmp35;
|
|
if (joined !== content) {
|
|
if (!closure_3(tmp2Result)) {
|
|
const first2 = tmp2Result.embeds[0];
|
|
let tmp37;
|
|
if (null != first2) {
|
|
const author = first2.author;
|
|
let name;
|
|
if (author != null) {
|
|
name = author.name;
|
|
}
|
|
const author2 = first2.author;
|
|
let iconProxyURL;
|
|
if (author2 != null) {
|
|
iconProxyURL = author2.iconProxyURL;
|
|
}
|
|
if (iconProxyURL == null) {
|
|
const author3 = first2.author;
|
|
let iconURL;
|
|
if (author3 != null) {
|
|
iconURL = author3.iconURL;
|
|
}
|
|
iconProxyURL = iconURL;
|
|
}
|
|
const footer = first2.footer;
|
|
let text;
|
|
if (footer != null) {
|
|
text = footer.text;
|
|
}
|
|
if (text == null) {
|
|
const provider = first2.provider;
|
|
let name1;
|
|
if (provider != null) {
|
|
name1 = provider.name;
|
|
}
|
|
text = name1;
|
|
}
|
|
const footer2 = first2.footer;
|
|
let iconProxyURL1;
|
|
if (footer2 != null) {
|
|
iconProxyURL1 = footer2.iconProxyURL;
|
|
}
|
|
if (iconProxyURL1 == null) {
|
|
const footer3 = first2.footer;
|
|
let iconURL1;
|
|
if (footer3 != null) {
|
|
iconURL1 = footer3.iconURL;
|
|
}
|
|
iconProxyURL1 = iconURL1;
|
|
}
|
|
({ url, color } = first2);
|
|
tmp37 = { authorName: name, authorIconUrl: iconProxyURL, providerName: text, providerIconUrl: iconProxyURL1, url, color };
|
|
const obj6 = { authorName: name, authorIconUrl: iconProxyURL, providerName: text, providerIconUrl: iconProxyURL1, url, color };
|
|
}
|
|
tmp35 = tmp37;
|
|
}
|
|
}
|
|
return { id: tmp2Result.id, media: result, title, body, content: joined, timestamp: reactions.timestamp, reactionCount: num5, embedSource: tmp35, poll: tmp2Result.poll };
|
|
}
|
|
}
|
|
const attachments = tmp2Result.attachments;
|
|
const found2 = attachments.find((content_type) => {
|
|
const obj = found4(found6[3]);
|
|
return obj.isImageContentType(content_type.content_type);
|
|
});
|
|
if (null != found2) {
|
|
const tmp3Result6 = found4(found6[2]);
|
|
result = tmp3Result6.messageAttachmentToMediaItem(found2, tmp2Result);
|
|
} else {
|
|
const attachments1 = tmp2Result.attachments;
|
|
const found3 = attachments1.find((content_type) => {
|
|
const obj = found4(found6[3]);
|
|
return obj.isVideoContentType(content_type.content_type);
|
|
});
|
|
if (null != found3) {
|
|
const tmp3Result7 = found4(found6[2]);
|
|
result = tmp3Result7.messageAttachmentToMediaItem(found3, tmp2Result);
|
|
} else {
|
|
const embeds1 = tmp2Result.embeds;
|
|
found4 = embeds1.find((video) => null != video.video && null != video.thumbnail);
|
|
let thumbnail1;
|
|
if (found4 != null) {
|
|
thumbnail1 = found4.thumbnail;
|
|
}
|
|
if (null != thumbnail1) {
|
|
const obj8 = { message: tmp2Result, identifier: obj9 };
|
|
obj9 = { type: "embed", embedIndex: embeds3.findIndex((item) => item === found4) };
|
|
embeds3 = tmp2Result.embeds;
|
|
const embedMediaToMediaItem3 = found4(tmp[2]).embedMediaToMediaItem;
|
|
const thumbnail2 = found4.thumbnail;
|
|
found4(found6[2]);
|
|
result = embedMediaToMediaItem3(thumbnail2, obj8, "IMAGE");
|
|
} else {
|
|
const embeds4 = tmp2Result.embeds;
|
|
found5 = embeds4.find((image) => null != image.image);
|
|
let image1;
|
|
if (found5 != null) {
|
|
image1 = found5.image;
|
|
}
|
|
if (null != image1) {
|
|
const obj10 = { message: tmp2Result, identifier: obj11 };
|
|
obj11 = { type: "embed", embedIndex: embeds2.findIndex((item) => item === found5) };
|
|
embeds2 = tmp2Result.embeds;
|
|
const embedMediaToMediaItem2 = found4(tmp[2]).embedMediaToMediaItem;
|
|
const image = found5.image;
|
|
found4(found6[2]);
|
|
result = embedMediaToMediaItem2(image, obj10, "IMAGE");
|
|
} else {
|
|
const embeds5 = tmp2Result.embeds;
|
|
found6 = embeds5.find((thumbnail) => null != thumbnail.thumbnail);
|
|
let thumbnail3;
|
|
if (found6 != null) {
|
|
thumbnail3 = found6.thumbnail;
|
|
}
|
|
if (null != thumbnail3) {
|
|
const obj12 = { message: tmp2Result, identifier: obj13 };
|
|
obj13 = { type: "embed", embedIndex: embeds.findIndex((item) => item === found6) };
|
|
embeds = tmp2Result.embeds;
|
|
const embedMediaToMediaItem = found4(tmp[2]).embedMediaToMediaItem;
|
|
const thumbnail = found6.thumbnail;
|
|
found4(found6[2]);
|
|
result = embedMediaToMediaItem(thumbnail, obj12, "IMAGE");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|
|
export const getPollExpiryLabel = function getPollExpiryLabel(poll) {
|
|
const obj = useFormattedExpirationLabel;
|
|
let result = obj.formatExpirationLabel(poll.expiry);
|
|
if (result == null) {
|
|
const intl = tmp(1126).intl;
|
|
result = intl.string(tmp(1126).t["e+J3JZ"]);
|
|
}
|
|
return result;
|
|
};
|
|
export const getPosterUrl = function getPosterUrl(proxyUrl, c12, c11) {
|
|
const obj = URLUtilsDefault;
|
|
const str = obj.toURLSafe(proxyUrl);
|
|
let str1 = null;
|
|
if (null != str) {
|
|
const searchParams = str.searchParams;
|
|
searchParams.append("format", "webp");
|
|
if (null != c12) {
|
|
const searchParams2 = str.searchParams;
|
|
searchParams2.append("width", c12.toString());
|
|
}
|
|
if (null != c11) {
|
|
const searchParams3 = str.searchParams;
|
|
searchParams3.append("height", c11.toString());
|
|
}
|
|
str1 = str.toString();
|
|
}
|
|
return str1;
|
|
};
|