Skip to content

Commit

Permalink
Fix: Show draft replies in the correct tree (#396)
Browse files Browse the repository at this point in the history
Fix: Show draft replies in the correct tree
  • Loading branch information
jakubbortlik authored Oct 13, 2024
1 parent 96efdc2 commit b359b47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lua/gitlab/actions/discussions/winbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ local function content()
local resolvable_notes, resolved_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions)

local draft_notes = require("gitlab.actions.draft_notes")
local inline_draft_notes = List.new(state.DRAFT_NOTES):filter(draft_notes.has_position)
local unlinked_draft_notes = List.new(state.DRAFT_NOTES):filter(function(note)
return not draft_notes.has_position(note)
local inline_draft_notes, unlinked_draft_notes = List.new(state.DRAFT_NOTES):partition(function(note)
if note.discussion_id == "" then
return draft_notes.has_position(note)
end
for _, discussion in ipairs(state.DISCUSSION_DATA.unlinked_discussions) do
if discussion.id == note.discussion_id then
return false
end
end
return true
end)

local t = {
Expand Down
17 changes: 17 additions & 0 deletions lua/gitlab/utils/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ function List:filter(func)
return result
end

---Partitions a given list into two lists
---@generic T
---@param func fun(v: T, i: integer):boolean
---@return List<T>, List<T> @Returns two lists: the 1st with elements for which func returns true, the 2nd with elements for which it returns false
function List:partition(func)
local result_true = List.new()
local result_false = List.new()
for i, v in ipairs(self) do
if func(v, i) == true then
table.insert(result_true, v)
else
table.insert(result_false, v)
end
end
return result_true, result_false
end

function List:reduce(func, agg)
for i, v in ipairs(self) do
agg = func(agg, v, i)
Expand Down

0 comments on commit b359b47

Please sign in to comment.