From 19cf4fa54bfdcfcc84cc97272221bcdeeff9c068 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 21 May 2020 12:18:11 +1000 Subject: [PATCH] Set profile name --- js/conversation_controller.js | 9 --------- js/models/conversations.js | 30 +---------------------------- js/models/messages.js | 13 ++++++++++++- ts/state/selectors/conversations.ts | 13 +++++++++++++ 4 files changed, 26 insertions(+), 39 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index ea93a3437..171703716 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -87,9 +87,6 @@ ); } - console.log('[vince] Creating conversation with id:', id); - - if (!this._initialFetchComplete) { throw new Error( 'ConversationController.get() needs complete initial fetch' @@ -197,12 +194,6 @@ conversations.remove(conversation); }, getOrCreateAndWait(id, type) { - const ourNumber = textsecure.storage.user.getNumber(); - - if (id !== ourNumber) { - console.log('[vince][core] getOrCreateAndWaiting.. with source:', id); - } - return this._initialPromise.then(() => { const conversation = this.getOrCreate(id, type); diff --git a/js/models/conversations.js b/js/models/conversations.js index 362f1f051..c9e51c27d 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -246,11 +246,6 @@ this.messageCollection.forEach(m => m.trigger('change')); }, async acceptFriendRequest() { - - console.log(`[vince][fr] accepting friend request from conversations.js`); - console.log('[vince][fr] this.id:', this.id); - console.log(`[vince][fr] primary pubkey`, this.getPrimaryDevicePubKey()); - // Friend request messages are always send to primary device conversation const messages = await window.Signal.Data.getMessagesByConversation( this.id, @@ -260,24 +255,7 @@ type: 'friend-request', } ); - - const priamryMessages = await window.Signal.Data.getMessagesByConversation( - this.getPrimaryDevicePubKey(), - { - limit: 1, - MessageCollection: Whisper.MessageCollection, - type: 'friend-request', - } - ); - - - console.log(`[vince][fr] messages: `, messages); - console.log(`[vince][fr] Primary messages: `, priamryMessages); - - - - // LAST MODEL IS POINTING TO THE PRIMARY DEVICE'S LASTMODEL. NOT SECONDARY FOR A2 --> B const lastMessageModel = messages.at(0); if (lastMessageModel) { lastMessageModel.acceptFriendRequest(); @@ -1014,7 +992,7 @@ const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( this.getPrimaryDevicePubKey() ); - + if (!allDevices.length) { return; } @@ -1663,8 +1641,6 @@ FriendRequestStatusEnum.pendingSend ); - - // Always share our profileKey in the friend request // This will get added automatically after the FR // is accepted, via the profileSharing flag @@ -1682,9 +1658,6 @@ direction: 'outgoing', friendStatus: 'pending', }); - - console.log(`[vince][core] Sending FR message from conversations.js`, messageWithSchema); - } if (this.isPrivate()) { @@ -2490,7 +2463,6 @@ }, // LOKI PROFILES - async setNickname(nickname) { const trimmed = nickname && nickname.trim(); if (this.get('nickname') === trimmed) { diff --git a/js/models/messages.js b/js/models/messages.js index bf7a36a54..520001515 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -415,14 +415,17 @@ }, async acceptFriendRequest() { + const primaryDevicePubKey = this.attributes.conversationId; + if (this.get('friendStatus') !== 'pending') { return; } const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( - this.attributes.conversationId + primaryDevicePubKey ); + let profileName; const allConversationsWithUser = allDevices.map(d => ConversationController.get(d)); allConversationsWithUser.forEach(conversation => { // If we somehow received an old friend request (e.g. after having restored @@ -435,8 +438,16 @@ return; } + profileName = conversation.getProfileName() || profileName; conversation.onAcceptFriendRequest(); }); + + // If you don't have a profile name for this device, and profileName is set, + // add profileName to conversation. + const primaryConversation = allConversationsWithUser.find(c => c.id === primaryDevicePubKey) + if (!primaryConversation.getProfileName() && profileName) { + await primaryConversation.setNickname(profileName); + } await window.Signal.Data.saveMessage(this.attributes, { Message: Whisper.Message, diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 4cc66343d..3ed5638b4 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -180,6 +180,8 @@ export const _getLeftPaneLists = ( return filteredGroup as T; }; + + const friends: Array = filterToPrimary(allFriends); const receivedFriendsRequest: Array< ConversationListItemPropsType @@ -188,6 +190,17 @@ export const _getLeftPaneLists = ( ConversationListItemPropsType > = filterToPrimary(allSentFriendsRequest); + + console.log('[vince][friends] allReceivedFriendsRequest:', allReceivedFriendsRequest); + console.log('[vince][friends] receivedFriendsRequest:', receivedFriendsRequest); + console.log('[vince][friends] allSentFriendsRequest:', allSentFriendsRequest); + console.log('[vince][friends] sentFriendsRequest:', sentFriendsRequest); + console.log('[vince][friends] allFriends:', allFriends); + console.log('[vince][friends] friends:', friends); + + + + return { conversations, archivedConversations,