Class: MeshChat::Message::NodeList
- Defined in:
- lib/meshchat/message/node_list.rb
Instance Attribute Summary
Attributes inherited from Base
#payload, #sender_location, #sender_name, #sender_uid, #time_recieved
Instance Method Summary collapse
- #handle ⇒ Object
- #message ⇒ Object
-
#respond ⇒ Object
only need to respond if this server has node entries that the sender of this message doesn’t have.
Methods inherited from Base
#client, #client_version, #display, #initialize, #render, #type
Constructor Details
This class inherits a constructor from MeshChat::Message::Base
Instance Method Details
#handle ⇒ Object
8 9 10 11 |
# File 'lib/meshchat/message/node_list.rb', line 8 def handle respond return end |
#message ⇒ Object
4 5 6 |
# File 'lib/meshchat/message/node_list.rb', line 4 def ||= Node.as_json end |
#respond ⇒ Object
only need to respond if this server has node entries that the sender of this message doesn’t have
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/meshchat/message/node_list.rb', line 15 def respond received_list = we_only_have, they_only_have = Node.diff(received_list) if they_only_have.present? they_only_have.each do |n| # be sure that we don't add ourselves unless n['uid'] == Settings['uid'] Node.from_json(n).save! end end end location = payload['sender']['location'] node = Node.find_by_location(location) if we_only_have.present? # give the sender our list MeshChat::Net::Client.send( node: node, message: NodeListDiff.new(message: we_only_have) ) # give people we know about # (but the sender of the Node List may not know about) # our node list diff Node.online.each do |entry| MeshChat::Net::Client.send( node: entry, message: NodeListDiff.new(message: they_only_have) ) end else # lists are in sync, confirm with hash MeshChat::Net::Client.send( node: node, message: NodeListHash.new ) end end |