mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 13:46:34 +02:00
feat: typing user list in chat
This commit is contained in:
@@ -97,6 +97,19 @@ function onConnection(socket) {
|
||||
}, onMessage, socket, payload);
|
||||
});
|
||||
|
||||
socket.on('disconnecting', () => {
|
||||
for (const room of socket.rooms) {
|
||||
if (room && room.match(/^chat_room_\d+$/)) {
|
||||
Sockets.server.in(room).emit('event:chats.typing', {
|
||||
roomId: room.split('_').pop(),
|
||||
uid: socket.uid,
|
||||
username: '',
|
||||
typing: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
onDisconnect(socket);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const validator = require('validator');
|
||||
|
||||
const db = require('../database');
|
||||
const Messaging = require('../messaging');
|
||||
@@ -264,5 +265,21 @@ SocketModules.chats.loadPinnedMessages = async (socket, data) => {
|
||||
return pinnedMsgs;
|
||||
};
|
||||
|
||||
SocketModules.chats.typing = async (socket, data) => {
|
||||
if (!data || !utils.isNumber(data.roomId) || typeof data.typing !== 'boolean') {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
const isInRoom = await Messaging.isUserInRoom(socket.uid, data.roomId);
|
||||
if (!isInRoom) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
socket.to(`chat_room_${data.roomId}`).emit('event:chats.typing', {
|
||||
uid: socket.uid,
|
||||
roomId: data.roomId,
|
||||
typing: data.typing,
|
||||
username: validator.escape(String(data.username)),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
require('../promisify')(SocketModules);
|
||||
|
||||
Reference in New Issue
Block a user