Skip to content

Commit

Permalink
Fix error to display profile picture for DMs with more than 2 people (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Silver-IT authored and corrideat committed Mar 4, 2024
1 parent ed1b24c commit 4e8e14b
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 16 deletions.
4 changes: 1 addition & 3 deletions frontend/controller/actions/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/chatroom/vuexModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/contracts/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/contracts/shared/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/model/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
})
}
Expand Down
1 change: 0 additions & 1 deletion frontend/views/containers/chatroom/ChatMembers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export default ({
},
computed: {
...mapGetters([
'ourContactProfiles',
'groupShouldPropose',
'ourGroupDirectMessages',
'chatRoomUnreadMentions',
Expand Down
2 changes: 0 additions & 2 deletions frontend/views/containers/chatroom/DMMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const DMMixin: Object = {
computed: {
...mapGetters([
'currentChatRoomId',
'ourContacts',
'ourContactProfiles',
'isDirectMessage',
'ourGroupDirectMessages',
'ourIdentityContractId',
Expand Down
3 changes: 1 addition & 2 deletions frontend/views/containers/chatroom/LeaveChannelModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default ({
'currentChatRoomId',
'currentChatRoomState',
'ourGroupDirectMessages',
'isDirectMessage',
'ourContactProfiles'
'isDirectMessage'
]),
...mapState(['loggedIn', 'currentGroupId']),
channelName () {
Expand Down

0 comments on commit 4e8e14b

Please sign in to comment.