This commit is contained in:
pengxiaolong
2025-05-13 19:39:53 +08:00
parent 37da6765b8
commit c006a8e63d
1232 changed files with 96963 additions and 883 deletions

View File

@@ -0,0 +1,62 @@
"use strict";
const TUIKit_utils_env = require("../../../utils/env.js");
const common_vendor = require("../../../../common/vendor.js");
const _ChatStorage = class _ChatStorage {
constructor() {
this.chatStorage = null;
}
static getInstance() {
if (!_ChatStorage.instance) {
_ChatStorage.instance = new _ChatStorage();
}
return _ChatStorage.instance;
}
getChatStorage(key) {
if (!this.chatStorage) {
this.chatStorage = this.getChatStorageFromLocalStorage();
}
if (key) {
return this.chatStorage[key];
} else {
throw new Error("No key provided");
}
}
setChatStorage(key, value) {
if (!this.chatStorage) {
this.chatStorage = this.getChatStorageFromLocalStorage();
}
this.chatStorage[key] = value;
try {
if (TUIKit_utils_env.isUniFrameWork) {
common_vendor.i.setStorageSync(_ChatStorage.CHAT_STORAGE_KEY, JSON.stringify(this.chatStorage));
} else {
localStorage.setItem(_ChatStorage.CHAT_STORAGE_KEY, JSON.stringify(this.chatStorage));
}
} catch (error) {
throw new Error("Fail to set chat storage");
}
}
getChatStorageFromLocalStorage() {
let chatStorageString = "";
if (TUIKit_utils_env.isUniFrameWork) {
chatStorageString = common_vendor.i.getStorageSync(_ChatStorage.CHAT_STORAGE_KEY) || "";
} else {
chatStorageString = localStorage.getItem(_ChatStorage.CHAT_STORAGE_KEY) || "";
}
if (!chatStorageString) {
return {};
}
try {
this.chatStorage = JSON.parse(chatStorageString);
} catch (error) {
this.chatStorage = {};
}
return this.chatStorage;
}
};
_ChatStorage.instance = null;
_ChatStorage.CHAT_STORAGE_KEY = "TUI_CHAT_STORAGE";
let ChatStorage = _ChatStorage;
const chatStorage = ChatStorage.getInstance();
exports.chatStorage = chatStorage;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/chatStorage.js.map

View File

@@ -0,0 +1,75 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
const TUIKit_components_TUIChat_emojiConfig_index = require("../emoji-config/index.js");
const TUIKit_utils_typeCheck = require("../../../utils/type-check.js");
const _ConversationDraftManager = class _ConversationDraftManager {
constructor() {
this.quoteMessageMap = /* @__PURE__ */ new Map();
}
static getInstance() {
if (!_ConversationDraftManager.instance) {
_ConversationDraftManager.instance = new _ConversationDraftManager();
}
return _ConversationDraftManager.instance;
}
setStore(conversationID, draftContent, abstract, quoteMessage) {
var _a, _b;
if (conversationID && (this.isEditorNotEmpty(draftContent) || ((_a = quoteMessage == null ? void 0 : quoteMessage.message) == null ? void 0 : _a.ID))) {
let additionalDraftInfo = {};
if ((_b = quoteMessage == null ? void 0 : quoteMessage.message) == null ? void 0 : _b.ID) {
this.quoteMessageMap.set(quoteMessage.message.ID, quoteMessage.message);
additionalDraftInfo = { messageID: quoteMessage.message.ID, type: quoteMessage.type };
}
const draftParams = {
conversationID,
draftInfo: {
html: draftContent,
abstract,
...additionalDraftInfo
}
};
common_vendor.Xt.setConversationDraft(draftParams);
common_vendor.Jt.update(common_vendor.o.CHAT, "quoteMessage", { message: void 0, type: "quote" });
}
}
getStore(conversationID, setEditorContentCallback) {
const conversation = common_vendor.Jt.getConversationModel(conversationID);
if (!conversation) {
return;
}
if (conversation.conversationID && conversation.draftText) {
const draftObject = TUIKit_utils_typeCheck.JSONToObject(conversation.draftText);
common_vendor.Jt.update(common_vendor.o.CHAT, "quoteMessage", { message: this.quoteMessageMap.get(draftObject.messageID) || void 0, type: draftObject.type });
setEditorContentCallback(draftObject.html);
}
common_vendor.Xt.setConversationDraft({ conversationID: conversation.conversationID });
}
generateAbstract(editorContent) {
let abstract = "";
editorContent == null ? void 0 : editorContent.forEach((item) => {
switch (item.type) {
case "text":
abstract += TUIKit_components_TUIChat_emojiConfig_index.transformTextWithKeysToEmojiNames(item.payload.text || "");
break;
case "image":
abstract += common_vendor.Wt.t("TUIChat.图片");
break;
case "video":
abstract += common_vendor.Wt.t("TUIChat.视频");
break;
case "file":
abstract += common_vendor.Wt.t("TUIChat.文件");
break;
}
});
return abstract;
}
isEditorNotEmpty(editorHTML) {
return editorHTML && !editorHTML.includes("is-empty") && editorHTML !== "<p></p>";
}
};
_ConversationDraftManager.instance = null;
let ConversationDraftManager = _ConversationDraftManager;
const DraftManager = ConversationDraftManager.getInstance();
exports.DraftManager = DraftManager;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/conversationDraft.js.map

View File

@@ -0,0 +1,50 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
const _Convertor = class _Convertor {
constructor() {
this.isUseCache = true;
this.convertCache = /* @__PURE__ */ new Map();
}
static getInstance() {
if (!_Convertor.instance) {
_Convertor.instance = new _Convertor();
}
return _Convertor.instance;
}
async get(message) {
if (this.isUseCache) {
const cache = this.convertCache.get(message.ID);
if (cache !== void 0) {
return cache;
}
}
const currentMessage = common_vendor.Jt.getMessageModel(message.ID);
if (!currentMessage) {
return Promise.reject("message not found");
}
const response = await common_vendor.Qt.convertVoiceToText({
message: currentMessage
});
let { data: { result } = {} } = response;
if (result) {
this.convertCache.set(currentMessage.ID, result);
} else {
result = "";
}
return result;
}
clear() {
this.convertCache.clear();
}
disableCache() {
this.isUseCache = false;
}
enableCache() {
this.isUseCache = true;
}
};
_Convertor.instance = void 0;
let Convertor = _Convertor;
const convertor = Convertor.getInstance();
exports.convertor = convertor;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/convertVoiceToText.js.map

View File

@@ -0,0 +1,107 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
const TUIKit_components_common_Toast_index = require("../../common/Toast/index.js");
const TUIKit_components_TUIChat_utils_utils = require("./utils.js");
const TUIKit_utils_enableSampleTaskStatus = require("../../../utils/enableSampleTaskStatus.js");
const TUIKit_components_TUIChat_offlinePushInfoManager_index = require("../offlinePushInfoManager/index.js");
const TUIKit_components_common_Toast_type = require("../../common/Toast/type.js");
const sendMessageErrorCodeMap = /* @__PURE__ */ new Map([
[3123, "文本包含本地审核拦截词"],
[4004, "图片消息失败,无效的图片格式"],
[4005, "文件消息失败,禁止发送违规封禁的文件"],
[7004, "文件不存在,请检查文件路径是否正确"],
[7005, "文件大小超出了限制,如果上传文件,最大限制是100MB"],
[8001, "消息长度超出限制,消息长度不要超过12K"],
[80001, "消息或者资料中文本存在敏感内容,发送失败"],
[80004, "消息中图片存在敏感内容,发送失败"],
[10017, "您已被禁止聊天"]
]);
const sendMessages = async (messageList, currentConversation) => {
if (common_vendor.Jt.getData(common_vendor.o.CHAT, "messageSource")) {
common_vendor.Jt.update(common_vendor.o.CHAT, "messageSource", void 0);
}
messageList == null ? void 0 : messageList.forEach(async (content) => {
var _a, _b, _c, _d, _e, _f, _g;
try {
const options = {
to: ((_a = currentConversation == null ? void 0 : currentConversation.groupProfile) == null ? void 0 : _a.groupID) || ((_b = currentConversation == null ? void 0 : currentConversation.userProfile) == null ? void 0 : _b.userID),
conversationType: currentConversation == null ? void 0 : currentConversation.type,
payload: {},
needReadReceipt: TUIKit_components_TUIChat_utils_utils.isEnabledMessageReadReceiptGlobal()
};
let textMessageContent;
const sendMessageOptions = {
offlinePushInfo: {}
};
const offlinePushInfoCreateParams = {
conversation: currentConversation,
payload: content.payload,
messageType: ""
};
switch (content == null ? void 0 : content.type) {
case "text":
textMessageContent = JSON.parse(JSON.stringify((_c = content.payload) == null ? void 0 : _c.text));
if (!textMessageContent) {
break;
}
options.payload = {
text: textMessageContent
};
offlinePushInfoCreateParams.messageType = common_vendor.qt.TYPES.MSG_TEXT;
sendMessageOptions.offlinePushInfo = TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams);
if ((_d = content.payload) == null ? void 0 : _d.atUserList) {
options.payload.atUserList = content.payload.atUserList;
await common_vendor.Qt.sendTextAtMessage(options, sendMessageOptions);
} else {
await common_vendor.Qt.sendTextMessage(options, sendMessageOptions);
}
break;
case "image":
options.payload = {
file: (_e = content.payload) == null ? void 0 : _e.file
};
offlinePushInfoCreateParams.messageType = common_vendor.qt.TYPES.MSG_IMAGE;
sendMessageOptions.offlinePushInfo = TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams);
await common_vendor.Qt.sendImageMessage(options, sendMessageOptions);
break;
case "video":
options.payload = {
file: (_f = content.payload) == null ? void 0 : _f.file
};
offlinePushInfoCreateParams.messageType = common_vendor.qt.TYPES.MSG_VIDEO;
sendMessageOptions.offlinePushInfo = TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams);
await common_vendor.Qt.sendVideoMessage(options, sendMessageOptions);
break;
case "file":
options.payload = {
file: (_g = content.payload) == null ? void 0 : _g.file
};
offlinePushInfoCreateParams.messageType = common_vendor.qt.TYPES.MSG_FILE;
sendMessageOptions.offlinePushInfo = TUIKit_components_TUIChat_offlinePushInfoManager_index.OfflinePushInfoManager.create(offlinePushInfoCreateParams);
await common_vendor.Qt.sendFileMessage(options, sendMessageOptions);
break;
default:
break;
}
TUIKit_utils_enableSampleTaskStatus.enableSampleTaskStatus("sendMessage");
} catch (error) {
TUIKit_components_common_Toast_index.Toast({
message: sendMessageErrorCodeMap.get(error == null ? void 0 : error.code) ? common_vendor.Wt.t(`TUIChat.${sendMessageErrorCodeMap.get(error.code)}`) : error == null ? void 0 : error.message,
type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR
});
if (common_vendor.Jt.getData(common_vendor.o.CHAT, "quoteMessage")) {
common_vendor.Jt.update(common_vendor.o.CHAT, "quoteMessage", {});
}
}
});
};
const sendTyping = (inputContentEmpty, inputBlur) => {
if (!inputContentEmpty && !inputBlur) {
common_vendor.Qt.enterTypingState();
} else {
common_vendor.Qt.leaveTypingState();
}
};
exports.sendMessages = sendMessages;
exports.sendTyping = sendTyping;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/sendMessage.js.map

View File

@@ -0,0 +1,154 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
const _Translator = class _Translator {
constructor() {
this.isUseCache = true;
this.translationCache = /* @__PURE__ */ new Map();
}
static getInstance() {
if (!_Translator.instance) {
_Translator.instance = new _Translator();
}
return _Translator.instance;
}
async get(message) {
if (this.isUseCache) {
const cache = this.translationCache.get(message.ID);
if (cache !== void 0) {
return cache;
}
}
const currentMessage = common_vendor.Jt.getMessageModel(message.ID);
if (!currentMessage) {
return [];
}
const { text } = currentMessage.getMessageContent() || {};
const textList = [];
const splittingList = await this.getNickList(currentMessage);
for (let i = 0; i < text.length; ++i) {
const item = text[i];
if (item.name === "img") {
textList.push({ type: "face", value: item.src });
continue;
}
const { transSplitingList, atNickList } = this.getSplitResult(item.text, splittingList);
for (let j = 0; j < transSplitingList.length; ++j) {
textList.push({ type: "text", value: transSplitingList[j] });
if (j < atNickList.length) {
textList.push({ type: "mention", value: atNickList[j] });
}
}
}
const needTranslateTextIndex = [];
const needTranslateText = textList.filter((item, index) => {
if (item.type === "text" && item.value.trim() !== "") {
needTranslateTextIndex.push(index);
return true;
}
return false;
}).map((item) => item.value);
if (needTranslateText.length === 0) {
this.translationCache.set(currentMessage.ID, textList);
return textList;
}
const translationResult = await this.getTranslationStandard(needTranslateText);
translationResult.forEach((item, index) => {
textList[needTranslateTextIndex[index]].value = item;
});
this.translationCache.set(currentMessage.ID, textList);
return textList;
}
/**
* Clears the translation cache.
*/
clear() {
this.translationCache.clear();
}
disableCache() {
this.isUseCache = false;
}
enableCache() {
this.isUseCache = true;
}
getTranslationStandard(originTextList) {
return new Promise((resolve, reject) => {
common_vendor.Qt.translateText({
sourceTextList: originTextList,
sourceLanguage: "auto"
}).then((response) => {
const {
data: { translatedTextList }
} = response;
resolve(translatedTextList);
}).catch((error) => {
reject(error);
});
});
}
/**
* the nick list is used to split the text by @ + {nick or userID}
* @param message
* @returns e.g. ['@james', '@john']
*/
async getNickList(message) {
const splittingList = [];
const { atUserList = [] } = message;
const atAllID = common_vendor.qt.TYPES.MSG_AT_ALL;
if (atUserList.includes(atAllID)) {
splittingList.push(`@${common_vendor.Wt.t("TUIChat.所有人")}`);
}
if (atUserList.length > 0) {
const { data: userProfileList } = await common_vendor.Zt.getUserProfile({ userIDList: atUserList });
userProfileList.forEach((user) => {
const atNick = `@${user.nick || user.userID}`;
splittingList.push(atNick);
});
}
return [...new Set(splittingList)];
}
/**
* Splits the given text into substrings based on the provided splitString array.
*
* @param {string} text - The text to be split.
* @param {string[]} splitString - The array of strings to split the text by.
* @return {{ transSplitingList: string[]; atNickList: string[] }} - An object containing two arrays:
* - transSplitingList: An array of substrings extracted from the text.
* - atNickList: An array of split strings that were found in the text.
*/
getSplitResult(text, splitString) {
let searchStartPos = 0;
const transSplitingList = [];
const atNickList = [];
while (searchStartPos < text.length) {
const nextAtCharPos = text.indexOf("@", searchStartPos);
if (nextAtCharPos === -1) {
transSplitingList.push(text.substring(searchStartPos));
break;
}
let found = false;
for (let i = 0; i < splitString.length; ++i) {
const pos = text.indexOf(splitString[i], nextAtCharPos);
if (pos !== -1 && pos === nextAtCharPos) {
transSplitingList.push(text.substring(searchStartPos, pos));
atNickList.push(splitString[i]);
searchStartPos = pos + splitString[i].length;
found = true;
break;
}
}
if (!found) {
transSplitingList.push(text.substring(searchStartPos));
break;
}
}
return {
transSplitingList,
atNickList
};
}
};
_Translator.instance = void 0;
let Translator = _Translator;
const translator = Translator.getInstance();
exports.translator = translator;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/translation.js.map

View File

@@ -0,0 +1,92 @@
"use strict";
const common_vendor = require("../../../../common/vendor.js");
function deepCopy(data, hash = /* @__PURE__ */ new WeakMap()) {
if (typeof data !== "object" || data === null || data === void 0) {
return data;
}
if (hash.has(data)) {
return hash.get(data);
}
const newData = Object.create(Object.getPrototypeOf(data));
const dataKeys = Object.keys(data);
dataKeys.forEach((value) => {
const currentDataValue = data[value];
if (typeof currentDataValue !== "object" || currentDataValue === null) {
newData[value] = currentDataValue;
} else if (Array.isArray(currentDataValue)) {
newData[value] = [...currentDataValue];
} else if (currentDataValue instanceof Set) {
newData[value] = /* @__PURE__ */ new Set([...currentDataValue]);
} else if (currentDataValue instanceof Map) {
newData[value] = new Map([...currentDataValue]);
} else {
hash.set(data, data);
newData[value] = deepCopy(currentDataValue, hash);
}
});
return newData;
}
const isCreateGroupCustomMessage = (message) => {
var _a;
return message.type === common_vendor.qt.TYPES.MSG_CUSTOM && ((_a = message == null ? void 0 : message.getMessageContent()) == null ? void 0 : _a.businessID) === "group_create";
};
function isEnabledMessageReadReceiptGlobal() {
return common_vendor.Jt.getData(common_vendor.o.USER, "displayMessageReadReceipt") && common_vendor.Jt.getData(common_vendor.o.APP, "enabledMessageReadReceipt");
}
function shallowCopyMessage(message) {
return Object.assign({}, message);
}
function calculateTimestamp(timestamp) {
const todayZero = (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0);
const thisYear = new Date(
(/* @__PURE__ */ new Date()).getFullYear(),
0,
1,
0,
0,
0,
0
).getTime();
const target = new Date(timestamp);
const oneDay = 24 * 60 * 60 * 1e3;
const oneWeek = 7 * oneDay;
const diff = todayZero - target.getTime();
function formatNum(num) {
return num < 10 ? "0" + num : num.toString();
}
if (diff <= 0) {
return `${formatNum(target.getHours())}:${formatNum(target.getMinutes())}`;
} else if (diff <= oneDay) {
return `${common_vendor.Wt.t("time.昨天")} ${formatNum(
target.getHours()
)}:${formatNum(target.getMinutes())}`;
} else if (diff <= oneWeek - oneDay) {
const weekdays = [
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六"
];
const weekday = weekdays[target.getDay()];
return `${common_vendor.Wt.t("time." + weekday)} ${formatNum(
target.getHours()
)}:${formatNum(target.getMinutes())}`;
} else if (target.getTime() >= thisYear) {
return `${target.getMonth() + 1}/${target.getDate()} ${formatNum(
target.getHours()
)}:${formatNum(target.getMinutes())}`;
} else {
return `${target.getFullYear()}/${target.getMonth() + 1}/${target.getDate()} ${formatNum(target.getHours())}:${formatNum(
target.getMinutes()
)}`;
}
}
exports.calculateTimestamp = calculateTimestamp;
exports.deepCopy = deepCopy;
exports.isCreateGroupCustomMessage = isCreateGroupCustomMessage;
exports.isEnabledMessageReadReceiptGlobal = isEnabledMessageReadReceiptGlobal;
exports.shallowCopyMessage = shallowCopyMessage;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/utils.js.map

View File

@@ -0,0 +1,32 @@
"use strict";
const wordsList = [
{
value: "在吗?在吗?在吗?重要的话说三遍。"
},
{
value: "好久没聊天了,快来和我说说话~"
},
{
value: "好的,就这么说定了。"
},
{
value: "感恩的心,感谢有你。"
},
{
value: "糟糕!是心动的感觉!"
},
{
value: "心疼地抱抱自己,我太难了!"
},
{
value: "没关系,别在意,事情过去就过去了。"
},
{
value: "早上好,今天也是让人期待的一天呢!"
},
{
value: "熬夜有什么用,又没人陪你聊天,早点休息吧。"
}
];
exports.wordsList = wordsList;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/utils/wordsList.js.map