MCPcopy Create free account
hub / github.com/async-labs/async / getList

Method getList

api/server/models/Message.ts:148–170  ·  view source on GitHub ↗
({ userId, chatId, batchNumberForMessages, limit })

Source from the content-addressed store, hash-verified

146
147class MessageClass extends mongoose.Model {
148 public static async getList({ userId, chatId, batchNumberForMessages, limit }) {
149 await this.checkPermission({ userId, chatId });
150
151 const filter = { chatId, parentMessageId: null };
152
153 const messages = await this.find(filter)
154 .sort({ createdAt: -1, _id: 1 })
155 .skip((batchNumberForMessages - 1) * limit)
156 .limit(limit)
157 .setOptions({ lean: true });
158
159 // use for...of instead of forEach
160 // forEach does not care about promises from await
161 for (const message of messages) {
162 const threadMessages = await this.find({
163 parentMessageId: message._id.toString(),
164 });
165
166 message.countOfThreadMessages = threadMessages.length;
167 }
168
169 return messages;
170 }
171
172 public static async getListForThread({ userId, chatId, messageId }) {
173 await this.checkPermission({ userId, chatId });

Callers

nothing calls this directly

Calls 1

checkPermissionMethod · 0.95

Tested by

no test coverage detected