mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-04 21:15:55 +01:00
closes #4063
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/* globals define, app, ajaxify, socket, RELATIVE_PATH */
|
/* globals define, app, config, ajaxify, socket, bootbox, translator */
|
||||||
|
|
||||||
define('forum/account/header', [
|
define('forum/account/header', [
|
||||||
'coverPhoto',
|
'coverPhoto',
|
||||||
@@ -30,7 +30,16 @@ define('forum/account/header', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
components.get('account/chat').on('click', function() {
|
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);
|
components.get('account/ban').on('click', banAccount);
|
||||||
@@ -65,7 +74,7 @@ define('forum/account/header', [
|
|||||||
}, callback);
|
}, callback);
|
||||||
},
|
},
|
||||||
function() {
|
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() + ')');
|
components.get('account/cover').css('background-image', 'url(' + imageUrlOnServer + '?v=' + Date.now() + ')');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -384,5 +384,44 @@ var async = require('async'),
|
|||||||
], callback);
|
], 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));
|
}(exports));
|
||||||
|
|||||||
@@ -294,6 +294,12 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {
|
|||||||
Messaging.getRecentChats(socket.uid, start, stop, 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 */
|
/* Sounds */
|
||||||
SocketModules.sounds.getSounds = function(socket, data, callback) {
|
SocketModules.sounds.getSounds = function(socket, data, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user