Skip to content

Commit

Permalink
added app.delete /:app_id/:group_id/conversations/timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Sponziello committed Feb 13, 2024
1 parent 3411afc commit 45b015c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
17 changes: 17 additions & 0 deletions chat21Api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ class Chat21Api {
});
}

/** removes all conversations with this ConversWith. Used when a group is removed and you want to
* remove all the old conversations belonging to this group, on all users timelines
*/
removeAllConversWithConversations(app_id, convers_with, callback) {
// NOTE! THIS ARRIVES DIRECTLY ON THE CLIENT! REFACTOR WITH SOME "OBSERVER.APPS....ARCHIVE" TOPIC
this.chatdb.deleteConversationsByConversWith(convers_with, function (err, doc) {
if (err) {
logger.error("Error deleting conversatios:", err);
callback(err);
return
}
else {
callback(null);
}
});
}

// createGroup(group, callback) {
// // 1. create group json
// // 2. save group json in mongodb
Expand Down
15 changes: 15 additions & 0 deletions chatdb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ class ChatDB {
});
}

deleteConversationsByConversWith(app_id, convers_with, callback) {
this.db.collection(this.instances_collection).deleteMany({app_id: app_id, conversWith: convers_with}, function(err, obj) {
if (err) {
if (callback) {
callback(err, null);
}
}
else {
if (callback) {
callback(null, obj);
}
}
});
}

}

module.exports = { ChatDB };
31 changes: 29 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,35 @@ app.get(BASEURL + "/:appid/:userid/conversations/archived", (req, res) => {
}
res.status(200).json(reply)
}
})
})
});
});

/** Delete all conversations from all timelines belonging to a group */
app.delete(BASEURL + '/:app_id/:group_id/conversations/timelines', async (req, res) => {
// app.delete('/groups/:group_id/members/:member_id', (req, res) => {
logger.debug('HTTP: Delete all conversations from all timelines belonging to a group');
if (!req.params.group_id) {
res.status(405).send('group_id is mandatory');
return
}
else if (!req.params.app_id) {
res.status(405).send('app_id is mandatory');
return
}
let group_id = req.params.group_id;
let app_id = req.params.app_id;
const user = req.user
logger.debug('app_id:' + app_id);
logger.debug('group_id:' + group_id);
chatapi.removeAllConversWithConversations(app_id, group_id, function(err) {
if (err) {
res.status(405).send(err)
}
else {
res.status(200).send({success: true})
}
});
});

function authorize(req, res) {
const appid = req.params.appid
Expand Down

0 comments on commit 45b015c

Please sign in to comment.