fix ghost users appearing in typing indicator
This commit is contained in:
parent
56a8302cfe
commit
77635e40de
@ -1,6 +1,5 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import { UsersTyping } from '/imports/api/group-chat-msg';
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
|
||||
export default function startUserTyping(credentials, chatId) {
|
||||
@ -15,13 +14,6 @@ export default function startUserTyping(credentials, chatId) {
|
||||
check(requesterUserId, String);
|
||||
check(chatId, String);
|
||||
|
||||
const userTyping = UsersTyping.findOne({
|
||||
meetingId,
|
||||
userId: requesterUserId,
|
||||
});
|
||||
|
||||
if (userTyping) return;
|
||||
|
||||
const payload = {
|
||||
chatId: chatId || PUBLIC_GROUP_CHAT_ID,
|
||||
};
|
||||
|
@ -14,6 +14,6 @@ export default function stopUserTyping(credentials) {
|
||||
});
|
||||
|
||||
if (userTyping) {
|
||||
stopTyping(meetingId, requesterUserId);
|
||||
stopTyping(meetingId, requesterUserId, true);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ import { check } from 'meteor/check';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import Users from '/imports/api/users';
|
||||
import { UsersTyping } from '/imports/api/group-chat-msg';
|
||||
import stopTyping from './stopTyping';
|
||||
|
||||
const TYPING_TIMEOUT = 3000;
|
||||
|
||||
export default function startTyping(meetingId, userId, chatId) {
|
||||
check(meetingId, String);
|
||||
@ -19,12 +22,17 @@ export default function startTyping(meetingId, userId, chatId) {
|
||||
userId,
|
||||
name: user.name,
|
||||
isTypingTo: chatId,
|
||||
time: (new Date()),
|
||||
};
|
||||
|
||||
const cb = (err) => {
|
||||
if (err) {
|
||||
return Logger.error(`Typing indicator update error: ${err}`);
|
||||
}
|
||||
|
||||
Meteor.setTimeout(() => {
|
||||
stopTyping(meetingId, userId);
|
||||
}, TYPING_TIMEOUT);
|
||||
return Logger.debug(`Typing indicator update for userId={${userId}} chatId={${chatId}}`);
|
||||
};
|
||||
|
||||
|
@ -2,15 +2,20 @@ import { check } from 'meteor/check';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { UsersTyping } from '/imports/api/group-chat-msg';
|
||||
|
||||
export default function stopTyping(meetingId, userId) {
|
||||
export default function stopTyping(meetingId, userId, sent = false) {
|
||||
check(meetingId, String);
|
||||
check(userId, String);
|
||||
check(sent, Boolean);
|
||||
|
||||
const selector = {
|
||||
meetingId,
|
||||
userId,
|
||||
};
|
||||
|
||||
const user = UsersTyping.findOne(selector);
|
||||
const stillTyping = !sent && user && (new Date()) - user.time < 3000;
|
||||
if (stillTyping) return;
|
||||
|
||||
const cb = (err) => {
|
||||
if (err) {
|
||||
return Logger.error(`Stop user=${userId} typing indicator error: ${err}`);
|
||||
@ -18,5 +23,5 @@ export default function stopTyping(meetingId, userId) {
|
||||
return Logger.debug(`Stopped typing indicator for user=${userId}`);
|
||||
};
|
||||
|
||||
return UsersTyping.remove(selector, cb);
|
||||
UsersTyping.remove(selector, cb);
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ const messages = defineMessages({
|
||||
});
|
||||
|
||||
const CHAT_ENABLED = Meteor.settings.public.chat.enabled;
|
||||
const IS_TYPING_INTERVAL = 2500;
|
||||
|
||||
class MessageForm extends PureComponent {
|
||||
constructor(props) {
|
||||
@ -204,14 +203,6 @@ class MessageForm extends PureComponent {
|
||||
|
||||
const handleUserTyping = () => {
|
||||
startUserTyping(chatId);
|
||||
setTimeout(() => {
|
||||
const { message: messageState } = this.state;
|
||||
const userStoppedTyping = messageState === '' || message.length === messageState.length;
|
||||
if (userStoppedTyping) {
|
||||
const { stopUserTyping } = this.props;
|
||||
stopUserTyping();
|
||||
}
|
||||
}, IS_TYPING_INTERVAL);
|
||||
};
|
||||
|
||||
this.setState({
|
||||
|
Loading…
Reference in New Issue
Block a user