3 var UserIdStrategy = require('gitter-web-user-serialization/lib/notifications/user-id-strategy');
5 transformVirtualUserIntoMockedFromUser
6 } = require('gitter-web-users/lib/virtual-user-service');
7 const getProfileUrlFromVirtualUser = require('gitter-web-shared/get-profile-url-from-virtual-user');
9 function ChatStrategy(options) {
10 if (!options) options = {};
12 var userStategy = new UserIdStrategy(options);
14 this.preload = function(items) {
15 var users = items.map(function(i) {
19 return userStategy.preload(users);
22 this.map = function(item) {
23 const serializedData = {
28 mentions: item.mentions
31 if (item.virtualUser) {
32 serializedData.virtualUser = {
33 type: item.virtualUser.type,
34 externalId: item.virtualUser.externalId,
35 displayName: item.virtualUser.displayName,
36 avatarUrl: item.virtualUser.avatarUrl,
38 // Used for the templates
39 isMatrix: item.virtualUser.type === 'matrix',
40 profileUrl: getProfileUrlFromVirtualUser(item.virtualUser)
43 serializedData.fromUser = transformVirtualUserIntoMockedFromUser(item.virtualUser);
44 } else if (options.user) {
45 serializedData.fromUser = options.user;
47 serializedData.fromUser = userStategy.map(item.fromUserId);
50 return serializedData;
54 ChatStrategy.prototype = {
58 module.exports = ChatStrategy;