-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add in-chat media gallery with lightbox image viewer Closes #499 #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,26 @@ router.get("/:id", protectRoute, getMessages); | |||||
| router.post("/send/:id", protectRoute, sendMessage); | ||||||
| router.post("/:id/react", protectRoute, reactToMessage); | ||||||
| router.delete("/:id", protectRoute, deleteMessage); | ||||||
| // Media Gallery Route | ||||||
| router.get("/:id/media", protectRoute, async (req, res) => { | ||||||
| try { | ||||||
| const myId = req.user._id; | ||||||
| const theirId = req.params.id; | ||||||
|
|
||||||
| const mediaMessages = await Message.find({ | ||||||
|
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Media endpoint will 500 due auth field mismatch and missing model import.
Suggested fix import express from "express";
import protectRoute from "../middleware/auth.middleware.js";
+import Message from "../models/message.model.js";
@@
- const myId = req.user._id;
+ const myId = req.userId;🤖 Prompt for AI Agents |
||||||
| $or: [ | ||||||
| { senderId: myId, receiverId: theirId }, | ||||||
| { senderId: theirId, receiverId: myId }, | ||||||
| ], | ||||||
| image: { $ne: null, $exists: true }, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current media filter still includes non-image messages.
Suggested fix- image: { $ne: null, $exists: true },
+ image: { $nin: [null, ""] },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| }) | ||||||
| .select("image createdAt senderId") | ||||||
| .sort({ createdAt: -1 }); | ||||||
|
|
||||||
| res.status(200).json(mediaMessages); | ||||||
| } catch (error) { | ||||||
| res.status(500).json({ error: "Internal server error" }); | ||||||
| } | ||||||
| }); | ||||||
| export default router; | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rollback throttle cache when
lastSeenDB write fails.The cache timestamp is set before the DB write, but on error it is never reverted. That suppresses retries for 30s despite no successful update, which can leave
lastSeenstale.Suggested fix
const throttledUpdateLastSeen = async (userId) => { const now = Date.now(); const lastUpdate = lastDbUpdateCache.get(userId) || 0; if (now - lastUpdate < 30000) return; // 30 second throttle lastDbUpdateCache.set(userId, now); try { await User.findByIdAndUpdate(userId, { lastSeen: new Date() }); } catch (err) { + lastDbUpdateCache.delete(userId); // allow immediate retry after transient failure console.error("Error updating lastSeen:", err); } };📝 Committable suggestion
🤖 Prompt for AI Agents