changed most of the ajax calls to use sockets

v1.18.x
Baris Usakli 12 years ago
parent 79074fd597
commit 93653e88df

@ -26,13 +26,9 @@
}
followBtn.on('click', function() {
$.post('/users/follow', {uid: theirid, _csrf:$('#csrf_token').val()},
function(data) {
followBtn.remove();
$('#user-action-alert').html('You are now following'+ $('.account-username').text() +'!').show();
}
);
followBtn.remove();
socket.emit('api:user.follow', {uid: theirid});
return false;
});

@ -82,17 +82,10 @@ $(document).ready(function() {
function changeUserPicture(type) {
var userData = {
uid: $('#inputUID').val(),
type: type,
_csrf:$('#csrf_token').val()
type: type
};
$.post('/users/changepicture',
userData,
function(data) {
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
}
);
socket.emit('api:user.changePicture', userData);
}
var selectedImageType = '';

@ -16,16 +16,13 @@
$('.unfollow-btn').hide();
}
else {
$('.unfollow-btn').on('click',function(){
$('.unfollow-btn').on('click',function() {
var removeBtn = $(this);
var followingUid = $(this).attr('followingUid');
$.post('/users/unfollow', {uid: followingUid, _csrf:$('#csrf_token').val()},
function(data) {
removeBtn.parent().remove();
}
);
removeBtn.parent().remove();
socket.emit('api:user.unfollow', {uid: followingUid});
return false;
});
}

@ -47,10 +47,12 @@
var userLabel = rightMenu.find('#user_label');
if(userLabel.length) {
userLabel.attr('href','/users/'+data['userslug']);
userLabel.find('img').attr('src',data['picture']+"?s=24&default=identicon");
userLabel.find('span').html(data['username']);
if(data['userslug'])
userLabel.attr('href','/users/' + data['userslug']);
if(data['picture'])
userLabel.find('img').attr('src',data['picture']+"?s=24&default=identicon");
if(data['username'])
userLabel.find('span').html(data['username']);
}
else {
var userli = $('<li> \

@ -166,52 +166,6 @@ var user = require('./../user.js'),
is.pipe(os);
}
app.post('/users/changepicture', function(req, res){
if(!req.user)
return res.redirect('/403');
if(req.user.uid != req.body.uid)
return res.redirect('/');
var type = req.body.type;
if(type == 'gravatar') {
user.getUserField(req.user.uid, 'gravatarpicture', function(gravatar) {
user.setUserField(req.user.uid, 'picture', gravatar);
});
}
else if(type == 'uploaded') {
user.getUserField(req.user.uid, 'uploadedpicture', function(uploadedpicture) {
user.setUserField(req.user.uid, 'picture', uploadedpicture);
});
}
res.send({});
});
app.post('/users/follow', function(req, res){
if(!req.user)
return res.redirect('/403');
if(req.user.uid == req.body.uid)
return res.redirect('/');
user.follow(req.user.uid, req.body.uid, function(data) {
res.json({ data:data });
});
});
app.post('/users/unfollow', function(req, res){
if(!req.user)
return res.redirect('/403');
if(req.user.uid == req.body.uid)
return res.redirect('/');
user.unfollow(req.user.uid, req.body.uid, function(data) {
res.json({ data:data });
});
});
app.get('/users/:userslug/following', function(req, res) {

@ -464,10 +464,16 @@ var utils = require('./../public/src/utils.js'),
RDB.sadd('following:' + uid, followid, function(err, data) {
if(!err) {
RDB.sadd('followers:' + followid, uid, function(err, data) {
callback(data);
if(!err) {
callback(true);
} else {
console.log(err);
callback(false);
}
});
} else {
console.log(err);
callback(false);
}
});
}

@ -202,6 +202,65 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
user.updateProfile(socket, uid, data);
});
socket.on('api:user.changePicture', function(data) {
var type = data.type;
function updateHeader() {
user.getUserFields(uid, ['picture'], function(fields) {
fields.uid = uid;
socket.emit('api:updateHeader', fields);
});
}
if(type === 'gravatar') {
user.getUserField(uid, 'gravatarpicture', function(gravatar) {
user.setUserField(uid, 'picture', gravatar);
updateHeader();
});
}
else if(type === 'uploaded') {
user.getUserField(uid, 'uploadedpicture', function(uploadedpicture) {
user.setUserField(uid, 'picture', uploadedpicture);
updateHeader();
});
}
});
socket.on('api:user.follow', function(data) {
user.follow(uid, data.uid, function(success) {
if(success) {
user.getUserField(data.uid, 'username', function(username) {
socket.emit('event:alert', {
title: 'Following',
message: 'You are now following ' + username + '!',
type: 'success',
timeout: 2000
});
});
}
});
});
socket.on('api:user.unfollow', function(data) {
user.unfollow(uid, data.uid, function(success) {
if(success) {
user.getUserField(data.uid, 'username', function(username) {
socket.emit('event:alert', {
title: 'Unfollowed',
message: 'You are no longer following ' + username + '!',
type: 'success',
timeout: 2000
});
});
}
});
});
socket.on('api:topics.post', function(data) {
topics.post(socket, uid, data.title, data.content, data.category_id);
});

Loading…
Cancel
Save