红点:优先提出好友推送系统

This commit is contained in:
luying
2021-05-31 12:55:21 +08:00
parent d7a49dfb9c
commit 17a90dea37
4 changed files with 280 additions and 82 deletions
+91 -4
View File
@@ -1,11 +1,98 @@
import { gameData, getDicFriendByLv } from "../pubUtils/data";
import { RoleType, RoleModel } from "../db/Role";
import { FriendRelationType, Relation } from "../db/FriendRelation";
import { getResStr } from "../pubUtils/util";
import { STATUS, FRIEND_RELATION_TYPE } from "../consts";
import { FriendRelationType, Relation, FriendRelationModel } from "../db/FriendRelation";
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 } from "./redisService";
import { isRoleOnline, getServerName } from "./redisService";
import { FriendApplyModel } from "../db/FriendApply";
import { FriendApplyParams, FriendListParam } from "../domain/roleField/friend";
import { FriendPointModel } from "../db/FriendPoint";
export async function getFriendList(role: RoleType) {
let { roleId } = role;
let list = new Array<FriendListParam>();
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND);
let friendList = myRelation ? myRelation.friends : [];
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 {
todayReceiveCnt,
todaySendCnt,
list,
friendCnt, blockCnt
}
}
/**
* 获取玩家申请列表
* @param roleId 玩家id
*/
export async function getApplyList(roleId: string) {
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);
return result;
}
/**
* 增加双方好友数