From 4e60fd56842b9d919f408521fe89435bc809c373 Mon Sep 17 00:00:00 2001 From: Alex Jin <57976479+Silver-IT@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:10:45 +0800 Subject: [PATCH] Fix error to display profile picture for DMs with more than 2 people (#1869) * fix: error to select avatar for direct messages * chore: follow-up process for changes of getters * fix: error in getting direct messages by groupID * fix: syntax error --- frontend/controller/actions/chatroom.js | 4 +--- frontend/model/chatroom/vuexModule.js | 2 +- frontend/model/contracts/chatroom.js | 2 +- frontend/model/contracts/shared/functions.js | 2 +- frontend/model/state.js | 10 +++++----- frontend/views/containers/chatroom/ChatMembers.vue | 1 - frontend/views/containers/chatroom/DMMixin.js | 2 -- .../views/containers/chatroom/LeaveChannelModal.vue | 3 +-- 8 files changed, 10 insertions(+), 16 deletions(-) diff --git a/frontend/controller/actions/chatroom.js b/frontend/controller/actions/chatroom.js index 6a42024cb7..5353d20a02 100644 --- a/frontend/controller/actions/chatroom.js +++ b/frontend/controller/actions/chatroom.js @@ -248,9 +248,7 @@ export default (sbp('sbp/selectors/register', { ...encryptedAction('gi.actions/chatroom/rename', L('Failed to rename chat channel.')), ...encryptedAction('gi.actions/chatroom/changeDescription', L('Failed to change chat channel description.')), ...encryptedAction('gi.actions/chatroom/leave', L('Failed to leave chat channel.'), async (sendMessage, params, signingKeyId) => { - const rootGetters = sbp('state/vuex/getters') - const userID = rootGetters.ourContactProfiles[params.data.memberID]?.contractID - + const userID = params.data.memberID const keyIds = userID && sbp('chelonia/contract/foreignKeysByContractID', params.contractID, userID) if (keyIds?.length) { diff --git a/frontend/model/chatroom/vuexModule.js b/frontend/model/chatroom/vuexModule.js index 9423306902..967f28956f 100644 --- a/frontend/model/chatroom/vuexModule.js +++ b/frontend/model/chatroom/vuexModule.js @@ -63,7 +63,7 @@ const getters = { // prefix (@), etc.) to make it impossible (or at least obvious) to impersonate // users (e.g., 'user1' changing their display name to 'user2') title: partners.map(cID => getters.userDisplayNameFromID(cID)).join(', '), - picture: getters.ourContactProfiles[lastJoinedPartner]?.picture + picture: getters.ourContactProfilesById[lastJoinedPartner]?.picture } } } diff --git a/frontend/model/contracts/chatroom.js b/frontend/model/contracts/chatroom.js index ba280ec9f0..79bb3dc883 100644 --- a/frontend/model/contracts/chatroom.js +++ b/frontend/model/contracts/chatroom.js @@ -234,7 +234,7 @@ sbp('chelonia/defineContract', { console.error('Error while syncing other members\' contracts at chatroom join', e) }) } else { - if (!rootGetters.ourContactProfiles[memberID]) { + if (!rootGetters.ourContactProfilesById[memberID]) { sbp('chelonia/contract/sync', memberID).catch((e) => { console.error(`Error while syncing new memberID's contract ${memberID}`, e) }) diff --git a/frontend/model/contracts/shared/functions.js b/frontend/model/contracts/shared/functions.js index 2665c5449e..f07f461902 100644 --- a/frontend/model/contracts/shared/functions.js +++ b/frontend/model/contracts/shared/functions.js @@ -143,7 +143,7 @@ export function makeMentionFromUsername (username: string, forceUsername: ?boole const rootGetters = sbp('state/vuex/getters') // Even if forceUsername is true, we want to look up the contract ID to ensure // that it exists, so that we know it'll later succeed. - const userID = rootGetters.ourContactProfiles[username]?.contractID + const userID = rootGetters.ourContactProfilesByUsername[username]?.contractID return makeMentionFromUserID(forceUsername && userID ? username : userID) } diff --git a/frontend/model/state.js b/frontend/model/state.js index 2044b23353..8cc22c0aa6 100644 --- a/frontend/model/state.js +++ b/frontend/model/state.js @@ -461,7 +461,7 @@ const getters = { return getters.ourContactProfilesById[memberID] } }, - ourContactProfiles (state, getters) { + ourContactProfilesByUsername (state, getters) { const profiles = {} Object.keys(state.contracts) .filter(contractID => state.contracts[contractID].type === 'gi.contracts/identity') @@ -493,11 +493,11 @@ const getters = { return nameA.normalize().toUpperCase() > nameB.normalize().toUpperCase() ? 1 : -1 }) }, - ourContacts (state, getters) { - return Object.keys(getters.ourContactProfiles) + ourContactsByUsername (state, getters) { + return Object.keys(getters.ourContactProfilesByUsername) .sort((usernameA, usernameB) => { - const nameA = getters.ourContactProfiles[usernameA].displayName || usernameA - const nameB = getters.ourContactProfiles[usernameB].displayName || usernameB + const nameA = getters.ourContactProfilesByUsername[usernameA].displayName || usernameA + const nameB = getters.ourContactProfilesByUsername[usernameB].displayName || usernameB return nameA.normalize().toUpperCase() > nameB.normalize().toUpperCase() ? 1 : -1 }) } diff --git a/frontend/views/containers/chatroom/ChatMembers.vue b/frontend/views/containers/chatroom/ChatMembers.vue index bcec5adaa6..6a811b6a51 100644 --- a/frontend/views/containers/chatroom/ChatMembers.vue +++ b/frontend/views/containers/chatroom/ChatMembers.vue @@ -68,7 +68,6 @@ export default ({ }, computed: { ...mapGetters([ - 'ourContactProfiles', 'groupShouldPropose', 'ourGroupDirectMessages', 'chatRoomUnreadMentions', diff --git a/frontend/views/containers/chatroom/DMMixin.js b/frontend/views/containers/chatroom/DMMixin.js index 0d4ad4eeb8..137618dda7 100644 --- a/frontend/views/containers/chatroom/DMMixin.js +++ b/frontend/views/containers/chatroom/DMMixin.js @@ -6,8 +6,6 @@ const DMMixin: Object = { computed: { ...mapGetters([ 'currentChatRoomId', - 'ourContacts', - 'ourContactProfiles', 'isDirectMessage', 'ourGroupDirectMessages', 'ourIdentityContractId', diff --git a/frontend/views/containers/chatroom/LeaveChannelModal.vue b/frontend/views/containers/chatroom/LeaveChannelModal.vue index 470a965564..9771eb96b9 100644 --- a/frontend/views/containers/chatroom/LeaveChannelModal.vue +++ b/frontend/views/containers/chatroom/LeaveChannelModal.vue @@ -38,8 +38,7 @@ export default ({ 'currentChatRoomId', 'currentChatRoomState', 'ourGroupDirectMessages', - 'isDirectMessage', - 'ourContactProfiles' + 'isDirectMessage' ]), ...mapState(['loggedIn', 'currentGroupId']), channelName () {