diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index c996af7b10..cb14d9acef 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -486,6 +486,21 @@ accountsController.getChats = function(req, res, next) { return next(err); } + // Remove entries if they were already present as a followed contact + if (res.locals.contacts && res.locals.contacts.length) { + var contactUids = res.locals.contacts.map(function(contact) { + return parseInt(contact.uid, 10); + }); + + chats = chats.filter(function(chatObj) { + if (contactUids.indexOf(parseInt(chatObj.uid, 10)) !== -1) { + return false; + } else { + return true; + } + }); + } + res.render('chats', { meta: res.locals.chatData, chats: chats, diff --git a/src/messaging.js b/src/messaging.js index 2d5b3ea272..035e038c42 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -81,6 +81,7 @@ var db = require('./database'), message.fromUser = self ? userData[0] : userData[1]; message.toUser = self ? userData[1] : userData[0]; message.timestampISO = new Date(parseInt(message.timestamp, 10)).toISOString(); + message.self = self ? 1 : 0; Messaging.parse(message.content, message.fromuid, fromuid, userData[1], userData[0], isNew, function(result) { message.content = result; diff --git a/src/routes/index.js b/src/routes/index.js index ea1ee05ccb..18ba258d06 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -119,8 +119,8 @@ 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); + app.get('/chats', middleware.buildHeader, middleware.authenticate, middleware.chat.getContactList, controllers.accounts.getChats); + app.get('/api/chats', middleware.authenticate, middleware.chat.getContactList, controllers.accounts.getChats); app.get('/chats/:userslug', middleware.buildHeader, middleware.authenticate, middleware.chat.getMetadata, middleware.chat.getContactList, middleware.chat.getMessages, controllers.accounts.getChats); app.get('/api/chats/:userslug', middleware.authenticate, middleware.chat.getMetadata, middleware.chat.getContactList, middleware.chat.getMessages, controllers.accounts.getChats); }