This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.js
53 lines (45 loc) · 1.48 KB
/
chat.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
var express = require('express');
var loginCheck = require('../app/login_check');
var request = require('request');
var api = require('../app/api');
var router = express.Router();
router.get('/', loginCheck, function (req, res, next) {
api.getProfileName(req.user.meta.id, function (profileName) {
res.render('chat.twig', {
title: 'Chat',
showNavBar: true,
name: profileName
});
}, api.createErrorCallback(next));
});
router.get('/send_message', loginCheck, function (req, res) {
api.sendMessage(req, res, req.query.message);
});
router.get('/history', loginCheck, function (req, res) {
if (req.isAuthenticated()) {
request({
url: api.root_url + "messagesForUser?secondsBeforeNow=604800&clientID=" + req.user.meta.id,
method: "POST",
headers: {
"content-type": "application/json",
"apikey": api.key
},
body: {
"matchers": [".*"]
},
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
res.render('chat_history_list.twig', {
chatList: body.reverse()
});
} else {
console.log(error)
}
}
);
} else {
res.send("");
}
});
module.exports = router;