editing of posts

This commit is contained in:
Julian Lam
2013-05-09 10:20:25 -04:00
parent f218e0f3a7
commit e9a552eab4
6 changed files with 89 additions and 16 deletions

View File

@@ -68,13 +68,11 @@ var RDB = require('./redis.js'),
pid.push(pids[i]);
}
Posts.getFavouritesByPostIDs(pids, current_user, function(fav_data) {
vote_data = fav_data;
generateThread();
});
RDB.multi()
.mget(content)
.mget(uid)
@@ -182,6 +180,7 @@ var RDB = require('./redis.js'),
RDB.set('pid:' + pid + ':uid', uid);
RDB.set('pid:' + pid + ':timestamp', new Date().getTime());
RDB.set('pid:' + pid + ':rep', 0);
RDB.set('pid:' + pid + ':tid', tid);
RDB.incr('tid:' + tid + ':postcount');
@@ -189,7 +188,7 @@ var RDB = require('./redis.js'),
RDB.lpush('uid:' + uid + ':posts', pid);
user.incrementUserFieldBy(uid, 'postcount', 1);
if (callback)
callback(pid);
});
@@ -262,4 +261,17 @@ var RDB = require('./redis.js'),
}(pids[i]))
}
}
Posts.getRawContent = function(pid, socket) {
RDB.get('pid:' + pid + ':content', function(err, raw) {
socket.emit('api:posts.getRawPost', { post: raw });
});
}
Posts.edit = function(pid, content) {
RDB.get('pid:' + pid + ':tid', function(err, tid) {
RDB.set('pid:' + pid + ':content', content);
io.sockets.in('topic_' + tid).emit('event:post_edited', { pid: pid, content: marked(content || '') });
});
}
}(exports));

View File

@@ -36,6 +36,7 @@ var config = require('../config.js'),
// a function I feel should be built in user not sure how baris is tackling this so oppa chicken wrapper here
User.getMultipleUserFields = function(uids, fields, callback) {
console.log(uids);
var uuids = uids.filter(function(value, index, self) {
return self.indexOf(value) === index;
});

View File

@@ -314,6 +314,12 @@ var express = require('express'),
});
}
app.get('/test', function(req, res) {
global.modules.posts.getRawContent(11, function(post) {
res.send(JSON.stringify(post));
});
});
// TODO move user related logic into another file ^^^^^^^^^^^^^^^^^^^^^^^
}(WebServer));

View File

@@ -214,6 +214,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
socket.on('api:topic.move', function(data) {
modules.topics.move(data.tid, data.cid, socket);
});
socket.on('api:posts.getRawPost', function(data) {
modules.posts.getRawContent(data.pid, socket);
});
socket.on('api:posts.edit', function(data) {
modules.posts.edit(data.pid, data.content);
});
});
}(SocketIO));