'use strict'; var topics = require('../topics'), categories = require('../categories'), privileges = require('../privileges'), threadTools = require('../threadTools'), websockets = require('./index'), user = require('../user'), db = require('./../database'), meta = require('./../meta'), utils = require('../../public/src/utils'), async = require('async'), SocketTopics = {}; SocketTopics.post = function(socket, data, callback) { if(!data) { return callback(new Error('[[error:invalid-data]]')); } topics.post({ uid: socket.uid, title: data.title, content: data.content, cid: data.category_id, thumb: data.topic_thumb, tags: data.tags, req: websockets.reqFromSocket(socket) }, function(err, result) { if(err) { return callback(err); } if (result) { websockets.server.sockets.in('category_' + data.category_id).emit('event:new_topic', result.topicData); websockets.server.sockets.in('recent_posts').emit('event:new_topic', result.topicData); websockets.server.sockets.in('home').emit('event:new_topic', result.topicData); websockets.server.sockets.in('home').emit('event:new_post', { posts: result.postData }); websockets.server.sockets.in('user/' + socket.uid).emit('event:new_post', { posts: result.postData }); module.parent.exports.emitTopicPostStats(); topics.pushUnreadCount(); callback(null, result.topicData); } }); }; SocketTopics.postcount = function(socket, tid, callback) { topics.getTopicField(tid, 'postcount', callback); }; SocketTopics.lastPostIndex = function(socket, tid, callback) { db.sortedSetCard('tid:' + tid + ':posts', callback); }; SocketTopics.increaseViewCount = function(socket, tid) { topics.increaseViewCount(tid); }; SocketTopics.markAsRead = function(socket, tid) { if(!tid || !socket.uid) { return; } topics.markAsRead(tid, socket.uid, function(err) { topics.pushUnreadCount(socket.uid); topics.markTopicNotificationsRead(tid, socket.uid); }); }; SocketTopics.markTidsRead = function(socket, tids, callback) { if (!Array.isArray(tids)) { return callback(new Error('[[error:invalid-data]]')); } topics.markTidsRead(socket.uid, tids, function(err) { if(err) { return callback(err); } topics.pushUnreadCount(socket.uid); for (var i=0; i