mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-19 19:01:13 +02:00
fix: chatwith message fix
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
"chat.placeholder": "Type chat message here, drag & drop images, press enter to send",
|
||||
"chat.scroll-up-alert": "You are looking at older messages, click here to go to most recent message.",
|
||||
"chat.usernames-and-x-others": "%1 & %2 others",
|
||||
"chat.chat-with-usernames": "Chat with %1",
|
||||
"chat.chat-with-usernames-and-x-others": "Chat with %1 & %2 others",
|
||||
"chat.send": "Send",
|
||||
"chat.no_active": "You have no active chats.",
|
||||
"chat.user_typing": "%1 is typing ...",
|
||||
|
||||
@@ -98,6 +98,8 @@ module.exports = function (Messaging) {
|
||||
} else if (index > 0 && message.fromuid !== messages[index - 1].fromuid) {
|
||||
// If the previous message was from the other person, this is also a new set
|
||||
message.newSet = true;
|
||||
} else if (index > 0 && messages[index - 1].system) {
|
||||
message.newSet = true;
|
||||
} else if (index === 0) {
|
||||
message.newSet = true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
const validator = require('validator');
|
||||
|
||||
const nconf = require('nconf');
|
||||
const db = require('../database');
|
||||
const user = require('../user');
|
||||
const privileges = require('../privileges');
|
||||
@@ -11,6 +11,8 @@ const meta = require('../meta');
|
||||
const utils = require('../utils');
|
||||
const translator = require('../translator');
|
||||
|
||||
const relative_path = nconf.get('relative_path');
|
||||
|
||||
const Messaging = module.exports;
|
||||
|
||||
require('./data')(Messaging);
|
||||
@@ -127,6 +129,9 @@ Messaging.getRecentChats = async (callerUid, uid, start, stop) => {
|
||||
room.usernames = Messaging.generateUsernames(room.users, uid);
|
||||
}
|
||||
});
|
||||
await Promise.all(results.roomData.map(async (room) => {
|
||||
room.chatWithMessage = await Messaging.generateChatWithMessage(room.users, uid);
|
||||
}));
|
||||
|
||||
results.roomData = results.roomData.filter(Boolean);
|
||||
const ref = { rooms: results.roomData, nextStart: stop + 1 };
|
||||
@@ -151,6 +156,28 @@ Messaging.generateUsernames = function (users, excludeUid) {
|
||||
return usernames.join(', ');
|
||||
};
|
||||
|
||||
Messaging.generateChatWithMessage = async function (users, excludeUid) {
|
||||
users = users.filter(u => u && parseInt(u.uid, 10) !== excludeUid);
|
||||
const usernames = users.map(u => `<a href="${relative_path}/uid/${u.uid}">${u.username}</a>`);
|
||||
let compiled = '';
|
||||
if (!users.length) {
|
||||
return '[[modules:chat.no-users-in-room]]';
|
||||
}
|
||||
if (users.length > 3) {
|
||||
compiled = translator.compile(
|
||||
'modules:chat.chat-with-usernames-and-x-others',
|
||||
usernames.slice(0, 2).join(', '),
|
||||
usernames.length - 2
|
||||
);
|
||||
} else {
|
||||
compiled = translator.compile(
|
||||
'modules:chat.chat-with-usernames',
|
||||
usernames.join(', '),
|
||||
);
|
||||
}
|
||||
return utils.decodeHTMLEntities(await translator.translate(compiled));
|
||||
};
|
||||
|
||||
Messaging.getTeaser = async (uid, roomId) => {
|
||||
const mid = await Messaging.getLatestUndeletedMessage(uid, roomId);
|
||||
if (!mid) {
|
||||
|
||||
@@ -249,6 +249,7 @@ module.exports = function (Messaging) {
|
||||
room.canReply = canReply;
|
||||
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : users.length > 2;
|
||||
room.usernames = Messaging.generateUsernames(users, uid);
|
||||
room.chatWithMessage = await Messaging.generateChatWithMessage(users, uid);
|
||||
room.maximumUsersInChatRoom = meta.config.maximumUsersInChatRoom;
|
||||
room.maximumChatMessageLength = meta.config.maximumChatMessageLength;
|
||||
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
|
||||
|
||||
Reference in New Issue
Block a user