红点:优先提出好友推送系统
This commit is contained in:
@@ -4,11 +4,11 @@ import { STATUS, ROLE_SELECT, FRIEND_DROP_TYPE, FRIEND_RELATION_TYPE, POPULATE_T
|
||||
import { RoleModel, RoleType } from "../../../db/Role";
|
||||
import { getTimeFun, getZeroPointD } from "../../../pubUtils/timeUtil";
|
||||
import { FriendApplyModel } from "../../../db/FriendApply";
|
||||
import { FriendApplyParams, FriendListParam, FriendRecommendParams, BlackListParam, FriendValueListParam } from "../../../domain/roleField/friend";
|
||||
import { FriendListParam, FriendRecommendParams, BlackListParam, FriendValueListParam } from "../../../domain/roleField/friend";
|
||||
import { FriendShipModel, FriendShipType } from "../../../db/FriendShip";
|
||||
import { FriendRelationModel, Relation } from "../../../db/FriendRelation";
|
||||
import { isRoleOnline, getServerName, getRoleOnlineInfo } from "../../../services/redisService";
|
||||
import { increaseFrdCnt, getRecommendType, sortByBeSentHeart } from "../../../services/friendService";
|
||||
import { increaseFrdCnt, getRecommendType, sortByBeSentHeart, getApplyList, getFriendList } from "../../../services/friendService";
|
||||
import { FriendPointModel } from "../../../db/FriendPoint";
|
||||
import { gameData, getDicFriendByLv } from "../../../pubUtils/data";
|
||||
import { addItems, handleCost } from "../../../services/rewardService";
|
||||
@@ -167,32 +167,7 @@ export class FriendHandler {
|
||||
public async getApplyList(msg: {}, session: BackendSession) {
|
||||
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
let myFriendRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.NOT);
|
||||
let list = await FriendApplyModel.getApplyList(roleId);
|
||||
let result = new Array<FriendApplyParams>();
|
||||
let delApplyCodeList = new Array<string>();
|
||||
for (let apply of list) {
|
||||
let friend = <RoleType>apply.friend;
|
||||
let type = getRecommendType(myFriendRelation, roleId, friend.roleId);
|
||||
|
||||
let param = new FriendApplyParams(apply.applyCode, friend);
|
||||
|
||||
let { serverId, userInfo: { serverType } } = friend;
|
||||
let serverName = await getServerName(serverType, serverId);
|
||||
param.setServerName(serverId, serverName);
|
||||
|
||||
param.setType(type);
|
||||
if (type != FRIEND_RELATION_TYPE.NORMAL) {
|
||||
delApplyCodeList.push(apply.applyCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push(param);
|
||||
}
|
||||
await FriendApplyModel.deleteApply(delApplyCodeList);
|
||||
await RoleModel.increaseFriendApplyCnt(roleId, -1 * delApplyCodeList.length, 50);
|
||||
|
||||
let result = await getApplyList(roleId);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: result
|
||||
});
|
||||
@@ -247,8 +222,8 @@ export class FriendHandler {
|
||||
await FriendRelationModel.addFriend(friend.roleId, role, friendShip);
|
||||
|
||||
let param = new FriendListParam(friend, roleId, friendShip);
|
||||
let isOnline = await isRoleOnline(friend.roleId);
|
||||
param.setOnline(isOnline);
|
||||
let hisOnlineInfo = await getRoleOnlineInfo(friend.roleId);
|
||||
param.setOnline(hisOnlineInfo.isOnline);
|
||||
|
||||
let { serverId, userInfo: { serverType } } = friend;
|
||||
let serverName = await getServerName(serverType, serverId);
|
||||
@@ -256,6 +231,10 @@ 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 }]);
|
||||
}
|
||||
|
||||
resultApplyCodeList.push(apply.applyCode);
|
||||
}
|
||||
} else {
|
||||
@@ -285,54 +264,9 @@ export class FriendHandler {
|
||||
let roleId: string = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let list = new Array<FriendListParam>();
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND);
|
||||
let friendList = myRelation ? myRelation.friends : [];
|
||||
let res = await getFriendList(role);
|
||||
|
||||
for (let friend of friendList) {
|
||||
let friendRole = <RoleType>friend.role;
|
||||
let friendShip = <FriendShipType>friend.friendShip;
|
||||
if (!friendRole || !friendShip) continue;
|
||||
|
||||
let fs = <FriendShipType>friend.friendShip;
|
||||
let ref = shouldRefresh(fs.refTime, new Date());
|
||||
if (ref) {
|
||||
friendShip = await FriendShipModel.refreshSendAndReceive(roleId, friendRole.roleId);
|
||||
}
|
||||
|
||||
let param = new FriendListParam(friendRole, roleId, friendShip);
|
||||
let { serverId, userInfo: { serverType } } = friendRole;
|
||||
let serverName = await getServerName(serverType, serverId);
|
||||
param.setServerName(serverId, serverName);
|
||||
|
||||
let isOnline = await isRoleOnline(friendRole.roleId);
|
||||
param.setOnline(isOnline);
|
||||
|
||||
param.setType(FRIEND_RELATION_TYPE.HAS_FRIEND);
|
||||
|
||||
list.push(param);
|
||||
}
|
||||
|
||||
list.sort((a, b) => {
|
||||
if (a.isOnline != b.isOnline) {
|
||||
return a.isOnline ? 1 : -1
|
||||
}
|
||||
if (a.quitTime != b.quitTime) {
|
||||
return b.quitTime - a.quitTime
|
||||
}
|
||||
return a.friendValue - b.friendValue;
|
||||
});
|
||||
|
||||
let { friendCnt = 0, blockCnt = 0 } = role;
|
||||
let frdPointRec = await FriendPointModel.getFrdPointRecToday(roleId, FRIEND_DROP_TYPE.SEND_GIFT);
|
||||
let { cnt: todayReceiveCnt = 0, sendCnt: todaySendCnt = 0 } = frdPointRec || {};
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
todayReceiveCnt,
|
||||
todaySendCnt,
|
||||
list,
|
||||
friendCnt, blockCnt
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
}
|
||||
|
||||
// 获取黑名单
|
||||
|
||||
Reference in New Issue
Block a user