3 var chatService
= require('gitter-web-chats');
4 var restSerializer
= require('../serializers/rest-serializer');
5 var Promise
= require('bluebird');
7 var cachedSamples
= null;
8 function getSamples() {
9 if (cachedSamples
) return Promise
.resolve(cachedSamples
);
12 .getRecentPublicChats()
13 .then(function(chatMessage
) {
14 // Remove any duplicate users
16 return chatMessage
.filter(function(chatMessage
) {
17 if (users
[chatMessage
.fromUserId
]) {
20 users
[chatMessage
.fromUserId
] = true;
24 .then(function(sampleChatMessages
) {
25 var sampleChatStrategy
= new restSerializer
.SampleChatStrategy();
26 var results
= restSerializer
.serialize(sampleChatMessages
, sampleChatStrategy
);
28 cachedSamples
= results
;
30 // Keep them cached for 30 seconds
31 setTimeout(function() {
40 getSamples
: getSamples