Class: Collavre::Topic

Inherits:
ApplicationRecord show all
Defined in:
app/models/collavre/topic.rb

Instance Method Summary collapse

Instance Method Details

#archive!Object



57
58
59
# File 'app/models/collavre/topic.rb', line 57

def archive!
  update!(archived_at: Time.current)
end

#archived?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/collavre/topic.rb', line 53

def archived?
  archived_at.present?
end

#primary_agentObject

Returns the primary agent User for this topic (from orchestration policy)



25
26
27
28
29
30
31
32
33
34
# File 'app/models/collavre/topic.rb', line 25

def primary_agent
  policy = OrchestratorPolicy.find_by(
    policy_type: "arbitration",
    scope_type: "Topic",
    scope_id: id
  )
  return nil unless policy&.config&.dig("primary_agent_id")

  User.find_by(id: policy.config["primary_agent_id"])
end

#set_primary_agent!(agent) ⇒ Object

Sets or replaces the primary agent for this topic



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/collavre/topic.rb', line 37

def set_primary_agent!(agent)
  policy = OrchestratorPolicy.find_or_initialize_by(
    policy_type: "arbitration",
    scope_type: "Topic",
    scope_id: id
  )
  policy.update!(
    config: {
      "strategy" => "primary_first",
      "primary_agent_id" => agent.id
    },
    priority: 10,
    enabled: true
  )
end

#unarchive!Object



61
62
63
# File 'app/models/collavre/topic.rb', line 61

def unarchive!
  update!(archived_at: nil)
end