added shadcn ui, ParticipantsBar.tsx, get conversation members api

This commit is contained in:
slawk0
2024-12-06 21:56:40 +01:00
parent 7bb7dcd669
commit 1388132a71
13 changed files with 1021 additions and 26 deletions

View File

@@ -722,6 +722,35 @@ async function deleteMessage(user_id, message_id) {
}
}
async function getMembers(conversation_id) {
const query = `
SELECT
a.user_id,
a.username
FROM Memberships m
JOIN Accounts a ON m.user_id = a.user_id
WHERE m.conversation_id = $1;
`;
try {
const result = await client.query(query, [conversation_id]);
const members = result.rows;
if (members.length > 0) {
console.log(`Members of conversation_id ${conversation_id}:`, members);
return members;
} else {
console.log(`No members found for conversation_id ${conversation_id}.`);
return [];
}
} catch (e) {
console.error(
`Failed to get members for conversation_id ${conversation_id}`,
e,
);
return null;
}
}
function getTime() {
return new Date();
}
@@ -746,4 +775,5 @@ module.exports = {
getConversationsForUser,
contactSuggestion,
deleteMessage,
getMembers,
};

View File

@@ -44,6 +44,7 @@ const {
addMemberToGroupByUsername,
contactSuggestion,
deleteMessage,
getMembers,
} = require("./db/db");
const { extname } = require("node:path");
@@ -388,6 +389,26 @@ app.delete(
},
);
app.get(
"/api/chat/groups/getMembers/:conversation_id",
authorizeUser,
async (req, res) => {
const conversation_id = req.params.conversation_id;
if (!conversation_id) {
return res.status(400).json({ message: "No conversation_id provided" });
}
const participants = await getMembers(conversation_id);
console.log(
`getMemers for conversation: ${conversation_id}, participants: ${participants} `,
);
if (participants) {
return res.status(200).json(participants);
} else {
return res.status(500).json({ message: "Failed to get group members" });
}
},
);
initializeSocket(io);
server.listen(PORT, () => {