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 { Meteor } from 'meteor/meteor';
|
||||||
import { useSubscription } from '@apollo/client';
|
import { useSubscription } from '@apollo/client';
|
||||||
import {
|
import {
|
||||||
IS_TYPING_SUBSCRIPTION,
|
IS_TYPING_PUBLIC_SUBSCRIPTION,
|
||||||
|
IS_TYPING_PRIVATE_SUBSCRIPTION,
|
||||||
} from '../queries';
|
} from '../queries';
|
||||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { User } from '/imports/ui/Types/user';
|
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 intl = useIntl();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: typingUsersData,
|
data: typingUsersData,
|
||||||
} = useSubscription(IS_TYPING_SUBSCRIPTION, {
|
} = useSubscription(isPrivate ? IS_TYPING_PRIVATE_SUBSCRIPTION : IS_TYPING_PUBLIC_SUBSCRIPTION, {
|
||||||
variables: {
|
variables: {
|
||||||
chatId: isTypingTo,
|
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
|
const typingUsersArray = typingUsers
|
||||||
.filter(user => user?.userId !== userId)
|
.filter(user => user?.userId !== userId)
|
||||||
.map(user => user.user);
|
.map(user => user.user);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { gql } from '@apollo/client';
|
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(
|
user_typing_public(
|
||||||
limit: 4,
|
limit: 4,
|
||||||
where: {
|
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 {
|
export default {
|
||||||
IS_TYPING_SUBSCRIPTION,
|
IS_TYPING_PUBLIC_SUBSCRIPTION,
|
||||||
|
IS_TYPING_PRIVATE_SUBSCRIPTION,
|
||||||
};
|
};
|
||||||
|
@ -376,7 +376,8 @@ class MessageForm extends PureComponent {
|
|||||||
</Styled.Wrapper>
|
</Styled.Wrapper>
|
||||||
<TypingIndicatorContainer
|
<TypingIndicatorContainer
|
||||||
{...{ idChatOpen, error }}
|
{...{ 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}
|
userId={Auth.userID}
|
||||||
/>
|
/>
|
||||||
</Styled.Form>
|
</Styled.Form>
|
||||||
|
Loading…
Reference in New Issue
Block a user