Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/components/feed/CommentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function CommentsSection({ postId, postAuthorId }: { postId: stri
const LIMIT = 20;

function timeAgo(dateString: string) {
const now = new Date().getTime();
const now = Date.now();
const past = new Date(dateString).getTime();
const diff = Math.floor((now - past) / 1000);
if (diff < 60) return `${diff}s ago`;
Expand Down Expand Up @@ -112,7 +112,7 @@ export default function CommentsSection({ postId, postAuthorId }: { postId: stri
};
const { data } = await axios.post(`${BACKEND_URL}/api/comments/${postId}`, payload, { withCredentials: true });
if (replyingTo) {
setComments(prev => prev.map(c => {
setComments(prev => (prev ?? []).map(c => {
if (c._id === replyingTo._id) {
return {
...c,
Expand Down
4 changes: 2 additions & 2 deletions client/components/feed/Postcard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function PostCard({ post, setPost }: PostCardProps) {
const imageTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);

function timeAgo(dateString: string) {
const now = new Date().getTime();
const now = Date.now();
const past = new Date(dateString).getTime();
const diff = Math.floor((now - past) / 1000);
if (diff < 60) return `${diff}s ago`;
Expand Down Expand Up @@ -148,7 +148,7 @@ export default function PostCard({ post, setPost }: PostCardProps) {
);
} else {
setPosts(prev =>
prev.map(p =>
(prev ?? []).map(p =>
p._id === post._id
? { ...p, likes: updatedLikes }
: p
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/conversation.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const createConversation = asyncHandler(async (req, res) => {
}

const participantsKey = [senderId.toString(), receiverId.toString()]
.sort()
.sort((a, b) => a - b)
.join(":");

let convo = await Conversation.findOne({ participantsKey });
Expand Down
6 changes: 3 additions & 3 deletions server/src/controllers/notification.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Follow from "../models/follow.model.js";
import asyncHandler from "../utils/asyncHandler.js";
export const getNotifications = asyncHandler(async (req, res) => {
const currentUserId = req.user?._id || req.user?.id;
const page = parseInt(req.query.page) || 1;
const limit = Math.min(parseInt(req.query.limit) || 10, 50);
const page = parseInt(req.query.page, 10) || 1;
const limit = Math.min(parseInt(req.query.limit, 10) || 10, 50);
const skip = (page - 1) * limit;
const blockers = await User.find({ blockedUsers: currentUserId }).select("_id");
const blockerIds = blockers.map(u => u._id);
const blockerIds = (blockers ?? []).map(u => u._id);
const blockedIds = req.user?.blockedUsers || [];
const excludeIds = [...blockedIds, ...blockerIds];
const filter = {
Expand Down
6 changes: 3 additions & 3 deletions server/src/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const updateProfile = asyncHandler(async (req, res) => {
);

const notifications = await Notification.insertMany(
pendingFollows.map(f => ({
(pendingFollows ?? []).map(f => ({
recipient: f.follower,
sender: userId,
type: "follow_request_accepted",
Expand Down Expand Up @@ -590,7 +590,7 @@ export const getFollowers = asyncHandler(async (req, res) => {
}

const cursor = req.query.cursor || null;
const limit = Math.min(Math.max(parseInt(req.query.limit) || 20, 1), MAX_LIMIT);
const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 20, 1), MAX_LIMIT);

let filter = { following: req.params.id, status: "accepted" };
if (cursor) {
Expand Down Expand Up @@ -649,7 +649,7 @@ export const getFollowing = asyncHandler(async (req, res) => {
}

const cursor = req.query.cursor || null;
const limit = Math.min(Math.max(parseInt(req.query.limit) || 20, 1), MAX_LIMIT);
const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 20, 1), MAX_LIMIT);

let filter = { follower: req.params.id, status: "accepted" };
if (cursor) {
Expand Down