diff --git a/game-server/app/servers/role/handler/friendHandler.ts b/game-server/app/servers/role/handler/friendHandler.ts index 682732f7c..e53aae1b3 100644 --- a/game-server/app/servers/role/handler/friendHandler.ts +++ b/game-server/app/servers/role/handler/friendHandler.ts @@ -8,7 +8,7 @@ import { FriendListParam, FriendRecommendParams, BlackListParam, FriendValueList import { FriendShipModel, FriendShipType } from "../../../db/FriendShip"; import { FriendRelationModel, Relation } from "../../../db/FriendRelation"; import { isRoleOnline, getServerName, getRoleOnlineInfo } from "../../../services/redisService"; -import { increaseFrdCnt, getRecommendType, sortByBeSentHeart, getApplyList, getFriendList } from "../../../services/friendService"; +import { increaseFrdCnt, getRecommendType, sortByBeSentHeart, getApplyList, getFriendList, getMyApplyParam, getMyParamAsFriend } from "../../../services/friendService"; import { FriendPointModel } from "../../../db/FriendPoint"; import { gameData, getDicFriendByLv } from "../../../pubUtils/data"; import { addItems, handleCost } from "../../../services/rewardService"; @@ -130,7 +130,6 @@ export class FriendHandler { let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT); let str = '', resultRoleIds = new Array(); - let uids = []; for (let hisRoleId of roleIds) { let type = getRecommendType(myFriendRelation, roleId, hisRoleId); if (type == FRIEND_RELATION_TYPE.HAS_FRIEND) { @@ -146,16 +145,17 @@ export class FriendHandler { str = getResStr(STATUS.FRIEND_HIS_APPLY_MAX); continue; } - await FriendApplyModel.createApply(hisRoleId, role); + let apply = await FriendApplyModel.createApply(hisRoleId, role); resultRoleIds.push(hisRoleId); let hisOnlineInfo = await getRoleOnlineInfo(hisRoleId); + let uids = []; if (hisOnlineInfo.isOnline) { uids.push({ uid: hisRoleId, sid: hisOnlineInfo.sid }); + let myApply = await getMyApplyParam(apply.applyCode, role); + this.channelService.pushMessageByUids('onFriendApply', resResult(STATUS.SUCCESS, { apply: myApply }), uids); } } - this.channelService.pushMessageByUids('onFriendApply', resResult(STATUS.SUCCESS, { roleId }), uids); - return resResult(STATUS.SUCCESS, { isSuccess: str == '', msg: str, @@ -232,7 +232,8 @@ export class FriendHandler { param.setType(FRIEND_RELATION_TYPE.HAS_FRIEND); list.push(param); if (hisOnlineInfo.isOnline) { - this.channelService.pushMessageByUids('onFriendAdd', resResult(STATUS.SUCCESS, { friend: param }), [{ uid: friend.roleId, sid: hisOnlineInfo.sid }]); + let myParam = await getMyParamAsFriend(friendShip, role, friend.roleId); + this.channelService.pushMessageByUids('onFriendAdd', resResult(STATUS.SUCCESS, { friend: myParam }), [{ uid: friend.roleId, sid: hisOnlineInfo.sid }]); } resultApplyCodeList.push(apply.applyCode); diff --git a/game-server/app/services/friendService.ts b/game-server/app/services/friendService.ts index d46316f57..15656b0fe 100644 --- a/game-server/app/services/friendService.ts +++ b/game-server/app/services/friendService.ts @@ -5,7 +5,7 @@ import { getResStr, shouldRefresh } from "../pubUtils/util"; import { STATUS, FRIEND_RELATION_TYPE, POPULATE_TYPE, FRIEND_DROP_TYPE } from "../consts"; import { FriendShipType, FriendShipModel } from "../db/FriendShip"; import { outputCnt } from '../pubUtils/friendUtil'; -import { isRoleOnline, getServerName } from "./redisService"; +import { isRoleOnline, getServerName, getRoleOnlineInfo } from "./redisService"; import { FriendApplyModel } from "../db/FriendApply"; import { FriendApplyParams, FriendListParam } from "../domain/roleField/friend"; import { FriendPointModel } from "../db/FriendPoint"; @@ -94,6 +94,30 @@ export async function getApplyList(roleId: string) { return result; } +export async function getMyApplyParam(applyCode: string, role: RoleType) { + let param = new FriendApplyParams(applyCode, role); + + let { serverId, userInfo: { serverType } } = role; + let serverName = await getServerName(serverType, serverId); + param.setServerName(serverId, serverName); + param.setType(FRIEND_RELATION_TYPE.NORMAL); + return param; +} + + +export async function getMyParamAsFriend(friendShip: FriendShipType, role: RoleType, friendRoleId: string) { + let param = new FriendListParam(role, friendRoleId, friendShip); + let hisOnlineInfo = await getRoleOnlineInfo(role.roleId); + param.setOnline(hisOnlineInfo.isOnline); + + let { serverId, userInfo: { serverType } } = role; + let serverName = await getServerName(serverType, serverId); + param.setServerName(serverId, serverName); + + param.setType(FRIEND_RELATION_TYPE.HAS_FRIEND); + return param; +} + /** * 增加双方好友数 * @param role1 我方 diff --git a/shared/consts/constModules/selectConst.ts b/shared/consts/constModules/selectConst.ts index 71e670ded..8de0e4653 100644 --- a/shared/consts/constModules/selectConst.ts +++ b/shared/consts/constModules/selectConst.ts @@ -9,7 +9,7 @@ export enum ROLE_SELECT { HANDLE_APPLY = 'roleId friendCnt lv', ATTR = 'attr', GET_LV = 'lv', - GET_ROLE_ID = 'roleId', + GET_ROLE_ID = 'roleId roleName lv head frame spine ce title friendCnt serverId userInfo.serverType', GET_MY_SERVER = 'lv serverId userInfo.serverType', COM_BATTLE = 'lv head frame spine topLineupCe', GET_HEADS = 'heads head frames frame spines spine',