Module: SelfSDK::Messages

Defined in:
lib/messages/base.rb,
lib/messages/chat.rb,
lib/messages/fact.rb,
lib/messages/message.rb,
lib/messages/chat_join.rb,
lib/messages/fact_issue.rb,
lib/messages/voice_busy.rb,
lib/messages/voice_stop.rb,
lib/messages/attestation.rb,
lib/messages/chat_invite.rb,
lib/messages/chat_remove.rb,
lib/messages/voice_setup.rb,
lib/messages/voice_start.rb,
lib/messages/chat_message.rb,
lib/messages/fact_request.rb,
lib/messages/voice_accept.rb,
lib/messages/fact_response.rb,
lib/messages/voice_summary.rb,
lib/messages/chat_message_read.rb,
lib/messages/connection_request.rb,
lib/messages/document_sign_resp.rb,
lib/messages/connection_response.rb,
lib/messages/chat_message_delivered.rb

Defined Under Namespace

Classes: Attestation, Base, Chat, ChatInvite, ChatJoin, ChatMessage, ChatMessageDelivered, ChatMessageRead, ChatRemove, ConnectionRequest, ConnectionResponse, DocumentSignResponse, Fact, FactIssue, FactRequest, FactResponse, UnmappedMessage, VoiceAccept, VoiceBusy, VoiceSetup, VoiceStart, VoiceStop, VoiceSummary

Constant Summary collapse

PRIORITY_VISIBLE =
1
PRIORITY_INVISIBLE =
2

Class Method Summary collapse

Class Method Details

.parse(input, messaging, original = nil) ⇒ Object



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/messages/message.rb', line 27

def self.parse(input, messaging, original=nil)
  envelope = nil
  body = if input.is_a? String
            input
         else
            envelope = input
            issuer = input.sender.split(":")
            messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last, input.offset)
         end

  jwt = JSON.parse(body, symbolize_names: true)
  payload = JSON.parse(messaging.jwt.decode(jwt[:payload]), symbolize_names: true)

  case payload[:typ]
  when SelfSDK::Messages::FactRequest::MSG_TYPE
    m = FactRequest.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::FactResponse::MSG_TYPE
    m = FactResponse.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessage::MSG_TYPE
    m = ChatMessage.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessageDelivered::MSG_TYPE
    m = ChatMessageDelivered.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatMessageRead::MSG_TYPE
    m = ChatMessageRead.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatInvite::MSG_TYPE
    m = ChatInvite.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatRemove::MSG_TYPE
    m = ChatRemove.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ChatJoin::MSG_TYPE
    m = ChatJoin.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::DocumentSignResponse::MSG_TYPE
    m = DocumentSignResponse.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::ConnectionResponse::MSG_TYPE
    m = ConnectionResponse.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceSetup::MSG_TYPE
    m = VoiceSetup.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceStart::MSG_TYPE
    m = VoiceStart.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceAccept::MSG_TYPE
    m = VoiceAccept.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceBusy::MSG_TYPE
    m = VoiceBusy.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceStop::MSG_TYPE
    m = VoiceStop.new(messaging)
    m.parse(body, envelope)
  when SelfSDK::Messages::VoiceSummary::MSG_TYPE
    m = VoiceSummary.new(messaging)
    m.parse(body, envelope)
  else
    raise UnmappedMessage.new("Invalid message type #{payload[:typ]}.")
  end
  return m
end