好友:好友排序以及一键赠送排序
This commit is contained in:
@@ -261,6 +261,7 @@ export class FriendHandler {
|
|||||||
let list = new Array<FriendListParam>();
|
let list = new Array<FriendListParam>();
|
||||||
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND);
|
let myRelation = await FriendRelationModel.findFriendByRole(roleId, POPULATE_TYPE.FRIEND);
|
||||||
let friendList = myRelation?myRelation.friends: [];
|
let friendList = myRelation?myRelation.friends: [];
|
||||||
|
|
||||||
for(let friend of friendList) {
|
for(let friend of friendList) {
|
||||||
let friendRole = <RoleType>friend.role;
|
let friendRole = <RoleType>friend.role;
|
||||||
let friendShip = <FriendShipType>friend.friendShip;
|
let friendShip = <FriendShipType>friend.friendShip;
|
||||||
@@ -285,6 +286,16 @@ export class FriendHandler {
|
|||||||
list.push(param);
|
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 { friendCnt = 0, blockCnt = 0 } = role;
|
||||||
let frdPointRec = await FriendPointModel.getFrdPointRecToday(roleId, FRIEND_DROP_TYPE.SEND_GIFT);
|
let frdPointRec = await FriendPointModel.getFrdPointRecToday(roleId, FRIEND_DROP_TYPE.SEND_GIFT);
|
||||||
let { cnt: todayReceiveCnt = 0, sendCnt: todaySendCnt = 0 } = frdPointRec||{};
|
let { cnt: todayReceiveCnt = 0, sendCnt: todaySendCnt = 0 } = frdPointRec||{};
|
||||||
@@ -452,7 +463,7 @@ export class FriendHandler {
|
|||||||
|
|
||||||
let { roleId: hisRoleId } = msg;
|
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 friends = myRelation?myRelation.friends: [];
|
||||||
let arr = new Array<Relation>();
|
let arr = new Array<Relation>();
|
||||||
if(hisRoleId != '') {
|
if(hisRoleId != '') {
|
||||||
@@ -463,7 +474,7 @@ export class FriendHandler {
|
|||||||
} else {
|
} else {
|
||||||
arr = friends;
|
arr = friends;
|
||||||
}
|
}
|
||||||
let canSendList = sortByBeSentHeart(roleId, arr);
|
let canSendList = await sortByBeSentHeart(roleId, arr);
|
||||||
|
|
||||||
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||||
let dicFriendLv = gameData.roleFriend.get(lv);
|
let dicFriendLv = gameData.roleFriend.get(lv);
|
||||||
@@ -515,7 +526,7 @@ export class FriendHandler {
|
|||||||
|
|
||||||
let { roleId: hisRoleId } = msg;
|
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 friends = myRelation?myRelation.friends: [];
|
||||||
let arr = new Array<Relation>();
|
let arr = new Array<Relation>();
|
||||||
if(hisRoleId != '') {
|
if(hisRoleId != '') {
|
||||||
@@ -526,7 +537,7 @@ export class FriendHandler {
|
|||||||
} else {
|
} else {
|
||||||
arr = friends;
|
arr = friends;
|
||||||
}
|
}
|
||||||
let canReceiveList = sortByBeSentHeart(roleId, arr);
|
let canReceiveList = await sortByBeSentHeart(roleId, arr);
|
||||||
|
|
||||||
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
let {lv} = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_LV);
|
||||||
let dicFriendLv = gameData.roleFriend.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 { STATUS, FRIEND_RELATION_TYPE } from "../consts";
|
||||||
import { FriendShipType, FriendShipModel } from "../db/FriendShip";
|
import { FriendShipType, FriendShipModel } from "../db/FriendShip";
|
||||||
import { outputCnt } from '../pubUtils/friendUtil';
|
import { outputCnt } from '../pubUtils/friendUtil';
|
||||||
|
import { isRoleOnline } from "./redisService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加双方好友数
|
* 增加双方好友数
|
||||||
@@ -58,17 +59,32 @@ export function getRecommendType(myFriendRelation: FriendRelationType, myRoleId:
|
|||||||
* @param roleId 自己的玩家id
|
* @param roleId 自己的玩家id
|
||||||
* @param list 需要排序列表
|
* @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);
|
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) => {
|
result.sort((a, b) => {
|
||||||
if(a.beSentHeart == b.beSentHeart) {
|
if(a.beSentHeart && b.beSentHeart) { // 只要有一方送过
|
||||||
return a.beSentHeartTime - b.beSentHeartTime;
|
if(a.beSentHeart == b.beSentHeart) {
|
||||||
} else {
|
return a.beSentHeartTime - b.beSentHeartTime;
|
||||||
return b.beSentHeart - a.beSentHeart;
|
} 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
|
return result
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ export default class FriendRelation extends BaseModel {
|
|||||||
return result.length > 0;
|
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) {
|
public static async deleteAccount(roleId: string) {
|
||||||
let result = await FriendRelationModel.deleteMany({ roleId });
|
let result = await FriendRelationModel.deleteMany({ roleId });
|
||||||
await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { 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 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 { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT } from '../consts';
|
||||||
import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil';
|
import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil';
|
||||||
import { reduceCe } from '../pubUtils/util';
|
import { reduceCe } from '../pubUtils/util';
|
||||||
import { now } from 'underscore';
|
|
||||||
|
|
||||||
class Structure {
|
class Structure {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
|
|||||||
+1
-1
@@ -232,7 +232,7 @@ export default class Role extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async findByUid(uid: number, serverId: number, select?: string, getters = false) {
|
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;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user