Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Comment on lines +179 to +182

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this could be moved into a util function, e.g. isTruthy or isParamSet for the scope of APIs. Surely would make this more readable :)

Of course, this can be done in another opportunity as we move on with this important hotfix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, definitely.. this should be standardized and used across the code base 👍

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