|
@@ -35,56 +35,51 @@ export class MessageService {
|
|
|
messageMapList: any = {
|
|
|
global_room: [
|
|
|
// 世界频道消息列表
|
|
|
- {
|
|
|
- is_self: true,
|
|
|
- avatar:
|
|
|
- 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
- msg_type: 1,
|
|
|
- content: 'nihao',
|
|
|
- create_time: new Date(),
|
|
|
- istoday: true,
|
|
|
- timeStamp: new Date(),
|
|
|
- },
|
|
|
- {
|
|
|
- is_self: true,
|
|
|
- avatar:
|
|
|
- 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
- msg_type: 1,
|
|
|
- content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
- create_time: new Date(),
|
|
|
- istoday: true,
|
|
|
- timeStamp: new Date(),
|
|
|
- },
|
|
|
- {
|
|
|
- is_self: true,
|
|
|
- avatar:
|
|
|
- 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
- msg_type: 1,
|
|
|
- content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
- create_time: new Date(),
|
|
|
- istoday: true,
|
|
|
- timeStamp: new Date(),
|
|
|
- },
|
|
|
- {
|
|
|
- is_self: true,
|
|
|
- avatar:
|
|
|
- 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
- msg_type: 1,
|
|
|
- content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
- create_time: new Date(),
|
|
|
- istoday: true,
|
|
|
- timeStamp: new Date(),
|
|
|
- },
|
|
|
- {
|
|
|
- is_self: false,
|
|
|
- avatar:
|
|
|
- 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
- msg_type: 1,
|
|
|
- content: 'nihao',
|
|
|
- create_time: new Date(),
|
|
|
- istoday: true,
|
|
|
- timeStamp: new Date(),
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // is_self: true,
|
|
|
+ // avatar:
|
|
|
+ // 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ // msg_type: 1,
|
|
|
+ // content: 'nihao',
|
|
|
+ // istoday: true,
|
|
|
+ // timestamp: new Date(),
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // is_self: true,
|
|
|
+ // avatar:
|
|
|
+ // 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ // msg_type: 1,
|
|
|
+ // content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
+ // istoday: true,
|
|
|
+ // timestamp: new Date(),
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // is_self: true,
|
|
|
+ // avatar:
|
|
|
+ // 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ // msg_type: 1,
|
|
|
+ // content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
+ // istoday: true,
|
|
|
+ // timestamp: new Date(),
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // is_self: true,
|
|
|
+ // avatar:
|
|
|
+ // 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ // msg_type: 1,
|
|
|
+ // content: `Use the pipe name to trace where the pipe is declared and used. To resolve this error: If the pipe is local to the NgModule, give it a unique name in the pipe's decorator and declared it in the NgModule. If the pipe is standalone or is declared in another NgModule, add it to the imports field of the standalone component or the current NgModule.`,
|
|
|
+ // istoday: true,
|
|
|
+ // timestamp: new Date(),
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // is_self: false,
|
|
|
+ // avatar:
|
|
|
+ // 'https://file-cloud.fmode.cn/Qje9D4bqol/20241109/2t1lp0032258601.png',
|
|
|
+ // msg_type: 1,
|
|
|
+ // content: 'nihao',
|
|
|
+ // istoday: true,
|
|
|
+ // timestamp: new Date(),
|
|
|
+ // },
|
|
|
],
|
|
|
};
|
|
|
|
|
@@ -329,6 +324,10 @@ export class MessageService {
|
|
|
console.log('subscribeMessage', res);
|
|
|
//订阅成功
|
|
|
this.channelNameList[channelName] = true;
|
|
|
+ if (this.messageMapList[channelName]?.length === 0) {
|
|
|
+ this.messageMapList[channelName] = [];
|
|
|
+ this.getHistoryMessage(channelName)
|
|
|
+ }
|
|
|
this.pageFun?.();
|
|
|
resolve(true);
|
|
|
})
|
|
@@ -338,6 +337,25 @@ export class MessageService {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ async getHistoryMessage(channelName: string) {
|
|
|
+ let query = new Parse.Query('MessageLog');
|
|
|
+ query.equalTo('channel', channelName);
|
|
|
+ query.descending('createdAt');
|
|
|
+ query.skip(this.messageMapList[channelName].length);
|
|
|
+ query.limit(50);
|
|
|
+ query.select('content','from_id');
|
|
|
+ let msgList = await query.find();
|
|
|
+ msgList.forEach((item: any) => {
|
|
|
+ let is_self = item?.get('from_id') == this.userId;
|
|
|
+ let data: any = item?.get('content');
|
|
|
+ data['is_self'] = is_self;
|
|
|
+ data['istoday'] = true;
|
|
|
+ data['timestamp'] = new Date(data.timestamp)
|
|
|
+ this.messageMapList[channelName].push(data)
|
|
|
+ });
|
|
|
+ // this.messageMapList[channelName].unshift(...msgList);
|
|
|
+ }
|
|
|
/* 取消订阅 */
|
|
|
unsubscribeMessage(channelName: string) {
|
|
|
this.rtmClient
|
|
@@ -355,11 +373,30 @@ export class MessageService {
|
|
|
async showMessage(param: any) {
|
|
|
let userData = await this.getUserMetadata(param.publisher);
|
|
|
let is_self = param.publisher == this.userId;
|
|
|
- console.log(userData);
|
|
|
+ // console.log(userData);
|
|
|
let message = JSON.parse(param.message);
|
|
|
if (!this.messageMapList[param.channelName])
|
|
|
this.messageMapList[param.channelName] = [];
|
|
|
- this.messageMapList[param.channelName].push({
|
|
|
+ if (is_self) {
|
|
|
+ this.saveMeesage({
|
|
|
+ from_id: this.userId,
|
|
|
+ from_username: Parse.User.current()?.get('nickname') ?? '未知用户',
|
|
|
+ target_id: param.channelName,
|
|
|
+ // target_name: userData.nickname.value ?? '未知用户',
|
|
|
+ channel: param.channelName,
|
|
|
+ content: {
|
|
|
+ avatar:
|
|
|
+ userData.avatar.value ??
|
|
|
+ 'https://file-cloud.fmode.cn/DXNgcD6zo6/20221202/j6p8kb034039.png',
|
|
|
+ msg_type: 1,
|
|
|
+ name: userData.nickname.value ?? '未知用户',
|
|
|
+ content: message?.text ?? '',
|
|
|
+ publisher: param.publisher,
|
|
|
+ timestamp: param.timestamp,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ let data: any = {
|
|
|
is_self: is_self,
|
|
|
avatar:
|
|
|
userData.avatar.value ??
|
|
@@ -367,12 +404,39 @@ export class MessageService {
|
|
|
msg_type: 1,
|
|
|
name: userData.nickname.value ?? '未知用户',
|
|
|
content: message?.text ?? '',
|
|
|
- create_time: new Date(param.timeStamp),
|
|
|
+ publisher: param.publisher,
|
|
|
+ timestamp: new Date(param.timestamp),
|
|
|
istoday: true,
|
|
|
- timeStamp: new Date(param.timeStamp),
|
|
|
- });
|
|
|
+ };
|
|
|
+ this.messageMapList[param.channelName].push(data);
|
|
|
this.pageFun?.();
|
|
|
}
|
|
|
+
|
|
|
+ async saveMeesage(parse: {
|
|
|
+ from_id: string;
|
|
|
+ from_username: string;
|
|
|
+ target_id: string;
|
|
|
+ // target_name: string;
|
|
|
+ channel: string;
|
|
|
+ content: Object;
|
|
|
+ }) {
|
|
|
+ console.log(parse);
|
|
|
+ let obj = Parse.Object.extend('MessageLog');
|
|
|
+ let message = new obj();
|
|
|
+ message.set('from_id', parse.from_id);
|
|
|
+ message.set('from_username', parse.from_username);
|
|
|
+ message.set('target_id', parse.target_id);
|
|
|
+ // message.set('target_name', parse.target_name);
|
|
|
+ message.set('channel', parse.channel);
|
|
|
+ message.set('content', parse.content);
|
|
|
+ message.set('company', {
|
|
|
+ __type: 'Pointer',
|
|
|
+ className: 'Company',
|
|
|
+ objectId: this.company,
|
|
|
+ });
|
|
|
+ await message.save();
|
|
|
+ }
|
|
|
+
|
|
|
async getUserMetadata(uid: string) {
|
|
|
try {
|
|
|
const result = await this.rtmClient?.storage.getUserMetadata({
|