Class: MarsBase10::SocialLounge

Inherits:
Controller show all
Defined in:
lib/mars_base_10/controller/social_lounge.rb

Instance Attribute Summary collapse

Attributes inherited from Controller

#manager, #panes, #ship, #viewport

Instance Method Summary collapse

Methods inherited from Controller

#action_bar, #active_node, #start, #stop

Constructor Details

#initialize(manager:, ship_connection:, viewport:, options: {}) ⇒ SocialLounge

Returns a new instance of SocialLounge.



9
10
11
12
13
14
# File 'lib/mars_base_10/controller/social_lounge.rb', line 9

def initialize(manager:, ship_connection:, viewport:, options: {})
  @index_ary = []
  @group_title = options[:group_title]
  @channel_title = options[:channel_title]
  super(manager: manager, ship_connection: ship_connection, viewport: viewport)
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



7
8
9
# File 'lib/mars_base_10/controller/social_lounge.rb', line 7

def channel
  @channel
end

Instance Method Details

#active_channelObject



16
17
18
19
20
21
# File 'lib/mars_base_10/controller/social_lounge.rb', line 16

def active_channel
  if self.channel.nil?
    self.channel = self.ship.fetch_channel(group_title: @group_title, channel_title: @channel_title)
  end
  self.channel
end

#active_node_indexObject



23
24
25
# File 'lib/mars_base_10/controller/social_lounge.rb', line 23

def active_node_index
  @index_ary[@pane_1.index]
end

#active_resourceObject



27
28
29
# File 'lib/mars_base_10/controller/social_lounge.rb', line 27

def active_resource
  self.active_channel.resource # '~winter-paches/top-shelf-6391'
end

#active_subject(pane:) ⇒ Object



31
32
33
# File 'lib/mars_base_10/controller/social_lounge.rb', line 31

def active_subject(pane:)
  pane.current_subject_index
end

#fetch_channel_messagesObject



35
36
37
38
39
40
41
42
# File 'lib/mars_base_10/controller/social_lounge.rb', line 35

def fetch_channel_messages
  if @pane_1 == self.viewport.active_pane
    @pane_1.clear
    @pane_1.subject.title = "Messages in #{self.active_channel.title}"
    @pane_1.subject.contents = self.load_messages(count: @pane_1.last_visible_row)
  end
  nil
end

#load_historyObject



44
45
46
47
48
49
# File 'lib/mars_base_10/controller/social_lounge.rb', line 44

def load_history
  return 0 unless @pane_1 == self.viewport.active_pane
  messages = self.node_indexes_to_messages(node_indexes: self.ship.fetch_older_nodes(resource: self.active_resource, node: self.active_node, count: @pane_1.last_visible_row))
  @pane_1.subject.prepend_content(ary: messages)
  messages.length
end

#load_messages(count:) ⇒ Object



51
52
53
# File 'lib/mars_base_10/controller/social_lounge.rb', line 51

def load_messages(count:)
  self.node_indexes_to_messages(node_indexes: self.ship.fetch_node_list(resource: self.active_resource, count: count))
end

#message(node:) ⇒ Object

This will eventually be a native part of the Airlock API



56
57
58
# File 'lib/mars_base_10/controller/social_lounge.rb', line 56

def message(node:)
  "~#{node.to_h[:author]}  #{self.message_content(node_content: node.to_h[:contents])}"
end

#message_content(node_content:) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mars_base_10/controller/social_lounge.rb', line 60

def message_content(node_content:)
  n0 = node_content[0]
  if n0["reference"]
    # http://localhost:8080/apps/landscape/perma/group/~winter-paches/the-great-north/graph/~winter-paches/top-shelf-6391/170141184505732100235824355185168220160
    ref = n0["reference"]["graph"]
    # grup = ref["group"].split('/').last
    # graf = ref["graph"].split('/').last
    return "=> #{node_content[2]["mention"]} -> #{node_content[3]["text"]} (#{ref["index"]})"
  end
  n0["text"] || n0["url"]
end

#node_indexes_to_messages(node_indexes:) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/mars_base_10/controller/social_lounge.rb', line 72

def node_indexes_to_messages(node_indexes:)
  @index_ary =  node_indexes + @index_ary
  messages = node_indexes.map do |i|
    # Can't use fetch_node_contents because we're formatting differently now.
    # This will eventually be a native part of the Airlock API
    self.message(node: self.ship.fetch_node(resource: self.active_resource, index: i))
  end
end

#send(key:) ⇒ Object

Called by a pane in this controller for bubbling a key press up



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mars_base_10/controller/social_lounge.rb', line 84

def send(key:)
  case key
  when 'g'    # (G)raph View
    unless @pane_1.active?
      self.viewport.activate pane: @pane_1
      self.action_bar.remove_actions([:g])
    end
  when 'i'    # (I)nspect
    begin
      self.viewport.activate pane: @pane_3
      self.action_bar.add_action({'g': 'Group List'})
    end
  when 'X'
    self.manager.swap_controller
  end
end

#showObject



101
102
103
# File 'lib/mars_base_10/controller/social_lounge.rb', line 101

def show
  self.fetch_channel_messages
end