feat(comments) : show heart giver profiles on comments and notifications
This commit is contained in:
@@ -78,6 +78,7 @@ export async function authorizeComment(id: string, viewer: CommentViewer | null,
|
||||
const root = alias(comments, "discussion_root");
|
||||
const parent = alias(comments, "discussion_parent");
|
||||
const recipient = alias(users, "discussion_recipient");
|
||||
const heartGiver = alias(users, "discussion_heart_giver");
|
||||
const likes = sql<number>`(select count(*)::int from ${commentReactions} where ${commentReactions.commentId} = ${comments.id} and ${commentReactions.value} = 1)`;
|
||||
const replyCount = sql<number>`(select count(*)::int from ${comments} replies where replies.root_id = ${comments.id})`;
|
||||
const publicTarget = sql<boolean>`(${commentThreads.guideId} is null or (${guides.isPublic} and ${guides.trashedAt} is null))`;
|
||||
@@ -146,6 +147,7 @@ export async function listComments(options: {
|
||||
authorAdmin: sql<boolean>`coalesce(${users.role} = 'admin' and ${users.emailVerified}, false)`,
|
||||
authorBanned: users.banned,
|
||||
replyToName: recipient.name, rootHidden: root.hidden, likes, replyCount,
|
||||
heartedByName: heartGiver.name, heartedByImage: heartGiver.image,
|
||||
hasReplies: sql<boolean>`exists(select 1 from ${comments} children where children.root_id = coalesce(${comments.rootId}, ${comments.id}) and children.reply_to_id = ${comments.id} and children.deleted_at is null)`,
|
||||
reaction: viewer ? sql<number>`coalesce((select value from ${commentReactions} where ${commentReactions.commentId} = ${comments.id} and ${commentReactions.userId} = ${viewer.id}), 0)` : sql<number>`0`,
|
||||
guideId: commentThreads.guideId, scheduleId: commentThreads.scheduleId, guideName: guides.name, guideCoverId: guides.coverMediaId, guideSlug: guides.slug, guideTrashedAt: guides.trashedAt,
|
||||
@@ -154,6 +156,7 @@ export async function listComments(options: {
|
||||
.innerJoin(commentThreads, eq(commentThreads.id, comments.threadId))
|
||||
.innerJoin(commentRevisions, and(eq(commentRevisions.commentId, comments.id), eq(commentRevisions.version, comments.version)))
|
||||
.innerJoin(users, eq(users.id, comments.authorId))
|
||||
.leftJoin(heartGiver, eq(heartGiver.id, comments.heartedById))
|
||||
.leftJoin(root, eq(root.id, comments.rootId)).leftJoin(parent, eq(parent.id, comments.replyToId)).leftJoin(recipient, eq(recipient.id, parent.authorId))
|
||||
.leftJoin(guides, eq(guides.id, commentThreads.guideId)).leftJoin(stygianSchedules, eq(stygianSchedules.scheduleId, commentThreads.scheduleId))
|
||||
.where(and(...conditions)).orderBy(...(top ? [desc(likes)] : []), ascending ? asc(comments.createdAt) : desc(comments.createdAt), ascending ? asc(comments.id) : desc(comments.id)).limit(21);
|
||||
@@ -172,6 +175,7 @@ export async function listComments(options: {
|
||||
text: contentAllowed ? row.revision.text : "", images: contentAllowed ? images.get(row.revision.id) ?? [] : [],
|
||||
version: c.version, createdAt: c.createdAt.toISOString(), editedAt: row.revision.createdAt.toISOString(), hidden, ownHidden: c.hidden,
|
||||
deleted: Boolean(c.deletedAt), hearted: Boolean(c.heartedById), likes: Number(row.likes), reaction: Number(row.reaction),
|
||||
heartedBy: c.heartedById && row.heartedByName !== null ? { id: c.heartedById, name: row.heartedByName, image: row.heartedByImage } : null,
|
||||
replyCount: Number(row.replyCount), hasReplies: row.hasReplies, canEdit: viewer?.id === c.authorId && !c.deletedAt && !hidden && !row.guideTrashedAt,
|
||||
canModerate: Boolean(viewer?.admin) && !row.guideTrashedAt,
|
||||
canInteract: !c.deletedAt && !hidden && !row.guideTrashedAt && (row.publicTarget || Boolean(viewer?.admin)),
|
||||
|
||||
Reference in New Issue
Block a user