mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-17 00:21:30 +02:00
refactor: redirect to first chat when accessing /chats
add new hook to disable chat modals
This commit is contained in:
@@ -16,21 +16,29 @@ define('chat', [
|
||||
module.center(chatModal);
|
||||
module.focusInput(chatModal);
|
||||
}
|
||||
|
||||
if (module.modalExists(roomId)) {
|
||||
loadAndCenter(module.getModal(roomId));
|
||||
} else {
|
||||
api.get(`/chats/${roomId}`, {
|
||||
uid: uid || app.user.uid,
|
||||
}).then((roomData) => {
|
||||
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);
|
||||
}).catch(alerts.error);
|
||||
}
|
||||
hooks.fire('filter:chat.openChat', {
|
||||
modal: true,
|
||||
roomId: roomId,
|
||||
uid: uid,
|
||||
}).then((hookData) => {
|
||||
if (!hookData.modal) {
|
||||
return ajaxify.go(`/chats/${roomId}`);
|
||||
}
|
||||
if (module.modalExists(roomId)) {
|
||||
loadAndCenter(module.getModal(roomId));
|
||||
} else {
|
||||
api.get(`/chats/${roomId}`, {
|
||||
uid: uid || app.user.uid,
|
||||
}).then((roomData) => {
|
||||
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);
|
||||
}).catch(alerts.error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.newChat = function (touid, callback) {
|
||||
@@ -122,24 +130,12 @@ define('chat', [
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
module.onChatMessageReceived = function (data) {
|
||||
const isSelf = data.self === 1;
|
||||
data.message.self = data.self;
|
||||
|
||||
newMessage = data.self === 0;
|
||||
if (module.modalExists(data.roomId)) {
|
||||
addMessageToModal(data);
|
||||
} else if (!ajaxify.data.template.chats) {
|
||||
api.get(`/chats/${data.roomId}`, {}).then((roomData) => {
|
||||
roomData.users = roomData.users.filter(function (user) {
|
||||
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
|
||||
});
|
||||
roomData.silent = true;
|
||||
roomData.uid = app.user.uid;
|
||||
roomData.isSelf = isSelf;
|
||||
module.createModal(roomData);
|
||||
}).catch(alerts.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ chatsController.get = async function (req, res, next) {
|
||||
}
|
||||
|
||||
if (!req.params.roomid) {
|
||||
if (recentChats.rooms.length && recentChats.rooms[0]) {
|
||||
return helpers.redirect(res, `/user/${req.params.userslug}/chats/${recentChats.rooms[0].roomId}`);
|
||||
}
|
||||
return res.render('chats', {
|
||||
rooms: recentChats.rooms,
|
||||
uid: uid,
|
||||
|
||||
Reference in New Issue
Block a user