mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
chat: Rename userId
to authorId
, userName
to displayName
This commit is contained in:
parent
0f47ca9046
commit
4c2f7f9a11
5 changed files with 50 additions and 20 deletions
|
@ -280,19 +280,19 @@ Pad.prototype.appendText = async function (newText) {
|
|||
*
|
||||
* @param {(ChatMessage|string)} msgOrText - Either a chat message object (recommended) or a string
|
||||
* containing the raw text of the user's chat message (deprecated).
|
||||
* @param {?string} [userId] - The user's author ID. Deprecated; use `msgOrText.userId` instead.
|
||||
* @param {?string} [authorId] - The user's author ID. Deprecated; use `msgOrText.authorId` instead.
|
||||
* @param {?number} [time] - Message timestamp (milliseconds since epoch). Deprecated; use
|
||||
* `msgOrText.time` instead.
|
||||
*/
|
||||
Pad.prototype.appendChatMessage = async function (msgOrText, userId = null, time = null) {
|
||||
Pad.prototype.appendChatMessage = async function (msgOrText, authorId = null, time = null) {
|
||||
const msg =
|
||||
msgOrText instanceof ChatMessage ? msgOrText : new ChatMessage(msgOrText, userId, time);
|
||||
msgOrText instanceof ChatMessage ? msgOrText : new ChatMessage(msgOrText, authorId, time);
|
||||
this.chatHead++;
|
||||
await Promise.all([
|
||||
// Don't save the display name in the database because the user can change it at any time. The
|
||||
// `userName` property will be populated with the current value when the message is read from
|
||||
// `displayName` property will be populated with the current value when the message is read from
|
||||
// the database.
|
||||
db.set(`pad:${this.id}:chat:${this.chatHead}`, {...msg, userName: undefined}),
|
||||
db.set(`pad:${this.id}:chat:${this.chatHead}`, {...msg, displayName: undefined}),
|
||||
this.saveToDatabase(),
|
||||
]);
|
||||
};
|
||||
|
@ -305,7 +305,7 @@ Pad.prototype.getChatMessage = async function (entryNum) {
|
|||
const entry = await db.get(`pad:${this.id}:chat:${entryNum}`);
|
||||
if (entry == null) return null;
|
||||
const message = ChatMessage.fromObject(entry);
|
||||
message.userName = await authorManager.getAuthorName(message.userId);
|
||||
message.displayName = await authorManager.getAuthorName(message.authorId);
|
||||
return message;
|
||||
};
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ const handleChatMessage = async (socket, message) => {
|
|||
const {padId, author: authorId} = sessioninfos[socket.id];
|
||||
// Don't trust the user-supplied values.
|
||||
chatMessage.time = Date.now();
|
||||
chatMessage.userId = authorId;
|
||||
chatMessage.authorId = authorId;
|
||||
await exports.sendChatMessageToPadClients(chatMessage, padId);
|
||||
};
|
||||
|
||||
|
@ -364,10 +364,10 @@ exports.sendChatMessageToPadClients = async (mt, puId, text = null, padId = null
|
|||
const message = mt instanceof ChatMessage ? mt : new ChatMessage(text, puId, mt);
|
||||
padId = mt instanceof ChatMessage ? puId : padId;
|
||||
const pad = await padManager.getPad(padId);
|
||||
// pad.appendChatMessage() ignores the userName property so we don't need to wait for
|
||||
// pad.appendChatMessage() ignores the displayName property so we don't need to wait for
|
||||
// authorManager.getAuthorName() to resolve before saving the message to the database.
|
||||
const promise = pad.appendChatMessage(message);
|
||||
message.userName = await authorManager.getAuthorName(message.userId);
|
||||
message.displayName = await authorManager.getAuthorName(message.userId);
|
||||
socketio.sockets.in(padId).json.send({
|
||||
type: 'COLLABROOM',
|
||||
data: {type: 'CHAT_MESSAGE', message},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue