"use strict"; const common_vendor = require("../../../../common/vendor.js"); const TUIKit_components_common_Toast_index = require("../../common/Toast/index.js"); const TUIKit_components_common_Toast_type = require("../../common/Toast/type.js"); const generateAvatar = (item) => { var _a; return (item == null ? void 0 : item.avatar) || ((_a = item == null ? void 0 : item.profile) == null ? void 0 : _a.avatar) || (item == null ? void 0 : item.groupID) && "https://web.sdk.qcloud.com/im/assets/images/Public.svg" || "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png"; }; const generateName = (item) => { var _a; return (item == null ? void 0 : item.remark) || (item == null ? void 0 : item.name) || ((_a = item == null ? void 0 : item.profile) == null ? void 0 : _a.nick) || (item == null ? void 0 : item.nick) || (item == null ? void 0 : item.groupID) || (item == null ? void 0 : item.userID) || ""; }; const generateContactInfoName = (item) => { var _a; return (item == null ? void 0 : item.name) || ((_a = item == null ? void 0 : item.profile) == null ? void 0 : _a.nick) || (item == null ? void 0 : item.nick) || (item == null ? void 0 : item.groupID) || (item == null ? void 0 : item.userID) || ""; }; const generateContactInfoBasic = (contactInfo) => { var _a; const res = [ { label: (contactInfo == null ? void 0 : contactInfo.groupID) ? "群ID" : "ID", data: (contactInfo == null ? void 0 : contactInfo.groupID) || (contactInfo == null ? void 0 : contactInfo.userID) || "" } ]; if (!isApplicationType(contactInfo)) { res.push({ label: (contactInfo == null ? void 0 : contactInfo.groupID) ? "群类型" : "个性签名", data: (contactInfo == null ? void 0 : contactInfo.type) || ((_a = contactInfo == null ? void 0 : contactInfo.profile) == null ? void 0 : _a.selfSignature) || "" }); } return res; }; const isApplicationType = (info) => { var _a, _b, _c, _d; return (info == null ? void 0 : info.type) === ((_b = (_a = common_vendor.qt) == null ? void 0 : _a.TYPES) == null ? void 0 : _b.SNS_APPLICATION_SENT_TO_ME) || (info == null ? void 0 : info.type) === ((_d = (_c = common_vendor.qt) == null ? void 0 : _c.TYPES) == null ? void 0 : _d.SNS_APPLICATION_SENT_BY_ME); }; const isFriend = (info) => { return new Promise((resolve, reject) => { if ((info == null ? void 0 : info.groupID) || !(info == null ? void 0 : info.userID)) { resolve(false); return; } if (info == null ? void 0 : info.addTime) { resolve(true); return; } common_vendor.ts.checkFriend({ userIDList: [info == null ? void 0 : info.userID], type: common_vendor.qt.TYPES.SNS_CHECK_TYPE_BOTH }).then((res) => { var _a, _b; switch ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.successUserIDList[0]) == null ? void 0 : _b.relation) { case common_vendor.qt.TYPES.SNS_TYPE_NO_RELATION: resolve(false); break; case common_vendor.qt.TYPES.SNS_TYPE_A_WITH_B: resolve(false); break; case common_vendor.qt.TYPES.SNS_TYPE_B_WITH_A: resolve(false); break; case common_vendor.qt.TYPES.SNS_TYPE_BOTH_WAY: resolve(true); break; default: resolve(false); break; } }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:111", "checkFriend error", error); reject(error); }); }); }; const updateFriendRemark = (userID, remark) => { var _a; if (((_a = remark == null ? void 0 : remark.replace(/[^\u0000-\u00ff]/g, "aa")) == null ? void 0 : _a.length) > 96) { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.修改备注失败: 备注长度不得超过 96 字节"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); return; } common_vendor.ts.updateFriend({ userID, remark }).then(() => { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.修改备注成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:138", "update friend remark failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.修改备注失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const deleteFriend = (userID) => { common_vendor.ts.deleteFriend({ userIDList: [userID], type: common_vendor.qt.TYPES.SNS_DELETE_TYPE_BOTH }).then((res) => { const { successUserIDList } = res.data; if (successUserIDList[0].userID === userID) { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.删除好友成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); } else { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.删除好友失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); } }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:167", "delete friend failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.删除好友失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const addFriend = (params) => { common_vendor.ts.addFriend(params).then(() => { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.申请已发送"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:185", "delete friend failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.申请发送失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const enterConversation = (item) => { const conversationID = (item == null ? void 0 : item.groupID) ? `GROUP${item == null ? void 0 : item.groupID}` : `C2C${item == null ? void 0 : item.userID}`; common_vendor.Xt.switchConversation(conversationID).catch( (error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:200", "switch conversation failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.进入会话失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); } ); }; const acceptFriendApplication = (userID) => { common_vendor.ts.acceptFriendApplication({ userID, type: common_vendor.qt.TYPES.SNS_APPLICATION_AGREE_AND_ADD }).then(() => { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.添加好友成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:222", "accept friend application failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.同意好友申请失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const refuseFriendApplication = (userID) => { common_vendor.ts.refuseFriendApplication(userID).then(() => { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.拒绝成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:240", "accept friend application failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.拒绝好友申请失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const dismissGroup = (groupID) => { common_vendor.es.dismissGroup(groupID).then(() => { var _a, _b; TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.解散群聊成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); ((_a = common_vendor.i) == null ? void 0 : _a.updateContactSearch) && ((_b = common_vendor.i) == null ? void 0 : _b.updateContactSearch()); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:259", "dismiss group failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.解散群聊失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const quitGroup = (groupID) => { common_vendor.es.quitGroup(groupID).then(() => { TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.退出群组成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:277", "quit group failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.退出群组失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const joinGroup = (groupID, applyMessage) => { common_vendor.es.joinGroup({ groupID, applyMessage }).then((imResponse) => { var _a; switch ((_a = imResponse == null ? void 0 : imResponse.data) == null ? void 0 : _a.status) { case common_vendor.qt.TYPES.JOIN_STATUS_WAIT_APPROVAL: TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.等待管理员同意"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); break; case common_vendor.qt.TYPES.JOIN_STATUS_SUCCESS: TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.加群成功"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); break; case common_vendor.qt.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.您已是群成员"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.SUCCESS }); break; } }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:316", "join group failed:", error); TUIKit_components_common_Toast_index.Toast({ message: "申请入群失败", type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const addToBlacklist = (userID, successCallBack) => { common_vendor.Zt.addToBlacklist({ userIDList: [userID] }).then(() => { successCallBack && successCallBack(); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:333", "add to blacklist failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.加入黑名单失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; const removeFromBlacklist = (userID, successCallBack) => { common_vendor.Zt.removeFromBlacklist({ userIDList: [userID] }).then(() => { successCallBack && successCallBack(); }).catch((error) => { common_vendor.index.__f__("warn", "at TUIKit/components/TUIContact/utils/index.ts:353", "remove from blacklist failed:", error); TUIKit_components_common_Toast_index.Toast({ message: common_vendor.Wt.t("TUIContact.移除黑名单失败"), type: TUIKit_components_common_Toast_type.TOAST_TYPE.ERROR }); }); }; exports.acceptFriendApplication = acceptFriendApplication; exports.addFriend = addFriend; exports.addToBlacklist = addToBlacklist; exports.deleteFriend = deleteFriend; exports.dismissGroup = dismissGroup; exports.enterConversation = enterConversation; exports.generateAvatar = generateAvatar; exports.generateContactInfoBasic = generateContactInfoBasic; exports.generateContactInfoName = generateContactInfoName; exports.generateName = generateName; exports.isApplicationType = isApplicationType; exports.isFriend = isFriend; exports.joinGroup = joinGroup; exports.quitGroup = quitGroup; exports.refuseFriendApplication = refuseFriendApplication; exports.removeFromBlacklist = removeFromBlacklist; exports.updateFriendRemark = updateFriendRemark; //# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIContact/utils/index.js.map