聊天分组bug
This commit is contained in:
parent
6eb61ece9c
commit
7d85f554f4
@ -4,6 +4,7 @@ import { MsgChat } from '../shared/protocols/msg_s2c/MsgChat';
|
|||||||
import { player } from '../shared/protocols/user/type';
|
import { player } from '../shared/protocols/user/type';
|
||||||
import { chatLog, chatMsgLog } from '../shared/protocols/type'
|
import { chatLog, chatMsgLog } from '../shared/protocols/type'
|
||||||
import { PublicShared } from '../shared/public/public';
|
import { PublicShared } from '../shared/public/public';
|
||||||
|
import { clusterRunOnce } from '../clusterUtils';
|
||||||
|
|
||||||
const msgListLen = {
|
const msgListLen = {
|
||||||
'cross': 30,
|
'cross': 30,
|
||||||
@ -28,13 +29,9 @@ export function getCrossChatGroupByOpenDay(){
|
|||||||
export class ChatFun {
|
export class ChatFun {
|
||||||
/**新增消息 */
|
/**新增消息 */
|
||||||
static async newMsg(sendData: MsgChat) {
|
static async newMsg(sendData: MsgChat) {
|
||||||
G.mongodb.collection('chat').updateOne(
|
let addToDB = 0;
|
||||||
{ type: `${sendData.type}${sendData.type == 'guild' ? (sendData.sender as player)?.ghId : ''}` },
|
|
||||||
{ $push: { list: { $each: [sendData], $slice: -msgListLen[sendData.type] } } },
|
|
||||||
{ upsert: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sendData.type == 'guild') {
|
if (sendData.type == 'guild') {
|
||||||
|
addToDB = 1;
|
||||||
G.server.broadcastClusterMsg('msg_s2c/Chat', sendData,{ghId:(sendData.sender as player)?.ghId});
|
G.server.broadcastClusterMsg('msg_s2c/Chat', sendData,{ghId:(sendData.sender as player)?.ghId});
|
||||||
}else if(sendData.type == 'cross'){
|
}else if(sendData.type == 'cross'){
|
||||||
//所有的子进程都会收到,不需要集群内分别广播
|
//所有的子进程都会收到,不需要集群内分别广播
|
||||||
@ -42,9 +39,27 @@ export class ChatFun {
|
|||||||
//如果时候同一个分组的
|
//如果时候同一个分组的
|
||||||
delete sendData?.otherData?.group;
|
delete sendData?.otherData?.group;
|
||||||
G.server.broadcastMsg('msg_s2c/Chat', sendData);
|
G.server.broadcastMsg('msg_s2c/Chat', sendData);
|
||||||
|
addToDB = 2;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
G.server.broadcastClusterMsg('msg_s2c/Chat', sendData);
|
G.server.broadcastClusterMsg('msg_s2c/Chat', sendData);
|
||||||
|
addToDB = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(addToDB == 1){
|
||||||
|
G.mongodb.collection('chat').updateOne(
|
||||||
|
{ type: `${sendData.type}${sendData.type == 'guild' ? (sendData.sender as player)?.ghId : ''}` },
|
||||||
|
{ $push: { list: { $each: [sendData], $slice: -msgListLen[sendData.type] } } },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
}else if(addToDB == 2){
|
||||||
|
clusterRunOnce(()=>{
|
||||||
|
G.mongodb.collection('chat').updateOne(
|
||||||
|
{ type: `${sendData.type}${sendData.type == 'guild' ? (sendData.sender as player)?.ghId : ''}` },
|
||||||
|
{ $push: { list: { $each: [sendData], $slice: -msgListLen[sendData.type] } } },
|
||||||
|
{ upsert: true }
|
||||||
|
);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user