This repository was archived by the owner on Oct 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathchatPanel.js
54 lines (43 loc) · 2.02 KB
/
chatPanel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
angular.module('chatApp.chatPanel', ['chatApp.chatMessages'])
.controller('chatPanelCtrl', function($scope, $rootScope, $resource, $timeout) {
$rootScope.$on("chatting", function() {
var Messages = $resource(MESSAGES_ENDPOINT);
var poll = function()
{
$timeout(function() {
if($rootScope.chatting)
{
console.log('Retrieving Messages from Server');
var apigClient = apigClientFactory.newClient({
region: AWS_REGION, // OPTIONAL: The region where the API is deployed, by default this parameter is set to us-east-1
accessKey: AWS.config.credentials.accessKeyId,
secretKey: AWS.config.credentials.secretAccessKey,
sessionToken: AWS.config.credentials.sessionToken
});
var body = '';
var params = '';
var additionalParams = '';
apigClient.zombieMessageGet(params, body, additionalParams)
.then(function(result){
if($rootScope.chatting) {
result.data.messages.forEach(element => {
element.message = unescape(element.message);
});
$scope.messages = result.data.messages;
} else {
$scope.messages = null;
}
}).catch(function(result){
console.log('error: ' + result);
});
poll();
}
}, 2000);
};
poll();
});
$rootScope.$on("not chatting", function() {
//clear our model, which will clear out the messages from the panel
$scope.messages = null;
});
});