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

@ -63,11 +63,11 @@ define('forum/chats', [
if (app.previousUrl && app.previousUrl.match(/chats/)) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats', function() {
app.openChat(roomId);
app.openChat(roomId, ajaxify.data.uid);
}, true);
} else {
window.history.go(-1);
app.openChat(roomId);
app.openChat(roomId, ajaxify.data.uid);
}
$(window).one('action:chat.loaded', function() {
@ -79,7 +79,7 @@ define('forum/chats', [
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.addScrollHandler(ajaxify.data.roomId, ajaxify.data.uid, $('.chat-content'));
};
@ -96,8 +96,8 @@ define('forum/chats', [
return;
}
loading = true;
socket.emit('modules.chats.getMessages', {roomId: roomId, uid: uid, start: $('.chat-content').children('[data-index]').first().attr('data-index')}, function(err, data) {
var start = parseInt($('.chat-content').children('[data-index]').first().attr('data-index'), 10) + 1;
socket.emit('modules.chats.getMessages', {roomId: roomId, uid: uid, start: start}, function(err, data) {
if (err) {
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() {
var since = $(this).attr('data-since');
sinceEl.removeClass('selected');
$(this).addClass('selected');
Chats.loadChatSince(roomId, chatContentEl, since);
Chats.loadChatSince(roomId, uid, chatContentEl, since);
return false;
});
};
@ -301,11 +301,11 @@ define('forum/chats', [
ajaxify.go('user/' + ajaxify.data.userslug + '/chats/' + roomid);
};
Chats.loadChatSince = function(roomId, chatContentEl, since) {
Chats.loadChatSince = function(roomId, uid, chatContentEl, since) {
if (!roomId) {
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) {
return app.alertError(err.message);
}

@ -83,6 +83,7 @@ define('chat', [
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
roomData.silent = true;
roomData.uid = app.user.uid;
module.createModal(roomData, function(modal) {
module.toggleNew(modal.attr('UUID'), !isSelf, true);
if (!isSelf) {
@ -254,7 +255,7 @@ define('chat', [
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.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.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);

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

@ -12,26 +12,13 @@ var server = require('./');
var user = require('../user');
var SocketModules = {
chats: {},
sounds: {},
settings: {}
};
chats: {},
sounds: {},
settings: {}
};
/* 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) {
if (!data || !data.hasOwnProperty('mid')) {
return callback(new Error('[[error:invalid-data]]'));
@ -119,10 +106,13 @@ SocketModules.chats.loadRoom = function(socket, data, callback) {
async.waterfall([
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) {
if (!inRoom) {
function (results, next) {
if (!results.isAdminOrGlobalMod && !results.inRoom) {
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) {
return callback(new Error('[[error:invalid-data]]'));
}
var params = {
uid: data.uid,
roomId: data.roomId,
start: parseInt(data.start, 10) + 1,
start: parseInt(data.start, 10) || 0,
count: 50,
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)) {
return Messaging.getMessages(params, callback);
}

Loading…
Cancel
Save