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

@ -55,7 +55,7 @@ export const orderedCollectionPage = (collectionId: string, orderedItems: (strin
return collection;
};
export const addLikeOrShare = async (articleId: number, person: Actor, likeOrShare: 1|2) => {
export const addLikeOrShare = async (articleId: number, person: Actor, likeOrShare: 1 | 2) => {
await db("remote_users")
.insert({
actor: person.id,
@ -75,7 +75,15 @@ export const addLikeOrShare = async (articleId: number, person: Actor, likeOrSha
created_at: new Date()
})
.onConflict().ignore()
;
;
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 { handleWebfingerGet } from "./net.js";
import { escapeHtml } from "./util.js";
import { getArticleCollection } from "./collection.js";
const port = parseInt(process.env.port || "8080");
const app = express();
@ -62,6 +63,9 @@ app.get(Routes.object, async (req, res) => {
const obj = createArticleObject(article, nickname);
obj["@context"] = CONTEXT;
const likes = await getArticleCollection(1, article.id);
obj.likes = likes;
console.log(`returning object id: ${article.id} as json`);
res.append("Content-Type", ACTIVITYPUB_TYPE);
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 activity = createArticleActivity(article, user);
const likes = await getArticleCollection(1, article.id);
activity.object.likes = likes;
console.log(`returning activity id: ${id} as json`);
res.append("Content-Type", ACTIVITYPUB_TYPE);
res.send(JSON.stringify(activity, null, 4));