r2/game-server/app/services/friendService.js
lightings b821c368f8 ...
2023-07-24 14:08:02 +08:00

84 lines
2.4 KiB
JavaScript

// friendService.js
const friendDao = require('../dao/friendDao');
const userDao = require("../dao/userDao");
const guildDao = require("../dao/guildDao");
class FriendService {
constructor(app) {
this.app = app;
this.channelService = app.get("channelService");
this.gcs = this.app.get("globalChannelService");
}
async sendFriendRequest(uid, fid) {
await friendDao.sendFriendRequest(uid, fid);
}
async acceptFriendRequest(uid, fid) {
await friendDao.acceptFriendRequest(uid, fid);
}
async rejectFriendRequest(uid, fid) {
await friendDao.rejectFriendRequest(uid, fid);
}
async addFriend(uid, fid) {
await friendDao.addFriend(uid, fid);
}
async deleteFriend(uid, fid) {
await friendDao.deleteFriend(uid, fid);
}
async getFriendList(uid) {
const uids = await friendDao.getAcceptedFriends(uid);
return await this.uidsToUsers(uid, uids);
}
async addToBlackList(uid, bid) {
await friendDao.addToBlackList(uid, bid);
}
async removeFromBlackList(uid, bid) {
await friendDao.removeFromBlackList(uid, bid);
}
async getBlackList(uid) {
const uids = await friendDao.getBlackList(uid);
return await this.uidsToUsers(uid, uids);
}
async getPendingFriendRequests(uid) {
const uids = await friendDao.getPendingFriendRequests(uid);
return await this.uidsToUsers(uid, uids);
}
async getPendingFriendInvitations(uid) {
const uids = await friendDao.getInviteFriendRequests(uid);
return await this.uidsToUsers(uid, uids);
}
async findUser(name, last_idx, limit, uid) {
return await userDao.findUser(name, last_idx, limit, uid);
}
async uidsToUsers(uid, uids) {
const users = await friendDao.idxsToUsers(uids);
const channelId = "worldChannel";
// const channel = this.channelService.getChannel(channelId, true);
const channel = this.app.get("channelService").getChannel(channelId, true);
for (const member of users) {
const list = await this.gcs.getMemberByUid(channelId, member.account_id);
member.online = list.length>0 ? 1 : 0;
const guildInfo = await guildDao.getGuildInfoByUID(member.account_id);
member.guildInfo = guildInfo;
// member.isMyFriend = await friendDao.isMyFriend(uid, member.account_id);
// member.isMyBlackUser = await friendDao.isMyBlackUser(uid, member.account_id);
}
return users;
}
}
module.exports = FriendService;