changes for live streaming of posts

v1.18.x
barisusakli 11 years ago
parent 1e9850b6b9
commit 813b3d6fcc

@ -4,7 +4,8 @@ var socket,
'username': null, 'username': null,
'uid': null, 'uid': null,
'isFocused': true, 'isFocused': true,
'currentRoom': null 'currentRoom': null,
'widgets': {}
}; };
(function () { (function () {

@ -3,23 +3,29 @@
define(function() { define(function() {
var home = {}; var home = {};
$(window).on('action:ajaxify.end', function(ev, data) {
if (data.url === '') {
socket.removeListener('event:new_topic', home.onNewTopic);
socket.removeListener('event:new_post', home.onNewPost);
}
});
home.init = function() { home.init = function() {
app.enterRoom('home'); app.enterRoom('home');
ajaxify.register_events([ socket.on('event:new_topic', home.onNewTopic);
'event:new_topic', socket.on('event:new_post', home.onNewPost);
'event:new_post' };
]);
socket.on('event:new_topic', function(data) { home.onNewTopic = function(data) {
}); };
socket.on('event:new_post', function(data) { home.onNewPost = function(data) {
}); };
}
return home; return home;
}); });

@ -329,7 +329,7 @@ var db = require('./database'),
if(stripTags) { if(stripTags) {
var s = S(content); var s = S(content);
postData.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i'])).s; postData.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i', 'p'])).s;
} else { } else {
postData.content = content; postData.content = content;
} }

@ -71,10 +71,7 @@ SocketPosts.reply = function(socket, data, callback) {
posts: [postData] posts: [postData]
}; };
var rooms = ['recent_posts', 'home', 'topic_' + postData.tid, 'user/' + postData.uid]; index.server.sockets.emit('event:new_post', socketData);
rooms.forEach(function(room) {
index.server.sockets.in(room).emit('event:new_post', socketData);
});
callback(); callback();
} }
@ -326,4 +323,9 @@ SocketPosts.loadMoreUserPosts = function(socket, data, callback) {
posts.getPostsByUid(socket.uid, data.uid, start, end, callback); posts.getPostsByUid(socket.uid, data.uid, start, end, callback);
}; };
SocketPosts.getRecentPosts = function(socket, term, callback) {
posts.getRecentPosts(socket.uid, 0, 19, term, callback);
};
module.exports = SocketPosts; module.exports = SocketPosts;

@ -3,7 +3,7 @@ var winston = require('winston');
var SocketTools = {}; var SocketTools = {};
SocketTools.log = function(socket, data, callback) { SocketTools.log = function(socket, data, callback) {
winston.info("captured console.log:", data) //winston.info("captured console.log:", data)
}; };
module.exports = SocketTools; module.exports = SocketTools;

@ -61,6 +61,9 @@ SocketTopics.post = function(socket, data, callback) {
index.server.sockets.in('category_' + data.category_id).emit('event:new_topic', result.topicData); index.server.sockets.in('category_' + data.category_id).emit('event:new_topic', result.topicData);
index.server.sockets.in('recent_posts').emit('event:new_topic', result.topicData); index.server.sockets.in('recent_posts').emit('event:new_topic', result.topicData);
index.server.sockets.in('home').emit('event:new_topic', result.topicData); index.server.sockets.in('home').emit('event:new_topic', result.topicData);
index.server.sockets.in('home').emit('event:new_post', {
posts: result.postData
});
index.server.sockets.in('user/' + socket.uid).emit('event:new_post', { index.server.sockets.in('user/' + socket.uid).emit('event:new_post', {
posts: result.postData posts: result.postData
}); });

Loading…
Cancel
Save