Files
tk-mini-program/unpackage/dist/dev/mp-weixin/TUIKit/components/TUIChat/utils/utils.js
pengxiaolong c006a8e63d 消息
2025-05-13 19:39:53 +08:00

93 lines
3.3 KiB
JavaScript

"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