|
@@ -1,5 +1,5 @@
|
|
|
import IComponentServer from '../IComponentServer';
|
|
|
-import { eventGlobal } from '/src/utils';
|
|
|
+
|
|
|
/**
|
|
|
* class TUIConversationServer
|
|
|
*
|
|
@@ -14,11 +14,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
super();
|
|
|
this.TUICore = TUICore;
|
|
|
this.bindTIMEvent();
|
|
|
- this.store = TUICore.setComponentStore(
|
|
|
- 'TUIConversation',
|
|
|
- {},
|
|
|
- this.updateStore.bind(this)
|
|
|
- );
|
|
|
+ this.store = TUICore.setComponentStore('TUIConversation', {}, this.updateStore.bind(this));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -57,7 +53,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
TUIName: 'TUIConversation',
|
|
|
callback: () => {
|
|
|
callback && callback(resolve, reject);
|
|
|
- }
|
|
|
+ },
|
|
|
};
|
|
|
this.TUICore.setAwaitFunc(config.TUIName, config.callback);
|
|
|
});
|
|
@@ -72,38 +68,16 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
*/
|
|
|
|
|
|
private bindTIMEvent() {
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.CONVERSATION_LIST_UPDATED,
|
|
|
- this.handleConversationListUpdate,
|
|
|
- this
|
|
|
- );
|
|
|
- this.TUICore.tim.on(
|
|
|
- this.TUICore.TIM.EVENT.NET_STATE_CHANGE,
|
|
|
- this.handleNetStateChange,
|
|
|
- this
|
|
|
- );
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.CONVERSATION_LIST_UPDATED, this.handleConversationListUpdate, this);
|
|
|
+ this.TUICore.tim.on(this.TUICore.TIM.EVENT.NET_STATE_CHANGE, this.handleNetStateChange, this);
|
|
|
}
|
|
|
|
|
|
private unbindTIMEvent() {
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.CONVERSATION_LIST_UPDATED,
|
|
|
- this.handleConversationListUpdate
|
|
|
- );
|
|
|
- this.TUICore.tim.off(
|
|
|
- this.TUICore.TIM.EVENT.NET_STATE_CHANGE,
|
|
|
- this.handleNetStateChange
|
|
|
- );
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.CONVERSATION_LIST_UPDATED, this.handleConversationListUpdate);
|
|
|
+ this.TUICore.tim.off(this.TUICore.TIM.EVENT.NET_STATE_CHANGE, this.handleNetStateChange);
|
|
|
}
|
|
|
|
|
|
private handleConversationListUpdate(res: any) {
|
|
|
- // 判断SDK是否初始化
|
|
|
- if (this.TUICore.tim.isReady()) {
|
|
|
- eventGlobal.emit(
|
|
|
- 'onNoReadMessageCount',
|
|
|
- this.TUICore.tim.getTotalUnreadMessageCount()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
this.handleFilterSystem(res.data);
|
|
|
}
|
|
|
|
|
@@ -120,65 +94,13 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
private handleFilterSystem(list: any) {
|
|
|
const options = {
|
|
|
allConversationList: list,
|
|
|
- conversationList: []
|
|
|
+ conversationList: [],
|
|
|
};
|
|
|
- const currentList = list.filter(
|
|
|
- (item: any) =>
|
|
|
- item?.conversationID === this?.currentStore?.currentConversationID
|
|
|
- );
|
|
|
+ const currentList = list.filter((item: any) => item?.conversationID === this?.currentStore?.currentConversationID);
|
|
|
if (currentList.length === 0) {
|
|
|
this.handleCurrentConversation({});
|
|
|
}
|
|
|
- options.conversationList = list.filter(
|
|
|
- (item: any) => item.type !== this.TUICore.TIM.TYPES.CONV_SYSTEM
|
|
|
- );
|
|
|
- this.store.allConversationList = options.allConversationList;
|
|
|
- this.store.conversationList = options.conversationList;
|
|
|
- return options;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理conversationList
|
|
|
- *
|
|
|
- * @param {Array} list conversationList
|
|
|
- * @returns {Object}
|
|
|
- */
|
|
|
- private handleFilterName(list: any, keyword: string) {
|
|
|
- const options = {
|
|
|
- allConversationList: list,
|
|
|
- conversationList: []
|
|
|
- };
|
|
|
- console.log(list, 'list');
|
|
|
- const currentList: any = [];
|
|
|
- list.forEach((item: any) => {
|
|
|
- console.log(item, 'item', keyword);
|
|
|
- if (item.type === 'GROUP') {
|
|
|
- console.log(
|
|
|
- item.type,
|
|
|
- item.groupProfile?.name,
|
|
|
- item.groupProfile?.name.indexOf(keyword)
|
|
|
- );
|
|
|
- if (item.groupProfile?.name.indexOf(keyword) >= 0) {
|
|
|
- currentList.push(item);
|
|
|
- }
|
|
|
- }
|
|
|
- if (item.type === 'C2C') {
|
|
|
- console.log(
|
|
|
- item.type,
|
|
|
- item.userProfile?.nick,
|
|
|
- item.userProfile?.nick.indexOf(keyword)
|
|
|
- );
|
|
|
- if (item.userProfile?.nick.indexOf(keyword) >= 0) {
|
|
|
- currentList.push(item);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- // if (currentList.length === 0) {
|
|
|
- // this.handleCurrentConversation({});
|
|
|
- // }
|
|
|
- options.conversationList = currentList.filter(
|
|
|
- (item: any) => item.type !== this.TUICore.TIM.TYPES.CONV_SYSTEM
|
|
|
- );
|
|
|
+ options.conversationList = list.filter((item: any) => item.type !== this.TUICore.TIM.TYPES.CONV_SYSTEM);
|
|
|
this.store.allConversationList = options.allConversationList;
|
|
|
this.store.conversationList = options.conversationList;
|
|
|
return options;
|
|
@@ -202,9 +124,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public async setMessageRead(conversationID: string) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse: any = await this.TUICore.tim.setMessageRead({
|
|
|
- conversationID
|
|
|
- });
|
|
|
+ const imResponse: any = await this.TUICore.tim.setMessageRead({ conversationID });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -221,9 +141,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public async deleteConversation(conversationID: string) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse: any = await this.TUICore.tim.deleteConversation(
|
|
|
- conversationID
|
|
|
- );
|
|
|
+ const imResponse: any = await this.TUICore.tim.deleteConversation(conversationID);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -257,9 +175,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public async muteConversation(options: any) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse: any = await this.TUICore.tim.setMessageRemindType(
|
|
|
- options
|
|
|
- );
|
|
|
+ const imResponse: any = await this.TUICore.tim.setMessageRemindType(options);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -275,9 +191,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public async getConversationProfile(conversationID: string) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.getConversationProfile(
|
|
|
- conversationID
|
|
|
- );
|
|
|
+ const imResponse = await this.TUICore.tim.getConversationProfile(conversationID);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -294,7 +208,6 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
const imResponse = await this.TUICore.tim.getConversationList();
|
|
|
- console.log(imResponse, 'getConversationList');
|
|
|
this.handleFilterSystem(imResponse.data.conversationList);
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
@@ -303,24 +216,6 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * 获取 conversationList
|
|
|
- *
|
|
|
- * @returns {Promise}
|
|
|
- */
|
|
|
- public async getConversationListForName(keyword: string) {
|
|
|
- return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
- try {
|
|
|
- const imResponse = await this.TUICore.tim.getConversationList();
|
|
|
- console.log(imResponse, 'getConversationListForName');
|
|
|
- this.handleFilterName(imResponse.data.conversationList, keyword);
|
|
|
- resolve(imResponse);
|
|
|
- } catch (error) {
|
|
|
- reject(error);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取其他用户资料
|
|
|
*
|
|
@@ -330,9 +225,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public async getUserProfile(userIDList: Array<string>) {
|
|
|
return this.handlePromiseCallback(async (resolve: any, reject: any) => {
|
|
|
try {
|
|
|
- const imResponse = await this.TUICore.tim.getUserProfile({
|
|
|
- userIDList
|
|
|
- });
|
|
|
+ const imResponse = await this.TUICore.tim.getUserProfile({ userIDList });
|
|
|
resolve(imResponse);
|
|
|
} catch (error) {
|
|
|
reject(error);
|
|
@@ -354,10 +247,9 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
* @param {Object} params 使用的数据
|
|
|
* @returns {Object} 数据
|
|
|
*/
|
|
|
- public async bind(params: any, callBack?: any) {
|
|
|
+ public async bind(params: any) {
|
|
|
this.currentStore = params;
|
|
|
await this.getConversationList();
|
|
|
- callBack && callBack();
|
|
|
return this.currentStore;
|
|
|
}
|
|
|
|
|
@@ -365,6 +257,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public handleCurrentConversation(value: any) {
|
|
|
// 通知 TUIChat 切换会话或关闭会话
|
|
|
this.TUICore.getStore().TUIChat.conversation = value || {};
|
|
|
+
|
|
|
if (!value?.conversationID) {
|
|
|
this.currentStore.currentConversationID = '';
|
|
|
return;
|