v3: various improvements and fixes to real-time updates
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 40s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 40s
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { Router } from "@oak/oak";
|
||||
import { authMiddleware } from "../middleware/auth.ts";
|
||||
import { getUserById, updateUserAvatar } from "../services/user-service.ts";
|
||||
import { updateClientAvatar } from "../services/ws-service.ts";
|
||||
import {
|
||||
broadcastUserUpdated,
|
||||
updateClientAvatar,
|
||||
} from "../services/ws-service.ts";
|
||||
import { APIErrorCode, APIException } from "../model/interfaces.ts";
|
||||
import {
|
||||
AVATARS_DIR,
|
||||
@@ -45,6 +48,11 @@ router.post("/api/avatars/me", authMiddleware, async (ctx) => {
|
||||
updateClientAvatar(authPayload.userId, mime);
|
||||
|
||||
const { passwordHash: _, ...publicUser } = getUserById(authPayload.userId);
|
||||
// Let every client refresh this user's avatar wherever it's shown (feeds,
|
||||
// comments, OP, profiles) — not just the presence row. updated_at, bumped on
|
||||
// the avatar write, doubles as the cache-busting version.
|
||||
const { email: _email, ...broadcastUser } = publicUser;
|
||||
broadcastUserUpdated(broadcastUser);
|
||||
ctx.response.status = 200;
|
||||
ctx.response.body = { success: true, data: publicUser };
|
||||
});
|
||||
|
||||
@@ -153,7 +153,7 @@ function handleVote(
|
||||
broadcastVoteUpdate(dumpId, newCount, client.userId, action);
|
||||
} catch (err) {
|
||||
const message = err instanceof APIException ? err.message : "Vote failed";
|
||||
socket.send(JSON.stringify({ type: "error", message }));
|
||||
socket.send(JSON.stringify({ type: "error", message, dumpId, action }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ function handleCommentLike(
|
||||
broadcastCommentLikeUpdate(commentId, newCount, client.userId, action);
|
||||
} catch (err) {
|
||||
const message = err instanceof APIException ? err.message : "Like failed";
|
||||
socket.send(JSON.stringify({ type: "error", message }));
|
||||
socket.send(JSON.stringify({ type: "error", message, commentId, action }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user