mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: deprecate app.openChat/newChat
use chat.openChat/newChat instead
This commit is contained in:
@@ -295,74 +295,16 @@ app.cacheBuster = null;
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.openChat = function (roomId, uid) {
|
app.openChat = function (roomId, uid) {
|
||||||
if (!app.user.uid) {
|
console.warn('[deprecated] app.openChat is deprecated, please use chat.openChat');
|
||||||
return app.alertError('[[error:not-logged-in]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
require(['chat'], function (chat) {
|
require(['chat'], function (chat) {
|
||||||
function loadAndCenter(chatModal) {
|
chat.openChat(roomId, uid);
|
||||||
chat.load(chatModal.attr('data-uuid'));
|
|
||||||
chat.center(chatModal);
|
|
||||||
chat.focusInput(chatModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chat.modalExists(roomId)) {
|
|
||||||
loadAndCenter(chat.getModal(roomId));
|
|
||||||
} else {
|
|
||||||
socket.emit('modules.chats.loadRoom', { roomId: roomId, uid: uid || app.user.uid }, function (err, roomData) {
|
|
||||||
if (err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
roomData.users = roomData.users.filter(function (user) {
|
|
||||||
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
|
|
||||||
});
|
|
||||||
roomData.uid = uid || app.user.uid;
|
|
||||||
roomData.isSelf = true;
|
|
||||||
chat.createModal(roomData, loadAndCenter);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.newChat = function (touid, callback) {
|
app.newChat = function (touid, callback) {
|
||||||
function createChat() {
|
console.warn('[deprecated] app.newChat is deprecated, please use chat.newChat');
|
||||||
socket.emit('modules.chats.newRoom', { touid: touid }, function (err, roomId) {
|
require(['chat'], function (chat) {
|
||||||
if (err) {
|
chat.newChat(touid, callback);
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ajaxify.data.template.chats) {
|
|
||||||
app.openChat(roomId);
|
|
||||||
} else {
|
|
||||||
ajaxify.go('chats/' + roomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(false, roomId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
callback = callback || function () { };
|
|
||||||
if (!app.user.uid) {
|
|
||||||
return app.alertError('[[error:not-logged-in]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parseInt(touid, 10) === parseInt(app.user.uid, 10)) {
|
|
||||||
return app.alertError('[[error:cant-chat-with-yourself]]');
|
|
||||||
}
|
|
||||||
socket.emit('modules.chats.isDnD', touid, function (err, isDnD) {
|
|
||||||
if (err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
if (!isDnD) {
|
|
||||||
return createChat();
|
|
||||||
}
|
|
||||||
require(['bootbox'], function (bootbox) {
|
|
||||||
bootbox.confirm('[[modules:chat.confirm-chat-with-dnd-user]]', function (ok) {
|
|
||||||
if (ok) {
|
|
||||||
createChat();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,21 +32,19 @@ define('forum/account/header', [
|
|||||||
toggleFollow('unfollow');
|
toggleFollow('unfollow');
|
||||||
});
|
});
|
||||||
|
|
||||||
components.get('account/chat').on('click', function () {
|
components.get('account/chat').on('click', async function () {
|
||||||
socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid, function (err, roomId) {
|
const roomId = await socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid);
|
||||||
if (err) {
|
const chat = await app.require('chat');
|
||||||
return app.alertError(err.message);
|
if (roomId) {
|
||||||
}
|
chat.openChat(roomId);
|
||||||
if (roomId) {
|
} else {
|
||||||
app.openChat(roomId);
|
chat.newChat(ajaxify.data.uid);
|
||||||
} else {
|
}
|
||||||
app.newChat(ajaxify.data.uid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
components.get('account/new-chat').on('click', function () {
|
components.get('account/new-chat').on('click', async function () {
|
||||||
app.newChat(ajaxify.data.uid, function () {
|
const chat = await app.require('chat');
|
||||||
|
chat.newChat(ajaxify.data.uid, function () {
|
||||||
components.get('account/chat').parent().removeClass('hidden');
|
components.get('account/chat').parent().removeClass('hidden');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ define('forum/chats', [
|
|||||||
'forum/chats/recent',
|
'forum/chats/recent',
|
||||||
'forum/chats/search',
|
'forum/chats/search',
|
||||||
'forum/chats/messages',
|
'forum/chats/messages',
|
||||||
'benchpress',
|
|
||||||
'composer/autocomplete',
|
'composer/autocomplete',
|
||||||
'hooks',
|
'hooks',
|
||||||
'bootbox',
|
'bootbox',
|
||||||
|
'chat',
|
||||||
], function (
|
], function (
|
||||||
components, translator, mousetrap,
|
components, translator, mousetrap,
|
||||||
recentChats, search, messages, Benchpress,
|
recentChats, search, messages,
|
||||||
autocomplete, hooks, bootbox
|
autocomplete, hooks, bootbox, chatModule
|
||||||
) {
|
) {
|
||||||
const Chats = {
|
const Chats = {
|
||||||
initialised: false,
|
initialised: false,
|
||||||
@@ -93,11 +93,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, ajaxify.data.uid);
|
chatModule.openChat(roomId, ajaxify.data.uid);
|
||||||
}, true);
|
}, true);
|
||||||
} else {
|
} else {
|
||||||
window.history.go(-1);
|
window.history.go(-1);
|
||||||
app.openChat(roomId, ajaxify.data.uid);
|
chatModule.openChat(roomId, ajaxify.data.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).one('action:chat.loaded', function () {
|
$(window).one('action:chat.loaded', function () {
|
||||||
@@ -294,9 +294,7 @@ define('forum/chats', [
|
|||||||
// Return user to chats page. If modal, close modal.
|
// Return user to chats page. If modal, close modal.
|
||||||
const modal = buttonEl.parents('.chat-modal');
|
const modal = buttonEl.parents('.chat-modal');
|
||||||
if (modal.length) {
|
if (modal.length) {
|
||||||
require(['chat'], function (chatLib) {
|
chatModule.close(modal);
|
||||||
chatLib.close(modal);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
ajaxify.go('chats');
|
ajaxify.go('chats');
|
||||||
}
|
}
|
||||||
@@ -408,12 +406,11 @@ define('forum/chats', [
|
|||||||
} else {
|
} else {
|
||||||
el.remove();
|
el.remove();
|
||||||
}
|
}
|
||||||
require(['chat'], function (chat) {
|
|
||||||
const modal = chat.getModal(roomId);
|
const modal = chatModule.getModal(roomId);
|
||||||
if (modal.length) {
|
if (modal.length) {
|
||||||
chat.close(modal);
|
chatModule.close(modal);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,9 @@ define('forum/chats/search', ['components', 'api'], function (components, api) {
|
|||||||
chats.switchChat(roomId);
|
chats.switchChat(roomId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
app.newChat(userObj.uid);
|
require(['chat'], function (chat) {
|
||||||
|
chat.newChat(userObj.uid);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api', 'bootbox'], function (FlagsList, components, translator, Benchpress, AccountHeader, AccountsDelete, api, bootbox) {
|
define('forum/flags/detail', [
|
||||||
|
'components', 'translator', 'benchpress', 'forum/account/header', 'accounts/delete', 'api', 'bootbox',
|
||||||
|
], function (components, translator, Benchpress, AccountHeader, AccountsDelete, api, bootbox) {
|
||||||
const Detail = {};
|
const Detail = {};
|
||||||
|
|
||||||
Detail.init = function () {
|
Detail.init = function () {
|
||||||
@@ -59,7 +61,9 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'chat':
|
case 'chat':
|
||||||
app.newChat(uid);
|
require(['chat'], function (chat) {
|
||||||
|
chat.newChat(uid);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ban':
|
case 'ban':
|
||||||
|
|||||||
@@ -420,8 +420,9 @@ define('forum/topic/postTools', [
|
|||||||
|
|
||||||
function openChat(button) {
|
function openChat(button) {
|
||||||
const post = button.parents('[data-pid]');
|
const post = button.parents('[data-pid]');
|
||||||
|
require(['chat'], function (chat) {
|
||||||
app.newChat(post.attr('data-uid'));
|
chat.newChat(post.attr('data-uid'));
|
||||||
|
});
|
||||||
button.parents('.btn-group').find('.dropdown-toggle').click();
|
button.parents('.btn-group').find('.dropdown-toggle').click();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,80 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
define('chat', [
|
define('chat', [
|
||||||
'components',
|
'components', 'taskbar', 'translator', 'hooks', 'bootbox',
|
||||||
'taskbar',
|
], function (components, taskbar, translator, hooks, bootbox) {
|
||||||
'translator',
|
|
||||||
'hooks',
|
|
||||||
], function (components, taskbar, translator, hooks) {
|
|
||||||
const module = {};
|
const module = {};
|
||||||
let newMessage = false;
|
let newMessage = false;
|
||||||
|
|
||||||
|
module.openChat = function (roomId, uid) {
|
||||||
|
if (!app.user.uid) {
|
||||||
|
return app.alertError('[[error:not-logged-in]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadAndCenter(chatModal) {
|
||||||
|
module.load(chatModal.attr('data-uuid'));
|
||||||
|
module.center(chatModal);
|
||||||
|
module.focusInput(chatModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (module.modalExists(roomId)) {
|
||||||
|
loadAndCenter(module.getModal(roomId));
|
||||||
|
} else {
|
||||||
|
socket.emit('modules.chats.loadRoom', { roomId: roomId, uid: uid || app.user.uid }, function (err, roomData) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
roomData.users = roomData.users.filter(function (user) {
|
||||||
|
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
|
||||||
|
});
|
||||||
|
roomData.uid = uid || app.user.uid;
|
||||||
|
roomData.isSelf = true;
|
||||||
|
module.createModal(roomData, loadAndCenter);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.newChat = function (touid, callback) {
|
||||||
|
function createChat() {
|
||||||
|
socket.emit('modules.chats.newRoom', { touid: touid }, function (err, roomId) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ajaxify.data.template.chats) {
|
||||||
|
module.openChat(roomId);
|
||||||
|
} else {
|
||||||
|
ajaxify.go('chats/' + roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, roomId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
callback = callback || function () { };
|
||||||
|
if (!app.user.uid) {
|
||||||
|
return app.alertError('[[error:not-logged-in]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(touid, 10) === parseInt(app.user.uid, 10)) {
|
||||||
|
return app.alertError('[[error:cant-chat-with-yourself]]');
|
||||||
|
}
|
||||||
|
socket.emit('modules.chats.isDnD', touid, function (err, isDnD) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
if (!isDnD) {
|
||||||
|
return createChat();
|
||||||
|
}
|
||||||
|
|
||||||
|
bootbox.confirm('[[modules:chat.confirm-chat-with-dnd-user]]', function (ok) {
|
||||||
|
if (ok) {
|
||||||
|
createChat();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.loadChatsDropdown = function (chatsListEl) {
|
module.loadChatsDropdown = function (chatsListEl) {
|
||||||
socket.emit('modules.chats.getRecentChats', {
|
socket.emit('modules.chats.getRecentChats', {
|
||||||
uid: app.user.uid,
|
uid: app.user.uid,
|
||||||
@@ -37,7 +103,7 @@ define('chat', [
|
|||||||
}
|
}
|
||||||
const roomId = $(this).attr('data-roomid');
|
const roomId = $(this).attr('data-roomid');
|
||||||
if (!ajaxify.currentPage.match(/^chats\//)) {
|
if (!ajaxify.currentPage.match(/^chats\//)) {
|
||||||
app.openChat(roomId);
|
module.openChat(roomId);
|
||||||
} else {
|
} else {
|
||||||
ajaxify.go('user/' + app.user.userslug + '/chats/' + roomId);
|
ajaxify.go('user/' + app.user.userslug + '/chats/' + roomId);
|
||||||
}
|
}
|
||||||
@@ -206,7 +272,7 @@ define('chat', [
|
|||||||
module.minimize(uuid);
|
module.minimize(uuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
chatModal.on('click', ':not(.close)', function () {
|
chatModal.on('mouseup', function () {
|
||||||
taskbar.updateActive(chatModal.attr('data-uuid'));
|
taskbar.updateActive(chatModal.attr('data-uuid'));
|
||||||
|
|
||||||
if (dragged) {
|
if (dragged) {
|
||||||
|
|||||||
Reference in New Issue
Block a user