|
@@ -1,5 +1,5 @@
|
|
|
import IComponentServer from '../IComponentServer';
|
|
|
-
|
|
|
+import { eventGlobal } from '/src/utils';
|
|
|
/**
|
|
|
* class TUIConversationServer
|
|
|
*
|
|
@@ -14,7 +14,11 @@ 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)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -53,7 +57,7 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
TUIName: 'TUIConversation',
|
|
|
callback: () => {
|
|
|
callback && callback(resolve, reject);
|
|
|
- },
|
|
|
+ }
|
|
|
};
|
|
|
this.TUICore.setAwaitFunc(config.TUIName, config.callback);
|
|
|
});
|
|
@@ -68,16 +72,38 @@ 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);
|
|
|
}
|
|
|
|
|
@@ -94,13 +120,65 @@ 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);
|
|
|
+ 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
|
|
|
+ );
|
|
|
this.store.allConversationList = options.allConversationList;
|
|
|
this.store.conversationList = options.conversationList;
|
|
|
return options;
|
|
@@ -124,7 +202,9 @@ 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);
|
|
@@ -141,7 +221,9 @@ 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);
|
|
@@ -175,7 +257,9 @@ 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);
|
|
@@ -191,7 +275,9 @@ 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);
|
|
@@ -208,6 +294,7 @@ 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) {
|
|
@@ -216,6 +303,24 @@ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取其他用户资料
|
|
|
*
|
|
@@ -225,7 +330,9 @@ 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);
|
|
@@ -247,9 +354,10 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
* @param {Object} params 使用的数据
|
|
|
* @returns {Object} 数据
|
|
|
*/
|
|
|
- public async bind(params: any) {
|
|
|
+ public async bind(params: any, callBack?: any) {
|
|
|
this.currentStore = params;
|
|
|
await this.getConversationList();
|
|
|
+ callBack && callBack();
|
|
|
return this.currentStore;
|
|
|
}
|
|
|
|
|
@@ -257,7 +365,6 @@ export default class TUIConversationServer extends IComponentServer {
|
|
|
public handleCurrentConversation(value: any) {
|
|
|
// 通知 TUIChat 切换会话或关闭会话
|
|
|
this.TUICore.getStore().TUIChat.conversation = value || {};
|
|
|
-
|
|
|
if (!value?.conversationID) {
|
|
|
this.currentStore.currentConversationID = '';
|
|
|
return;
|