v1.18.x
barisusakli 8 years ago
parent 3a50c46572
commit a93ee97926

@ -266,7 +266,7 @@ app.cacheBuster = null;
} }
}; };
app.openChat = function (roomId) { app.openChat = function (roomId, uid) {
if (!app.user.uid) { if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]'); return app.alertError('[[error:not-logged-in]]');
} }
@ -288,6 +288,7 @@ app.cacheBuster = null;
roomData.users = roomData.users.filter(function(user) { roomData.users = roomData.users.filter(function(user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10); return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
}); });
roomData.uid = uid || app.user.uid;
chat.createModal(roomData, loadAndCenter); chat.createModal(roomData, loadAndCenter);
}); });
} }

@ -63,11 +63,11 @@ define('forum/chats', [
if (app.previousUrl && app.previousUrl.match(/chats/)) { if (app.previousUrl && app.previousUrl.match(/chats/)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats', function() { ajaxify.go('user/' + ajaxify.data.userslug + '/chats', function() {
app.openChat(roomId); app.openChat(roomId, ajaxify.data.uid);
}, true); }, true);
} else { } else {
window.history.go(-1); window.history.go(-1);
app.openChat(roomId); app.openChat(roomId, ajaxify.data.uid);
} }
$(window).one('action:chat.loaded', function() { $(window).one('action:chat.loaded', function() {
@ -79,7 +79,7 @@ define('forum/chats', [
recentChats.init(); recentChats.init();
Chats.addSinceHandler(ajaxify.data.roomId, $('.expanded-chat .chat-content'), $('.expanded-chat [data-since]')); Chats.addSinceHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.expanded-chat .chat-content'), $('.expanded-chat [data-since]'));
Chats.addRenameHandler(ajaxify.data.roomId, $('[component="chat/room/name"]')); Chats.addRenameHandler(ajaxify.data.roomId, $('[component="chat/room/name"]'));
Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content')); Chats.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content'));
}; };
@ -96,8 +96,8 @@ define('forum/chats', [
return; return;
} }
loading = true; loading = true;
var start = parseInt($('.chat-content').children('[data-index]').first().attr('data-index'), 10) + 1;
socket.emit('modules.chats.getMessages', {roomId: roomId, uid: uid, start: $('.chat-content').children('[data-index]').first().attr('data-index')}, function(err, data) { socket.emit('modules.chats.getMessages', {roomId: roomId, uid: uid, start: start}, function(err, data) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
@ -156,12 +156,12 @@ define('forum/chats', [
}); });
}; };
Chats.addSinceHandler = function(roomId, chatContentEl, sinceEl) { Chats.addSinceHandler = function(roomId, uid, chatContentEl, sinceEl) {
sinceEl.on('click', function() { sinceEl.on('click', function() {
var since = $(this).attr('data-since'); var since = $(this).attr('data-since');
sinceEl.removeClass('selected'); sinceEl.removeClass('selected');
$(this).addClass('selected'); $(this).addClass('selected');
Chats.loadChatSince(roomId, chatContentEl, since); Chats.loadChatSince(roomId, uid, chatContentEl, since);
return false; return false;
}); });
}; };
@ -301,11 +301,11 @@ define('forum/chats', [
ajaxify.go('user/' + ajaxify.data.userslug + '/chats/' + roomid); ajaxify.go('user/' + ajaxify.data.userslug + '/chats/' + roomid);
}; };
Chats.loadChatSince = function(roomId, chatContentEl, since) { Chats.loadChatSince = function(roomId, uid, chatContentEl, since) {
if (!roomId) { if (!roomId) {
return; return;
} }
socket.emit('modules.chats.get', {roomId: roomId, since: since}, function(err, messageData) { socket.emit('modules.chats.getMessages', {roomId: roomId, uid: uid, since: since, markRead: true}, function(err, messageData) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -83,6 +83,7 @@ define('chat', [
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10); return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
}); });
roomData.silent = true; roomData.silent = true;
roomData.uid = app.user.uid;
module.createModal(roomData, function(modal) { module.createModal(roomData, function(modal) {
module.toggleNew(modal.attr('UUID'), !isSelf, true); module.toggleNew(modal.attr('UUID'), !isSelf, true);
if (!isSelf) { if (!isSelf) {
@ -254,7 +255,7 @@ define('chat', [
messagesEl.css('height', module.calculateChatListHeight(chatModal)); messagesEl.css('height', module.calculateChatListHeight(chatModal));
}); });
Chats.addSinceHandler(chatModal.attr('roomId'), chatModal.find('.chat-content'), chatModal.find('[data-since]')); Chats.addSinceHandler(chatModal.attr('roomId'), data.uid, chatModal.find('.chat-content'), chatModal.find('[data-since]'));
Chats.addRenameHandler(chatModal.attr('roomId'), chatModal.find('[component="chat/room/name"]')); Chats.addRenameHandler(chatModal.attr('roomId'), chatModal.find('[component="chat/room/name"]'));
Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn')); Chats.addSendHandlers(chatModal.attr('roomId'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn'));
@ -262,9 +263,9 @@ define('chat', [
Chats.createTagsInput(chatModal.find('.users-tag-input'), data); Chats.createTagsInput(chatModal.find('.users-tag-input'), data);
Chats.createAutoComplete(chatModal.find('[component="chat/input"]')); Chats.createAutoComplete(chatModal.find('[component="chat/input"]'));
Chats.loadChatSince(chatModal.attr('roomId'), chatModal.find('.chat-content'), 'recent'); Chats.loadChatSince(chatModal.attr('roomId'), data.uid, chatModal.find('.chat-content'), 'recent');
Chats.addScrollHandler(chatModal.attr('roomId'), app.user.uid, chatModal.find('.chat-content')); Chats.addScrollHandler(chatModal.attr('roomId'), data.uid, chatModal.find('.chat-content'));
checkStatus(chatModal); checkStatus(chatModal);

@ -52,7 +52,7 @@ var async = require('async'),
var uid = params.uid; var uid = params.uid;
var roomId = params.roomId; var roomId = params.roomId;
var since = params.since; var since = params.since;
var isNew = params.isNew; var isNew = params.isNew || false;
var start = params.hasOwnProperty('start') ? params.start : 0; var start = params.hasOwnProperty('start') ? params.start : 0;
var count = params.count || 250; var count = params.count || 250;
var markRead = params.markRead || true; var markRead = params.markRead || true;

@ -19,19 +19,6 @@ var SocketModules = {
/* Chat */ /* Chat */
SocketModules.chats.get = function(socket, data, callback) {
if(!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
Messaging.getMessages({
uid: socket.uid,
roomId: data.roomId,
since: data.since,
isNew: false
}, callback);
};
SocketModules.chats.getRaw = function(socket, data, callback) { SocketModules.chats.getRaw = function(socket, data, callback) {
if (!data || !data.hasOwnProperty('mid')) { if (!data || !data.hasOwnProperty('mid')) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
@ -119,10 +106,13 @@ SocketModules.chats.loadRoom = function(socket, data, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
Messaging.isUserInRoom(socket.uid, data.roomId, next); async.parallel({
inRoom: async.apply(Messaging.isUserInRoom, socket.uid, data.roomId),
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, socket.uid)
}, next);
}, },
function (inRoom, next) { function (results, next) {
if (!inRoom) { if (!results.isAdminOrGlobalMod && !results.inRoom) {
return next(new Error('[[error:not-allowed]]')); return next(new Error('[[error:not-allowed]]'));
} }
@ -321,13 +311,23 @@ SocketModules.chats.getMessages = function(socket, data, callback) {
if (!socket.uid || !data.uid || !data.roomId) { if (!socket.uid || !data.uid || !data.roomId) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var params = { var params = {
uid: data.uid, uid: data.uid,
roomId: data.roomId, roomId: data.roomId,
start: parseInt(data.start, 10) + 1, start: parseInt(data.start, 10) || 0,
count: 50, count: 50,
markRead: false markRead: false
}; };
if (data.hasOwnProperty('since')) {
params.since = data.since;
}
if (data.hasOwnProperty('markRead')) {
params.markRead = data.markRead;
}
if (socket.uid === parseInt(data.uid, 10)) { if (socket.uid === parseInt(data.uid, 10)) {
return Messaging.getMessages(params, callback); return Messaging.getMessages(params, callback);
} }

Loading…
Cancel
Save