@@ -40,6 +40,7 @@ export type MessageComposerState = {
40
40
id : string ;
41
41
quotedMessage : LocalMessageBase | null ;
42
42
pollId : string | null ;
43
+ draftId : string | null ;
43
44
} ;
44
45
45
46
export type MessageComposerConfig = {
@@ -82,18 +83,22 @@ const initState = (
82
83
id : MessageComposer . generateId ( ) ,
83
84
quotedMessage : null ,
84
85
pollId : null ,
86
+ draftId : null ,
85
87
} ;
86
88
}
87
89
88
90
const quotedMessage = composition . quoted_message ;
89
91
let message ;
92
+ let draftId = null ;
90
93
if ( compositionIsMessageDraft ( composition ) ) {
91
94
message = composition . message ;
95
+ draftId = composition . message . id ;
92
96
} else {
93
97
message = composition ;
94
98
}
95
99
96
100
return {
101
+ draftId,
97
102
id : message . id ,
98
103
quotedMessage : quotedMessage
99
104
? formatMessage ( quotedMessage as MessageResponseBase )
@@ -180,6 +185,11 @@ export class MessageComposer {
180
185
get id ( ) {
181
186
return this . state . getLatestValue ( ) . id ;
182
187
}
188
+
189
+ get draftId ( ) {
190
+ return this . state . getLatestValue ( ) . draftId ;
191
+ }
192
+
183
193
get lastChange ( ) {
184
194
return this . editingAuditState . getLatestValue ( ) . lastChange ;
185
195
}
@@ -539,12 +549,14 @@ export class MessageComposer {
539
549
const composition = await this . composeDraft ( ) ;
540
550
if ( ! composition ) return ;
541
551
const { draft } = composition ;
552
+ this . state . partialNext ( { draftId : draft . id } ) ;
542
553
this . logDraftUpdateTimestamp ( ) ;
543
554
await this . channel . createDraft ( draft ) ;
544
555
} ;
545
556
546
557
deleteDraft = async ( ) => {
547
- if ( this . editedMessage || ! this . config . draftsEnabled ) return ;
558
+ if ( this . editedMessage || ! this . config . draftsEnabled || ! this . draftId ) return ;
559
+ this . state . partialNext ( { draftId : null } ) ; // todo: should we clear the whole state?
548
560
this . logDraftUpdateTimestamp ( ) ;
549
561
await this . channel . deleteDraft ( { parent_id : this . threadId ?? undefined } ) ;
550
562
} ;
0 commit comments