Skip to content

Commit

Permalink
Remove sendMessage try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
morajabi committed Dec 11, 2024
1 parent 04abc6e commit eac5aca
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions server/src/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,43 +109,35 @@ export const handler = async (input: Input, context: HandlerContext): Promise<Re

await updateLastMessageId(chatId, newMessageId)

try {
const encodedMessage = encodeMessageInfo(newMessage, {
currentUserId: context.currentUserId,
peerId: peerId,
})

sendMessageUpdate({
message: newMessage,
peerId,
const encodedMessage = encodeMessageInfo(newMessage, {
currentUserId: context.currentUserId,
peerId: peerId,
})

sendMessageUpdate({
message: newMessage,
peerId,
currentUserId: context.currentUserId,
})

const title: string = await db
.select({ firstName: users.firstName, username: users.username })
.from(users)
.where(eq(users.id, context.currentUserId))
.then(([user]) => user?.firstName ?? user?.username ?? "New Message")

if (input.peerUserId) {
sendPushNotificationToUser({
userId: Number(input.peerUserId),
title,
chatId,
message: input.text,
currentUserId: context.currentUserId,
currentUser,
})

const title: string = await db
.select({ firstName: users.firstName, username: users.username })
.from(users)
.where(eq(users.id, context.currentUserId))
.then(([user]) => user?.firstName ?? user?.username ?? "New Message")

if (input.peerUserId) {
sendPushNotificationToUser({
userId: Number(input.peerUserId),
title,
chatId,
message: input.text,
currentUserId: context.currentUserId,
currentUser,
})
}

return { message: encodedMessage }
} catch (encodeError) {
Log.shared.error("Failed to encode message", {
error: encodeError,
message: newMessage,
})
throw new InlineError(InlineError.ApiError.INTERNAL)
}

return { message: encodedMessage }
}

export const getChatIdFromPeer = async (
Expand Down

0 comments on commit eac5aca

Please sign in to comment.