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 43 |
# 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
92 93 94 |
# File 'lib/meshchat/network/message/base.rb', line 92 def client APP_CONFIG[:client_name] end |
#client_version ⇒ Object
96 97 98 |
# File 'lib/meshchat/network/message/base.rb', line 96 def client_version APP_CONFIG[:client_version] end |
#display ⇒ Object
shows the message should be used locally, before sending a message
102 103 104 105 106 107 108 |
# File 'lib/meshchat/network/message/base.rb', line 102 def display { time: time_received_as_date, from: sender_name, message: } end |
#encrypt_for(node) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/meshchat/network/message/base.rb', line 131 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
114 115 116 |
# File 'lib/meshchat/network/message/base.rb', line 114 def handle display end |
#message ⇒ Object
64 65 66 |
# File 'lib/meshchat/network/message/base.rb', line 64 def || payload['message'] end |
#render ⇒ Object Also known as: jsonized_payload
this message should be called immediately before sending to the whomever
125 126 127 |
# File 'lib/meshchat/network/message/base.rb', line 125 def render payload.to_json end |
#respond ⇒ Object
Most message types aren’t going to need to have an immediate response.
120 121 |
# File 'lib/meshchat/network/message/base.rb', line 120 def respond end |
#sender ⇒ Object
68 69 70 |
# File 'lib/meshchat/network/message/base.rb', line 68 def sender payload['sender'] end |
#sender_location ⇒ Object
76 77 78 |
# File 'lib/meshchat/network/message/base.rb', line 76 def sender_location _sender_location || sender['location'] end |
#sender_name ⇒ Object
72 73 74 |
# File 'lib/meshchat/network/message/base.rb', line 72 def sender_name _sender_name || sender['alias'] end |
#sender_uid ⇒ Object
80 81 82 |
# File 'lib/meshchat/network/message/base.rb', line 80 def sender_uid _sender_uid || sender['uid'] end |
#time_received ⇒ Object
84 85 86 |
# File 'lib/meshchat/network/message/base.rb', line 84 def time_received _time_received || payload['time_sent'] end |
#time_received_as_date ⇒ Object
88 89 90 |
# File 'lib/meshchat/network/message/base.rb', line 88 def time_received_as_date DateTime.parse(time_received) if time_received end |