This commit is contained in:
slawk0
2024-11-28 18:58:53 +01:00
parent cec5d8e50b
commit 7e362de7e6
3 changed files with 7 additions and 5 deletions

View File

@@ -82,6 +82,7 @@ function MessagesArea({
read: false,
id: msg.message_id,
user_id: msg.sender_id,
conversation_id: msg.conversation_id,
},
false,
);

View File

@@ -18,6 +18,7 @@ export type ChatMessages = {
pending: boolean;
attachment_url: string | null;
sender_id: number;
conversation_id: number;
};
export type ContactsProps = {

View File

@@ -221,7 +221,7 @@ async function insertMessage(
INSERT INTO Messages (conversation_id, user_id, content, attachment_url)
SELECT conversation_id, sender.user_id, $3, $4
FROM final_conversation, sender
RETURNING message_id, content, sent_at, attachment_url, user_id AS sender_id;
RETURNING message_id, content, sent_at, attachment_url, user_id AS sender_id, conversation_id;
`;
try {
@@ -300,8 +300,8 @@ async function getMessages(user_id, receiverUsername, limit = 50, cursor = 0) {
m.content,
m.sent_at,
m.attachment_url,
a.username AS sender_username,
r.username AS recipient_username
a.username AS sender,
r.username AS recipient
FROM Messages m
JOIN Accounts a ON m.user_id = a.user_id
JOIN Memberships mem ON m.conversation_id = mem.conversation_id AND mem.user_id = (SELECT user_id FROM recipient)
@@ -344,8 +344,8 @@ async function getMessages(user_id, receiverUsername, limit = 50, cursor = 0) {
m.content,
m.sent_at,
m.attachment_url,
a.username AS sender_username,
r.username AS recipient_username
a.username AS sender,
r.username AS recipient
FROM Messages m
JOIN Accounts a ON m.user_id = a.user_id
JOIN Memberships mem ON m.conversation_id = mem.conversation_id AND mem.user_id = (SELECT user_id FROM recipient)