好友:好友排序以及一键赠送排序
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
|
||||
|
||||
@@ -96,6 +96,11 @@ export default class FriendRelation extends BaseModel {
|
||||
return result.length > 0;
|
||||
}
|
||||
|
||||
public static async updateInfo(roleId: string, update: friendShipUpdate) {
|
||||
const result = await FriendRelationModel.findOneAndUpdate({ roleId }, {$set: update}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await FriendRelationModel.deleteMany({ roleId });
|
||||
await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { roleId } }});
|
||||
@@ -105,4 +110,5 @@ export default class FriendRelation extends BaseModel {
|
||||
|
||||
export const FriendRelationModel = getModelForClass(FriendRelation);
|
||||
|
||||
export interface FriendRelationType extends Pick<DocumentType<FriendRelation>, keyof FriendRelation> { };
|
||||
export interface FriendRelationType extends Pick<DocumentType<FriendRelation>, keyof FriendRelation> { };
|
||||
type friendShipUpdate = Partial<FriendRelationType>; // 将所有字段变成可选项
|
||||
@@ -5,7 +5,6 @@ import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT } from '../consts';
|
||||
import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { reduceCe } from '../pubUtils/util';
|
||||
import { now } from 'underscore';
|
||||
|
||||
class Structure {
|
||||
@prop({ required: true })
|
||||
|
||||
@@ -232,7 +232,7 @@ export default class Role extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findByUid(uid: number, serverId: number, select?: string, getters = false) {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: nowSeconds() }, { new: true }).select(select).lean({ getters });
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: nowSeconds(), quitTime: nowSeconds() }, { new: true }).select(select).lean({ getters });
|
||||
return role;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user