40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
import { db } from "../../db/postgre.js";
|
|
import { Users } from "../index.js";
|
|
import { Following } from "../entities/following.js";
|
|
import { awaitAll } from "../../prelude/await-all.js";
|
|
export const FollowingRepository = db.getRepository(Following).extend({
|
|
isLocalFollower (following) {
|
|
return following.followerHost == null;
|
|
},
|
|
isRemoteFollower (following) {
|
|
return following.followerHost != null;
|
|
},
|
|
isLocalFollowee (following) {
|
|
return following.followeeHost == null;
|
|
},
|
|
isRemoteFollowee (following) {
|
|
return following.followeeHost != null;
|
|
},
|
|
async pack (src, me, opts) {
|
|
const following = typeof src === "object" ? src : await this.findOneByOrFail({
|
|
id: src
|
|
});
|
|
if (opts == null) opts = {};
|
|
return await awaitAll({
|
|
id: following.id,
|
|
createdAt: following.createdAt.toISOString(),
|
|
followeeId: following.followeeId,
|
|
followerId: following.followerId,
|
|
followee: opts.populateFollowee ? Users.pack(following.followee || following.followeeId, me, {
|
|
detail: true
|
|
}) : undefined,
|
|
follower: opts.populateFollower ? Users.pack(following.follower || following.followerId, me, {
|
|
detail: true
|
|
}) : undefined
|
|
});
|
|
},
|
|
packMany (followings, me, opts) {
|
|
return Promise.all(followings.map((x)=>this.pack(x, me, opts)));
|
|
}
|
|
});
|