fix(convex): preserve original timestamps in message migration
- commit
- e7b86a4aac545e5902ad82c0e750021e15b76fc3
- author
- bnema · · 2026-01-18 20:36 UTC
- parent
- f8c7979
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -4
M src/convex/http.ts +4 -2
| @@ -256,7 +256,8 @@ http.route({ | |||
| 256 | 256 | handler: httpAction(async (ctx, request) => { | |
| 257 | 257 | if (!validateSecret(request)) return unauthorizedResponse(); | |
| 258 | 258 | ||
| 259 | - | const { chatRoomId, senderId, content, type, styleData, hasFormatting } = await request.json(); | |
| 259 | + | const { chatRoomId, senderId, content, type, styleData, hasFormatting, timestamp } = | |
| 260 | + | await request.json(); | |
| 260 | 261 | try { | |
| 261 | 262 | const message = await ctx.runMutation(internal.messagesInternal.send, { | |
| 262 | 263 | chatRoomId, | |
| @@ -264,7 +265,8 @@ http.route({ | |||
| 264 | 265 | content, | |
| 265 | 266 | type, | |
| 266 | 267 | styleData, | |
| 267 | - | hasFormatting | |
| 268 | + | hasFormatting, | |
| 269 | + | timestamp | |
| 268 | 270 | }); | |
| 269 | 271 | return new Response(JSON.stringify(message), { | |
| 270 | 272 | headers: { 'Content-Type': 'application/json' } | |
| @@ -256,7 +256,8 @@ http.route({ | |||||
| 256 | handler: httpAction(async (ctx, request) => { | 256 | handler: httpAction(async (ctx, request) => { | ||
| 257 | if (!validateSecret(request)) return unauthorizedResponse(); | 257 | if (!validateSecret(request)) return unauthorizedResponse(); | ||
| 258 | 258 | ||||
| 259 | - | const { chatRoomId, senderId, content, type, styleData, hasFormatting } = await request.json(); | 259 | + | const { chatRoomId, senderId, content, type, styleData, hasFormatting, timestamp } = |
| 260 | + | await request.json(); | |||
| 260 | try { | 261 | try { | ||
| 261 | const message = await ctx.runMutation(internal.messagesInternal.send, { | 262 | const message = await ctx.runMutation(internal.messagesInternal.send, { | ||
| 262 | chatRoomId, | 263 | chatRoomId, | ||
| @@ -264,7 +265,8 @@ http.route({ | |||||
| 264 | content, | 265 | content, | ||
| 265 | type, | 266 | type, | ||
| 266 | styleData, | 267 | styleData, | ||
| 267 | - | hasFormatting | 268 | + | hasFormatting, |
| 269 | + | timestamp | |||
| 268 | }); | 270 | }); | ||
| 269 | return new Response(JSON.stringify(message), { | 271 | return new Response(JSON.stringify(message), { | ||
| 270 | headers: { 'Content-Type': 'application/json' } | 272 | headers: { 'Content-Type': 'application/json' } | ||
M src/convex/messagesInternal.ts +3 -2
| @@ -41,7 +41,8 @@ export const send = internalMutation({ | |||
| 41 | 41 | content: v.string(), | |
| 42 | 42 | type: v.optional(v.string()), | |
| 43 | 43 | styleData: v.optional(v.string()), | |
| 44 | - | hasFormatting: v.optional(v.boolean()) | |
| 44 | + | hasFormatting: v.optional(v.boolean()), | |
| 45 | + | timestamp: v.optional(v.number()) | |
| 45 | 46 | }, | |
| 46 | 47 | handler: async (ctx, args) => { | |
| 47 | 48 | // Verify room exists | |
| @@ -61,7 +62,7 @@ export const send = internalMutation({ | |||
| 61 | 62 | senderId: args.senderId, | |
| 62 | 63 | content: args.content, | |
| 63 | 64 | type: args.type ?? 'chat', | |
| 64 | - | timestamp: Date.now(), | |
| 65 | + | timestamp: args.timestamp ?? Date.now(), | |
| 65 | 66 | styleData: args.styleData, | |
| 66 | 67 | hasFormatting: args.hasFormatting ?? false | |
| 67 | 68 | }); | |
| @@ -41,7 +41,8 @@ export const send = internalMutation({ | |||||
| 41 | content: v.string(), | 41 | content: v.string(), | ||
| 42 | type: v.optional(v.string()), | 42 | type: v.optional(v.string()), | ||
| 43 | styleData: v.optional(v.string()), | 43 | styleData: v.optional(v.string()), | ||
| 44 | - | hasFormatting: v.optional(v.boolean()) | 44 | + | hasFormatting: v.optional(v.boolean()), |
| 45 | + | timestamp: v.optional(v.number()) | |||
| 45 | }, | 46 | }, | ||
| 46 | handler: async (ctx, args) => { | 47 | handler: async (ctx, args) => { | ||
| 47 | // Verify room exists | 48 | // Verify room exists | ||
| @@ -61,7 +62,7 @@ export const send = internalMutation({ | |||||
| 61 | senderId: args.senderId, | 62 | senderId: args.senderId, | ||
| 62 | content: args.content, | 63 | content: args.content, | ||
| 63 | type: args.type ?? 'chat', | 64 | type: args.type ?? 'chat', | ||
| 64 | - | timestamp: Date.now(), | 65 | + | timestamp: args.timestamp ?? Date.now(), |
| 65 | styleData: args.styleData, | 66 | styleData: args.styleData, | ||
| 66 | hasFormatting: args.hasFormatting ?? false | 67 | hasFormatting: args.hasFormatting ?? false | ||
| 67 | }); | 68 | }); | ||