@@ -355,8 +355,9 @@ export class ChatActions extends Actions<ChatState> {
355
355
}
356
356
357
357
// Used to edit sent messages.
358
- // TODO: this is **Extremely** shockingly inefficient; it assumes
359
- // the number of edits is small.
358
+ // NOTE: this is inefficient; it assumes
359
+ // the number of edits is small, which is reasonable -- nobody makes hundreds of distinct
360
+ // edits of a single message.
360
361
public send_edit ( message : ChatMessageTyped , content : string ) : void {
361
362
if ( this . syncdb == null ) {
362
363
// WARNING: give an error or try again later?
@@ -432,13 +433,24 @@ export class ChatActions extends Actions<ChatState> {
432
433
this . store ?. get ( "messages" ) ?? ( fromJS ( { } ) as ChatMessages ) ,
433
434
) ;
434
435
const time = reply_to ?. valueOf ( ) ?? 0 ;
435
- this . delete_draft ( - time ) ;
436
- return this . send_chat ( {
436
+ const time_stamp_str = this . send_chat ( {
437
437
input : reply ,
438
438
sender_id : from ?? this . redux . getStore ( "account" ) . get_account_id ( ) ,
439
439
reply_to,
440
440
noNotification,
441
441
} ) ;
442
+ this . delete_draft ( - time ) ;
443
+ // it's conceivable that for some clients they recreate the draft
444
+ // message right as the editor for that message is being removed.
445
+ // Thus we do an extra delete a moment after send (after successfully
446
+ // sending the message) to be sure the draft is really gone.
447
+ // See https://github.com/sagemathinc/cocalc/issues/7662
448
+ // and note that I'm not able to reproduce this, so it might not
449
+ // be the right solution.
450
+ setTimeout ( ( ) => {
451
+ this . delete_draft ( - time ) ;
452
+ } , 500 ) ;
453
+ return time_stamp_str ;
442
454
}
443
455
444
456
// negative date is used for replies.
@@ -451,11 +463,13 @@ export class ChatActions extends Actions<ChatState> {
451
463
sender_id = sender_id ?? this . redux . getStore ( "account" ) . get_account_id ( ) ;
452
464
// date should always be negative for drafts (stupid, but that's the code),
453
465
// so I'm just deleting both for now.
454
- this . syncdb . delete ( {
455
- event : "draft" ,
456
- sender_id,
457
- date,
458
- } ) ;
466
+ if ( date ) {
467
+ this . syncdb . delete ( {
468
+ event : "draft" ,
469
+ sender_id,
470
+ date,
471
+ } ) ;
472
+ }
459
473
this . syncdb . delete ( {
460
474
event : "draft" ,
461
475
sender_id,
0 commit comments