Skip to content
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

- Forward Update #999

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
60 changes: 60 additions & 0 deletions convex/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,66 @@ export const markMessageRead = mutation({
},
});

export const forwardMessage = mutation({
args: {
forwardObjects: v.array(
v.object({
username: v.string(),
userId: v.string(),
chatId: v.id("privateChats"),
}),
),

messageId: v.string(),
},
handler: async (ctx, args) => {
const identity = await ctx.auth.getUserIdentity();

if (identity === null) {
console.error("Unauthenticated call to mutation");
return null;
}

for (const forwardObject of args.forwardObjects) {
const chat = await ctx.table("privateChats").getX(forwardObject.chatId);

const usersInChat = await chat.edge("users");

const user = usersInChat.find(
(user) => user.clerkId === identity.tokenIdentifier,
);

if (!user) {
throw new ConvexError(
"UNAUTHORIZED REQUEST: User tried to forward a message to a chat in which he is not in.",
);
}

const parsedMessageId = ctx.table("messages").normalizeId(args.messageId);
Gamius00 marked this conversation as resolved.
Show resolved Hide resolved

if (!parsedMessageId) {
throw new ConvexError("messageId was invalid");
}

const message = await ctx.table("messages").getX(parsedMessageId);

if (!message) {
throw new ConvexError("Message does not exist");
}

await ctx.table("messages").insert({
userId: user._id,
privateChatId: forwardObject.chatId,
content: message.content,
deleted: false,
readBy: [user._id],
modified: false,
replyTo: message.replyTo,
});
}
},
});

export const editMessage = mutation({
args: { messageId: v.id("messages"), newContent: v.string() },
handler: async (ctx, args) => {
Expand Down
83 changes: 42 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,80 +15,81 @@
"convex:deploy": "convex deploy"
},
"dependencies": {
"@clerk/nextjs": "^6.5.1",
"@clerk/nextjs": "^6.10.3",
"@emoji-mart/data": "^1.2.1",
"@emoji-mart/react": "^1.1.1",
"@floating-ui/react": "^0.27.0",
"@hookform/resolvers": "^3.9.1",
"@ianvs/prettier-plugin-sort-imports": "^4.4.0",
"@icons-pack/react-simple-icons": "^11.0.0",
"@legendapp/state": "^3.0.0-beta.16",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.2",
"@floating-ui/react": "^0.27.3",
"@hookform/resolvers": "^3.10.0",
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
"@icons-pack/react-simple-icons": "^11.2.0",
"@legendapp/state": "3.0.0-beta.26",
"@radix-ui/react-avatar": "^1.1.2",
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-dialog": "^1.1.5",
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4",
"@reactuses/core": "^6.0.0",
"@sentry/nextjs": "^8",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-popover": "^1.1.5",
"@radix-ui/react-progress": "^1.1.1",
"@radix-ui/react-select": "^2.1.5",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-tooltip": "^1.1.7",
"@reactuses/core": "^6.0.1",
"@sentry/nextjs": "^8.52.0",
"@serwist/next": "9.0.11",
"@t3-oss/env-nextjs": "^0.12.0",
"babel-plugin-react-compiler": "19.0.0-beta-e552027-20250112",
"class-variance-authority": "^0.7.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"convex": "^1.18.2",
"convex-ents": "^0.13.0",
"convex-helpers": "^0.1.67",
"dayjs": "^1.11.13",
"emoji-mart": "^5.6.0",
"emoji-regex": "^10.4.0",
"framer-motion": "^12.0.0-alpha.2",
"framer-motion": "^12.0.6",
"geist": "^1.3.1",
"jiti": "^2.4.1",
"jiti": "^2.4.2",
"lucide-react": "^0.474.0",
"next": "^15.0.3",
"next-axiom": "^1.7.0",
"next": "^15.1.6",
"next-axiom": "^1.9.1",
"next-themes": "^0.4.4",
"npm-run-all2": "^7.0.1",
"npm-run-all2": "^7.0.2",
"nuqs": "^2.3.1",
"posthog-js": "^1.195.0",
"posthog-js": "^1.211.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "7.54.2",
"react-intersection-observer": "^9.13.1",
"react-intersection-observer": "^9.15.1",
"react-resizable-panels": "^2.1.7",
"react-responsive": "^10.0.0",
"react-scan": "^0.1.0",
"sonner": "^1.7.0",
"tailwind-merge": "^2.5.4",
"react-scan": "^0.1.1",
"sonner": "^1.7.2",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
"zod": "^3.24.1"
},
"devDependencies": {
"@eslint/compat": "^1.2.3",
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "9.19.0",
"@total-typescript/ts-reset": "^0.6.1",
"@types/eslint": "^9.6.1",
"@types/eslint__js": "^8.42.3",
"@types/node": "^22.10.7",
"@types/react": "^19.0.7",
"@types/node": "^22.12.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"@typescript-eslint/eslint-plugin": "^8.22.0",
"@typescript-eslint/parser": "^8.22.0",
"autoprefixer": "^10.4.20",
"eslint": "9.19.0",
"eslint-config-next": "^15.0.3",
"eslint-plugin-react-hooks": "^5.0.0",
"postcss": "^8.4.49",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.8",
"serwist": "^9.0.10",
"tailwindcss": "^3.4.15",
"typescript": "^5.6.3"
"eslint-config-next": "^15.1.6",
"eslint-plugin-react-hooks": "^5.1.0",
"postcss": "^8.5.1",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.11",
"serwist": "^9.0.11",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.3"
},
"ct3aMetadata": {
"initVersion": "7.30.0"
Expand Down
Loading