好友:拉黑对方聊天也屏蔽
This commit is contained in:
@@ -8,7 +8,7 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||
import { genCode, resResult } from '../pubUtils/util';
|
||||
import { pinus } from 'pinus';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, MSG_TYPE, MSG_SOURCE, PUSH_ROUTE } from '../consts';
|
||||
import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, MSG_TYPE, MSG_SOURCE, PUSH_ROUTE, FRIEND_RELATION_TYPE } from '../consts';
|
||||
import { getRoleOnlineInfo } from './redisService';
|
||||
import { ChatInfoModel } from '../db/ChatInfo';
|
||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||
@@ -49,7 +49,7 @@ function msgCounterName(roomId: string) {
|
||||
*/
|
||||
async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
||||
msg.msgCode = genCode(MSG_CODE_LEN);
|
||||
msg.status = MSG_STATUS.NORMAL;
|
||||
if(!msg.status) msg.status = MSG_STATUS.NORMAL;
|
||||
if (!msg.roomId) {
|
||||
console.error('roomId needed while setup msg parameter');
|
||||
return;
|
||||
@@ -60,9 +60,10 @@ async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
||||
/**
|
||||
* @description 生成私聊消息数据
|
||||
*/
|
||||
async function createPrivateMsgData(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
||||
async function createPrivateMsgData(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string, relation: number) {
|
||||
const result: PrivateMessageParam = {roleId, roleName, type, source, content, targetRoleId, targetMsgCode};
|
||||
result.roomId = privateRoomId(roleId, targetRoleId);
|
||||
result.status = relation == FRIEND_RELATION_TYPE.HAS_BLOCKED? MSG_STATUS.BLOCKED: MSG_STATUS.NORMAL;
|
||||
await setupBaseMsgParm(result);
|
||||
return result;
|
||||
}
|
||||
@@ -89,13 +90,15 @@ async function createGroupMsgData(roleId: string, roleName: string, channel: str
|
||||
* @param {string} targetMsgCode 回复某条消息的唯一标识
|
||||
* @returns
|
||||
*/
|
||||
export async function createPrivateMsg(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
||||
const msgData: PrivateMessageParam = await createPrivateMsgData(roleId, roleName, type, source, content, targetRoleId, targetMsgCode);
|
||||
export async function createPrivateMsg(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string, relation: number) {
|
||||
const msgData: PrivateMessageParam = await createPrivateMsgData(roleId, roleName, type, source, content, targetRoleId, targetMsgCode, relation);
|
||||
const result: PrivateMessageType = await PrivateMessageModel.createMsg(msgData);
|
||||
|
||||
const curTime = new Date();
|
||||
await updateRecentChats(true, roleId, targetRoleId, curTime);
|
||||
await updateRecentChats(false, targetRoleId, roleId, curTime);
|
||||
if(result.status == MSG_STATUS.NORMAL) {
|
||||
await updateRecentChats(false, targetRoleId, roleId, curTime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -127,6 +130,8 @@ export async function createGroupMsg(roleId: string, roleName: string, channel:
|
||||
*/
|
||||
export async function pushMsgToRole(msg: PrivateMessageType | GroupMessageType) {
|
||||
const targetRoleId = msg.targetRoleId!;
|
||||
if(msg.status == MSG_STATUS.BLOCKED) return;
|
||||
|
||||
const { sid } = await getRoleOnlineInfo(targetRoleId);
|
||||
if (sid) {
|
||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||
@@ -380,8 +385,8 @@ export async function pushTeamInviteMsg(roleId: string, roleName: string, server
|
||||
* @description 发送组队私人邀请消息
|
||||
* @param {string} teamCode 队伍唯一标识
|
||||
*/
|
||||
export async function pushFriendTeamInviteMsg(roleId: string, roleName: string, teamCode: string, blueprtId: number, targetRoleId) {
|
||||
const msgData = await createPrivateMsg(roleId, roleName, MSG_TYPE.RICH_TEXT, MSG_SOURCE.TEAM_INVITE, JSON.stringify({ roleName, teamCode, blueprtId}), targetRoleId, null);
|
||||
export async function pushFriendTeamInviteMsg(roleId: string, roleName: string, teamCode: string, blueprtId: number, targetRoleId: string, relation: number) {
|
||||
const msgData = await createPrivateMsg(roleId, roleName, MSG_TYPE.RICH_TEXT, MSG_SOURCE.TEAM_INVITE, JSON.stringify({ roleName, teamCode, blueprtId}), targetRoleId, null, relation);
|
||||
await pushMsgToRole(msgData);
|
||||
return msgData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user