send notification to refresh contacts list on adding member to group
This commit is contained in:
@@ -192,10 +192,11 @@ async function createGroup(user_id, groupname) {
|
||||
const result = await client.query(query, [groupname]);
|
||||
const group_id = result.rows[0].group_id;
|
||||
|
||||
await addMemberToGroup(group_id, user_id);
|
||||
return group_id;
|
||||
const contact_user_id = await addMemberToGroup(group_id, user_id);
|
||||
return { group_id, contact_user_id };
|
||||
} catch (e) {
|
||||
console.error("Failed to create conversation ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +211,10 @@ async function addMemberToGroup(conversation_id, user_id) {
|
||||
console.log(
|
||||
`Added user_id ${user_id} to conversation_id ${conversation_id}`,
|
||||
);
|
||||
return user_id;
|
||||
} catch (e) {
|
||||
console.error("Failed to add member to group ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,10 +340,11 @@ app.post("/api/chat/groups/create", authorizeUser, async (req, res) => {
|
||||
if (!groupname) {
|
||||
return res.status(400).json({ message: "Groupname not provided" });
|
||||
}
|
||||
const group_id = await createGroup(user_id, groupname);
|
||||
const { group_id, contact_user_id } = await createGroup(user_id, groupname);
|
||||
if (!group_id) {
|
||||
return res.status(500).json({ message: "Failed to create group" });
|
||||
}
|
||||
io.to(contact_user_id).emit("added to group");
|
||||
return res.status(200).json({
|
||||
message: `Successfully created group: ${groupname}`,
|
||||
group_id: group_id,
|
||||
@@ -361,6 +362,8 @@ app.post("/api/chat/groups/addMember", async (req, res) => {
|
||||
}
|
||||
const result = await addMemberToGroupByUsername(group_id, username);
|
||||
if (result !== null) {
|
||||
io.to(result).emit("added to group");
|
||||
console.log("added to group: ", result);
|
||||
return res.status(200).json({ message: "Successfully added member" });
|
||||
}
|
||||
res.status(500).json({ message: "Failed to add member" });
|
||||
|
||||
@@ -65,17 +65,11 @@ function initializeSocket(io) {
|
||||
try {
|
||||
const conversations = await getConversationsForUser(socket.user_id);
|
||||
conversations.push(socket.user_id);
|
||||
console.log("join conversations: ", conversations);
|
||||
socket.join(conversations);
|
||||
} catch (e) {
|
||||
console.error("(socket) Failed to get user conversations");
|
||||
}
|
||||
|
||||
socket.on("join socket", (msg) => {
|
||||
socket.join(msg.conversation_id);
|
||||
console.log("joinsocket: ", msg.conversation_id);
|
||||
});
|
||||
|
||||
socket.on("chat message", async (msg, callback) => {
|
||||
const { message, recipient, recipient_id, attachment_url } = msg;
|
||||
const sender = socket.username;
|
||||
|
||||
Reference in New Issue
Block a user