Skip to content

Commit

Permalink
fix: migrate utils to TS
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 11, 2024
1 parent 63008df commit b11f5e9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import IconCheck from 'vue-material-design-icons/Check.vue'
import AvatarWrapper from '../AvatarWrapper/AvatarWrapper.vue'
import { getPreloadedUserStatus, getStatusMessage } from '../../utils/userStatus.js'
import { getPreloadedUserStatus, getStatusMessage } from '../../utils/userStatus.ts'
export default {
name: 'SelectableParticipant',
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConversationIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +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'
import { getPreloadedUserStatus } from '../utils/userStatus.ts'
const supportsAvatar = hasTalkFeature('local', 'avatar')
Expand Down
2 changes: 1 addition & 1 deletion 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 { getPreloadedUserStatus, getStatusMessage } from '../../../utils/userStatus.js'
import { getPreloadedUserStatus, getStatusMessage } from '../../../utils/userStatus.ts'
export default {
name: 'Participant',
Expand Down
2 changes: 1 addition & 1 deletion 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 { getStatusMessage } from '../../utils/userStatus.ts'
import { localCallParticipantModel, localMediaModel } from '../../utils/webrtc/index.js'
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useSortParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { computed } from 'vue'

import { useStore } from './useStore.js'
import { ATTENDEE, PARTICIPANT } from '../constants.js'
import { isDoNotDisturb } from '../utils/userStatus.js'
import { isDoNotDisturb } from '../utils/userStatus.ts'

const MODERATOR_TYPES = [PARTICIPANT.TYPE.OWNER, PARTICIPANT.TYPE.MODERATOR, PARTICIPANT.TYPE.GUEST_MODERATOR]

Expand Down
15 changes: 15 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,22 @@ export type JoinRoomFullResponse = {
}

// Participants
export type ParticipantStatus = {
status?: string | null,
message?: string | null,
icon?: string | null,
clearAt?: number | null,
}
export type Participant = components['schemas']['Participant']
export type ParticipantSearchResult = {
id: string,
label: string,
icon: string,
source: string,
subline: string,
shareWithDisplayNameUnique: string,
status: ParticipantStatus | '',
}

// Chats
export type Mention = RichObject<'server'|'call-type'|'icon-url'>
Expand Down
22 changes: 13 additions & 9 deletions src/utils/userStatus.js → src/utils/userStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
*/
import { t } from '@nextcloud/l10n'

import type {
Conversation,
Participant,
ParticipantSearchResult,
ParticipantStatus,
} from '../types/index.ts'

/**
* Generate user status object to use as preloaded status with NcAvatar
*
* @param {object} userData user data (from conversation, participant, search result)
* @param userData user data (from conversation, participant, search result)
*/
export function getPreloadedUserStatus(userData) {
export function getPreloadedUserStatus(userData?: Conversation | Participant | ParticipantSearchResult): ParticipantStatus | undefined {
if (!userData || typeof userData !== 'object') {
return undefined
}
Expand All @@ -37,10 +44,9 @@ export function getPreloadedUserStatus(userData) {
/**
* Generate full status message for user according to its status data
*
* @param {object} userData user data
* @return {string}
* @param userData user data
*/
export function getStatusMessage(userData) {
export function getStatusMessage(userData?: Conversation | Participant | ParticipantSearchResult | ''): string {
if (!userData) {
return ''
}
Expand All @@ -67,10 +73,8 @@ export function getStatusMessage(userData) {
/**
* Check if current status is "Do not disturb"
*
* @param {object} userData user data
* @param {string} [userData.status] status of user
* @return {boolean}
* @param userData user data
*/
export function isDoNotDisturb(userData) {
export function isDoNotDisturb(userData: Conversation | Participant | ParticipantSearchResult): boolean {
return userData?.status === 'dnd'
}

0 comments on commit b11f5e9

Please sign in to comment.