|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
PropsData as ConversationListItemPropsType,
|
|
|
|
|
ConversationListItem,
|
|
|
|
|
PropsData as ConversationListItemPropsType
|
|
|
|
|
} from '../ConversationListItem';
|
|
|
|
|
import { PropsData as SearchResultsProps } from '../SearchResults';
|
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
@ -11,8 +11,8 @@ import { SearchOptions } from '../../types/Search';
|
|
|
|
|
import { LeftPane, RowRendererParamsType } from '../LeftPane';
|
|
|
|
|
import {
|
|
|
|
|
SessionButton,
|
|
|
|
|
SessionButtonType,
|
|
|
|
|
SessionButtonColor,
|
|
|
|
|
SessionButtonType,
|
|
|
|
|
} from './SessionButton';
|
|
|
|
|
import { AutoSizer, List } from 'react-virtualized';
|
|
|
|
|
import { validateNumber } from '../../types/PhoneNumber';
|
|
|
|
@ -65,9 +65,11 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
|
|
|
|
|
public renderHeader(): JSX.Element | undefined {
|
|
|
|
|
const labels = [window.i18n('contactsHeader'), window.i18n('lists')];
|
|
|
|
|
const friendRequestCount = ActionsPanel.getFriendRequestsCount(this.props.conversations);
|
|
|
|
|
const friendRequestCount = ActionsPanel.GET_FRIEND_REQUESTS_COUNT(
|
|
|
|
|
this.props.conversations
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return LeftPane.renderHeader(
|
|
|
|
|
return LeftPane.RENDER_HEADER(
|
|
|
|
|
labels,
|
|
|
|
|
this.handleTabSelected,
|
|
|
|
|
undefined,
|
|
|
|
@ -81,7 +83,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
<div className="left-pane-contact-section">
|
|
|
|
|
{this.renderHeader()}
|
|
|
|
|
{this.state.showAddContactView
|
|
|
|
|
? LeftPane.renderClosableOverlay(
|
|
|
|
|
? LeftPane.RENDER_CLOSABLE_OVERLAY(
|
|
|
|
|
true,
|
|
|
|
|
this.handleRecipientSessionIDChanged,
|
|
|
|
|
this.handleToggleOverlay,
|
|
|
|
@ -93,6 +95,99 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getCurrentFriends(): Array<ConversationType> {
|
|
|
|
|
const { friends } = this.props;
|
|
|
|
|
|
|
|
|
|
let friendList = friends;
|
|
|
|
|
if (friendList !== undefined) {
|
|
|
|
|
friendList = friendList.filter(
|
|
|
|
|
friend => friend.type === 'direct' && !friend.isMe
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return friendList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderRow = ({
|
|
|
|
|
index,
|
|
|
|
|
key,
|
|
|
|
|
style,
|
|
|
|
|
}: RowRendererParamsType): JSX.Element | undefined => {
|
|
|
|
|
const receivedFriendsRequest = this.getFriendRequests(true);
|
|
|
|
|
const sentFriendsRequest = this.getFriendRequests(false);
|
|
|
|
|
const friends = this.getCurrentFriends();
|
|
|
|
|
|
|
|
|
|
const combined = [
|
|
|
|
|
...receivedFriendsRequest,
|
|
|
|
|
...sentFriendsRequest,
|
|
|
|
|
...friends,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const item = combined[index];
|
|
|
|
|
let onClick;
|
|
|
|
|
if (index >= receivedFriendsRequest.length) {
|
|
|
|
|
onClick = this.props.openConversationInternal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ConversationListItem
|
|
|
|
|
key={key}
|
|
|
|
|
style={style}
|
|
|
|
|
{...item}
|
|
|
|
|
i18n={window.i18n}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public updateSearch(searchTerm: string) {
|
|
|
|
|
const { updateSearchTerm, clearSearch } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) {
|
|
|
|
|
clearSearch();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
|
|
|
|
|
this.setState({ pubKeyPasted: '' }, () => {
|
|
|
|
|
window.Session.emptyContentEditableDivs();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (updateSearchTerm) {
|
|
|
|
|
updateSearchTerm(searchTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (searchTerm.length < 2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cleanedTerm = cleanSearchTerm(searchTerm);
|
|
|
|
|
if (!cleanedTerm) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.debouncedSearch(cleanedTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public clearSearch() {
|
|
|
|
|
this.props.clearSearch();
|
|
|
|
|
//this.setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public search() {
|
|
|
|
|
const { search } = this.props;
|
|
|
|
|
const { searchTerm, isSecondaryDevice } = this.props;
|
|
|
|
|
|
|
|
|
|
if (search) {
|
|
|
|
|
search(searchTerm, {
|
|
|
|
|
noteToSelf: window.i18n('noteToSelf').toLowerCase(),
|
|
|
|
|
ourNumber: window.textsecure.storage.user.getNumber(),
|
|
|
|
|
regionCode: '',
|
|
|
|
|
isSecondaryDevice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleToggleOverlay() {
|
|
|
|
|
this.setState((prevState: { showAddContactView: any }) => ({
|
|
|
|
|
showAddContactView: !prevState.showAddContactView,
|
|
|
|
@ -136,6 +231,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
const edit = window.i18n('edit');
|
|
|
|
|
const addContact = window.i18n('addContact');
|
|
|
|
|
const createGroup = window.i18n('createGroup');
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="left-pane-contact-bottom-buttons">
|
|
|
|
|
<SessionButton
|
|
|
|
@ -162,33 +258,23 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getCurrentFriends():
|
|
|
|
|
| Array<ConversationType> {
|
|
|
|
|
const { friends } = this.props;
|
|
|
|
|
|
|
|
|
|
let friendList = friends;
|
|
|
|
|
if (friendList !== undefined) {
|
|
|
|
|
friendList = friendList.filter(
|
|
|
|
|
friend =>
|
|
|
|
|
friend.type ==='direct' && !friend.isMe
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return friendList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// true: received only, false: sent only
|
|
|
|
|
private getFriendRequests(received:boolean): Array<ConversationListItemPropsType> {
|
|
|
|
|
private getFriendRequests(
|
|
|
|
|
received: boolean
|
|
|
|
|
): Array<ConversationListItemPropsType> {
|
|
|
|
|
const { conversations } = this.props;
|
|
|
|
|
|
|
|
|
|
let conversationsList = conversations;
|
|
|
|
|
if (conversationsList !== undefined) {
|
|
|
|
|
if (received) {
|
|
|
|
|
conversationsList = conversationsList.filter(
|
|
|
|
|
conversation => (conversation.hasReceivedFriendRequest));
|
|
|
|
|
conversation => conversation.hasReceivedFriendRequest
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
conversationsList = conversationsList.filter(
|
|
|
|
|
conversation => (conversation.hasSentFriendRequest));
|
|
|
|
|
conversation => conversation.hasSentFriendRequest
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -200,7 +286,11 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
const sentFriendsRequest = this.getFriendRequests(false);
|
|
|
|
|
const friends = this.getCurrentFriends();
|
|
|
|
|
|
|
|
|
|
const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends];
|
|
|
|
|
const combined = [
|
|
|
|
|
...receivedFriendsRequest,
|
|
|
|
|
...sentFriendsRequest,
|
|
|
|
|
...friends,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const length = combined.length;
|
|
|
|
|
|
|
|
|
@ -224,80 +314,4 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
|
|
|
|
|
|
|
|
|
|
return [list];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public renderRow = ({
|
|
|
|
|
index,
|
|
|
|
|
key,
|
|
|
|
|
style,
|
|
|
|
|
}: RowRendererParamsType): JSX.Element | undefined => {
|
|
|
|
|
|
|
|
|
|
const receivedFriendsRequest = this.getFriendRequests(true);
|
|
|
|
|
const sentFriendsRequest = this.getFriendRequests(false);
|
|
|
|
|
const friends = this.getCurrentFriends();
|
|
|
|
|
|
|
|
|
|
const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends];
|
|
|
|
|
|
|
|
|
|
const item = combined[index];
|
|
|
|
|
let onClick = undefined;
|
|
|
|
|
if (index >= receivedFriendsRequest.length) {
|
|
|
|
|
onClick = this.props.openConversationInternal;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<ConversationListItem
|
|
|
|
|
key={key}
|
|
|
|
|
style={style}
|
|
|
|
|
{...item}
|
|
|
|
|
i18n={window.i18n}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public updateSearch(searchTerm: string) {
|
|
|
|
|
const { updateSearchTerm, clearSearch } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!searchTerm) {
|
|
|
|
|
clearSearch();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
|
|
|
|
|
this.setState({ pubKeyPasted: '' }, () => {
|
|
|
|
|
window.Session.emptyContentEditableDivs();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (updateSearchTerm) {
|
|
|
|
|
updateSearchTerm(searchTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (searchTerm.length < 2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const cleanedTerm = cleanSearchTerm(searchTerm);
|
|
|
|
|
if (!cleanedTerm) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.debouncedSearch(cleanedTerm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public clearSearch() {
|
|
|
|
|
this.props.clearSearch();
|
|
|
|
|
//this.setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public search() {
|
|
|
|
|
const { search } = this.props;
|
|
|
|
|
const { searchTerm, isSecondaryDevice } = this.props;
|
|
|
|
|
|
|
|
|
|
if (search) {
|
|
|
|
|
search(searchTerm, {
|
|
|
|
|
noteToSelf: window.i18n('noteToSelf').toLowerCase(),
|
|
|
|
|
ourNumber: window.textsecure.storage.user.getNumber(),
|
|
|
|
|
regionCode: '',
|
|
|
|
|
isSecondaryDevice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|