Skip to content

Commit

Permalink
fix: move getPreloadedUserStatus to util
Browse files Browse the repository at this point in the history
Signed-off-by: Antreesy <[email protected]>
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Sep 6, 2024
1 parent 7998f67 commit be57bb4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
9 changes: 7 additions & 2 deletions src/components/BreakoutRoomsEditor/SelectableParticipant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:source="participant.source || participant.actorType"
disable-menu
disable-tooltip
:preloaded-user-status="preloadedUserStatus"
show-user-status />

<span class="selectable-participant__content">
Expand All @@ -36,7 +37,7 @@ import IconCheck from 'vue-material-design-icons/Check.vue'
import AvatarWrapper from '../AvatarWrapper/AvatarWrapper.vue'
import { getStatusMessage } from '../../utils/userStatus.js'
import { getPreloadedUserStatus, getStatusMessage } from '../../utils/userStatus.js'
export default {
name: 'SelectableParticipant',
Expand Down Expand Up @@ -73,8 +74,12 @@ export default {
},
},
preloadedUserStatus() {
return getPreloadedUserStatus(this.participant)
},
participantStatus() {
return getStatusMessage(this.participant)
return getStatusMessage(this.preloadedUserStatus)
},
},
}
Expand Down
13 changes: 5 additions & 8 deletions src/components/ConversationIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { useIsDarkTheme } from '../composables/useIsDarkTheme.ts'
import { AVATAR, CONVERSATION } from '../constants.js'
import { getConversationAvatarOcsUrl } from '../services/avatarService.ts'
import { hasTalkFeature } from '../services/CapabilitiesManager.ts'
import { getPreloadedUserStatus } from '../utils/userStatus.js'
const supportsAvatar = hasTalkFeature('local', 'avatar')
Expand Down Expand Up @@ -151,15 +152,11 @@ export default {
},
preloadedUserStatus() {
if (!this.hideUserStatus && Object.prototype.hasOwnProperty.call(this.item, 'statusMessage')) {
// We preloaded the status
return {
status: this.item.status || null,
message: this.item.statusMessage || null,
icon: this.item.statusIcon || null,
}
if (this.hideUserStatus) {
return undefined
}
return undefined
return getPreloadedUserStatus(this.item)
},
menuContainer() {
Expand Down
22 changes: 3 additions & 19 deletions src/components/RightSidebar/Participants/Participant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ import {
import { hasTalkFeature } from '../../../services/CapabilitiesManager.ts'
import { formattedTime } from '../../../utils/formattedTime.ts'
import { readableNumber } from '../../../utils/readableNumber.ts'
import { getStatusMessage } from '../../../utils/userStatus.js'
import { getPreloadedUserStatus, getStatusMessage } from '../../../utils/userStatus.js'
export default {
name: 'Participant',
Expand Down Expand Up @@ -546,7 +546,7 @@ export default {
: '💬 ' + t('spreed', '{time} talking time', { time: formattedTime(this.timeSpeaking, true) })
}
return getStatusMessage(this.participant)
return getStatusMessage(this.preloadedUserStatus)
},
/**
Expand Down Expand Up @@ -826,23 +826,7 @@ export default {
},
preloadedUserStatus() {
if (Object.prototype.hasOwnProperty.call(this.participant, 'statusMessage')) {
// We preloaded the status when via participants API
return {
status: this.participant.status || null,
message: this.participant.statusMessage || null,
icon: this.participant.statusIcon || null,
}
}
if (Object.prototype.hasOwnProperty.call(this.participant, 'status')) {
// We preloaded the status when via search API
return {
status: this.participant.status.status || null,
message: this.participant.status.message || null,
icon: this.participant.status.icon || null,
}
}
return undefined
return getPreloadedUserStatus(this.participant)
},
attendeePermissions() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/TopBar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import { AVATAR, CONVERSATION } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import { getStatusMessage } from '../../utils/userStatus.js'
import { getPreloadedUserStatus, getStatusMessage } from '../../utils/userStatus.js'
import { localCallParticipantModel, localMediaModel } from '../../utils/webrtc/index.js'
export default {
Expand Down Expand Up @@ -230,7 +230,7 @@ export default {
},
statusMessage() {
return getStatusMessage(this.conversation)
return getStatusMessage(getPreloadedUserStatus(this.conversation))
},
renderedDescription() {
Expand Down
43 changes: 34 additions & 9 deletions src/utils/userStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { t } from '@nextcloud/l10n'

export function getPreloadedUserStatus(userData) {
if (!userData || typeof userData !== 'object') {
return undefined
}

if ('statusMessage' in userData) {
// We preloaded the status when via participants API
return {
status: userData.status || null,
message: userData.statusMessage || null,
icon: userData.statusIcon || null,
}
}
if ('status' in userData && typeof userData.status === 'object') {
// We preloaded the status when via search API
return {
status: userData.status.status || null,
message: userData.status.message || null,
icon: userData.status.icon || null,
}
}
return undefined
}

/**
* Generate full status message for user according to its status data
*
Expand All @@ -14,18 +39,18 @@ import { t } from '@nextcloud/l10n'
* @return {string}
*/
export function getStatusMessage(userData) {
let status = userData.statusIcon
? userData.statusIcon + ' '
: ''
if (!userData) {
return ''
}

let status = userData.icon ?? ''

if (userData.statusMessage) {
status += userData.statusMessage
if (userData.message) {
status += ' ' + userData.message
} else if (userData.status === 'dnd') {
status += t('spreed', 'Do not disturb')
status += ' ' + t('spreed', 'Do not disturb')
} else if (userData.status === 'away') {
status += t('spreed', 'Away')
} else {
status += ''
status += ' ' + t('spreed', 'Away')
}

return status
Expand Down

0 comments on commit be57bb4

Please sign in to comment.