Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/components/chatInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ type Props = {
onBlur: ?Function,
};

export const cleanSuggestionUserObject = (user: ?Object) => {
if (!user) return null;
return {
...user,
id: user.username,
display: user.username,
filterName: user.name.toLowerCase(),
};
};

// $FlowFixMe
const ChatInput = (props: Props) => {
const cacheKey = `last-content-${props.thread}`;
Expand Down Expand Up @@ -312,6 +322,7 @@ const ChatInput = (props: Props) => {
const searchUsers = async (queryString, callback) => {
const filteredParticipants = props.participants
? props.participants
.map(cleanSuggestionUserObject)
.filter(Boolean)
.filter(participant => {
return (
Expand Down Expand Up @@ -352,13 +363,7 @@ const ChatInput = (props: Props) => {
.filter(edge => edge.node.username)
.map(edge => {
const user = edge.node;
return {
...user,
id: user.username,
display: user.username,
username: user.username,
filterName: user.name.toLowerCase(),
};
return cleanSuggestionUserObject(user);
});

// Prepend the filtered participants in case a user is tabbing down right now
Expand Down
10 changes: 3 additions & 7 deletions src/views/directMessages/containers/existingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { withApollo } from 'react-apollo';
import setLastSeenMutation from 'shared/graphql/mutations/directMessageThread/setDMThreadLastSeen';
import Messages from '../components/messages';
import Header from '../components/header';
import ChatInput from 'src/components/chatInput';
import ChatInput, { cleanSuggestionUserObject } from 'src/components/chatInput';
import viewNetworkHandler from 'src/components/viewNetworkHandler';
import getDirectMessageThread, {
type GetDirectMessageThreadType,
Expand Down Expand Up @@ -111,12 +111,8 @@ class ExistingThread extends React.Component<Props> {
if (data.directMessageThread) {
const thread = data.directMessageThread;
const mentionSuggestions = thread.participants
.map(user => ({
...user,
id: user.username,
display: user.username,
}))
.filter(user => user.username !== currentUser.username);
.map(cleanSuggestionUserObject)
.filter(user => user && user.username !== currentUser.username);
return (
<MessagesContainer>
<ViewContent
Expand Down
15 changes: 4 additions & 11 deletions src/views/thread/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,23 +404,16 @@ class ThreadContainer extends React.Component<Props, State> {

if (!messageConnection || messageConnection.edges.length === 0)
return this.setState({
participants: [
{ ...author.user, filterName: author.user.name.toLowerCase() },
],
participants: [author.user],
});

const participants = messageConnection.edges
.map(edge => edge.node)
.map(node => node.author.user);

const participantsWithAuthor = [...participants, author.user]
.filter((user, index, array) => array.indexOf(user) === index)
.map(user => ({
...user,
id: user.username,
display: user.username,
filterName: user.name.toLowerCase(),
}));
const participantsWithAuthor = [...participants, author.user].filter(
(user, index, array) => array.indexOf(user) === index
);

return this.setState({ participants: participantsWithAuthor });
};
Expand Down