fixed contacts list sorting
This commit is contained in:
@@ -176,6 +176,7 @@ async function insertMessage(
|
||||
attachmentUrls,
|
||||
]);
|
||||
console.log("insertmessageresult: ", result.rows);
|
||||
updateConversationLastActive(conversation_id);
|
||||
return result.rows[0];
|
||||
} catch (e) {
|
||||
console.error("Failed to insert message ", e);
|
||||
@@ -433,10 +434,11 @@ async function insertContact(userUsername, receiverUsername, read) {
|
||||
WHEN ci.user_id = (SELECT sender_id FROM user_ids) THEN (SELECT username FROM Accounts WHERE user_id = (SELECT receiver_id FROM user_ids))
|
||||
ELSE (SELECT username FROM Accounts WHERE user_id = (SELECT sender_id FROM user_ids))
|
||||
END AS username,
|
||||
c.last_active,
|
||||
ci.read,
|
||||
ci.last_active,
|
||||
'direct' AS type
|
||||
FROM contact_insert ci;
|
||||
FROM contact_insert ci
|
||||
JOIN Conversations c ON ci.conversation_id = c.conversation_id;
|
||||
`;
|
||||
|
||||
try {
|
||||
@@ -458,7 +460,7 @@ async function getContacts(user_id) {
|
||||
c.contact_id AS id,
|
||||
a2.user_id AS user_id,
|
||||
a2.username AS username,
|
||||
c.last_active,
|
||||
conv.last_active,
|
||||
c.conversation_id,
|
||||
conv.conversation_type AS type,
|
||||
c.read
|
||||
@@ -469,7 +471,7 @@ async function getContacts(user_id) {
|
||||
WHERE c.user_id = $1
|
||||
AND conv.conversation_type = 'direct'
|
||||
AND a2.user_id != $1
|
||||
ORDER BY c.last_active DESC;
|
||||
ORDER BY conv.last_active DESC;
|
||||
`;
|
||||
|
||||
const groupsQuery = `
|
||||
@@ -591,6 +593,21 @@ async function updateContactLastActive(user_id, contact_id) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateConversationLastActive(conversation_id) {
|
||||
//TODO CHECK IF USER IS MEMBER OF THAT CONVERSATION
|
||||
const query = `
|
||||
UPDATE Conversations
|
||||
SET last_active = NOW()
|
||||
WHERE conversation_id = $1
|
||||
`;
|
||||
try {
|
||||
await client.query(query, [conversation_id]);
|
||||
console.log("Successfully update conversation last active time");
|
||||
} catch (e) {
|
||||
console.error("Failed to update conversation last active time ", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function getConversationsForUser(user_id) {
|
||||
const query = `
|
||||
SELECT conversation_id
|
||||
|
||||
Reference in New Issue
Block a user