Class: Meshchat::Network::Message::Base
- Inherits:
-
Object
- Object
- Meshchat::Network::Message::Base
- Defined in:
- lib/meshchat/network/message/base.rb
Overview
NOTE:
#display: shows the message
should be used locally, before *sending* a message
#handle: processing logic for the message
should be used when receiving a message, and there
needs to be a response right away
#respond: where the actual logic for the response goes
Direct Known Subclasses
Chat, Disconnect, NodeList, NodeListDiff, NodeListHash, Ping, PingReply, Whisper
Instance Attribute Summary collapse
-
#_message ⇒ Object
Returns the value of attribute _message.
-
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
-
#_message_factory ⇒ Object
Returns the value of attribute _message_factory.
-
#_sender_location ⇒ Object
Returns the value of attribute _sender_location.
-
#_sender_name ⇒ Object
Returns the value of attribute _sender_name.
-
#_sender_uid ⇒ Object
Returns the value of attribute _sender_uid.
-
#_time_received ⇒ Object
Returns the value of attribute _time_received.
-
#payload ⇒ Object
Returns the value of attribute payload.
Instance Method Summary collapse
- #client ⇒ Object
- #client_version ⇒ Object
-
#display ⇒ Object
shows the message should be used locally, before sending a message.
- #encrypt_for(node) ⇒ Object
-
#handle ⇒ Object
processing logic for the message should be used when receiving a message, and there needs to be a response right away.
-
#initialize(message: '', sender: {}, payload: {}, message_dispatcher: nil, message_factory: nil) ⇒ Base
constructor
A new instance of Base.
- #message ⇒ Object
-
#render ⇒ Object
(also: #jsonized_payload)
this message should be called immediately before sending to the whomever.
-
#respond ⇒ Object
Most message types aren’t going to need to have an immediate response.
- #sender ⇒ Object
- #sender_location ⇒ Object
- #sender_name ⇒ Object
- #sender_uid ⇒ Object
- #time_received ⇒ Object
- #time_received_as_date ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(message: '', sender: {}, payload: {}, message_dispatcher: nil, message_factory: nil) ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/meshchat/network/message/base.rb', line 23 def initialize( message: '', sender: {}, payload: {}, message_dispatcher: nil, message_factory: nil) if payload.present? @payload = payload.deep_stringify_keys else @_message = @_sender_name = sender['alias'] @_sender_location = sender['location'] @_sender_uid = sender['uid'] @_time_received = Time.now.iso8601 end @_message_dispatcher = @_message_factory = end |
Instance Attribute Details
#_message ⇒ Object
Returns the value of attribute _message.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def @_message end |
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def @_message_dispatcher end |
#_message_factory ⇒ Object
Returns the value of attribute _message_factory.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def @_message_factory end |
#_sender_location ⇒ Object
Returns the value of attribute _sender_location.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def _sender_location @_sender_location end |
#_sender_name ⇒ Object
Returns the value of attribute _sender_name.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def _sender_name @_sender_name end |
#_sender_uid ⇒ Object
Returns the value of attribute _sender_uid.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def _sender_uid @_sender_uid end |
#_time_received ⇒ Object
Returns the value of attribute _time_received.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def _time_received @_time_received end |
#payload ⇒ Object
Returns the value of attribute payload.
13 14 15 |
# File 'lib/meshchat/network/message/base.rb', line 13 def payload @payload end |
Instance Method Details
#client ⇒ Object
91 92 93 |
# File 'lib/meshchat/network/message/base.rb', line 91 def client APP_CONFIG[:client_name] end |
#client_version ⇒ Object
95 96 97 |
# File 'lib/meshchat/network/message/base.rb', line 95 def client_version APP_CONFIG[:client_version] end |
#display ⇒ Object
shows the message should be used locally, before sending a message
101 102 103 104 105 106 107 |
# File 'lib/meshchat/network/message/base.rb', line 101 def display { time: time_received_as_date, from: sender_name, message: } end |
#encrypt_for(node) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/meshchat/network/message/base.rb', line 130 def encrypt_for(node) result = jsonized_payload public_key = node.public_key result = Encryption.encrypt(result, public_key) if node.public_key Base64.strict_encode64(result) end |
#handle ⇒ Object
processing logic for the message should be used when receiving a message, and there needs to be a response right away. this may call display, if the response is always to be displayed
113 114 115 |
# File 'lib/meshchat/network/message/base.rb', line 113 def handle display end |
#message ⇒ Object
63 64 65 |
# File 'lib/meshchat/network/message/base.rb', line 63 def || payload['message'] end |
#render ⇒ Object Also known as: jsonized_payload
this message should be called immediately before sending to the whomever
124 125 126 |
# File 'lib/meshchat/network/message/base.rb', line 124 def render payload.to_json end |
#respond ⇒ Object
Most message types aren’t going to need to have an immediate response.
119 120 |
# File 'lib/meshchat/network/message/base.rb', line 119 def respond end |
#sender ⇒ Object
67 68 69 |
# File 'lib/meshchat/network/message/base.rb', line 67 def sender payload['sender'] end |
#sender_location ⇒ Object
75 76 77 |
# File 'lib/meshchat/network/message/base.rb', line 75 def sender_location _sender_location || sender['location'] end |
#sender_name ⇒ Object
71 72 73 |
# File 'lib/meshchat/network/message/base.rb', line 71 def sender_name _sender_name || sender['alias'] end |
#sender_uid ⇒ Object
79 80 81 |
# File 'lib/meshchat/network/message/base.rb', line 79 def sender_uid _sender_uid || sender['uid'] end |
#time_received ⇒ Object
83 84 85 |
# File 'lib/meshchat/network/message/base.rb', line 83 def time_received _time_received || payload['time_sent'] end |
#time_received_as_date ⇒ Object
87 88 89 |
# File 'lib/meshchat/network/message/base.rb', line 87 def time_received_as_date DateTime.parse(time_received) if time_received end |