[IMPROVE] Replace mentionedMessages publication to REST (#15540)
parent
e37ea635a8
commit
6eeb30da89
@ -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, |
||||
}; |
||||
} |
@ -1,3 +0,0 @@ |
||||
import { Mongo } from 'meteor/mongo'; |
||||
|
||||
export const MentionedMessage = new Mongo.Collection('rocketchat_mentioned_message'); |
@ -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); |
||||
} |
||||
} |
Loading…
Reference in new issue