added return conversation_id on inserting contact
This commit is contained in:
@@ -254,7 +254,6 @@ async function addMemberToGroupByUsername(conversation_id, username) {
|
||||
}
|
||||
|
||||
async function getMessages(user_id, conversation_id, limit = 50, cursor = 0) {
|
||||
// Check if the user is a member of the conversation
|
||||
const checkMembershipQuery = `
|
||||
SELECT 1 FROM Memberships
|
||||
WHERE conversation_id = $1 AND user_id = $2
|
||||
@@ -263,8 +262,8 @@ async function getMessages(user_id, conversation_id, limit = 50, cursor = 0) {
|
||||
|
||||
try {
|
||||
const checkResult = await client.query(checkMembershipQuery, [
|
||||
conversation_id, // $1
|
||||
user_id, // $2
|
||||
conversation_id,
|
||||
user_id,
|
||||
]);
|
||||
if (checkResult.rows.length === 0) {
|
||||
console.error("User is not a member of the conversation");
|
||||
@@ -470,14 +469,15 @@ async function insertContact(userUsername, receiverUsername, read) {
|
||||
INSERT INTO Contacts (user_id, contact_user_id, read, last_active)
|
||||
SELECT (SELECT user_id FROM sender), (SELECT user_id FROM receiver), $3, CURRENT_TIMESTAMP
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING contact_id AS id, contact_user_id AS user_id, last_active
|
||||
RETURNING contact_id AS id, contact_user_id AS user_id, last_active, (SELECT conversation_id FROM final_conversation) AS conversation_id
|
||||
)
|
||||
SELECT
|
||||
ic.id,
|
||||
ic.user_id,
|
||||
a.username AS username,
|
||||
ic.last_active,
|
||||
'direct' AS type
|
||||
'direct' AS type,
|
||||
ic.conversation_id
|
||||
FROM insert_contact ic
|
||||
JOIN Accounts a ON a.user_id = ic.user_id;
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user