mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
change some socket calls to use the callback, when user changes their email if they are using a gravatar picture it will be updated too, fixed email updating
This commit is contained in:
@@ -195,7 +195,29 @@ var socket,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.alertSuccess = function(message, timeout) {
|
||||||
|
if(!timeout)
|
||||||
|
timeout = 2000;
|
||||||
|
|
||||||
|
app.alert({
|
||||||
|
title: 'Success',
|
||||||
|
message: message,
|
||||||
|
type: 'success',
|
||||||
|
timeout: timeout
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
app.alertError = function(message, timeout) {
|
||||||
|
if(!timeout)
|
||||||
|
timeout = 2000;
|
||||||
|
|
||||||
|
app.alert({
|
||||||
|
title: 'Error',
|
||||||
|
message: message,
|
||||||
|
type: 'error',
|
||||||
|
timeout: timeout
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.current_room = null;
|
app.current_room = null;
|
||||||
app.enter_room = function(room) {
|
app.enter_room = function(room) {
|
||||||
@@ -254,9 +276,8 @@ var socket,
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
app.showLoginMessage = function() {
|
app.showLoginMessage = function() {
|
||||||
if(location.href.indexOf('loggedin') !== -1) {
|
function showAlert() {
|
||||||
app.alert({
|
app.alert({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
title: 'Welcome Back ' + app.username + '!',
|
title: 'Welcome Back ' + app.username + '!',
|
||||||
@@ -264,6 +285,14 @@ var socket,
|
|||||||
timeout: 5000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(location.href.indexOf('loggedin') !== -1) {
|
||||||
|
if(document.readyState !== 'complete') {
|
||||||
|
$(document).ready(showAlert);
|
||||||
|
} else {
|
||||||
|
showAlert();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery('document').ready(function() {
|
jQuery('document').ready(function() {
|
||||||
@@ -272,7 +301,7 @@ var socket,
|
|||||||
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
|
|
||||||
function addTouchEvents() {
|
function addTouchEvents() {
|
||||||
return; // later.
|
return; // later.
|
||||||
|
|
||||||
|
|||||||
@@ -12,23 +12,63 @@
|
|||||||
postcount.html(app.addCommas(postcount.html()));
|
postcount.html(app.addCommas(postcount.html()));
|
||||||
|
|
||||||
var followBtn = $('#follow-btn');
|
var followBtn = $('#follow-btn');
|
||||||
if(yourid === "0") {
|
var unfollowBtn = $('#unfollow-btn');
|
||||||
followBtn.hide();
|
|
||||||
}
|
if(yourid !== theirid) {
|
||||||
else if(yourid !== theirid) {
|
if(isFollowing) {
|
||||||
if(isFollowing)
|
|
||||||
followBtn.hide();
|
followBtn.hide();
|
||||||
else
|
unfollowBtn.show();
|
||||||
|
} else {
|
||||||
followBtn.show();
|
followBtn.show();
|
||||||
|
unfollowBtn.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
followBtn.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
followBtn.on('click', function() {
|
followBtn.on('click', function() {
|
||||||
|
socket.emit('api:user.follow', {uid: theirid}, function(success) {
|
||||||
followBtn.remove();
|
var username = $('.account-username a').html();
|
||||||
socket.emit('api:user.follow', {uid: theirid});
|
if(success) {
|
||||||
|
followBtn.hide();
|
||||||
|
unfollowBtn.show();
|
||||||
|
app.alert({
|
||||||
|
title: 'Following',
|
||||||
|
message: 'You are now following ' + username + '!',
|
||||||
|
type: 'success',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.alert({
|
||||||
|
title: 'Error',
|
||||||
|
message: 'There was an error following' + username + '!',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
unfollowBtn.on('click', function() {
|
||||||
|
socket.emit('api:user.unfollow', {uid: theirid}, function(success) {
|
||||||
|
var username = $('.account-username a').html();
|
||||||
|
if(success) {
|
||||||
|
followBtn.show();
|
||||||
|
unfollowBtn.hide();
|
||||||
|
app.alert({
|
||||||
|
title: 'Unfollowing',
|
||||||
|
message: 'You are no longer following ' + username + '!',
|
||||||
|
type: 'success',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.alert({
|
||||||
|
title: 'Error',
|
||||||
|
message: 'There was an error unfollowing' + username + '!',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,16 @@ $(document).ready(function() {
|
|||||||
type: type
|
type: type
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.emit('api:user.changePicture', userData);
|
socket.emit('api:user.changePicture', userData, function(success) {
|
||||||
|
if(!success) {
|
||||||
|
app.alert({
|
||||||
|
title: 'Error',
|
||||||
|
message: 'There was an error changing picture!',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedImageType = '';
|
var selectedImageType = '';
|
||||||
@@ -102,7 +111,21 @@ $(document).ready(function() {
|
|||||||
signature:$('#inputSignature').val()
|
signature:$('#inputSignature').val()
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.emit('api:user.updateProfile', userData);
|
socket.emit('api:user.updateProfile', userData, function(data) {
|
||||||
|
if(data.success) {
|
||||||
|
app.alertSuccess('Your profile has been updated successfully!');
|
||||||
|
if(data.picture) {
|
||||||
|
$('#user-current-picture').attr('src', data.picture);
|
||||||
|
$('#user_label img').attr('src', data.picture);
|
||||||
|
}
|
||||||
|
if(data.gravatarpicture) {
|
||||||
|
$('#user-gravatar-picture').attr('src', data.gravatarpicture);
|
||||||
|
gravatarPicture = data.gravatarpicture;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
app.alertError('There was an error updating your profile!');
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -231,24 +254,29 @@ $(document).ready(function() {
|
|||||||
password_confirm.on('keyup', onPasswordConfirmChanged);
|
password_confirm.on('keyup', onPasswordConfirmChanged);
|
||||||
|
|
||||||
$('#changePasswordBtn').on('click', function() {
|
$('#changePasswordBtn').on('click', function() {
|
||||||
|
|
||||||
if(passwordvalid && passwordsmatch && currentPassword.val()) {
|
if(passwordvalid && passwordsmatch && currentPassword.val()) {
|
||||||
socket.emit('api:user.changePassword', {
|
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(data) {
|
||||||
'currentPassword': currentPassword.val(),
|
|
||||||
'newPassword': password.val()
|
currentPassword.val('');
|
||||||
|
password.val('');
|
||||||
|
password_confirm.val('');
|
||||||
|
password_notify.html('');
|
||||||
|
password_confirm_notify.html('');
|
||||||
|
passwordsmatch = false;
|
||||||
|
passwordvalid = false;
|
||||||
|
|
||||||
|
if(data.err) {
|
||||||
|
app.alertError(data.err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.alertSuccess('Your password is updated!');
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.changePassword', function(data) {
|
|
||||||
currentPassword.val('');
|
|
||||||
password.val('');
|
|
||||||
password_confirm.val('');
|
|
||||||
password_notify.html('');
|
|
||||||
password_confirm_notify.html('');
|
|
||||||
passwordsmatch = false;
|
|
||||||
passwordvalid = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
});
|
});
|
||||||
@@ -9,7 +9,13 @@ $(document).ready(function() {
|
|||||||
showemail: $('#showemailCheckBox').is(':checked')?1:0
|
showemail: $('#showemailCheckBox').is(':checked')?1:0
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.emit('api:user.saveSettings', settings);
|
socket.emit('api:user.saveSettings', settings, function(success) {
|
||||||
|
if(success) {
|
||||||
|
app.alertSuccess('Settings saved!');
|
||||||
|
} else {
|
||||||
|
app.alertError('There was an error saving settings!');
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,17 +10,34 @@
|
|||||||
$('#no-following-notice').show();
|
$('#no-following-notice').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(yourid !== theirid) {
|
if(yourid !== theirid) {
|
||||||
$('.unfollow-btn').hide();
|
$('.unfollow-btn').hide();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('.unfollow-btn').on('click',function() {
|
$('.unfollow-btn').on('click',function() {
|
||||||
|
var unfollowBtn = $(this);
|
||||||
var removeBtn = $(this);
|
|
||||||
var followingUid = $(this).attr('followingUid');
|
var followingUid = $(this).attr('followingUid');
|
||||||
|
|
||||||
removeBtn.parent().remove();
|
socket.emit('api:user.unfollow', {uid: followingUid}, function(success) {
|
||||||
socket.emit('api:user.unfollow', {uid: followingUid});
|
var username = unfollowBtn.attr('data-username');
|
||||||
|
if(success) {
|
||||||
|
unfollowBtn.parent().remove();
|
||||||
|
app.alert({
|
||||||
|
title: 'Unfollowing',
|
||||||
|
message: 'You are no longer following ' + username + '!',
|
||||||
|
type: 'success',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
app.alert({
|
||||||
|
title: 'Error',
|
||||||
|
message: 'There was an error unfollowing ' + username + '!',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,18 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#mark-allread-btn').on('click', function() {
|
$('#mark-allread-btn').on('click', function() {
|
||||||
socket.emit('api:topics.markAllRead');
|
var btn = $(this);
|
||||||
$(this).remove();
|
socket.emit('api:topics.markAllRead', {} , function(success) {
|
||||||
$('#topics-container').empty();
|
if(success) {
|
||||||
$('#category-no-topics').removeClass('hidden');
|
btn.remove();
|
||||||
|
$('#topics-container').empty();
|
||||||
|
$('#category-no-topics').removeClass('hidden');
|
||||||
|
app.alertSuccess('All topics marked as read!');
|
||||||
|
} else {
|
||||||
|
app.alertError('There was an error marking topics read!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
<span><i class="icon-circle-blank"></i> <span>offline</span></span>
|
<span><i class="icon-circle-blank"></i> <span>offline</span></span>
|
||||||
</div>
|
</div>
|
||||||
<div id="user-actions">
|
<div id="user-actions">
|
||||||
<a id="follow-btn" href="#" class="btn">Follow</a>
|
<a id="follow-btn" href="#" class="btn hide">Follow</a>
|
||||||
|
<a id="unfollow-btn" href="#" class="btn hide">Unfollow</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<!-- BEGIN following -->
|
<!-- BEGIN following -->
|
||||||
|
|
||||||
<div class="users-box">
|
<div class="users-box">
|
||||||
<a href="/users/{following.userslug}">
|
<a href="/users/{following.userslug}">
|
||||||
<img src="{following.picture}" class="img-polaroid"/>
|
<img src="{following.picture}" class="img-polaroid"/>
|
||||||
@@ -34,9 +33,8 @@
|
|||||||
<span class='postcount'>{following.postcount}</span>
|
<span class='postcount'>{following.postcount}</span>
|
||||||
<i class='icon-pencil'></i>
|
<i class='icon-pencil'></i>
|
||||||
</div>
|
</div>
|
||||||
<a id="unfollow-btn" href="#" class="btn unfollow-btn" followingUid="{following.uid}">Unfollow</a>
|
<a id="unfollow-btn" href="#" class="btn unfollow-btn" followingUid="{following.uid}" data-username="{following.username}">Unfollow</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- END following -->
|
<!-- END following -->
|
||||||
</div>
|
</div>
|
||||||
<div id="no-following-notice" class="alert alert-warning hide">This user isn't following anyone :(</div>
|
<div id="no-following-notice" class="alert alert-warning hide">This user isn't following anyone :(</div>
|
||||||
|
|||||||
125
src/user.js
125
src/user.js
@@ -185,9 +185,10 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.updateProfile = function(socket, uid, data) {
|
User.updateProfile = function(uid, data, callback) {
|
||||||
|
|
||||||
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature'];
|
||||||
|
var returnData = {success:false};
|
||||||
|
|
||||||
function isSignatureValid(next) {
|
function isSignatureValid(next) {
|
||||||
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
if(data['signature'] !== undefined && data['signature'].length > 150) {
|
||||||
@@ -198,61 +199,69 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isEmailAvailable(next) {
|
function isEmailAvailable(next) {
|
||||||
if(data['email'] !== undefined) {
|
if(!data['email']) {
|
||||||
User.getUserField(uid, 'email', function(email) {
|
return next(null, true);
|
||||||
if(email !== data['email']) {
|
|
||||||
User.isEmailAvailable(data['email'], function(available) {
|
|
||||||
if(!available) {
|
|
||||||
next({error:'Email not available!'}, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next(null, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next(null, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.getUserField(uid, 'email', function(email) {
|
||||||
|
if(email !== data['email']) {
|
||||||
|
User.isEmailAvailable(data['email'], function(available) {
|
||||||
|
if(!available) {
|
||||||
|
next({error:'Email not available!'}, false);
|
||||||
|
} else {
|
||||||
|
next(null, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next(null, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.series([isSignatureValid, isEmailAvailable], function(err, results) {
|
async.series([isSignatureValid, isEmailAvailable], function(err, results) {
|
||||||
if(err) {
|
if(err) {
|
||||||
socket.emit('event:alert', {
|
console.log(err);
|
||||||
title: 'Error',
|
callback(returnData);
|
||||||
message: err.error,
|
|
||||||
type: 'error',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
updateFields();
|
async.each(fields, updateField, function(err) {
|
||||||
|
if(err) {
|
||||||
|
console.log(err);
|
||||||
|
callback(returnData);
|
||||||
|
} else {
|
||||||
|
returnData.success = true;
|
||||||
|
callback(returnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateFields() {
|
function updateField(field, callback) {
|
||||||
for(var i = 0, key, ii = fields.length; i < ii; ++i) {
|
if(data[field] !== undefined) {
|
||||||
key = fields[i];
|
if(field === 'email') {
|
||||||
|
var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
|
||||||
|
User.setUserField(uid, 'gravatarpicture', gravatarpicture);
|
||||||
|
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(userData) {
|
||||||
|
RDB.del('email:' + userData['email'] + ':uid');
|
||||||
|
RDB.set('email:' + data['email'] + ':uid', uid);
|
||||||
|
User.setUserField(uid, field, data[field]);
|
||||||
|
if(userData.picture !== userData.uploadedpicture) {
|
||||||
|
returnData.picture = gravatarpicture;
|
||||||
|
User.setUserField(uid, 'picture', gravatarpicture);
|
||||||
|
}
|
||||||
|
returnData.gravatarpicture = gravatarpicture;
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} else if(field === 'signature') {
|
||||||
|
data[field] = utils.strip_tags(data[field]);
|
||||||
|
}
|
||||||
|
|
||||||
if(data[key] !== undefined) {
|
User.setUserField(uid, field, data[field]);
|
||||||
if(key === 'email') {
|
|
||||||
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
|
|
||||||
user.getUserField(uid, 'email', function(email) {
|
|
||||||
RDB.del('email:' + email + ':uid');
|
|
||||||
RDB.set('email:' + data['email'] + ':uid', uid);
|
|
||||||
});
|
|
||||||
} else if(key === 'signature') {
|
|
||||||
data[key] = utils.strip_tags(data[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
User.setUserField(uid, key, data[key]);
|
callback(null);
|
||||||
}
|
} else {
|
||||||
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('event:alert', {
|
|
||||||
title: 'Success',
|
|
||||||
message: 'Your profile has been updated successfully!',
|
|
||||||
type: 'success',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,15 +277,9 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.changePassword = function(socket, uid, data, callback) {
|
User.changePassword = function(uid, data, callback) {
|
||||||
if(!utils.isPasswordValid(data.newPassword)) {
|
if(!utils.isPasswordValid(data.newPassword)) {
|
||||||
socket.emit('event:alert', {
|
callback({err:'Invalid password!'});
|
||||||
title: 'Error',
|
|
||||||
message: 'Invalid password!',
|
|
||||||
type: 'error',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
callback(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +287,7 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
bcrypt.compare(data.currentPassword, user_password, function(err, res) {
|
bcrypt.compare(data.currentPassword, user_password, function(err, res) {
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
callback(false);
|
callback({err:'bcrpyt compare error!'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,22 +295,10 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
User.hashPassword(data.newPassword, function(hash) {
|
User.hashPassword(data.newPassword, function(hash) {
|
||||||
User.setUserField(uid, 'password', hash);
|
User.setUserField(uid, 'password', hash);
|
||||||
|
|
||||||
socket.emit('event:alert', {
|
callback({err:null});
|
||||||
title: 'Success',
|
|
||||||
message: 'Your password is updated!',
|
|
||||||
type: 'success',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
callback(true);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
socket.emit('event:alert', {
|
callback({err:'Your current password is not correct!'});
|
||||||
title: 'Warning',
|
|
||||||
message: 'Your current password is not correct!',
|
|
||||||
type: 'warning',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
callback(false);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -247,19 +247,15 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
|||||||
socket.emit('api:user.isOnline', isUserOnline(uid));
|
socket.emit('api:user.isOnline', isUserOnline(uid));
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.changePassword', function(data) {
|
socket.on('api:user.changePassword', function(data, callback) {
|
||||||
user.changePassword(socket, uid, data, function(success) {
|
user.changePassword(uid, data, callback);
|
||||||
if(success) {
|
|
||||||
socket.emit('api:user.changePassword');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.updateProfile', function(data) {
|
socket.on('api:user.updateProfile', function(data, callback) {
|
||||||
user.updateProfile(socket, uid, data);
|
user.updateProfile(uid, data, callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:user.changePicture', function(data) {
|
socket.on('api:user.changePicture', function(data, callback) {
|
||||||
|
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
|
|
||||||
@@ -267,71 +263,43 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
|||||||
user.getUserFields(uid, ['picture'], function(fields) {
|
user.getUserFields(uid, ['picture'], function(fields) {
|
||||||
fields.uid = uid;
|
fields.uid = uid;
|
||||||
socket.emit('api:updateHeader', fields);
|
socket.emit('api:updateHeader', fields);
|
||||||
|
callback(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type === 'gravatar') {
|
if(type === 'gravatar') {
|
||||||
user.getUserField(uid, 'gravatarpicture', function(gravatar) {
|
user.getUserField(uid, 'gravatarpicture', function(gravatar) {
|
||||||
user.setUserField(uid, 'picture', gravatar);
|
user.setUserField(uid, 'picture', gravatar);
|
||||||
updateHeader();
|
updateHeader();
|
||||||
});
|
});
|
||||||
}
|
} else if(type === 'uploaded') {
|
||||||
else if(type === 'uploaded') {
|
|
||||||
user.getUserField(uid, 'uploadedpicture', function(uploadedpicture) {
|
user.getUserField(uid, 'uploadedpicture', function(uploadedpicture) {
|
||||||
user.setUserField(uid, 'picture', uploadedpicture);
|
user.setUserField(uid, 'picture', uploadedpicture);
|
||||||
updateHeader();
|
updateHeader();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
callback(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('api:user.follow', function(data, callback) {
|
||||||
socket.on('api:user.follow', function(data) {
|
|
||||||
if(uid) {
|
if(uid) {
|
||||||
user.follow(uid, data.uid, function(success) {
|
user.follow(uid, data.uid, callback);
|
||||||
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) {
|
socket.on('api:user.unfollow', function(data, callback) {
|
||||||
if(uid) {
|
if(uid) {
|
||||||
user.unfollow(uid, data.uid, function(success) {
|
user.unfollow(uid, data.uid, callback);
|
||||||
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:user.saveSettings', function(data) {
|
socket.on('api:user.saveSettings', function(data, callback) {
|
||||||
if(uid) {
|
if(uid) {
|
||||||
user.setUserFields(uid, {
|
user.setUserFields(uid, {
|
||||||
showemail:data.showemail
|
showemail:data.showemail
|
||||||
});
|
});
|
||||||
|
callback(true);
|
||||||
socket.emit('event:alert', {
|
|
||||||
title: 'Saved',
|
|
||||||
message: 'Settings saved!',
|
|
||||||
type: 'success',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -339,15 +307,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
|||||||
topics.post(socket, uid, data.title, data.content, data.category_id, data.images);
|
topics.post(socket, uid, data.title, data.content, data.category_id, data.images);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('api:topics.markAllRead', function(data) {
|
socket.on('api:topics.markAllRead', function(data, callback) {
|
||||||
topics.markAllRead(uid, function(err, success) {
|
topics.markAllRead(uid, function(err, success) {
|
||||||
if(!err && success) {
|
if(!err && success) {
|
||||||
socket.emit('event:alert', {
|
callback(true);
|
||||||
title: 'Success',
|
} else {
|
||||||
message: 'All topics marked as read!',
|
callback(false);
|
||||||
type: 'success',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user