好友:拉黑对方聊天也屏蔽
This commit is contained in:
@@ -27,6 +27,7 @@ import { checkTask, checkTaskInComBattleStart } from '../../../services/task/tas
|
|||||||
import { gameData, getWarByBlueprtId } from '../../../pubUtils/data';
|
import { gameData, getWarByBlueprtId } from '../../../pubUtils/data';
|
||||||
import { HeroModel } from '../../../db/Hero';
|
import { HeroModel } from '../../../db/Hero';
|
||||||
import { addUserToTeamChannel, delTeamChannel, removeFromTeamChannel, sendMessageToTeam, sendMessageToUsersWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
|
import { addUserToTeamChannel, delTeamChannel, removeFromTeamChannel, sendMessageToTeam, sendMessageToUsersWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
|
||||||
|
import { getFriendRelationType } from '../../../services/friendService';
|
||||||
|
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new ComBattleHandler(app);
|
return new ComBattleHandler(app);
|
||||||
@@ -706,7 +707,8 @@ export class ComBattleHandler {
|
|||||||
let teamStatus = this.teamMap.get(teamCode);
|
let teamStatus = this.teamMap.get(teamCode);
|
||||||
if(!teamStatus) return resResult(STATUS.WRONG_PARMS);
|
if(!teamStatus) return resResult(STATUS.WRONG_PARMS);
|
||||||
|
|
||||||
const msgData = await pushFriendTeamInviteMsg(roleId, roleName, teamCode, teamStatus.blueprtId, targetRoleId);
|
let relation = await getFriendRelationType(roleId, targetRoleId);
|
||||||
|
const msgData = await pushFriendTeamInviteMsg(roleId, roleName, teamCode, teamStatus.blueprtId, targetRoleId, relation);
|
||||||
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
||||||
const roleInfo = await getSimpleRoleInfo(targetRoleId);
|
const roleInfo = await getSimpleRoleInfo(targetRoleId);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages,
|
|||||||
import { getSimpleRoleInfo } from '../../../services/roleService';
|
import { getSimpleRoleInfo } from '../../../services/roleService';
|
||||||
import { checkTask } from '../../../services/task/taskService';
|
import { checkTask } from '../../../services/task/taskService';
|
||||||
import { RoleModel } from '../../../db/Role';
|
import { RoleModel } from '../../../db/Role';
|
||||||
|
import { getFriendRelationType } from '../../../services/friendService';
|
||||||
|
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
@@ -58,7 +59,8 @@ export class ChatHandler {
|
|||||||
const roleName = session.get('roleName');
|
const roleName = session.get('roleName');
|
||||||
|
|
||||||
const sid = session.get('sid');
|
const sid = session.get('sid');
|
||||||
const msgData = await createPrivateMsg(roleId, roleName, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode);
|
let relation = await getFriendRelationType(roleId, targetRoleId);
|
||||||
|
const msgData = await createPrivateMsg(roleId, roleName, type, MSG_SOURCE.ROLE_SEND_TEXT, content, targetRoleId, targetMsgCode, relation);
|
||||||
await pushMsgToRole(msgData);
|
await pushMsgToRole(msgData);
|
||||||
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
if (!msgData) return resResult(STATUS.WRONG_PARMS);
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ import { FriendPresentLogModel } from '../../../db/FriendPresentLog';
|
|||||||
import { HeroModel, EPlace } from "../../../db/Hero";
|
import { HeroModel, EPlace } from "../../../db/Hero";
|
||||||
import { FRIEND } from "../../../pubUtils/dicParam";
|
import { FRIEND } from "../../../pubUtils/dicParam";
|
||||||
import { PlayerDetail, PlayerDetailHero } from "../../../domain/battleField/guild";
|
import { PlayerDetail, PlayerDetailHero } from "../../../domain/battleField/guild";
|
||||||
import { createPrivateMsg, pushMsgToRole, pushPresent } from "../../../services/chatService";
|
import { createPrivateMsg, delPrivateMsg, privateRoomId, pushMsgToRole, pushPresent } from "../../../services/chatService";
|
||||||
import { Rank } from "../../../services/rankService";
|
import { Rank } from "../../../services/rankService";
|
||||||
import { checkTaskWithRoles, checkTask } from "../../../services/task/taskService";
|
import { checkTaskWithRoles, checkTask } from "../../../services/task/taskService";
|
||||||
import { ComBattleTeamModel } from "../../../db/ComBattleTeam";
|
import { ComBattleTeamModel } from "../../../db/ComBattleTeam";
|
||||||
import { JewelModel } from "../../../db/Jewel";
|
import { JewelModel } from "../../../db/Jewel";
|
||||||
import { getHeroesAttributes } from "../../../services/playerCeService";
|
import { getHeroesAttributes } from "../../../services/playerCeService";
|
||||||
import { sendMessageToUsersWithSuc, sendMessageToUserWithSuc } from "../../../services/pushService";
|
import { sendMessageToUsersWithSuc, sendMessageToUserWithSuc } from "../../../services/pushService";
|
||||||
|
import { PrivateMessageModel } from "../../../db/PrivateMessage";
|
||||||
|
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
@@ -346,6 +347,9 @@ export class FriendHandler {
|
|||||||
|
|
||||||
await FriendRelationModel.moveFromFriend(hisRoleId, role, friendShip, false, !!curFriend); //从对方好友删除
|
await FriendRelationModel.moveFromFriend(hisRoleId, role, friendShip, false, !!curFriend); //从对方好友删除
|
||||||
await FriendRelationModel.moveFromFriend(roleId, friend, friendShip, true, !!curFriend); // 删除好友关系并拉黑
|
await FriendRelationModel.moveFromFriend(roleId, friend, friendShip, true, !!curFriend); // 删除好友关系并拉黑
|
||||||
|
await PrivateMessageModel.blockMsg(privateRoomId(roleId, hisRoleId)); // 屏蔽掉双方对话
|
||||||
|
await delPrivateMsg(roleId, hisRoleId);
|
||||||
|
|
||||||
let { myRecApplyCount, hisRecApplyCount } = await FriendApplyModel.deleteApplyByRoles(roleId, hisRoleId); // 删除双方的申请
|
let { myRecApplyCount, hisRecApplyCount } = await FriendApplyModel.deleteApplyByRoles(roleId, hisRoleId); // 删除双方的申请
|
||||||
if(myRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * myRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
if(myRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * myRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||||
if(hisRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * hisRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
if(hisRecApplyCount > 0) await RoleModel.increaseFriendApplyCnt(roleId, -1 * hisRecApplyCount, FRIEND.FRIEND_MANAGE_APPLICATION);
|
||||||
@@ -601,10 +605,10 @@ export class FriendHandler {
|
|||||||
let result = await FriendShipModel.addFriendValue(roleId, hisRoleId, friendValueInc);
|
let result = await FriendShipModel.addFriendValue(roleId, hisRoleId, friendValueInc);
|
||||||
if (!result) return resResult(STATUS.FRIEND_NOT_FOUND);
|
if (!result) return resResult(STATUS.FRIEND_NOT_FOUND);
|
||||||
|
|
||||||
// TODO 日志可以转到log服
|
|
||||||
await FriendPresentLogModel.createRecord(roleId, hisRoleId, items);
|
await FriendPresentLogModel.createRecord(roleId, hisRoleId, items);
|
||||||
for (let { id, count } of items) {
|
for (let { id, count } of items) {
|
||||||
const msgData = await createPrivateMsg(roleId, roleName, MSG_TYPE.RICH_TEXT, MSG_SOURCE.PRIVATE_SEND_GIFT, JSON.stringify({ id, count }), hisRoleId, null);
|
let relation = getRecommendType(myRelation, roleId, hisRoleId);
|
||||||
|
const msgData = await createPrivateMsg(roleId, roleName, MSG_TYPE.RICH_TEXT, MSG_SOURCE.PRIVATE_SEND_GIFT, JSON.stringify({ id, count }), hisRoleId, null, relation);
|
||||||
await pushMsgToRole(msgData);
|
await pushMsgToRole(msgData);
|
||||||
let hisRole = <RoleType>curFriend.role;
|
let hisRole = <RoleType>curFriend.role;
|
||||||
await pushPresent(roleId, roleName, serverId, hisRole.roleName, id);
|
await pushPresent(roleId, roleName, serverId, hisRole.roleName, id);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { PrivateMessageModel, PrivateMessageParam, PrivateMessageType } from './
|
|||||||
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
import { GroupMessageParam, GroupMessageType } from '../db/GroupMessage';
|
||||||
import { genCode, resResult } from '../pubUtils/util';
|
import { genCode, resResult } from '../pubUtils/util';
|
||||||
import { pinus } from 'pinus';
|
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 { getRoleOnlineInfo } from './redisService';
|
||||||
import { ChatInfoModel } from '../db/ChatInfo';
|
import { ChatInfoModel } from '../db/ChatInfo';
|
||||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||||
@@ -49,7 +49,7 @@ function msgCounterName(roomId: string) {
|
|||||||
*/
|
*/
|
||||||
async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
||||||
msg.msgCode = genCode(MSG_CODE_LEN);
|
msg.msgCode = genCode(MSG_CODE_LEN);
|
||||||
msg.status = MSG_STATUS.NORMAL;
|
if(!msg.status) msg.status = MSG_STATUS.NORMAL;
|
||||||
if (!msg.roomId) {
|
if (!msg.roomId) {
|
||||||
console.error('roomId needed while setup msg parameter');
|
console.error('roomId needed while setup msg parameter');
|
||||||
return;
|
return;
|
||||||
@@ -60,9 +60,10 @@ async function setupBaseMsgParm(msg: PrivateMessageParam | GroupMessageParam ) {
|
|||||||
/**
|
/**
|
||||||
* @description 生成私聊消息数据
|
* @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};
|
const result: PrivateMessageParam = {roleId, roleName, type, source, content, targetRoleId, targetMsgCode};
|
||||||
result.roomId = privateRoomId(roleId, targetRoleId);
|
result.roomId = privateRoomId(roleId, targetRoleId);
|
||||||
|
result.status = relation == FRIEND_RELATION_TYPE.HAS_BLOCKED? MSG_STATUS.BLOCKED: MSG_STATUS.NORMAL;
|
||||||
await setupBaseMsgParm(result);
|
await setupBaseMsgParm(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -89,13 +90,15 @@ async function createGroupMsgData(roleId: string, roleName: string, channel: str
|
|||||||
* @param {string} targetMsgCode 回复某条消息的唯一标识
|
* @param {string} targetMsgCode 回复某条消息的唯一标识
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function createPrivateMsg(roleId: string, roleName: string, type: number, source: number, content: string, targetRoleId: string, targetMsgCode: string) {
|
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);
|
const msgData: PrivateMessageParam = await createPrivateMsgData(roleId, roleName, type, source, content, targetRoleId, targetMsgCode, relation);
|
||||||
const result: PrivateMessageType = await PrivateMessageModel.createMsg(msgData);
|
const result: PrivateMessageType = await PrivateMessageModel.createMsg(msgData);
|
||||||
|
|
||||||
const curTime = new Date();
|
const curTime = new Date();
|
||||||
await updateRecentChats(true, roleId, targetRoleId, curTime);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +130,8 @@ export async function createGroupMsg(roleId: string, roleName: string, channel:
|
|||||||
*/
|
*/
|
||||||
export async function pushMsgToRole(msg: PrivateMessageType | GroupMessageType) {
|
export async function pushMsgToRole(msg: PrivateMessageType | GroupMessageType) {
|
||||||
const targetRoleId = msg.targetRoleId!;
|
const targetRoleId = msg.targetRoleId!;
|
||||||
|
if(msg.status == MSG_STATUS.BLOCKED) return;
|
||||||
|
|
||||||
const { sid } = await getRoleOnlineInfo(targetRoleId);
|
const { sid } = await getRoleOnlineInfo(targetRoleId);
|
||||||
if (sid) {
|
if (sid) {
|
||||||
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
const roleInfo = await getSimpleRoleInfo(msg.roleId);
|
||||||
@@ -380,8 +385,8 @@ export async function pushTeamInviteMsg(roleId: string, roleName: string, server
|
|||||||
* @description 发送组队私人邀请消息
|
* @description 发送组队私人邀请消息
|
||||||
* @param {string} teamCode 队伍唯一标识
|
* @param {string} teamCode 队伍唯一标识
|
||||||
*/
|
*/
|
||||||
export async function pushFriendTeamInviteMsg(roleId: string, roleName: string, teamCode: string, blueprtId: number, targetRoleId) {
|
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);
|
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);
|
await pushMsgToRole(msgData);
|
||||||
return msgData;
|
return msgData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,11 @@ export async function increaseFrdCnt(role1: RoleType, role2: RoleType, originalF
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getFriendRelationType(myRoleId: string, roleId: string) {
|
||||||
|
let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||||
|
return getRecommendType(myFriendRelation, roleId, myRoleId);
|
||||||
|
}
|
||||||
|
|
||||||
export function getRecommendType(myFriendRelation: FriendRelationType, myRoleId: string, roleId: string) {
|
export function getRecommendType(myFriendRelation: FriendRelationType, myRoleId: string, roleId: string) {
|
||||||
if(myRoleId == roleId) {
|
if(myRoleId == roleId) {
|
||||||
return FRIEND_RELATION_TYPE.MYSELF;
|
return FRIEND_RELATION_TYPE.MYSELF;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||||
|
import { MSG_STATUS } from '../consts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 私聊信息
|
* 私聊信息
|
||||||
@@ -48,19 +49,23 @@ export default class PrivateMessage extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getMsgs(roomId: string, fromSeqId: number, count: number) {
|
public static async getMsgs(roomId: string, fromSeqId: number, count: number) {
|
||||||
const result = await PrivateMessageModel.find({ roomId, seqId: { $lt: fromSeqId } }).sort({ seqId: -1 }).limit(count).lean();
|
const result = await PrivateMessageModel.find({ roomId, seqId: { $lt: fromSeqId }, status: MSG_STATUS.NORMAL }).sort({ seqId: -1 }).limit(count).lean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getMsgsByTime(roomId: string, time: Date, count: number) {
|
public static async getMsgsByTime(roomId: string, time: Date, count: number) {
|
||||||
const result = await PrivateMessageModel.find({ roomId, createdAt: { $gt: time } }).sort({ seqId: -1 }).limit(count).lean();
|
const result = await PrivateMessageModel.find({ roomId, createdAt: { $gt: time }, status: MSG_STATUS.NORMAL }).sort({ seqId: -1 }).limit(count).lean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getMsgByRooms(roomIds: string[], count: number) {
|
public static async getMsgByRooms(roomIds: string[], count: number) {
|
||||||
const result = await PrivateMessageModel.find({ roomId: { $in: roomIds } }).sort({ seqId: -1 }).limit(count).lean();
|
const result = await PrivateMessageModel.find({ roomId: { $in: roomIds }, status: MSG_STATUS.NORMAL }).sort({ seqId: -1 }).limit(count).lean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async blockMsg(roomId: string) {
|
||||||
|
await PrivateMessageModel.updateMany({ roomId }, { $set: { status: MSG_STATUS.BLOCKED } });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user