From 06aeb126c20c2d7ce57c2a1394eb8cce2e91204c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 26 Feb 2020 17:18:41 +1100 Subject: [PATCH 1/3] enable search by username in message view #928 --- ts/components/SearchResults.tsx | 26 +++++++++++++++++++ .../session/LeftPaneMessageSection.tsx | 5 ++++ ts/state/ducks/search.ts | 15 +++-------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/ts/components/SearchResults.tsx b/ts/components/SearchResults.tsx index fc1de4c8f..cd6f1c04b 100644 --- a/ts/components/SearchResults.tsx +++ b/ts/components/SearchResults.tsx @@ -75,6 +75,10 @@ export class SearchResults extends React.Component { ))} ) : null} + {haveFriends + ? this.renderContacts(i18n('friendsHeader'), friends, true) + : null} + {haveMessages ? (
{hideMessagesHeader ? null : ( @@ -95,4 +99,26 @@ export class SearchResults extends React.Component {
); } + private renderContacts( + header: string, + items: Array, + friends?: boolean + ) { + const { i18n, openConversation } = this.props; + + return ( +
+
{header}
+ {items.map(contact => ( + + ))} +
+ ); + } } diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index 9841257ea..e29b942b1 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -132,11 +132,16 @@ export class LeftPaneMessageSection extends React.Component { public renderList(): JSX.Element | Array { const { openConversationInternal, searchResults } = this.props; + const friends = + (searchResults && + searchResults.contacts.filter(contact => contact.isFriend)) || + []; if (searchResults) { return ( diff --git a/ts/state/ducks/search.ts b/ts/state/ducks/search.ts index f5e38b259..c92fdd814 100644 --- a/ts/state/ducks/search.ts +++ b/ts/state/ducks/search.ts @@ -172,7 +172,7 @@ async function queryConversationsAndContacts( providedQuery: string, options: SearchOptions ) { - const { ourNumber, noteToSelf, isSecondaryDevice } = options; + const { ourNumber, isSecondaryDevice } = options; const query = providedQuery.replace(/[+-.()]*/g, ''); const searchResults: Array = await searchConversations( @@ -193,8 +193,8 @@ async function queryConversationsAndContacts( ); // Split into two groups - active conversations and items just from address book - let conversations: Array = []; - let contacts: Array = []; + const conversations: Array = []; + const contacts: Array = []; const max = searchResults.length; for (let i = 0; i < max; i += 1) { const conversation = searchResults[i]; @@ -215,15 +215,6 @@ async function queryConversationsAndContacts( } } - // Inject synthetic Note to Self entry if query matches localized 'Note to Self' - if (noteToSelf.indexOf(providedQuery.toLowerCase()) !== -1) { - // ensure that we don't have duplicates in our results - contacts = contacts.filter(id => id !== ourNumber); - conversations = conversations.filter(id => id !== ourNumber); - - contacts.unshift(ourNumber); - } - return { conversations, contacts }; } From 0528a4c8ac8828b8f9d9e49da2b32b351b4cb226 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 26 Feb 2020 17:20:23 +1100 Subject: [PATCH 2/3] fix lint --- js/modules/loki_message_api.js | 7 ++++++- js/modules/loki_rpc.js | 7 +++++-- js/modules/loki_snode_api.js | 21 +++++++++++++++---- libtextsecure/message_receiver.js | 5 ++++- .../conversation/CreateGroupDialog.tsx | 6 +++++- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index 98411fd85..88b02b7af 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -217,7 +217,12 @@ class LokiMessageAPI { } return true; } catch (e) { - log.warn('Loki send message error:', e.code, e.message, `from ${address}`); + log.warn( + 'Loki send message error:', + e.code, + e.message, + `from ${address}` + ); if (e instanceof textsecure.WrongSwarmError) { const { newSwarm } = e; await lokiSnodeAPI.updateSwarmNodes(params.pubKey, newSwarm); diff --git a/js/modules/loki_rpc.js b/js/modules/loki_rpc.js index 61fb83926..5f29f6c38 100644 --- a/js/modules/loki_rpc.js +++ b/js/modules/loki_rpc.js @@ -70,7 +70,10 @@ const sendToProxy = async (options = {}, targetNode) => { // detect SNode is not ready (not in swarm; not done syncing) if (response.status === 503) { const ciphertext = await response.text(); - log.error(`lokiRpc sendToProxy snode ${randSnode.ip}:${randSnode.port} error`, ciphertext); + log.error( + `lokiRpc sendToProxy snode ${randSnode.ip}:${randSnode.port} error`, + ciphertext + ); // mark as bad for this round (should give it some time and improve success rates) lokiSnodeAPI.markRandomNodeUnreachable(randSnode); // retry for a new working snode @@ -104,7 +107,7 @@ const sendToProxy = async (options = {}, targetNode) => { const textDecoder = new TextDecoder(); plaintext = textDecoder.decode(plaintextBuffer); - } catch(e) { + } catch (e) { log.error( 'lokiRpc sendToProxy decode error', e.code, diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index 7bc2944ed..7d163a215 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -31,7 +31,10 @@ class LokiSnodeAPI { ]; } - async initialiseRandomPool(seedNodes = [...window.seedNodeList], consecutiveErrors = 0) { + async initialiseRandomPool( + seedNodes = [...window.seedNodeList], + consecutiveErrors = 0 + ) { const params = { limit: 20, active_only: true, @@ -71,7 +74,10 @@ class LokiSnodeAPI { if (consecutiveErrors < 3) { // retry after a possible delay setTimeout(() => { - log.info('Retrying initialising random snode pool, try #', consecutiveErrors); + log.info( + 'Retrying initialising random snode pool, try #', + consecutiveErrors + ); this.initialiseRandomPool(seedNodes, consecutiveErrors + 1); }, consecutiveErrors * consecutiveErrors * 5000); } else { @@ -181,7 +187,12 @@ class LokiSnodeAPI { const snodes = result.snodes.filter(tSnode => tSnode.ip !== '0.0.0.0'); return snodes; } catch (e) { - log.error('getSnodesForPubkey error', e.code, e.message, `for ${snode.ip}:${snode.port}`); + log.error( + 'getSnodesForPubkey error', + e.code, + e.message, + `for ${snode.ip}:${snode.port}` + ); this.markRandomNodeUnreachable(snode); return []; } @@ -197,7 +208,9 @@ class LokiSnodeAPI { const resList = await this.getSnodesForPubkey(rSnode, pubKey); // should we only activate entries that are in all results? resList.map(item => { - const hasItem = snodes.some(hItem => item.ip === hItem.ip && item.port === hItem.port); + const hasItem = snodes.some( + hItem => item.ip === hItem.ip && item.port === hItem.port + ); if (!hasItem) { snodes.push(item); } diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 0e6204016..b6b24f355 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -59,7 +59,10 @@ function MessageReceiver(username, password, signalingKey, options = {}) { lokiPublicChatAPI.removeAllListeners('publicMessage'); // we only need one MR in the system handling these // bind events - lokiPublicChatAPI.on('publicMessage', this.handleUnencryptedMessage.bind(this)); + lokiPublicChatAPI.on( + 'publicMessage', + this.handleUnencryptedMessage.bind(this) + ); openGroupBound = true; } } else { diff --git a/ts/components/conversation/CreateGroupDialog.tsx b/ts/components/conversation/CreateGroupDialog.tsx index ce853d4ce..482a35579 100644 --- a/ts/components/conversation/CreateGroupDialog.tsx +++ b/ts/components/conversation/CreateGroupDialog.tsx @@ -95,7 +95,11 @@ export class CreateGroupDialog extends React.Component { ); return ( - null}> + null} + >

{this.state.errorMessage}

From 7a86a68c22eb134656bd03b7e7a1989891ba5346 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 4 Mar 2020 14:05:05 +1100 Subject: [PATCH 3/3] enable back note to self in search result --- ts/state/ducks/search.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ts/state/ducks/search.ts b/ts/state/ducks/search.ts index c92fdd814..194823a79 100644 --- a/ts/state/ducks/search.ts +++ b/ts/state/ducks/search.ts @@ -172,7 +172,7 @@ async function queryConversationsAndContacts( providedQuery: string, options: SearchOptions ) { - const { ourNumber, isSecondaryDevice } = options; + const { ourNumber, noteToSelf, isSecondaryDevice } = options; const query = providedQuery.replace(/[+-.()]*/g, ''); const searchResults: Array = await searchConversations( @@ -193,8 +193,8 @@ async function queryConversationsAndContacts( ); // Split into two groups - active conversations and items just from address book - const conversations: Array = []; - const contacts: Array = []; + let conversations: Array = []; + let contacts: Array = []; const max = searchResults.length; for (let i = 0; i < max; i += 1) { const conversation = searchResults[i]; @@ -214,6 +214,14 @@ async function queryConversationsAndContacts( conversations.push(conversation.id); } } + // Inject synthetic Note to Self entry if query matches localized 'Note to Self' + if (noteToSelf.indexOf(providedQuery.toLowerCase()) !== -1) { + // ensure that we don't have duplicates in our results + contacts = contacts.filter(id => id !== ourNumber); + conversations = conversations.filter(id => id !== ourNumber); + + contacts.unshift(ourNumber); + } return { conversations, contacts }; }