好友:好友排序以及一键赠送排序

This commit is contained in:
luying
2021-02-24 17:06:48 +08:00
parent 1a4f3e84d5
commit 87d7bf6a8e
5 changed files with 47 additions and 15 deletions
+24 -8
View File
@@ -5,6 +5,7 @@ import { getResStr } from "../pubUtils/util";
import { STATUS, FRIEND_RELATION_TYPE } from "../consts";
import { FriendShipType, FriendShipModel } from "../db/FriendShip";
import { outputCnt } from '../pubUtils/friendUtil';
import { isRoleOnline } from "./redisService";
/**
* 增加双方好友数
@@ -58,17 +59,32 @@ export function getRecommendType(myFriendRelation: FriendRelationType, myRoleId:
* @param roleId 自己的玩家id
* @param list 需要排序列表
*/
export function sortByBeSentHeart(roleId: string, list: Relation[]) {
export async function sortByBeSentHeart(roleId: string, list: Relation[]) {
let result = list.map(cur => {
let result = new Array<Relation & {beSentHeart: number, beSentHeartTime: number} & { quitTime: number, friendValue: number, isOnline: boolean}>();
for(let cur of list) {
let json = getSentHeart(roleId, cur);
return {...cur, ...json};
})
let friendRole = <RoleType>cur.role;
let friendShip = <FriendShipType>cur.friendShip;
let isOnline = await isRoleOnline(friendRole.roleId);
result.push({...cur, ...json, isOnline, quitTime: friendRole.quitTime, friendValue: friendShip.friendValue});
}
result.sort((a, b) => {
if(a.beSentHeart == b.beSentHeart) {
return a.beSentHeartTime - b.beSentHeartTime;
} else {
return b.beSentHeart - a.beSentHeart;
if(a.beSentHeart && b.beSentHeart) { // 只要有一方送过
if(a.beSentHeart == b.beSentHeart) {
return a.beSentHeartTime - b.beSentHeartTime;
} else {
return b.beSentHeart - a.beSentHeart;
}
} else { // 都没送过的情况
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;
}
});
return result