Skip to content

Commit

Permalink
[FIX] Prune messages from particular user(s) (#22506)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Jun 30, 2021
1 parent 44f9f89 commit 39b2362
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
37 changes: 22 additions & 15 deletions app/api/server/v1/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,37 @@ API.v1.addRoute('rooms.cleanHistory', { authRequired: true }, {
post() {
const findResult = findRoomByIdOrName({ params: this.bodyParams });

if (!this.bodyParams.latest) {
const {
latest,
oldest,
inclusive = false,
limit,
excludePinned,
filesOnly,
ignoreThreads,
ignoreDiscussion,
users,
} = this.bodyParams;

if (!latest) {
return API.v1.failure('Body parameter "latest" is required.');
}

if (!this.bodyParams.oldest) {
if (!oldest) {
return API.v1.failure('Body parameter "oldest" is required.');
}

const latest = new Date(this.bodyParams.latest);
const oldest = new Date(this.bodyParams.oldest);

const inclusive = this.bodyParams.inclusive || false;

const count = Meteor.runAsUser(this.userId, () => Meteor.call('cleanRoomHistory', {
roomId: findResult._id,
latest,
oldest,
latest: new Date(latest),
oldest: new Date(oldest),
inclusive,
limit: this.bodyParams.limit,
excludePinned: [true, 'true', 1, '1'].includes(this.bodyParams.excludePinned),
filesOnly: [true, 'true', 1, '1'].includes(this.bodyParams.filesOnly),
ignoreThreads: [true, 'true', 1, '1'].includes(this.bodyParams.ignoreThreads),
ignoreDiscussion: [true, 'true', 1, '1'].includes(this.bodyParams.ignoreDiscussion),
fromUsers: this.bodyParams.users,
limit,
excludePinned: [true, 'true', 1, '1'].includes(excludePinned),
filesOnly: [true, 'true', 1, '1'].includes(filesOnly),
ignoreThreads: [true, 'true', 1, '1'].includes(ignoreThreads),
ignoreDiscussion: [true, 'true', 1, '1'].includes(ignoreDiscussion),
fromUsers: users,
}));

return API.v1.success({ count });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const PruneMessagesWithData = ({ rid, tabBar }) => {
filesOnly: attached,
ignoreDiscussion: discussion,
ignoreThreads: threads,
fromUsers: users,
users,
});

setCounter(count);
Expand Down

0 comments on commit 39b2362

Please sign in to comment.