v3: added comment likes, added votes/likes list view, added db migrations mechanism, updated project dependencies
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s
This commit is contained in:
@@ -2,6 +2,7 @@ import { Router } from "@oak/oak";
|
||||
import { ALLOWED_ORIGINS } from "../config.ts";
|
||||
import { verifyJWT } from "../lib/jwt.ts";
|
||||
import {
|
||||
broadcastCommentLikeUpdate,
|
||||
broadcastPresence,
|
||||
broadcastVoteUpdate,
|
||||
getOnlineUsers,
|
||||
@@ -15,6 +16,11 @@ import {
|
||||
getUserVotes,
|
||||
removeVote,
|
||||
} from "../services/vote-service.ts";
|
||||
import {
|
||||
castCommentLike,
|
||||
getUserCommentLikes,
|
||||
removeCommentLike,
|
||||
} from "../services/comment-like-service.ts";
|
||||
import { getUnreadCount } from "../services/notification-service.ts";
|
||||
import { getUserById } from "../services/user-service.ts";
|
||||
import {
|
||||
@@ -63,6 +69,9 @@ router.get("/ws", async (ctx) => {
|
||||
|
||||
try {
|
||||
const myVotes = authPayload ? getUserVotes(authPayload.userId) : [];
|
||||
const myCommentLikes = authPayload
|
||||
? getUserCommentLikes(authPayload.userId)
|
||||
: [];
|
||||
const unreadNotificationCount = authPayload
|
||||
? getUnreadCount(authPayload.userId)
|
||||
: 0;
|
||||
@@ -70,6 +79,7 @@ router.get("/ws", async (ctx) => {
|
||||
type: "welcome",
|
||||
users: getOnlineUsers(),
|
||||
myVotes,
|
||||
myCommentLikes,
|
||||
unreadNotificationCount,
|
||||
}));
|
||||
} catch (err) {
|
||||
@@ -98,6 +108,12 @@ router.get("/ws", async (ctx) => {
|
||||
case "vote_remove":
|
||||
handleVote(client, msg.dumpId, "remove");
|
||||
break;
|
||||
case "comment_like_cast":
|
||||
handleCommentLike(client, msg.commentId, "cast");
|
||||
break;
|
||||
case "comment_like_remove":
|
||||
handleCommentLike(client, msg.commentId, "remove");
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -141,4 +157,37 @@ function handleVote(
|
||||
}
|
||||
}
|
||||
|
||||
function handleCommentLike(
|
||||
client: WsClient,
|
||||
commentId: string,
|
||||
action: "cast" | "remove",
|
||||
): void {
|
||||
const { socket } = client;
|
||||
|
||||
if (!client.userId) {
|
||||
socket.send(
|
||||
JSON.stringify({ type: "error", message: "Authentication required" }),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const newCount = action === "cast"
|
||||
? castCommentLike(commentId, client.userId)
|
||||
: removeCommentLike(commentId, client.userId);
|
||||
|
||||
socket.send(JSON.stringify({
|
||||
type: "comment_like_ack",
|
||||
commentId,
|
||||
action,
|
||||
likeCount: newCount,
|
||||
}));
|
||||
|
||||
broadcastCommentLikeUpdate(commentId, newCount, client.userId, action);
|
||||
} catch (err) {
|
||||
const message = err instanceof APIException ? err.message : "Like failed";
|
||||
socket.send(JSON.stringify({ type: "error", message }));
|
||||
}
|
||||
}
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user