|
@@ -2,6 +2,7 @@ import { App, Inject, OnWSConnection, OnWSDisConnection, OnWSMessage, WSControll
|
|
|
import { Context } from '@midwayjs/ws';
|
|
|
import * as http from 'http';
|
|
|
import get = require('lodash/get');
|
|
|
+import group = require('lodash/group');
|
|
|
import { Application } from '@midwayjs/ws';
|
|
|
import last = require('lodash/last');
|
|
|
import { Types } from 'mongoose';
|
|
@@ -38,8 +39,14 @@ export class WsSocketController {
|
|
|
async checkNeedSend(client) {
|
|
|
const to = get(client, 'token');
|
|
|
if (!to) return;
|
|
|
- await this.model.find({ to }).lean();
|
|
|
- await this.toSend({ type: 'needCheck' }, to);
|
|
|
+ let list = await this.model.find({ to }).lean();
|
|
|
+ list = list.map(i => ({ ...i, type: get(i, 'msg.type') }));
|
|
|
+ const groups = group(list, 'type');
|
|
|
+ for (const key in groups) {
|
|
|
+ const list = groups[key];
|
|
|
+ const type = get(last(list), 'type');
|
|
|
+ await this.toSend({ type }, to);
|
|
|
+ }
|
|
|
await this.model.deleteMany({ to });
|
|
|
}
|
|
|
|