add support to private chat typing indicator
This commit is contained in:
parent
af93e0c283
commit
ffbc437d55
@ -2,7 +2,8 @@ import React from 'react';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { useSubscription } from '@apollo/client';
|
||||
import {
|
||||
IS_TYPING_SUBSCRIPTION,
|
||||
IS_TYPING_PUBLIC_SUBSCRIPTION,
|
||||
IS_TYPING_PRIVATE_SUBSCRIPTION,
|
||||
} from '../queries';
|
||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||
import { User } from '/imports/ui/Types/user';
|
||||
@ -99,18 +100,22 @@ const TypingIndicator: React.FC<TypingIndicatorProps> = ({
|
||||
);
|
||||
};
|
||||
|
||||
const TypingIndicatorContainer: React.FC = ({ userId, isTypingTo, error }) => {
|
||||
const TypingIndicatorContainer: React.FC = ({ userId, isTypingTo, isPrivate, error }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const {
|
||||
data: typingUsersData,
|
||||
} = useSubscription(IS_TYPING_SUBSCRIPTION, {
|
||||
} = useSubscription(isPrivate ? IS_TYPING_PRIVATE_SUBSCRIPTION : IS_TYPING_PUBLIC_SUBSCRIPTION, {
|
||||
variables: {
|
||||
chatId: isTypingTo,
|
||||
}
|
||||
});
|
||||
|
||||
const typingUsers = typingUsersData?.user_typing_public || [];
|
||||
const publicTypingUsers = typingUsersData?.user_typing_public || [];
|
||||
const privateTypingUsers = typingUsersData?.user_typing_private || [];
|
||||
|
||||
const typingUsers = privateTypingUsers.concat(publicTypingUsers);
|
||||
|
||||
const typingUsersArray = typingUsers
|
||||
.filter(user => user?.userId !== userId)
|
||||
.map(user => user.user);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const IS_TYPING_SUBSCRIPTION = gql`subscription IsTyping($chatId: String!) {
|
||||
export const IS_TYPING_PUBLIC_SUBSCRIPTION = gql`subscription IsTyping($chatId: String!) {
|
||||
user_typing_public(
|
||||
limit: 4,
|
||||
where: {
|
||||
@ -19,6 +19,26 @@ export const IS_TYPING_SUBSCRIPTION = gql`subscription IsTyping($chatId: String!
|
||||
}
|
||||
}`;
|
||||
|
||||
export const IS_TYPING_PRIVATE_SUBSCRIPTION = gql`subscription IsTyping($chatId: String!) {
|
||||
user_typing_private(
|
||||
limit: 4,
|
||||
where: {
|
||||
isCurrentlyTyping: {_eq: true}
|
||||
chatId: {_eq: $chatId}
|
||||
}
|
||||
) {
|
||||
meetingId
|
||||
chatId
|
||||
userId
|
||||
typingAt
|
||||
isCurrentlyTyping
|
||||
user {
|
||||
name
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
export default {
|
||||
IS_TYPING_SUBSCRIPTION,
|
||||
IS_TYPING_PUBLIC_SUBSCRIPTION,
|
||||
IS_TYPING_PRIVATE_SUBSCRIPTION,
|
||||
};
|
||||
|
@ -376,7 +376,8 @@ class MessageForm extends PureComponent {
|
||||
</Styled.Wrapper>
|
||||
<TypingIndicatorContainer
|
||||
{...{ idChatOpen, error }}
|
||||
isTypingTo={idChatOpen === PUBLIC_CHAT_KEY ? PUBLIC_CHAT_GROUP_KEY : Auth.userID}
|
||||
isPrivate={idChatOpen !== PUBLIC_CHAT_KEY}
|
||||
isTypingTo={idChatOpen === PUBLIC_CHAT_KEY ? PUBLIC_CHAT_GROUP_KEY : idChatOpen}
|
||||
userId={Auth.userID}
|
||||
/>
|
||||
</Styled.Form>
|
||||
|
Loading…
Reference in New Issue
Block a user