@@ -15,14 +15,19 @@ limitations under the License.
15
15
*/
16
16
17
17
import { Optional } from "matrix-events-sdk" ;
18
+ import { Room } from "matrix-js-sdk/src/models/room" ;
19
+ import { RelationType } from "matrix-js-sdk/src/@types/event" ;
20
+ import { IEventRelation } from "matrix-js-sdk/src/models/event" ;
18
21
19
22
import { AsyncStoreWithClient } from "./AsyncStoreWithClient" ;
20
23
import defaultDispatcher from "../dispatcher/dispatcher" ;
21
24
import { ActionPayload } from "../dispatcher/payloads" ;
22
25
import { VoiceRecording } from "../audio/VoiceRecording" ;
23
26
27
+ const SEPARATOR = "|" ;
28
+
24
29
interface IState {
25
- [ roomId : string ] : Optional < VoiceRecording > ;
30
+ [ voiceRecordingId : string ] : Optional < VoiceRecording > ;
26
31
}
27
32
28
33
export class VoiceRecordingStore extends AsyncStoreWithClient < IState > {
@@ -45,48 +50,54 @@ export class VoiceRecordingStore extends AsyncStoreWithClient<IState> {
45
50
return ;
46
51
}
47
52
53
+ public static getVoiceRecordingId ( room : Room , relation ?: IEventRelation ) : string {
54
+ if ( relation ?. rel_type === "io.element.thread" || relation ?. rel_type === RelationType . Thread ) {
55
+ return room . roomId + SEPARATOR + relation . event_id ;
56
+ } else {
57
+ return room . roomId ;
58
+ }
59
+ }
60
+
48
61
/**
49
62
* Gets the active recording instance, if any.
50
- * @param {string } roomId The room ID to get the recording in.
63
+ * @param {string } voiceRecordingId The room ID (with optionally the thread ID if in one) to get the recording in.
51
64
* @returns {Optional<VoiceRecording> } The recording, if any.
52
65
*/
53
- public getActiveRecording ( roomId : string ) : Optional < VoiceRecording > {
54
- return this . state [ roomId ] ;
66
+ public getActiveRecording ( voiceRecordingId : string ) : Optional < VoiceRecording > {
67
+ return this . state [ voiceRecordingId ] ;
55
68
}
56
69
57
70
/**
58
71
* Starts a new recording if one isn't already in progress. Note that this simply
59
72
* creates a recording instance - whether or not recording is actively in progress
60
73
* can be seen via the VoiceRecording class.
61
- * @param {string } roomId The room ID to start recording in.
74
+ * @param {string } voiceRecordingId The room ID (with optionally the thread ID if in one) to start recording in.
62
75
* @returns {VoiceRecording } The recording.
63
76
*/
64
- public startRecording ( roomId : string ) : VoiceRecording {
77
+ public startRecording ( voiceRecordingId : string ) : VoiceRecording {
65
78
if ( ! this . matrixClient ) throw new Error ( "Cannot start a recording without a MatrixClient" ) ;
66
- if ( ! roomId ) throw new Error ( "Recording must be associated with a room" ) ;
67
- if ( this . state [ roomId ] ) throw new Error ( "A recording is already in progress" ) ;
79
+ if ( ! voiceRecordingId ) throw new Error ( "Recording must be associated with a room" ) ;
80
+ if ( this . state [ voiceRecordingId ] ) throw new Error ( "A recording is already in progress" ) ;
68
81
69
82
const recording = new VoiceRecording ( this . matrixClient ) ;
70
83
71
84
// noinspection JSIgnoredPromiseFromCall - we can safely run this async
72
- this . updateState ( { ...this . state , [ roomId ] : recording } ) ;
85
+ this . updateState ( { ...this . state , [ voiceRecordingId ] : recording } ) ;
73
86
74
87
return recording ;
75
88
}
76
89
77
90
/**
78
91
* Disposes of the current recording, no matter the state of it.
79
- * @param {string } roomId The room ID to dispose of the recording in.
92
+ * @param {string } voiceRecordingId The room ID (with optionally the thread ID if in one) to dispose of the recording in.
80
93
* @returns {Promise<void> } Resolves when complete.
81
94
*/
82
- public disposeRecording ( roomId : string ) : Promise < void > {
83
- if ( this . state [ roomId ] ) {
84
- this . state [ roomId ] . destroy ( ) ; // stops internally
85
- }
95
+ public disposeRecording ( voiceRecordingId : string ) : Promise < void > {
96
+ this . state [ voiceRecordingId ] ?. destroy ( ) ; // stops internally
86
97
87
98
const {
88
99
// eslint-disable-next-line @typescript-eslint/no-unused-vars
89
- [ roomId ] : _toDelete ,
100
+ [ voiceRecordingId ] : _toDelete ,
90
101
...newState
91
102
} = this . state ;
92
103
// unexpectedly AsyncStore.updateState merges state
0 commit comments