聊天:举报接口及测试
This commit is contained in:
@@ -2,7 +2,7 @@ import { CHANNEL_PREFIX, MSG_SOURCE } from './../../../consts/constModules/chatC
|
||||
import {Application, BackendSession} from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { DEFAULT_MSG_PER_PAGE, STATUS } from '../../../consts';
|
||||
import { createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo } from '../../../services/chatService';
|
||||
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo } from '../../../services/chatService';
|
||||
|
||||
|
||||
export default function(app: Application) {
|
||||
@@ -148,4 +148,19 @@ export class ChatHandler {
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 举报玩家的消息
|
||||
* @param {{targetRoleId: string, targetMsgCode: string; reason: number}} msg 被举报玩家的 Id,被举报的消息编号,举报原因
|
||||
* @param {BackendSession} session
|
||||
* @returns
|
||||
* @memberof ChatHandler
|
||||
*/
|
||||
async accuse(msg: {targetRoleId: string, targetMsgCode: string; reason: number}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const { targetRoleId, targetMsgCode, reason } = msg;
|
||||
const accuseRec = await createAccuseData(roleId, targetRoleId, targetMsgCode, reason);
|
||||
if (!accuseRec) return resResult(STATUS.WRONG_PARMS);
|
||||
return resResult(STATUS.SUCCESS, accuseRec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { CHANNEL_PREFIX, MSG_CODE_LEN, MSG_STATUS, ON_PRIVATE_MSG_ROUTE, RECENT_
|
||||
import { getRoleOnlineInfo } from './redisService';
|
||||
import { ChatInfoModel } from '../db/ChatInfo';
|
||||
import { channelServer } from './chatChannelService';
|
||||
import { AccuseRecModel, AccueseParam } from '../db/AccuseRec';
|
||||
|
||||
export * from './chatChannelService';
|
||||
export * from './sysChatService';
|
||||
@@ -295,3 +296,11 @@ export async function pushTeamInviteMsg(roleId: string, roleName: string, server
|
||||
await pushGroupMsgToRoom(msgData);
|
||||
return msgData;
|
||||
}
|
||||
|
||||
export async function createAccuseData(roleId: string, targetRoleId: string, targetMsgCode: string, reason: number) {
|
||||
const data: AccueseParam = {
|
||||
roleId, targetRoleId, targetMsgCode, reason
|
||||
};
|
||||
const result = await AccuseRecModel.createRec(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -368,4 +368,15 @@ describe('聊天测试', function() {
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
it('举报消息', function(done) {
|
||||
pinusClient.request('chat.chatHandler.accuse', {targetRoleId: roleInfoT.roleId, targetMsgCode: 'test', reason: 1}, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data).to.be.an('object');
|
||||
expect(res.data.roleId).to.be.equal(roleInfo.roleId);
|
||||
expect(res.data.targetRoleId).to.be.equal(roleInfoT.roleId);
|
||||
expect(res.data.targetMsgCode).to.be.equal('test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user