|
@@ -1,7 +1,7 @@
|
|
|
-import { TUINotification } from '../../../TUIPlugin';
|
|
|
-import Message from '../../../TUICore/tim/index';
|
|
|
-import IComponentServer from '../IComponentServer';
|
|
|
-import { JSONToObject } from './utils/utils';
|
|
|
+import { TUINotification } from "../../../TUIPlugin";
|
|
|
+import Message from "../../../TUICore/tim/index";
|
|
|
+import IComponentServer from "../IComponentServer";
|
|
|
+import { JSONToObject } from "./utils/utils";
|
|
|
/**
|
|
|
* class TUIChatServer
|
|
|
*
|
|
@@ -15,11 +15,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
super();
|
|
|
this.TUICore = TUICore;
|
|
|
this.bindTIMEvent();
|
|
|
- this.store = TUICore.setComponentStore(
|
|
|
- 'TUIChat',
|
|
|
- {},
|
|
|
- this.updateStore.bind(this)
|
|
|
- );
|
|
|
+ this.store = TUICore.setComponentStore("TUIChat", {}, this.updateStore.bind(this));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -44,11 +40,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
this.currentStore.messageList = [];
|
|
|
return;
|
|
|
}
|
|
|
- if (
|
|
|
- newValue.conversation.conversationID &&
|
|
|
- newValue.conversation.conversationID !==
|
|
|
- oldValue.conversation.conversationID
|
|
|
- ) {
|
|
|
+ if (newValue.conversation.conversationID && newValue.conversation.conversationID !== oldValue.conversation.conversationID) {
|
|
|
this.render(newValue.conversation);
|
|
|
}
|
|
|
}
|
|
@@ -60,13 +52,13 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
this.currentStore.readSet.clear();
|
|
|
this.getMessageList({
|
|
|
conversationID: conversation.conversationID,
|
|
|
- count: len
|
|
|
+ count: len,
|
|
|
});
|
|
|
if (conversation.type === this.TUICore.TIM.TYPES.CONV_GROUP) {
|
|
|
this.currentStore.userInfo.isGroup = true;
|
|
|
const options = {
|
|
|
groupID: conversation.groupProfile.groupID,
|
|
|
- userIDList: [conversation.groupProfile.selfInfo.userID]
|
|
|
+ userIDList: [conversation.groupProfile.selfInfo.userID],
|
|
|
};
|
|
|
this.getGroupProfile({ groupID: conversation.groupProfile.groupID });
|
|
|
this.getGroupMemberProfile(options).then((res: any) => {
|
|
@@ -77,7 +69,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
this?.TUICore?.TUIServer?.TUIGroup?.getGroupMemberList({
|
|
|
groupID: conversation.groupProfile.groupID,
|
|
|
count: 100,
|
|
|
- offset: 0
|
|
|
+ offset: 0,
|
|
|
}).then((res: any) => {
|
|
|
this.currentStore.allMemberList = res.data?.memberList;
|
|
|
});
|
|
@@ -97,74 +89,27 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
*/
|
|
|
|
|
|
private bindTIMEvent() {
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_RECEIVED,
|
|
|
- this.handleMessageReceived,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_MODIFIED,
|
|
|
- this.handleMessageModified,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_REVOKED,
|
|
|
- this.handleMessageRevoked,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_READ_BY_PEER,
|
|
|
- this.handleMessageReadByPeer,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED,
|
|
|
- this.handleGroupListUpdated,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_READ_RECEIPT_RECEIVED,
|
|
|
- this.handleMessageReadReceiptReceived,
|
|
|
- this
|
|
|
- );
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_RECEIVED, this.handleMessageReceived, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_MODIFIED, this.handleMessageModified, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_REVOKED, this.handleMessageRevoked, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_READ_BY_PEER, this.handleMessageReadByPeer, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED, this.handleGroupListUpdated, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.MESSAGE_READ_RECEIPT_RECEIVED, this.handleMessageReadReceiptReceived, this);
|
|
|
}
|
|
|
|
|
|
private unbindTIMEvent() {
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_RECEIVED,
|
|
|
- this.handleMessageReceived
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_MODIFIED,
|
|
|
- this.handleMessageModified
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_REVOKED,
|
|
|
- this.handleMessageRevoked
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_READ_BY_PEER,
|
|
|
- this.handleMessageReadByPeer
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED,
|
|
|
- this.handleGroupListUpdated
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.MESSAGE_READ_RECEIPT_RECEIVED,
|
|
|
- this.handleMessageReadReceiptReceived
|
|
|
- );
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.MESSAGE_RECEIVED, this.handleMessageReceived);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.MESSAGE_MODIFIED, this.handleMessageModified);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.MESSAGE_REVOKED, this.handleMessageRevoked);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.MESSAGE_READ_BY_PEER, this.handleMessageReadByPeer);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.GROUP_LIST_UPDATED, this.handleGroupListUpdated);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.MESSAGE_READ_RECEIPT_RECEIVED, this.handleMessageReadReceiptReceived);
|
|
|
}
|
|
|
|
|
|
private handleMessageReceived(event: any) {
|
|
|
event?.data?.forEach((message: Message) => {
|
|
|
- if (
|
|
|
- message?.conversationID === this?.store?.conversation?.conversationID
|
|
|
- ) {
|
|
|
- this.currentStore.messageList = [
|
|
|
- ...this.currentStore.messageList,
|
|
|
- message
|
|
|
- ];
|
|
|
+ if (message?.conversationID === this?.store?.conversation?.conversationID) {
|
|
|
+ this.currentStore.messageList = [...this.currentStore.messageList, message];
|
|
|
}
|
|
|
TUINotification.getInstance().notify(message);
|
|
|
});
|
|
@@ -222,42 +167,31 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
* @param {any} to 发送的对象
|
|
|
* @returns {options} 消息参数
|
|
|
*/
|
|
|
- public handleMessageOptions(
|
|
|
- content: any,
|
|
|
- type: string,
|
|
|
- callback?: any,
|
|
|
- to?: any
|
|
|
- ) {
|
|
|
+ public handleMessageOptions(content: any, type: string, callback?: any, to?: any) {
|
|
|
const options: any = {
|
|
|
- to: '',
|
|
|
+ to: "",
|
|
|
conversationType: to?.type || this.store.conversation.type,
|
|
|
payload: content,
|
|
|
- needReadReceipt: this.currentStore.needReadReceipt
|
|
|
+ needReadReceipt: this.currentStore.needReadReceipt,
|
|
|
};
|
|
|
if (this.currentStore.needTyping) {
|
|
|
options.cloudCustomData = {
|
|
|
messageFeature: {
|
|
|
needTyping: 1,
|
|
|
- version: 1
|
|
|
- }
|
|
|
+ version: 1,
|
|
|
+ },
|
|
|
};
|
|
|
options.cloudCustomData = JSON.stringify(options.cloudCustomData);
|
|
|
}
|
|
|
- if (type === 'file' && callback) {
|
|
|
+ if (type === "file" && callback) {
|
|
|
options.onProgress = callback;
|
|
|
}
|
|
|
switch (options.conversationType) {
|
|
|
case this.TUICore.TIM.TYPES.CONV_C2C:
|
|
|
- options.to =
|
|
|
- to?.userProfile?.userID ||
|
|
|
- this.store.conversation?.userProfile?.userID ||
|
|
|
- '';
|
|
|
+ options.to = to?.userProfile?.userID || this.store.conversation?.userProfile?.userID || "";
|
|
|
break;
|
|
|
case this.TUICore.TIM.TYPES.CONV_GROUP:
|
|
|
- options.to =
|
|
|
- to?.groupProfile?.groupID ||
|
|
|
- this.store.conversation?.groupProfile?.groupID ||
|
|
|
- '';
|
|
|
+ options.to = to?.groupProfile?.groupID || this.store.conversation?.groupProfile?.groupID || "";
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
@@ -275,10 +209,10 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public handlePromiseCallback(callback: any) {
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
const config = {
|
|
|
- TUIName: 'TUIChat',
|
|
|
+ TUIName: "TUIChat",
|
|
|
callback: () => {
|
|
|
callback && callback(resolve, reject);
|
|
|
- }
|
|
|
+ },
|
|
|
};
|
|
|
this.TUICore.setAwaitFunc(config.TUIName, config.callback);
|
|
|
});
|
|
@@ -310,10 +244,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
callback()
|
|
|
.then(resolve)
|
|
|
.catch((error: any) => {
|
|
|
- if (
|
|
|
- times > intervalList.length ||
|
|
|
- (retryBreakFn && retryBreakFn(error))
|
|
|
- ) {
|
|
|
+ if (times > intervalList.length || (retryBreakFn && retryBreakFn(error))) {
|
|
|
reject(error);
|
|
|
return;
|
|
|
}
|
|
@@ -341,6 +272,23 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 删除会话
|
|
|
+ *
|
|
|
+ * @param {string} conversationID 会话ID
|
|
|
+ * @returns {Promise}
|
|
|
+ */
|
|
|
+ public async deleteConversation(conversationID: string) {
|
|
|
+ return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
+ try {
|
|
|
+ const imResponse: any = await this.TUICore.tim.deleteConversation(conversationID);
|
|
|
+ resolve(imResponse);
|
|
|
+ } catch (error) {
|
|
|
+ reject(error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* /////////////////////////////////////////////////////////////////////////////////
|
|
|
* //
|
|
|
* // TIM 方法
|
|
@@ -361,18 +309,16 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendFaceMessage(data: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(data, 'face');
|
|
|
+ const options = this.handleMessageOptions(data, "face");
|
|
|
const message = this.TUICore.tim.createFaceMessage(options);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -393,25 +339,19 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendImageMessage(image: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(
|
|
|
- { file: image },
|
|
|
- 'file',
|
|
|
- (progress: number) => {
|
|
|
- this.handleUploadProgress(progress, message);
|
|
|
- }
|
|
|
- );
|
|
|
+ const options = this.handleMessageOptions({ file: image }, "file", (progress: number) => {
|
|
|
+ this.handleUploadProgress(progress, message);
|
|
|
+ });
|
|
|
const message = this.TUICore.tim.createImageMessage(options);
|
|
|
message.progress = 0.01;
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -432,26 +372,20 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendVideoMessage(video: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(
|
|
|
- { file: video },
|
|
|
- 'file',
|
|
|
- (progress: number) => {
|
|
|
- this.handleUploadProgress(progress, message);
|
|
|
- }
|
|
|
- );
|
|
|
+ const options = this.handleMessageOptions({ file: video }, "file", (progress: number) => {
|
|
|
+ this.handleUploadProgress(progress, message);
|
|
|
+ });
|
|
|
const message = this.TUICore.tim.createVideoMessage(options);
|
|
|
message.progress = 0.01;
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -472,25 +406,19 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendFileMessage(file: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(
|
|
|
- { file },
|
|
|
- 'file',
|
|
|
- (progress: number) => {
|
|
|
- this.handleUploadProgress(progress, message);
|
|
|
- }
|
|
|
- );
|
|
|
+ const options = this.handleMessageOptions({ file }, "file", (progress: number) => {
|
|
|
+ this.handleUploadProgress(progress, message);
|
|
|
+ });
|
|
|
const message = this.TUICore.tim.createFileMessage(options);
|
|
|
message.progress = 0.01;
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -515,18 +443,16 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
data.data = JSON.stringify(data.data);
|
|
|
- const options = this.handleMessageOptions(data, 'custom');
|
|
|
+ const options = this.handleMessageOptions(data, "custom");
|
|
|
const message = this.TUICore.tim.createCustomMessage(options);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -550,7 +476,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendLocationMessage(data: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(data, 'location');
|
|
|
+ const options = this.handleMessageOptions(data, "location");
|
|
|
const message = this.TUICore.tim.createLocationMessage(options);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
@@ -575,13 +501,10 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public forwardMessage(message: any, to: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(message, 'forward', {}, to);
|
|
|
+ const options = this.handleMessageOptions(message, "forward", {}, to);
|
|
|
const imMessage = this.TUICore.tim.createForwardMessage(options);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(imMessage);
|
|
|
- if (
|
|
|
- this.store.conversation.conversationID ===
|
|
|
- imResponse.data.message.conversationID
|
|
|
- ) {
|
|
|
+ if (this.store.conversation.conversationID === imResponse.data.message.conversationID) {
|
|
|
this.currentStore.messageList.push(imResponse.data.message);
|
|
|
}
|
|
|
resolve(imResponse);
|
|
@@ -604,9 +527,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public async sendMessageReadReceipt(messageList: Array<any>) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse: any = await this.TUICore.tim.sendMessageReadReceipt(
|
|
|
- messageList
|
|
|
- );
|
|
|
+ const imResponse: any = await this.TUICore.tim.sendMessageReadReceipt(messageList);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -624,8 +545,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public async getMessageReadReceiptList(messageList: Array<any>) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse: any =
|
|
|
- await this.TUICore.tim.getMessageReadReceiptList(messageList);
|
|
|
+ const imResponse: any = await this.TUICore.tim.getMessageReadReceiptList(messageList);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -659,10 +579,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
if (!history) {
|
|
|
this.currentStore.messageList = imResponse.data.messageList;
|
|
|
} else {
|
|
|
- this.currentStore.messageList = [
|
|
|
- ...imResponse.data.messageList,
|
|
|
- ...this.currentStore.messageList
|
|
|
- ];
|
|
|
+ this.currentStore.messageList = [...imResponse.data.messageList, ...this.currentStore.messageList];
|
|
|
}
|
|
|
this.currentStore.nextReqMessageID = imResponse.data.nextReqMessageID;
|
|
|
this.currentStore.isCompleted = imResponse.data.isCompleted;
|
|
@@ -684,7 +601,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
const options = {
|
|
|
conversationID: this.currentStore.conversation.conversationID,
|
|
|
nextReqMessageID: this.currentStore.nextReqMessageID,
|
|
|
- count: 15
|
|
|
+ count: 15,
|
|
|
};
|
|
|
if (!this.currentStore.isCompleted) {
|
|
|
this.getMessageList(options, true);
|
|
@@ -702,7 +619,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendTextMessage(text: any, data: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions({ text }, 'text');
|
|
|
+ const options = this.handleMessageOptions({ text }, "text");
|
|
|
let cloudCustomDataObj = {};
|
|
|
if (options.cloudCustomData) {
|
|
|
try {
|
|
@@ -714,19 +631,17 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
const cloudCustomData = JSON.stringify(data);
|
|
|
const secondOptions = Object.assign(options, {
|
|
|
cloudCustomData,
|
|
|
- ...cloudCustomDataObj
|
|
|
+ ...cloudCustomDataObj,
|
|
|
});
|
|
|
const message = this.TUICore.tim.createTextMessage(secondOptions);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -751,10 +666,10 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
data.data = JSON.stringify(data.data);
|
|
|
- const options = this.handleMessageOptions(data, 'custom');
|
|
|
+ const options = this.handleMessageOptions(data, "custom");
|
|
|
const message = this.TUICore.tim.createCustomMessage(options);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message, {
|
|
|
- onlineUserOnly: true
|
|
|
+ onlineUserOnly: true,
|
|
|
});
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
@@ -780,18 +695,16 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendTextAtMessage(data: any) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(data, 'text');
|
|
|
+ const options = this.handleMessageOptions(data, "text");
|
|
|
const message = this.TUICore.tim.createTextAtMessage(options);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -816,18 +729,16 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public sendMergerMessage(data: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const options = this.handleMessageOptions(data, 'merger');
|
|
|
+ const options = this.handleMessageOptions(data, "merger");
|
|
|
const message = this.TUICore.tim.createMergerMessage(options);
|
|
|
this.currentStore.messageList.push(message);
|
|
|
const imResponse = await this.TUICore.tim.sendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.map(
|
|
|
- (item: any) => {
|
|
|
- if (item.ID === imResponse.data.message.ID) {
|
|
|
- return imResponse.data.message;
|
|
|
- }
|
|
|
- return item;
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.map((item: any) => {
|
|
|
+ if (item.ID === imResponse.data.message.ID) {
|
|
|
+ return imResponse.data.message;
|
|
|
}
|
|
|
- );
|
|
|
+ return item;
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -874,9 +785,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
const imResponse = await this.TUICore.tim.resendMessage(message);
|
|
|
- this.currentStore.messageList = this.currentStore.messageList.filter(
|
|
|
- (item: any) => item.ID !== message.ID
|
|
|
- );
|
|
|
+ this.currentStore.messageList = this.currentStore.messageList.filter((item: any) => item.ID !== message.ID);
|
|
|
this.currentStore.messageList.push(imResponse.data.message);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
@@ -924,16 +833,11 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
const code = (error as any)?.code;
|
|
|
const data = (error as any)?.data;
|
|
|
if (code === 2480) {
|
|
|
- console.warn(
|
|
|
- 'MODIFY_MESSAGE_ERROR',
|
|
|
- '修改消息发生冲突,data.message 是最新的消息',
|
|
|
- 'data.message:',
|
|
|
- data?.message
|
|
|
- );
|
|
|
+ console.warn("MODIFY_MESSAGE_ERROR", "修改消息发生冲突,data.message 是最新的消息", "data.message:", data?.message);
|
|
|
} else if (code === 2481) {
|
|
|
- console.warn('MODIFY_MESSAGE_ERROR', '不支持修改直播群消息');
|
|
|
+ console.warn("MODIFY_MESSAGE_ERROR", "不支持修改直播群消息");
|
|
|
} else if (code === 20026) {
|
|
|
- console.warn('MODIFY_MESSAGE_ERROR', '消息不存在');
|
|
|
+ console.warn("MODIFY_MESSAGE_ERROR", "消息不存在");
|
|
|
}
|
|
|
reject(error);
|
|
|
}
|
|
@@ -956,29 +860,24 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
messageType: message?.type,
|
|
|
messageTime: message?.time,
|
|
|
messageSequence: message?.sequence,
|
|
|
- version: 1
|
|
|
+ version: 1,
|
|
|
};
|
|
|
if (!messageRoot) {
|
|
|
const cloudCustomData = JSONToObject(message?.cloudCustomData);
|
|
|
const messageRootID = cloudCustomData?.messageReply?.messageRootID;
|
|
|
- messageRoot =
|
|
|
- (await this?.currentStore?.messageList?.find(
|
|
|
- (item: any) => item?.ID === messageRootID
|
|
|
- )) || this.findMessage(messageRootID);
|
|
|
+ messageRoot = (await this?.currentStore?.messageList?.find((item: any) => item?.ID === messageRootID)) || this.findMessage(messageRootID);
|
|
|
}
|
|
|
- const rootCloudCustomData = messageRoot?.cloudCustomData
|
|
|
- ? JSONToObject(messageRoot?.cloudCustomData)
|
|
|
- : { messageReplies: {} };
|
|
|
+ const rootCloudCustomData = messageRoot?.cloudCustomData ? JSONToObject(messageRoot?.cloudCustomData) : { messageReplies: {} };
|
|
|
if (rootCloudCustomData?.messageReplies?.replies) {
|
|
|
rootCloudCustomData.messageReplies.replies = [
|
|
|
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
|
...rootCloudCustomData?.messageReplies?.replies,
|
|
|
- repliesObject
|
|
|
+ repliesObject,
|
|
|
];
|
|
|
} else {
|
|
|
rootCloudCustomData.messageReplies = {
|
|
|
replies: [repliesObject],
|
|
|
- version: 1
|
|
|
+ version: 1,
|
|
|
};
|
|
|
}
|
|
|
messageRoot.cloudCustomData = JSON.stringify(rootCloudCustomData);
|
|
@@ -993,11 +892,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
if (error && error?.code === 2480) return false;
|
|
|
return true;
|
|
|
};
|
|
|
- return this.handlePromiseCallbackRetry(
|
|
|
- replyFunction,
|
|
|
- [500, 1000, 3000],
|
|
|
- retryBreakFunction
|
|
|
- );
|
|
|
+ return this.handlePromiseCallbackRetry(replyFunction, [500, 1000, 3000], retryBreakFunction);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1013,18 +908,11 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
if (!messageRoot) {
|
|
|
const cloudCustomData = JSONToObject(message?.cloudCustomData);
|
|
|
const messageRootID = cloudCustomData?.messageReply?.messageRootID;
|
|
|
- messageRoot =
|
|
|
- (await this?.currentStore?.messageList?.find(
|
|
|
- (item: any) => item?.ID === messageRootID
|
|
|
- )) || this.findMessage(messageRootID);
|
|
|
+ messageRoot = (await this?.currentStore?.messageList?.find((item: any) => item?.ID === messageRootID)) || this.findMessage(messageRootID);
|
|
|
}
|
|
|
- const rootCloudCustomData = messageRoot?.cloudCustomData
|
|
|
- ? JSONToObject(messageRoot?.cloudCustomData)
|
|
|
- : { messageReplies: {} };
|
|
|
+ const rootCloudCustomData = messageRoot?.cloudCustomData ? JSONToObject(messageRoot?.cloudCustomData) : { messageReplies: {} };
|
|
|
if (rootCloudCustomData?.messageReplies?.replies) {
|
|
|
- const index = rootCloudCustomData.messageReplies.replies.findIndex(
|
|
|
- (item: any) => item?.messageID === message?.ID
|
|
|
- );
|
|
|
+ const index = rootCloudCustomData.messageReplies.replies.findIndex((item: any) => item?.messageID === message?.ID);
|
|
|
rootCloudCustomData?.messageReplies?.replies?.splice(index, 1);
|
|
|
}
|
|
|
messageRoot.cloudCustomData = JSON.stringify(rootCloudCustomData);
|
|
@@ -1039,11 +927,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
if (error && error?.code === 2480) return false;
|
|
|
return true;
|
|
|
};
|
|
|
- return this.handlePromiseCallbackRetry(
|
|
|
- revokeReplyFunction,
|
|
|
- [500, 1000, 3000],
|
|
|
- retryBreakFunction
|
|
|
- );
|
|
|
+ return this.handlePromiseCallbackRetry(revokeReplyFunction, [500, 1000, 3000], retryBreakFunction);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1057,29 +941,17 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
if (!message || !message?.ID || !emojiID) reject();
|
|
|
- const userID =
|
|
|
- this.TUICore?.TUIServer?.TUIProfile?.store?.profile?.userID;
|
|
|
- message =
|
|
|
- (await this?.currentStore?.messageList?.find(
|
|
|
- (item: any) => item?.ID === message?.ID
|
|
|
- )) || this.findMessage(message?.ID);
|
|
|
- const cloudCustomData = message?.cloudCustomData
|
|
|
- ? JSONToObject(message?.cloudCustomData)
|
|
|
- : { messageReact: {} };
|
|
|
+ const userID = this.TUICore?.TUIServer?.TUIProfile?.store?.profile?.userID;
|
|
|
+ message = (await this?.currentStore?.messageList?.find((item: any) => item?.ID === message?.ID)) || this.findMessage(message?.ID);
|
|
|
+ const cloudCustomData = message?.cloudCustomData ? JSONToObject(message?.cloudCustomData) : { messageReact: {} };
|
|
|
if (cloudCustomData?.messageReact?.reacts) {
|
|
|
if (cloudCustomData?.messageReact?.reacts[emojiID]) {
|
|
|
- const index =
|
|
|
- cloudCustomData?.messageReact?.reacts[emojiID]?.indexOf(userID);
|
|
|
+ const index = cloudCustomData?.messageReact?.reacts[emojiID]?.indexOf(userID);
|
|
|
if (index === -1) {
|
|
|
cloudCustomData?.messageReact?.reacts[emojiID]?.push(userID);
|
|
|
} else {
|
|
|
- cloudCustomData?.messageReact?.reacts[emojiID]?.splice(
|
|
|
- index,
|
|
|
- 1
|
|
|
- );
|
|
|
- if (
|
|
|
- cloudCustomData?.messageReact?.reacts[emojiID]?.length === 0
|
|
|
- ) {
|
|
|
+ cloudCustomData?.messageReact?.reacts[emojiID]?.splice(index, 1);
|
|
|
+ if (cloudCustomData?.messageReact?.reacts[emojiID]?.length === 0) {
|
|
|
delete cloudCustomData?.messageReact?.reacts[emojiID];
|
|
|
}
|
|
|
}
|
|
@@ -1089,7 +961,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
} else {
|
|
|
cloudCustomData.messageReact = {
|
|
|
reacts: {},
|
|
|
- version: 1
|
|
|
+ version: 1,
|
|
|
};
|
|
|
cloudCustomData.messageReact.reacts[emojiID] = [userID];
|
|
|
}
|
|
@@ -1105,11 +977,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
if (error && error?.code === 2480) return false;
|
|
|
return true;
|
|
|
};
|
|
|
- return this.handlePromiseCallbackRetry(
|
|
|
- emojiReactFunction,
|
|
|
- [500, 1000, 3000],
|
|
|
- retryBreakFunction
|
|
|
- );
|
|
|
+ return this.handlePromiseCallbackRetry(emojiReactFunction, [500, 1000, 3000], retryBreakFunction);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1163,9 +1031,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public getGroupMemberProfile(options: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.getGroupMemberProfile(
|
|
|
- options
|
|
|
- );
|
|
|
+ const imResponse = await this.TUICore.tim.getGroupMemberProfile(options);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -1188,9 +1054,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
public handleGroupApplication(options: any): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.handleGroupApplication(
|
|
|
- options
|
|
|
- );
|
|
|
+ const imResponse = await this.TUICore.tim.handleGroupApplication(options);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -1209,7 +1073,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
const imResponse = await this.TUICore.tim.getUserProfile({
|
|
|
- userIDList
|
|
|
+ userIDList,
|
|
|
});
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
@@ -1248,7 +1112,7 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
try {
|
|
|
const imResponse = await this.TUICore.tim.checkFriend({
|
|
|
userIDList: [userID],
|
|
|
- type
|
|
|
+ type,
|
|
|
});
|
|
|
const isFriendShip = imResponse?.data?.successUserIDList[0]?.relation;
|
|
|
resolve(isFriendShip);
|
|
@@ -1267,21 +1131,15 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
* @param {number} count 分页拉取的个数/The number of page pulls
|
|
|
* @returns {Promise}
|
|
|
*/
|
|
|
- public async getGroupReadMemberList(
|
|
|
- message: any,
|
|
|
- cursor = '',
|
|
|
- count = 15
|
|
|
- ): Promise<any> {
|
|
|
+ public async getGroupReadMemberList(message: any, cursor = "", count = 15): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList(
|
|
|
- {
|
|
|
- message,
|
|
|
- filter: 0,
|
|
|
- cursor,
|
|
|
- count
|
|
|
- }
|
|
|
- );
|
|
|
+ const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList({
|
|
|
+ message,
|
|
|
+ filter: 0,
|
|
|
+ cursor,
|
|
|
+ count,
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -1298,21 +1156,15 @@ export default class TUIChatServer extends IComponentServer {
|
|
|
* @param {number} count 分页拉取的个数/The number of page pulls
|
|
|
* @returns {Promise}
|
|
|
*/
|
|
|
- public async getGroupUnreadMemberList(
|
|
|
- message: any,
|
|
|
- cursor = '',
|
|
|
- count = 15
|
|
|
- ): Promise<any> {
|
|
|
+ public async getGroupUnreadMemberList(message: any, cursor = "", count = 15): Promise<any> {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList(
|
|
|
- {
|
|
|
- message,
|
|
|
- filter: 1,
|
|
|
- cursor,
|
|
|
- count
|
|
|
- }
|
|
|
- );
|
|
|
+ const imResponse = await this.TUICore.tim.getGroupMessageReadMemberList({
|
|
|
+ message,
|
|
|
+ filter: 1,
|
|
|
+ cursor,
|
|
|
+ count,
|
|
|
+ });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|