Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMPROVE] Replace mentionedMessages publication to REST (#15540)
- Loading branch information
1 parent
e37ea63
commit 6eeb30d
Showing
14 changed files
with
182 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom'; | ||
import { Rooms, Messages, Users } from '../../../models/server/raw'; | ||
|
||
export async function findMentionedMessages({ uid, roomId, pagination: { offset, count, sort } }) { | ||
const room = await Rooms.findOneById(roomId); | ||
if (!await canAccessRoomAsync(room, { _id: uid })) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
const user = await Users.findOneById(uid, { fields: { username: 1 } }); | ||
if (!user) { | ||
throw new Error('invalid-user'); | ||
} | ||
|
||
const cursor = await Messages.findVisibleByMentionAndRoomId(user.username, roomId, { | ||
sort: sort || { ts: -1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
|
||
const total = await cursor.count(); | ||
|
||
const messages = await cursor.toArray(); | ||
|
||
return { | ||
messages, | ||
count: messages.length, | ||
offset, | ||
total, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BaseRaw } from './BaseRaw'; | ||
|
||
export class MessagesRaw extends BaseRaw { | ||
findVisibleByMentionAndRoomId(username, rid, options) { | ||
const query = { | ||
_hidden: { $ne: true }, | ||
'mentions.username': username, | ||
rid, | ||
}; | ||
|
||
return this.find(query, options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters