Class: MeshChat::Message::Ping

Inherits:
Base
  • Object
show all
Defined in:
lib/meshchat/message/ping.rb

Instance Attribute Summary

Attributes inherited from Base

#message, #payload, #sender_location, #sender_name, #sender_uid, #time_recieved

Instance Method Summary collapse

Methods inherited from Base

#client, #client_version, #initialize, #render, #type

Constructor Details

This class inherits a constructor from MeshChat::Message::Base

Instance Method Details

#displayObject



5
6
7
8
9
10
11
12
13
# File 'lib/meshchat/message/ping.rb', line 5

def display
  # we'll never display our own ping to someone else...
  # or shouldn't.... or there should be different output
  # TODO: display is a bad method name
  name = payload['sender']['alias']
  location = payload['sender']['location']

  "#{name}@#{location} pinged you."
end

#handleObject



15
16
17
18
# File 'lib/meshchat/message/ping.rb', line 15

def handle
  respond
  display
end

#respondObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/meshchat/message/ping.rb', line 20

def respond
  location = payload['sender']['location']

  node = Node.find_by_location(location)

  MeshChat::Net::Client.send(
    node: node,
    message: PingReply.new
  )
end