Skip to content

Commit

Permalink
[FIX] Prune messages not removing thumbnails (#26443)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoPierdona authored Aug 17, 2022
1 parent dc0510f commit f28db32
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/meteor/app/lib/server/functions/cleanRoomHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export const cleanRoomHistory = function ({

let fileCount = 0;
Messages.findFilesByRoomIdPinnedTimestampAndUsers(rid, excludePinned, ignoreDiscussion, ts, fromUsers, ignoreThreads, {
fields: { 'file._id': 1, 'pinned': 1 },
fields: { pinned: 1, files: 1 },
limit,
}).forEach((document: IMessage) => {
FileUpload.getStore('Uploads').deleteById(document.file?._id);
const uploadsStore = FileUpload.getStore('Uploads');

document.files?.forEach((file) => uploadsStore.deleteById(file._id));
fileCount++;
if (filesOnly) {
Messages.update({ _id: document._id }, { $unset: { file: 1 }, $set: { attachments: [{ color: '#FD745E', text }] } });
Expand Down
45 changes: 45 additions & 0 deletions apps/meteor/tests/end-to-end/api/09-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,51 @@ describe('[Rooms]', function () {
})
.end(done);
});
it('should successfully delete an image and thumbnail from public channel', (done) => {
request
.post(api(`rooms.upload/${publicChannel._id}`))
.set(credentials)
.attach('file', imgURL)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
const { message } = res.body;
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('message._id', message._id);
expect(res.body).to.have.nested.property('message.rid', publicChannel._id);
expect(res.body).to.have.nested.property('message.file._id', message.file._id);
expect(res.body).to.have.nested.property('message.file.type', message.file.type);
});

request
.post(api('rooms.cleanHistory'))
.set(credentials)
.send({
roomId: publicChannel._id,
latest: '9999-12-31T23:59:59.000Z',
oldest: '0001-01-01T00:00:00.000Z',
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});

request
.get(api('channels.files'))
.set(credentials)
.query({
roomId: publicChannel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('files').and.to.be.an('array');
expect(res.body.files).to.have.lengthOf(0);
})
.end(done);
});
it('should return success when send a valid private channel', (done) => {
request
.post(api('rooms.cleanHistory'))
Expand Down

0 comments on commit f28db32

Please sign in to comment.