72 lines
2.9 KiB
JavaScript
72 lines
2.9 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../../common/vendor.js");
|
|
const TUIKit_components_TUIChat_config = require("./config.js");
|
|
class TUIChatServer {
|
|
constructor() {
|
|
this.currentConversationID = "";
|
|
this.currentMessageList = [];
|
|
common_vendor.R.registerService(common_vendor.E.TUIChat.SERVICE.NAME, this);
|
|
common_vendor.R.registerEvent(common_vendor.E.TUITheme.EVENT.THEME_CHANGED, common_vendor.E.TUITheme.EVENT_SUB_KEY.CHANGE_SUCCESS, this);
|
|
common_vendor.R.registerEvent(common_vendor.E.TUIChat.EVENT.CHAT_TYPE_CHANGED, common_vendor.E.TUIChat.EVENT_SUB_KEY.CHANGE_SUCCESS, this);
|
|
common_vendor.zt.watch(common_vendor.o.CONV, {
|
|
currentConversationID: (id) => {
|
|
this.currentConversationID = id;
|
|
}
|
|
});
|
|
}
|
|
onCall(method, params, callback) {
|
|
let message;
|
|
switch (method) {
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.UPDATE_MESSAGE_LIST:
|
|
message = params.message;
|
|
if ((message == null ? void 0 : message.conversationID) === this.currentConversationID) {
|
|
common_vendor.Zt.updateMessageList([message], "push");
|
|
}
|
|
break;
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.SEND_CUSTOM_MESSAGE:
|
|
common_vendor.Zt.sendCustomMessage(params).then((res) => {
|
|
callback && callback(res);
|
|
});
|
|
break;
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.SEND_TEXT_MESSAGE:
|
|
common_vendor.Zt.sendTextMessage(params).then((res) => {
|
|
callback && callback(res);
|
|
});
|
|
break;
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.SET_CHAT_TYPE:
|
|
TUIKit_components_TUIChat_config.ChatConfig.setChatType(params == null ? void 0 : params.chatType);
|
|
break;
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.CLOSE_MESSAGE_POP_MENU:
|
|
common_vendor.zt.update(common_vendor.o.CUSTOM, "isShowMessagePopMenu", false);
|
|
break;
|
|
case common_vendor.E.TUIChat.SERVICE.METHOD.UPDATE_MESSAGE_INFO:
|
|
common_vendor.Zt.updateMessageInfo(params == null ? void 0 : params.userInfo);
|
|
break;
|
|
}
|
|
}
|
|
/**
|
|
* Listen for the success notification.
|
|
*/
|
|
onNotifyEvent(eventName, subKey, params) {
|
|
if (eventName === common_vendor.E.TUITheme.EVENT.THEME_CHANGED) {
|
|
switch (subKey) {
|
|
case common_vendor.E.TUITheme.EVENT_SUB_KEY.CHANGE_SUCCESS:
|
|
if (params == null ? void 0 : params.theme) {
|
|
TUIKit_components_TUIChat_config.ChatConfig.setTheme(params.theme.toLowerCase());
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (eventName === common_vendor.E.TUIChat.EVENT.CHAT_TYPE_CHANGED) {
|
|
switch (subKey) {
|
|
case common_vendor.E.TUIChat.EVENT_SUB_KEY.CHANGE_SUCCESS:
|
|
if (params == null ? void 0 : params.chatType) {
|
|
TUIKit_components_TUIChat_config.ChatConfig.setChatType(params == null ? void 0 : params.chatType);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exports.TUIChatServer = TUIChatServer;
|