@@ -36,12 +36,14 @@ local M = {
3636
3737--- Load the discussion data, storage them in M.discussions and M.unlinked_discussions and call
3838--- callback with data
39- --- @param callback fun ( data : DiscussionData ): nil
39+ --- @param callback ( fun ( data : DiscussionData ): nil )?
4040M .load_discussions = function (callback )
4141 job .run_job (" /discussions/list" , " POST" , { blacklist = state .settings .discussion_tree .blacklist }, function (data )
4242 M .discussions = data .discussions
4343 M .unlinked_discussions = data .unlinked_discussions
44- callback (data )
44+ if type (callback ) == " function" then
45+ callback (data )
46+ end
4547 end )
4648end
4749
@@ -482,6 +484,7 @@ M.send_reply = function(tree, discussion_id)
482484 job .run_job (" /reply" , " POST" , body , function (data )
483485 u .notify (" Sent reply!" , vim .log .levels .INFO )
484486 M .add_reply_to_tree (tree , data .note , discussion_id )
487+ M .load_discussions ()
485488 end )
486489 end
487490end
@@ -506,7 +509,7 @@ M.send_deletion = function(tree, unlinked)
506509 local root_node = M .get_root_node (tree , current_node )
507510 local note_id = note_node .is_root and root_node .root_note_id or note_node .id
508511
509- local body = { discussion_id = root_node .id , note_id = note_id }
512+ local body = { discussion_id = root_node .id , note_id = tonumber ( note_id ) }
510513
511514 job .run_job (" /comment" , " DELETE" , body , function (data )
512515 u .notify (data .message , vim .log .levels .INFO )
@@ -553,11 +556,14 @@ M.edit_comment = function(tree, unlinked)
553556 vim .api .nvim_buf_set_lines (currentBuffer , 0 , - 1 , false , lines )
554557 state .set_popup_keymaps (
555558 edit_popup ,
556- M .send_edits (tostring (root_node .id ), note_node .root_note_id or note_node .id , unlinked )
559+ M .send_edits (tostring (root_node .id ), tonumber ( note_node .root_note_id or note_node .id ) , unlinked )
557560 )
558561end
559562
560- -- This function sends the edited comment to the Go server
563+ --- This function sends the edited comment to the Go server
564+ --- @param discussion_id string
565+ --- @param note_id integer
566+ --- @param unlinked boolean
561567M .send_edits = function (discussion_id , note_id , unlinked )
562568 return function (text )
563569 local body = {
@@ -568,10 +574,10 @@ M.send_edits = function(discussion_id, note_id, unlinked)
568574 job .run_job (" /comment" , " PATCH" , body , function (data )
569575 u .notify (data .message , vim .log .levels .INFO )
570576 if unlinked then
571- M .unlinked_discussions = M . replace_text (M .unlinked_discussions , discussion_id , note_id , text )
577+ M .replace_text (M .unlinked_discussions , discussion_id , note_id , text )
572578 M .rebuild_unlinked_discussion_tree ()
573579 else
574- M .discussions = M . replace_text (M .discussions , discussion_id , note_id , text )
580+ M .replace_text (M .discussions , discussion_id , note_id , text )
575581 M .rebuild_discussion_tree ()
576582 end
577583 end )
@@ -869,13 +875,17 @@ M.redraw_resolved_status = function(tree, note, mark_resolved)
869875 tree :render ()
870876end
871877
878+ --- Replace text in discussion after note update.
879+ --- @param data Discussion[] | UnlinkedDiscussion[]
880+ --- @param discussion_id string
881+ --- @param note_id integer
882+ --- @param text string
872883M .replace_text = function (data , discussion_id , note_id , text )
873884 for i , discussion in ipairs (data ) do
874885 if discussion .id == discussion_id then
875886 for j , note in ipairs (discussion .notes ) do
876887 if note .id == note_id then
877888 data [i ].notes [j ].body = text
878- return data
879889 end
880890 end
881891 end
@@ -919,7 +929,7 @@ M.get_note_node = function(tree, node)
919929end
920930
921931M .add_reply_to_tree = function (tree , note , discussion_id )
922- local note_node = M .build_note (note )
932+ local note_node = discussions_tree .build_note (note )
923933 note_node :expand ()
924934 tree :add_node (note_node , discussion_id and (" -" .. discussion_id ) or nil )
925935 tree :render ()
0 commit comments