Node.js based forum software built for the modern web
closes #1445
barisusaklic5d9a68b4bb9
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.jsonindex 90ad8c6546..b1d1903a79 100644--- a/public/language/en_GB/modules.json+++ b/public/language/en_GB/modules.json@@ -4,5 +4,6 @@"chat.send": "Send","chat.no_active": "You have no active chats.","chat.user_typing": "%1 is typing ...",- "chat.user_has_messaged_you": "%1 has messaged you."+ "chat.user_has_messaged_you": "%1 has messaged you.",+ "chat.see_all": "See all Chats"}\ No newline at end of filediff --git a/public/src/forum/chats.js b/public/src/forum/chats.jsnew file mode 100644index 0000000000..58a758d031--- /dev/null+++ b/public/src/forum/chats.js@@ -0,0 +1,16 @@+'use strict';++/* globals define, app*/++define(function() {+ var Chats = {};++ Chats.init = function() {++ $('.chats-list').on('click', 'li', function(e) {+ app.openChat($(this).attr('data-username'), $(this).attr('data-uid'));+ });+ };++ return Chats;+});diff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex 93c2c93f7a..e68130519f 100644--- a/public/src/modules/chat.js+++ b/public/src/modules/chat.js@@ -47,6 +47,11 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {userObj.username + '</a>').appendTo(chatsListEl);}++ var seeAll = '<li class="pagelink"><a href="' + config.relative_path + '/chats">[[modules:chat.see_all]]</a></li>';+ translator.translate(seeAll, function(translated) {+ $(translated).appendTo(chatsListEl);+ });});});diff --git a/src/controllers/accounts.js b/src/controllers/accounts.jsindex bb5c6a0e05..dfeee5ae2b 100644--- a/src/controllers/accounts.js+++ b/src/controllers/accounts.js@@ -11,6 +11,7 @@ var fs = require('fs'),user = require('./../user'),posts = require('./../posts'),topics = require('./../topics'),+ messaging = require('../messaging'),postTools = require('../postTools'),utils = require('./../../public/src/utils'),meta = require('./../meta'),@@ -448,7 +449,7 @@ accountsController.uploadPicture = function (req, res, next) {});}- if(err) {+ if (err) {fs.unlink(req.files.userPhoto.path);return res.json({error:err.message});}@@ -487,4 +488,16 @@ accountsController.getNotifications = function(req, res, next) {});};+accountsController.getChats = function(req, res, next) {+ messaging.getRecentChats(req.user.uid, 0, -1, function(err, chats) {+ if (err) {+ return next(err);+ }++ res.render('chats', {+ chats: chats+ });+ });+};+module.exports = accountsController;diff --git a/src/messaging.js b/src/messaging.jsindex 49426d971c..25bdeb9c51 100644--- a/src/messaging.js+++ b/src/messaging.js@@ -121,8 +121,8 @@ var db = require('./database'),});};- Messaging.getRecentChats = function(uid, callback) {- db.getSortedSetRevRange('uid:' + uid + ':chats', 0, 9, function(err, uids) {+ Messaging.getRecentChats = function(uid, start, end, callback) {+ db.getSortedSetRevRange('uid:' + uid + ':chats', start, end, function(err, uids) {if(err) {return callback(err);}diff --git a/src/routes/index.js b/src/routes/index.jsindex 71deb793df..247350d77a 100644--- a/src/routes/index.js+++ b/src/routes/index.js@@ -101,6 +101,9 @@ function accountRoutes(app, middleware, controllers) {app.get('/notifications', middleware.buildHeader, middleware.authenticate, controllers.accounts.getNotifications);app.get('/api/notifications', middleware.authenticate, controllers.accounts.getNotifications);++ app.get('/chats', middleware.buildHeader, middleware.authenticate, controllers.accounts.getChats);+ app.get('/api/chats', middleware.authenticate, controllers.accounts.getChats);}function userRoutes(app, middleware, controllers) {diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 74b5a4c280..2a7159b0da 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -238,7 +238,7 @@ function sendTypingNotification(event, socket, data, callback) {}SocketModules.chats.list = function(socket, data, callback) {- Messaging.getRecentChats(socket.uid, callback);+ Messaging.getRecentChats(socket.uid, 0, 9, callback);};/* Notifications */