3 const Promise = require('bluebird');
4 const UserIdStrategy = require('./user-id-strategy');
5 const ChatIdStrategy = require('./chat-id-strategy');
7 function ChatMessageReportStrategy() {
8 const userIdStategy = new UserIdStrategy();
9 const chatIdStategy = new ChatIdStrategy({
10 serializeToTroupeId: true
13 this.preload = function(chatMessageReports) {
14 // We can't use a `Array.reduce` because there is some magic `Sequence` methods expected that would get stripped :shrug:
15 const reporterUserIds = chatMessageReports.map(report => report.reporterUserId);
16 const messageUserIds = chatMessageReports.map(report => report.messageUserId);
18 const chatIds = chatMessageReports.map(report => report.messageId);
21 userIdStategy.preload(reporterUserIds.concat(messageUserIds)),
22 chatIdStategy.preload(chatIds)
25 return Promise.all(strategies);
28 this.map = function(report) {
29 const reporterUser = userIdStategy.map(report.reporterUserId);
30 const messageUser = userIdStategy.map(report.messageUserId);
32 const message = chatIdStategy.map(report.messageId);
37 weight: report.weight,
38 // Included because the `messageUser` may have been deleted
39 reporterUserId: report.reporterUserId,
40 reporterUser: reporterUser,
41 messageId: report.messageId,
42 // Included because the `messageUser` may have been deleted
43 messageUserId: report.messageUserId,
44 messageUser: messageUser,
45 // messageText contains the text when the report was made
46 // which may differ from the current message
47 messageText: report.text,
52 ChatMessageReportStrategy.prototype = {
53 name: 'ChatMessageReportStrategy'
56 module.exports = ChatMessageReportStrategy;