好友:好友排序以及一键赠送排序
This commit is contained in:
@@ -261,6 +261,7 @@ export class FriendHandler {
|
||||
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;
|
||||
@@ -285,6 +286,16 @@ export class FriendHandler {
|
||||
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||{};
|
||||
@@ -452,7 +463,7 @@ export class FriendHandler {
|
||||
|
||||
let { roleId: hisRoleId } = msg;
|
||||
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIENDSHIP); // 好友关系,只有friendship被populate了
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND); // 好友关系,只有friendship被populate了
|
||||
let friends = myRelation?myRelation.friends: [];
|
||||
let arr = new Array<Relation>();
|
||||
if(hisRoleId != '') {
|
||||
@@ -463,7 +474,7 @@ export class FriendHandler {
|
||||
} else {
|
||||
arr = friends;
|
||||
}
|
||||
let canSendList = sortByBeSentHeart(roleId, arr);
|
||||
let canSendList = await sortByBeSentHeart(roleId, arr);
|
||||
|
||||
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let dicFriendLv = gameData.roleFriend.get(lv);
|
||||
@@ -515,7 +526,7 @@ export class FriendHandler {
|
||||
|
||||
let { roleId: hisRoleId } = msg;
|
||||
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIENDSHIP); // 好友关系,只有friendship被populate了
|
||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND); // 好友关系,只有friendship被populate了
|
||||
let friends = myRelation?myRelation.friends: [];
|
||||
let arr = new Array<Relation>();
|
||||
if(hisRoleId != '') {
|
||||
@@ -526,7 +537,7 @@ export class FriendHandler {
|
||||
} else {
|
||||
arr = friends;
|
||||
}
|
||||
let canReceiveList = sortByBeSentHeart(roleId, arr);
|
||||
let canReceiveList = await sortByBeSentHeart(roleId, arr);
|
||||
|
||||
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||
let dicFriendLv = gameData.roleFriend.get(lv);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user