Assignments working

This commit is contained in:
Jorge Manrubia
2025-05-06 06:42:26 +02:00
parent 65d809dd8d
commit 72ffcfac8b
7 changed files with 107 additions and 14 deletions
+33 -7
View File
@@ -1,15 +1,41 @@
class Command::Parser
attr_reader :user
attr_reader :context
def initialize(user)
@user = user
delegate :user, :cards, to: :context
def initialize(context)
@context = context
end
def parse(string)
if card = user.accessible_cards.find_by_id(string)
Command::GoToCard.new(card: card)
else
Command::Search.new(query: string)
command_name, *command_arguments = string.split(" ")
case command_name
when "/assign", "/assign_to"
Command::Assign.new(assignee_ids: assignees_from(command_arguments).collect(&:id), card_ids: cards.ids)
else
search(string)
end
end
private
def search(string)
if card = user.accessible_cards.find_by_id(string)
Command::GoToCard.new(card_id: card.id)
else
Command::Search.new(query: string)
end
end
def assignees_from(strings)
Array(strings).filter_map do |string|
assignee_from(string)
end
end
# TODO: This is temporary as it can be ambiguous. We should inject the user ID in the command
# instead, as determined by the user picker.
def assignee_from(string)
User.all.find { |user| user.mentionable_handles.include?(string) }
end
end