likes collection

This commit is contained in:
Moon Man 2023-12-31 15:48:42 -05:00
parent 05591df126
commit 6ce7e802a6
2 changed files with 17 additions and 2 deletions

View File

@ -79,3 +79,11 @@ export const addLikeOrShare = async (articleId: number, person: Actor, likeOrSha
console.log("Like/Share added"); console.log("Like/Share added");
}; };
export const getArticleCollection = async (collectionTypeId: 1 | 2, articleId: number) =>
db<CollectionEntry>("collections")
.where("collection_types_id", collectionTypeId)
.where("articles_id", articleId)
.orderBy("created_at", "desc")
.then((collection) => collection.map((c) => c.value))
;

View File

@ -8,6 +8,7 @@ import { userToPerson, TYPE as ACTIVITYPUB_TYPE, handleInboxPost, createArticleO
import { handleFollowerGet } from "./follower.js"; import { handleFollowerGet } from "./follower.js";
import { handleWebfingerGet } from "./net.js"; import { handleWebfingerGet } from "./net.js";
import { escapeHtml } from "./util.js"; import { escapeHtml } from "./util.js";
import { getArticleCollection } from "./collection.js";
const port = parseInt(process.env.port || "8080"); const port = parseInt(process.env.port || "8080");
const app = express(); const app = express();
@ -62,6 +63,9 @@ app.get(Routes.object, async (req, res) => {
const obj = createArticleObject(article, nickname); const obj = createArticleObject(article, nickname);
obj["@context"] = CONTEXT; obj["@context"] = CONTEXT;
const likes = await getArticleCollection(1, article.id);
obj.likes = likes;
console.log(`returning object id: ${article.id} as json`); console.log(`returning object id: ${article.id} as json`);
res.append("Content-Type", ACTIVITYPUB_TYPE); res.append("Content-Type", ACTIVITYPUB_TYPE);
res.send(JSON.stringify(obj, null, 4)); res.send(JSON.stringify(obj, null, 4));
@ -100,6 +104,9 @@ app.get(Routes.activity, async (req, res) => {
const user = await getUserById(article.users_id) as User; const user = await getUserById(article.users_id) as User;
const activity = createArticleActivity(article, user); const activity = createArticleActivity(article, user);
const likes = await getArticleCollection(1, article.id);
activity.object.likes = likes;
console.log(`returning activity id: ${id} as json`); console.log(`returning activity id: ${id} as json`);
res.append("Content-Type", ACTIVITYPUB_TYPE); res.append("Content-Type", ACTIVITYPUB_TYPE);
res.send(JSON.stringify(activity, null, 4)); res.send(JSON.stringify(activity, null, 4));