v1.18.x
barisusakli 9 years ago
parent a133374c0b
commit cb91587567

@ -1,5 +1,5 @@
'use strict';
/* globals define, app, ajaxify, socket, RELATIVE_PATH */
/* globals define, app, config, ajaxify, socket, bootbox, translator */
define('forum/account/header', [
'coverPhoto',
@ -30,7 +30,16 @@ define('forum/account/header', [
});
components.get('account/chat').on('click', function() {
app.newChat(theirid);
socket.emit('modules.chats.hasPrivateChat', theirid, function(err, roomId) {
if (err) {
return app.alertError(err.message);
}
if (roomId) {
app.openChat(roomId);
} else {
app.newChat(theirid);
}
});
});
components.get('account/ban').on('click', banAccount);
@ -65,7 +74,7 @@ define('forum/account/header', [
}, callback);
},
function() {
uploader.open(RELATIVE_PATH + '/api/user/' + ajaxify.data.userslug + '/uploadcover', { uid: yourid }, 0, function(imageUrlOnServer) {
uploader.open(config.RELATIVE_PATH + '/api/user/' + ajaxify.data.userslug + '/uploadcover', { uid: yourid }, 0, function(imageUrlOnServer) {
components.get('account/cover').css('background-image', 'url(' + imageUrlOnServer + '?v=' + Date.now() + ')');
});
},

@ -384,5 +384,44 @@ var async = require('async'),
], callback);
};
Messaging.hasPrivateChat = function(uid, withUid, callback) {
async.waterfall([
function (next) {
async.parallel({
myRooms: async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':chat:rooms', 0, -1),
theirRooms: async.apply(db.getSortedSetRevRange, 'uid:' + withUid + ':chat:rooms', 0, -1)
}, next);
},
function (results, next) {
var roomIds = results.myRooms.filter(function(roomId) {
return roomId && results.theirRooms.indexOf(roomId) !== -1;
});
if (!roomIds.length) {
return callback();
}
var index = 0;
var roomId = 0;
async.whilst(function() {
return index < roomIds.length && !roomId;
}, function(next) {
Messaging.getUserCountInRoom(roomIds[index], function(err, count) {
if (err) {
return next(err);
}
if (count === 2) {
roomId = roomIds[index];
next(null, roomId);
} else {
++ index;
next();
}
});
}, next);
}
], callback);
};
}(exports));

@ -294,6 +294,12 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, start, stop, callback);
};
SocketModules.chats.hasPrivateChat = function(socket, uid, callback) {
if (!socket.uid || !uid) {
return callback(null, new Error('[[error:invalid-data]]'));
}
Messaging.hasPrivateChat(socket.uid, uid, callback);
};
/* Sounds */
SocketModules.sounds.getSounds = function(socket, data, callback) {

Loading…
Cancel
Save