Skip to content

Commit

Permalink
fix: self dm is not found with im.messages (RocketChat#29497)
Browse files Browse the repository at this point in the history
Co-authored-by: Matheus Barbosa Silva <36537004+matheusbsilva137@users.noreply.github.com>
Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 22, 2023
1 parent f64b8b5 commit f38211a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-terms-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: self dm is not found with `im.messages`
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export const getRoomByNameOrIdWithOptionToJoin = async ({
});
}

const rid = isObject(roomUser) ? [user._id, roomUser._id].sort().join('') : nameOrId;
room = await Rooms.findOneById(rid);
room = isObject(roomUser)
? await Rooms.findOneDirectRoomContainingAllUserIDs([...new Set([user._id, roomUser._id])])
: await Rooms.findOneById(nameOrId);

// If the room hasn't been found yet, let's try some more
if (!isObject(room)) {
Expand All @@ -55,7 +56,7 @@ export const getRoomByNameOrIdWithOptionToJoin = async ({
}
}

await createDirectMessage([roomUser.username], user._id);
const { rid } = await createDirectMessage([roomUser.username], user._id);

return Rooms.findOneById(rid);
}
Expand Down
18 changes: 18 additions & 0 deletions apps/meteor/tests/end-to-end/api/04-direct-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@ describe('[Direct Messages]', function () {
await testFileUploads('im.files', directMessage, 'invalid-channel');
});

describe('/im.messages', () => {
it('should return all DM messages that were sent to yourself using your username', (done) => {
request
.get(api('im.messages'))
.set(credentials)
.query({
username: adminUsername,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages').and.to.be.an('array');
})
.end(done);
});
});

describe('/im.messages.others', () => {
it('should fail when the endpoint is disabled', (done) => {
updateSetting('API_Enable_Direct_Message_History_EndPoint', false).then(() => {
Expand Down

0 comments on commit f38211a

Please sign in to comment.