Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add typings for EventBus #14122

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/components/PollViewer/PollDraftHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import EmptyView from '../EmptyView.vue'
import Poll from '../MessagesList/MessagesGroup/Message/MessagePart/Poll.vue'

import { useStore } from '../../composables/useStore.js'
import { EventBus } from '../../services/EventBus.ts'
import { usePollsStore } from '../../stores/polls.ts'

Expand All @@ -60,7 +59,6 @@ const emit = defineEmits<{
(event: 'close'): void,
}>()

const store = useStore()
const pollsStore = usePollsStore()
/**
* Receive poll drafts for the current conversation as owner/moderator
Expand All @@ -72,7 +70,7 @@ const pollDrafts = computed(() => pollsStore.getDrafts(props.token))
* Opens poll editor pre-filled from the draft
* @param id poll draft ID
*/
function openPollEditor(id) {
function openPollEditor(id: number) {
EventBus.emit('poll-editor-open', id)
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EventBus.on('signaling-join-room', (payload) => {
store.dispatch('updateLastJoinedConversationToken', token)
})

EventBus.on('signaling-recording-status-changed', (token, status) => {
EventBus.on('signaling-recording-status-changed', ([token, status]) => {
store.dispatch('setConversationProperties', { token, properties: { callRecording: status } })

if (status !== CALL.RECORDING.FAILED) {
Expand Down
43 changes: 42 additions & 1 deletion src/services/EventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,49 @@

import mitt from 'mitt'
import type { Emitter, EventType, Handler, WildcardHandler } from 'mitt'
import type { Route } from 'vue-router'

type Events = Record<EventType, unknown>
import type { ChatMessage, Conversation, Participant } from '../types/index.ts'
import type { components } from '../types/openapi/openapi-full.ts'

// List of used events across the app
type Events = Record<EventType, unknown> & {
'audio-player-ended': number,
'conversations-received': { singleConversation: boolean },
'deleted-session-detected': void,
'duplicate-session-detected': void,
'editing-message': void,
'editing-message-processing': { messageId: number, value: boolean },
'focus-chat-input': void,
'focus-message': number, // TODO: listener method can receive ...[messageId, smooth, highlightAnimation]
'forbidden-route': { error: string },
'joined-conversation': { token: string },
'message-height-changed': { heightDiff: number },
'poll-drafts-open': void,
'poll-editor-open': number,
'refresh-peer-list': void,
'retry-message': number,
'route-change': { from: Route, to: Route },
'scroll-chat-to-bottom': { smooth?: boolean, force?: boolean },
'should-refresh-chat-messages': void,
'should-refresh-conversations': { token: string, properties: Partial<Conversation> } | { all: true } | void,
'signaling-join-call': [string, number],
'signaling-join-call-failed': [string, { meta: components['schemas']['OCSMeta'], data: { error: string } }],
'signaling-join-room': [string],
'signaling-participant-list-changed': void,
'signaling-recording-status-changed': [string, number],
'signaling-servers-updated': { server: string, verify: boolean }[],
'signaling-users-changed': [(Partial<Participant> & ({ sessionId: string } | { nextcloudSessionId: string }))[]],
'signaling-users-in-room': [{ sessionId: string, userId: string }[]],
'smart-picker-open': void,
'switch-to-conversation': { token: string },
'talk:poll-added': { token: string, message: ChatMessage },
'upload-discard': void,
'upload-finished': void,
'upload-start': void,
}

// Extended types for mitt() library
type GenericEventHandler = Handler<Events[keyof Events]> | WildcardHandler<Events>
type ExtendedEmitter = Emitter<Events> & {
once<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void
Expand Down
2 changes: 1 addition & 1 deletion src/utils/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ Signaling.Standalone.prototype.processRoomMessageEvent = function(token, data) {
EventBus.emit('should-refresh-chat-messages')
break
case 'recording':
EventBus.emit('signaling-recording-status-changed', token, data.recording.status)
EventBus.emit('signaling-recording-status-changed', [token, data.recording.status])
break
default:
console.error('Unknown room message event', data)
Expand Down
Loading