4
4
*/
5
5
6
6
import { IDocumentManager } from '@jupyterlab/docmanager' ;
7
+ import { ArrayExt } from '@lumino/algorithm' ;
7
8
import { CommandRegistry } from '@lumino/commands' ;
8
9
import { IDisposable } from '@lumino/disposable' ;
9
10
import { ISignal , Signal } from '@lumino/signaling' ;
@@ -59,6 +60,11 @@ export interface IChatModel extends IDisposable {
59
60
*/
60
61
readonly input : IInputModel ;
61
62
63
+ /**
64
+ * The current writer list.
65
+ */
66
+ readonly writers : IChatModel . IWriter [ ] ;
67
+
62
68
/**
63
69
* Get the active cell manager.
64
70
*/
@@ -82,7 +88,7 @@ export interface IChatModel extends IDisposable {
82
88
/**
83
89
* A signal emitting when the messages list is updated.
84
90
*/
85
- get configChanged ( ) : ISignal < IChatModel , IConfig > ;
91
+ readonly configChanged : ISignal < IChatModel , IConfig > ;
86
92
87
93
/**
88
94
* A signal emitting when unread messages change.
@@ -97,7 +103,12 @@ export interface IChatModel extends IDisposable {
97
103
/**
98
104
* A signal emitting when the writers change.
99
105
*/
100
- readonly writersChanged ?: ISignal < IChatModel , IUser [ ] > ;
106
+ readonly writersChanged ?: ISignal < IChatModel , IChatModel . IWriter [ ] > ;
107
+
108
+ /**
109
+ * A signal emitting when the message edition input changed change.
110
+ */
111
+ readonly messageEditionAdded : ISignal < IChatModel , IChatModel . IMessageEdition > ;
101
112
102
113
/**
103
114
* Send a message, to be defined depending on the chosen technology.
@@ -172,12 +183,22 @@ export interface IChatModel extends IDisposable {
172
183
/**
173
184
* Update the current writers list.
174
185
*/
175
- updateWriters ( writers : IUser [ ] ) : void ;
186
+ updateWriters ( writers : IChatModel . IWriter [ ] ) : void ;
176
187
177
188
/**
178
189
* Create the chat context that will be passed to the input model.
179
190
*/
180
191
createChatContext ( ) : IChatContext ;
192
+
193
+ /**
194
+ * Get the input model of the edited message, given its id.
195
+ */
196
+ getEditionModel ( messageID : string ) : IInputModel | undefined ;
197
+
198
+ /**
199
+ * Add an input model of the edited message.
200
+ */
201
+ addEditionModel ( messageID : string , inputModel : IInputModel ) : void ;
181
202
}
182
203
183
204
/**
@@ -256,6 +277,13 @@ export abstract class AbstractChatModel implements IChatModel {
256
277
return this . _inputModel ;
257
278
}
258
279
280
+ /**
281
+ * The current writer list.
282
+ */
283
+ get writers ( ) : IChatModel . IWriter [ ] {
284
+ return this . _writers ;
285
+ }
286
+
259
287
/**
260
288
* Get the active cell manager.
261
289
*/
@@ -418,10 +446,17 @@ export abstract class AbstractChatModel implements IChatModel {
418
446
/**
419
447
* A signal emitting when the writers change.
420
448
*/
421
- get writersChanged ( ) : ISignal < IChatModel , IUser [ ] > {
449
+ get writersChanged ( ) : ISignal < IChatModel , IChatModel . IWriter [ ] > {
422
450
return this . _writersChanged ;
423
451
}
424
452
453
+ /**
454
+ * A signal emitting when the message edition input changed change.
455
+ */
456
+ get messageEditionAdded ( ) : ISignal < IChatModel , IChatModel . IMessageEdition > {
457
+ return this . _messageEditionAdded ;
458
+ }
459
+
425
460
/**
426
461
* Send a message, to be defined depending on the chosen technology.
427
462
* Default to no-op.
@@ -546,15 +581,47 @@ export abstract class AbstractChatModel implements IChatModel {
546
581
* Update the current writers list.
547
582
* This implementation only propagate the list via a signal.
548
583
*/
549
- updateWriters ( writers : IUser [ ] ) : void {
550
- this . _writersChanged . emit ( writers ) ;
584
+ updateWriters ( writers : IChatModel . IWriter [ ] ) : void {
585
+ const compareWriters = ( a : IChatModel . IWriter , b : IChatModel . IWriter ) => {
586
+ return (
587
+ a . user . username === b . user . username &&
588
+ a . user . display_name === b . user . display_name &&
589
+ a . messageID === b . messageID
590
+ ) ;
591
+ } ;
592
+ if ( ! ArrayExt . shallowEqual ( this . _writers , writers , compareWriters ) ) {
593
+ this . _writers = writers ;
594
+ this . _writersChanged . emit ( writers ) ;
595
+ }
551
596
}
552
597
553
598
/**
554
599
* Create the chat context that will be passed to the input model.
555
600
*/
556
601
abstract createChatContext ( ) : IChatContext ;
557
602
603
+ /**
604
+ * Get the input model of the edited message, given its id.
605
+ */
606
+ getEditionModel ( messageID : string ) : IInputModel | undefined {
607
+ return this . _messageEditions . get ( messageID ) ;
608
+ }
609
+
610
+ /**
611
+ * Add an input model of the edited message.
612
+ */
613
+ addEditionModel ( messageID : string , inputModel : IInputModel ) : void {
614
+ // Dispose of an hypothetic previous model for this message.
615
+ this . getEditionModel ( messageID ) ?. dispose ( ) ;
616
+
617
+ this . _messageEditions . set ( messageID , inputModel ) ;
618
+ this . _messageEditionAdded . emit ( { id : messageID , model : inputModel } ) ;
619
+
620
+ inputModel . onDisposed . connect ( ( ) => {
621
+ this . _messageEditions . delete ( messageID ) ;
622
+ } ) ;
623
+ }
624
+
558
625
/**
559
626
* Add unread messages to the list.
560
627
* @param indexes - list of new indexes.
@@ -617,11 +684,17 @@ export abstract class AbstractChatModel implements IChatModel {
617
684
private _selectionWatcher : ISelectionWatcher | null ;
618
685
private _documentManager : IDocumentManager | null ;
619
686
private _notificationId : string | null = null ;
687
+ private _writers : IChatModel . IWriter [ ] = [ ] ;
688
+ private _messageEditions = new Map < string , IInputModel > ( ) ;
620
689
private _messagesUpdated = new Signal < IChatModel , void > ( this ) ;
621
690
private _configChanged = new Signal < IChatModel , IConfig > ( this ) ;
622
691
private _unreadChanged = new Signal < IChatModel , number [ ] > ( this ) ;
623
692
private _viewportChanged = new Signal < IChatModel , number [ ] > ( this ) ;
624
- private _writersChanged = new Signal < IChatModel , IUser [ ] > ( this ) ;
693
+ private _writersChanged = new Signal < IChatModel , IChatModel . IWriter [ ] > ( this ) ;
694
+ private _messageEditionAdded = new Signal <
695
+ IChatModel ,
696
+ IChatModel . IMessageEdition
697
+ > ( this ) ;
625
698
}
626
699
627
700
/**
@@ -662,6 +735,34 @@ export namespace IChatModel {
662
735
*/
663
736
documentManager ?: IDocumentManager | null ;
664
737
}
738
+
739
+ /**
740
+ * Representation of a message edition.
741
+ */
742
+ export interface IMessageEdition {
743
+ /**
744
+ * The id of the edited message.
745
+ */
746
+ id : string ;
747
+ /**
748
+ * The model of the input editing the message.
749
+ */
750
+ model : IInputModel ;
751
+ }
752
+
753
+ /**
754
+ * Writer interface, including the message ID if the writer is editing a message.
755
+ */
756
+ export interface IWriter {
757
+ /**
758
+ * The user currently writing.
759
+ */
760
+ user : IUser ;
761
+ /**
762
+ * The message ID (optional)
763
+ */
764
+ messageID ?: string ;
765
+ }
665
766
}
666
767
667
768
/**
0 commit comments