lrf 2 سال پیش
والد
کامیت
e5c85b56bf
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      src/socket/ws.controller.ts

+ 9 - 2
src/socket/ws.controller.ts

@@ -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 });
   }