selfsdk 0.0.182 → 0.0.184
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/messages/fact_request.rb +2 -0
- data/lib/messaging.rb +5 -0
- data/lib/selfsdk.rb +1 -1
- data/lib/services/chat.rb +37 -5
- data/lib/services/facts.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c16f1734a708b0ebd37ca4fa0cea0e48db09344d4efb0654e5b4df6a37fd2d4
|
|
4
|
+
data.tar.gz: 32313fa1c28a57370c43d7100bdacc06bad28f0722ba0589a63c24bd0327bfd2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a015baa1ed364efcc422af5de6a54f87cbb953cdb45de7f397aa8cd2273b99c8ce4f6fbba0fc62f0ef803f38edf8155fbb1e9e14042b4f4ff76b391147da614
|
|
7
|
+
data.tar.gz: dfec1973db212e016774292d57bda452727cadd201ecdb80ab0f507a97ff3df244887ffde06704a618de63e0d101c75b7e8c879ff983654892d9496a50db7889
|
|
@@ -34,6 +34,7 @@ module SelfSDK
|
|
|
34
34
|
@options = opts.fetch(:options, false)
|
|
35
35
|
@description = opts.include?(:description) ? opts[:description] : nil
|
|
36
36
|
@exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
|
|
37
|
+
@allowed_for = opts.fetch(:allowed_for, nil)
|
|
37
38
|
|
|
38
39
|
@intermediary = if opts.include?(:intermediary)
|
|
39
40
|
opts[:intermediary]
|
|
@@ -89,6 +90,7 @@ module SelfSDK
|
|
|
89
90
|
}
|
|
90
91
|
b[:options] = @options unless (@options.nil? || @options == false)
|
|
91
92
|
b[:description] = @description unless (@description.nil? || @description.empty?)
|
|
93
|
+
b[:allowed_until] = (SelfSDK::Time.now + @allowed_for).strftime('%FT%TZ') unless @allowed_for.nil?
|
|
92
94
|
b
|
|
93
95
|
end
|
|
94
96
|
|
data/lib/messaging.rb
CHANGED
|
@@ -92,6 +92,11 @@ module SelfSDK
|
|
|
92
92
|
send_message m
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
def session?(identifier, device)
|
|
96
|
+
path = @encryption_client.session_path(identifier, device)
|
|
97
|
+
File.file?(path)
|
|
98
|
+
end
|
|
99
|
+
|
|
95
100
|
# Send custom mmessage
|
|
96
101
|
#
|
|
97
102
|
# @param recipient [string] selfID to be requested
|
data/lib/selfsdk.rb
CHANGED
data/lib/services/chat.rb
CHANGED
|
@@ -14,7 +14,9 @@ module SelfSDK
|
|
|
14
14
|
def initialize(messaging, client)
|
|
15
15
|
@messaging = messaging
|
|
16
16
|
@client = client
|
|
17
|
-
@app_id = @client.jwt.id
|
|
17
|
+
@app_id = @messaging.client.client.jwt.id
|
|
18
|
+
@auth_token = @messaging.client.client.jwt.auth_token
|
|
19
|
+
@self_url = @messaging.client.client.self_url
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
# Sends a message to a list of recipients.
|
|
@@ -32,7 +34,7 @@ module SelfSDK
|
|
|
32
34
|
payload[:rid] = opts[:rid] if opts.key? :rid
|
|
33
35
|
payload[:objects] = opts[:objects] if opts.key? :objects
|
|
34
36
|
|
|
35
|
-
m = SelfSDK::Chat::Message.new(self, recipients, payload, @
|
|
37
|
+
m = SelfSDK::Chat::Message.new(self, recipients, payload, @auth_token, @self_url)
|
|
36
38
|
_req = send(m.recipients, m.payload)
|
|
37
39
|
|
|
38
40
|
m
|
|
@@ -41,8 +43,7 @@ module SelfSDK
|
|
|
41
43
|
# Subscribes to an incoming chat message
|
|
42
44
|
def on_message(opts = {}, &block)
|
|
43
45
|
@messaging.subscribe :chat_message do |msg|
|
|
44
|
-
|
|
45
|
-
cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @messaging.client.jwt.auth_token, @client.self_url)
|
|
46
|
+
cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @auth_token, @self_url)
|
|
46
47
|
|
|
47
48
|
cm.mark_as_delivered unless opts[:mark_as_delivered] == false
|
|
48
49
|
cm.mark_as_read if opts[:mark_as_read] == true
|
|
@@ -127,7 +128,7 @@ module SelfSDK
|
|
|
127
128
|
members: members }
|
|
128
129
|
|
|
129
130
|
if opts.key? :data
|
|
130
|
-
obj = SelfSDK::Chat::FileObject.new(@
|
|
131
|
+
obj = SelfSDK::Chat::FileObject.new(@auth_token, @self_url)
|
|
131
132
|
obj_payload = obj.build_from_data("", opts[:data], opts[:mime]).to_payload
|
|
132
133
|
obj_payload.delete(:name)
|
|
133
134
|
payload.merge! obj_payload
|
|
@@ -142,6 +143,12 @@ module SelfSDK
|
|
|
142
143
|
# @param gid [string] group id.
|
|
143
144
|
# @param members [array] list of group members.
|
|
144
145
|
def join(gid, members)
|
|
146
|
+
# Allow incoming connections from the given members
|
|
147
|
+
|
|
148
|
+
# Create missing sessions with group members.
|
|
149
|
+
create_missing_sessions(members)
|
|
150
|
+
|
|
151
|
+
# Send joining confirmation.
|
|
145
152
|
send(members, typ: 'chat.join', gid: gid, aud: gid)
|
|
146
153
|
end
|
|
147
154
|
|
|
@@ -173,6 +180,31 @@ module SelfSDK
|
|
|
173
180
|
end
|
|
174
181
|
m
|
|
175
182
|
end
|
|
183
|
+
|
|
184
|
+
# Group invites may come with members of the group we haven't set up a session
|
|
185
|
+
# previously, for those identitiese need to establish a session, but only if
|
|
186
|
+
# our identity appears before the others in the list members.
|
|
187
|
+
def create_missing_sessions(members)
|
|
188
|
+
return if members.empty?
|
|
189
|
+
|
|
190
|
+
posterior_members = false
|
|
191
|
+
requests = []
|
|
192
|
+
|
|
193
|
+
members.each do |m|
|
|
194
|
+
if posterior_members
|
|
195
|
+
@client.devices(m).each do |d|
|
|
196
|
+
continue unless @messaging.client.session?(m, d)
|
|
197
|
+
|
|
198
|
+
requests << @messaging.send("#{m}:#{d}", {
|
|
199
|
+
typ: 'sessions.create',
|
|
200
|
+
aud: m
|
|
201
|
+
})
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
posterior_members = true if m == @app_id
|
|
206
|
+
end
|
|
207
|
+
end
|
|
176
208
|
end
|
|
177
209
|
end
|
|
178
210
|
end
|
data/lib/services/facts.rb
CHANGED
|
@@ -40,6 +40,7 @@ module SelfSDK
|
|
|
40
40
|
# @param [Hash] opts the options to authenticate.
|
|
41
41
|
# @option opts [String] :cid The unique identifier of the authentication request.
|
|
42
42
|
# @option opts [Integer] :exp_timeout timeout in seconds to expire the request.
|
|
43
|
+
# @option opts [Integer] :allowed_for number of seconds for enabling recurrent requests.
|
|
43
44
|
# @return [Object] SelfSDK:::Messages::FactRequest
|
|
44
45
|
def request(selfid, facts, opts = {}, &block)
|
|
45
46
|
SelfSDK.logger.info "authenticating #{selfid}"
|