Skip to content

Commit

Permalink
chore: move EventBus to TS
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy authored and backportbot[bot] committed Oct 29, 2024
1 parent 8d1da70 commit 84f88ac
Show file tree
Hide file tree
Showing 42 changed files with 73 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js'
import { CONVERSATION, PARTICIPANT } from './constants.js'
import Router from './router/router.js'
import BrowserStorage from './services/BrowserStorage.js'
import { EventBus } from './services/EventBus.js'
import { EventBus } from './services/EventBus.ts'
import { leaveConversationSync } from './services/participantsService.js'
import { useCallViewStore } from './stores/callView.js'
import { useFederationStore } from './stores/federation.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/FilesSidebarTabApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import LoadingComponent from './components/LoadingComponent.vue'
import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js'
import { EventBus } from './services/EventBus.js'
import { EventBus } from './services/EventBus.ts'
import { getFileConversation } from './services/filesIntegrationServices.js'
import {
leaveConversationSync,
Expand Down
2 changes: 1 addition & 1 deletion src/PublicShareAuthSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import TransitionWrapper from './components/UIShared/TransitionWrapper.vue'
import { useHashCheck } from './composables/useHashCheck.js'
import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js'
import { EventBus } from './services/EventBus.js'
import { EventBus } from './services/EventBus.ts'
import {
leaveConversationSync,
setGuestUserName
Expand Down
2 changes: 1 addition & 1 deletion src/PublicShareSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import TransitionWrapper from './components/UIShared/TransitionWrapper.vue'
import { useHashCheck } from './composables/useHashCheck.js'
import { useIsInCall } from './composables/useIsInCall.js'
import { useSessionIssueHandler } from './composables/useSessionIssueHandler.js'
import { EventBus } from './services/EventBus.js'
import { EventBus } from './services/EventBus.ts'
import { getPublicShareConversationData } from './services/filesIntegrationServices.js'
import {
leaveConversationSync,
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings/HostedSignalingServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
export default {
name: 'HostedSignalingServer',
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings/RecordingServers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import TransitionWrapper from '../UIShared/TransitionWrapper.vue'
import { CONFIG } from '../../constants.js'
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
const recordingConsentCapability = hasTalkFeature('local', 'recording-consent')
const recordingConsentOptions = [
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings/SIPBridge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { setSIPSettings } from '../../services/settingsService.js'
import { getWelcomeMessage } from '../../services/signalingService.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminSettings/SignalingServers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import SignalingServer from '../../components/AdminSettings/SignalingServer.vue'
import TransitionWrapper from '../UIShared/TransitionWrapper.vue'
import { SIGNALING } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
export default {
name: 'SignalingServers',
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/CallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ import { SIMULCAST } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { fetchPeers } from '../../services/callsService.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { useCallViewStore } from '../../stores/callView.js'
import { useSettingsStore } from '../../stores/settings.js'
import { satisfyVersion } from '../../utils/satisfyVersion.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/CallView/shared/VideoVue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import AvatarWrapper from '../../AvatarWrapper/AvatarWrapper.vue'
import TransitionWrapper from '../../UIShared/TransitionWrapper.vue'
import { ATTENDEE, AVATAR } from '../../../constants.js'
import { EventBus } from '../../../services/EventBus.js'
import { EventBus } from '../../../services/EventBus.ts'
import { useCallViewStore } from '../../../stores/callView.js'
import { useGuestNameStore } from '../../../stores/guestName.js'
import attachMediaStream from '../../../utils/attachmediastream.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import TransitionWrapper from './UIShared/TransitionWrapper.vue'
import { CONVERSATION, PARTICIPANT } from '../constants.js'
import { getTalkConfig, hasTalkFeature } from '../services/CapabilitiesManager.ts'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import { useChatExtrasStore } from '../stores/chatExtras.js'
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LeftSidebar/LeftSidebar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LeftSidebar from './LeftSidebar.vue'

import router from '../../__mocks__/router.js'
import { searchPossibleConversations, searchListedConversations } from '../../services/conversationsService.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import storeConfig from '../../store/storeConfig.js'
import { findNcListItems, findNcActionButton, findNcButton } from '../../test-helpers.js'
import { requestTabLeadership } from '../../utils/requestTabLeadership.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ import {
searchPossibleConversations,
searchListedConversations,
} from '../../services/conversationsService.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { talkBroadcastChannel } from '../../services/talkBroadcastChannel.js'
import { useFederationStore } from '../../stores/federation.ts'
import { useTalkHashStore } from '../../stores/talkHash.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Quote from '../../../Quote.vue'

import * as useIsInCallModule from '../../../../composables/useIsInCall.js'
import { CONVERSATION, ATTENDEE, PARTICIPANT } from '../../../../constants.js'
import { EventBus } from '../../../../services/EventBus.js'
import { EventBus } from '../../../../services/EventBus.ts'
import storeConfig from '../../../../store/storeConfig.js'

// needed because of https://github.com/vuejs/vue-test-utils/issues/1507
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import Reactions from './MessagePart/Reactions.vue'
import { CONVERSATION, PARTICIPANT } from '../../../../constants.js'
import { getTalkConfig } from '../../../../services/CapabilitiesManager.ts'
import { EventBus } from '../../../../services/EventBus.js'
import { EventBus } from '../../../../services/EventBus.ts'
import { useChatExtrasStore } from '../../../../stores/chatExtras.js'
import { getItemTypeFromMessage } from '../../../../utils/getItemTypeFromMessage.ts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { t } from '@nextcloud/l10n'
import { encodePath } from '@nextcloud/paths'
import { generateRemoteUrl } from '@nextcloud/router'
import { EventBus } from '../../../../../services/EventBus.js'
import { EventBus } from '../../../../../services/EventBus.ts'
export default {
name: 'AudioPlayer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ import CallButton from '../../../../TopBar/CallButton.vue'
import { useIsInCall } from '../../../../../composables/useIsInCall.js'
import { useMessageInfo } from '../../../../../composables/useMessageInfo.js'
import { EventBus } from '../../../../../services/EventBus.js'
import { EventBus } from '../../../../../services/EventBus.ts'
import { usePollsStore } from '../../../../../stores/polls.ts'
import { parseSpecialSymbols, parseMentions } from '../../../../../utils/textParse.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import TransitionWrapper from '../UIShared/TransitionWrapper.vue'
import { useDocumentVisibility } from '../../composables/useDocumentVisibility.ts'
import { useIsInCall } from '../../composables/useIsInCall.js'
import { ATTENDEE, CHAT, CONVERSATION } from '../../constants.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import { debugTimer } from '../../utils/debugTimer.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ import { ATTENDEE, CONVERSATION, PARTICIPANT, PRIVACY } from '../../constants.js
import { getConversationAvatarOcsUrl, getUserProxyAvatarOcsUrl } from '../../services/avatarService.ts'
import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig, hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { shareFile } from '../../services/filesSharingServices.js'
import { searchPossibleMentions } from '../../services/mentionsService.js'
import { useBreakoutRoomsStore } from '../../stores/breakoutRooms.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewMessage/NewMessageAttachments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
export default {
name: 'NewMessageAttachments',
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewMessage/NewMessagePollEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import { useStore } from '../../composables/useStore.js'
import { POLL } from '../../constants.js'
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { usePollsStore } from '../../stores/polls.ts'
import type { createPollParams } from '../../types/index.ts'
import { convertToJSONDataURI } from '../../utils/fileDownload.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/PollViewer/PollDraftHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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.js'
import { EventBus } from '../../services/EventBus.ts'
import { usePollsStore } from '../../stores/polls.ts'
const props = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion src/components/PollViewer/PollViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ import { useId } from '../../composables/useId.ts'
import { useIsInCall } from '../../composables/useIsInCall.js'
import { POLL } from '../../constants.js'
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { usePollsStore } from '../../stores/polls.ts'
import { convertToJSONDataURI } from '../../utils/fileDownload.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Quote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import FilePreview from './MessagesList/MessagesGroup/Message/MessagePart/FilePr
import { useMessageInfo } from '../composables/useMessageInfo.js'
import { ATTENDEE, AVATAR } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import { useChatExtrasStore } from '../stores/chatExtras.js'
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import SendMessageDialog from '../../BreakoutRoomsEditor/SendMessageDialog.vue'
import { CONVERSATION, PARTICIPANT } from '../../../constants.js'
import { EventBus } from '../../../services/EventBus.js'
import { EventBus } from '../../../services/EventBus.ts'
import { useBreakoutRoomsStore } from '../../../stores/breakoutRooms.ts'
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ import SendMessageDialog from '../../BreakoutRoomsEditor/SendMessageDialog.vue'
import { useId } from '../../../composables/useId.ts'
import { useIsInCall } from '../../../composables/useIsInCall.js'
import { CONVERSATION, PARTICIPANT } from '../../../constants.js'
import { EventBus } from '../../../services/EventBus.js'
import { EventBus } from '../../../services/EventBus.ts'
import { useBreakoutRoomsStore } from '../../../stores/breakoutRooms.ts'
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import { useSortParticipants } from '../../../composables/useSortParticipants.js
import { ATTENDEE } from '../../../constants.js'
import { getTalkConfig, hasTalkFeature } from '../../../services/CapabilitiesManager.ts'
import { searchPossibleConversations } from '../../../services/conversationsService.js'
import { EventBus } from '../../../services/EventBus.js'
import { EventBus } from '../../../services/EventBus.ts'
import { addParticipant } from '../../../services/participantsService.js'
import { useSidebarStore } from '../../../stores/sidebar.js'
import CancelableRequest from '../../../utils/cancelableRequest.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/RightSidebar/SharedItems/SharedItemsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import {
sharedItemTitle,
} from './sharedItemsConstants.js'
import { hasTalkFeature } from '../../../services/CapabilitiesManager.ts'
import { EventBus } from '../../../services/EventBus.js'
import { EventBus } from '../../../services/EventBus.ts'
import { useSharedItemsStore } from '../../../stores/sharedItems.js'
import { useSidebarStore } from '../../../stores/sidebar.js'
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ import { useIsInCall } from '../../composables/useIsInCall.js'
import { ATTENDEE, CALL, CONVERSATION, PARTICIPANT } from '../../constants.js'
import { callSIPDialOut } from '../../services/callsService.js'
import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { useBreakoutRoomsStore } from '../../stores/breakoutRooms.ts'
import { useCallViewStore } from '../../stores/callView.js'
import { useSettingsStore } from '../../stores/settings.js'
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useGetParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useDocumentVisibility } from './useDocumentVisibility.ts'
import { useIsInCall } from './useIsInCall.js'
import { useStore } from './useStore.js'
import { CONVERSATION } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'

/**
* @param {import('vue').Ref} isActive whether the participants tab is active
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useIsInCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { computed, onBeforeMount, onBeforeUnmount, ref } from 'vue'

import { useStore } from './useStore.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import SessionStorage from '../services/SessionStorage.js'
import { useCallViewStore } from '../stores/callView.js'

Expand Down
2 changes: 1 addition & 1 deletion src/composables/useSessionIssueHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { nextTick, onBeforeMount, onBeforeUnmount, ref } from 'vue'

import { generateUrl } from '@nextcloud/router'

import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import SessionStorage from '../services/SessionStorage.js'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { t } from '@nextcloud/l10n'

import { CALL, PARTICIPANT, VIRTUAL_BACKGROUND } from './constants.js'
import BrowserStorage from './services/BrowserStorage.js'
import { EventBus } from './services/EventBus.js'
import { EventBus } from './services/EventBus.ts'
import store from './store/index.js'
import { useIntegrationsStore } from './stores/integrations.js'

Expand Down
22 changes: 0 additions & 22 deletions src/services/EventBus.js

This file was deleted.

33 changes: 33 additions & 0 deletions src/services/EventBus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import mitt from 'mitt'
import type { Emitter, EventType, Handler, WildcardHandler } from 'mitt'

type Events = Record<EventType, unknown>
type GenericEventHandler = Handler<Events[keyof Events]> | WildcardHandler<Events>
type ExtendedEmitter = Emitter<Events> & {
once<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void
once(type: '*', handler: WildcardHandler<Events>): void
}
export const EventBus: ExtendedEmitter = mitt() as ExtendedEmitter

/**
* Register a one-time event handler for the given type
*
* @param type - type of event to listen for, or `'*'` for all events
* @param handler - handler to call in response to given event
*/
EventBus.once = function<Key extends keyof Events>(type: Key, handler: GenericEventHandler) {
/**
* @param args - event arguments: (type, event) or (event)
*/
const fn = (...args: Parameters<GenericEventHandler>) => {
// @ts-expect-error: Vue: A spread argument must either have a tuple type or be passed to a rest parameter.
handler(...args)
this.off(type, fn)
}
this.on(type, fn)
}
2 changes: 1 addition & 1 deletion src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getUploader } from '@nextcloud/upload'

import { SHARED_ITEM } from '../constants.js'
import { getDavClient } from '../services/DavClient.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import {
getFileTemplates,
shareFile,
Expand Down
2 changes: 1 addition & 1 deletion src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../constants.js'
import { hasTalkFeature } from '../services/CapabilitiesManager.ts'
import { fetchNoteToSelfConversation } from '../services/conversationsService.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import {
deleteMessage,
editMessage,
Expand Down
2 changes: 1 addition & 1 deletion src/store/participantsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
leaveCall,
} from '../services/callsService.js'
import { hasTalkFeature, setRemoteCapabilities } from '../services/CapabilitiesManager.ts'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import {
promoteToModerator,
demoteFromModerator,
Expand Down
2 changes: 1 addition & 1 deletion src/store/participantsStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
leaveCall,
} from '../services/callsService.js'
import { fetchConversation } from '../services/conversationsService.js'
import { EventBus } from '../services/EventBus.js'
import { EventBus } from '../services/EventBus.ts'
import {
promoteToModerator,
demoteFromModerator,
Expand Down
2 changes: 1 addition & 1 deletion src/stores/__tests__/chatExtras.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { setActivePinia, createPinia } from 'pinia'

import BrowserStorage from '../../services/BrowserStorage.js'
import { EventBus } from '../../services/EventBus.js'
import { EventBus } from '../../services/EventBus.ts'
import { getUserAbsence } from '../../services/participantsService.js'
import { generateOCSErrorResponse, generateOCSResponse } from '../../test-helpers.js'
import { useChatExtrasStore } from '../chatExtras.js'
Expand Down
Loading

0 comments on commit 84f88ac

Please sign in to comment.