activematrix 0.0.0 → 0.0.1
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/{matrix_sdk → active_matrix}/api.rb +18 -22
- data/lib/{matrix_sdk → active_matrix}/bot/base.rb +42 -39
- data/lib/{matrix_sdk → active_matrix}/bot/main.rb +4 -5
- data/lib/active_matrix/bot.rb +7 -0
- data/lib/{matrix_sdk → active_matrix}/client.rb +17 -20
- data/lib/{matrix_sdk → active_matrix}/errors.rb +4 -4
- data/lib/active_matrix/logging.rb +56 -0
- data/lib/{matrix_sdk → active_matrix}/mxid.rb +2 -2
- data/lib/{matrix_sdk → active_matrix}/protocols/as.rb +1 -1
- data/lib/{matrix_sdk → active_matrix}/protocols/cs.rb +6 -8
- data/lib/{matrix_sdk → active_matrix}/protocols/is.rb +1 -1
- data/lib/{matrix_sdk → active_matrix}/protocols/msc.rb +6 -8
- data/lib/{matrix_sdk → active_matrix}/protocols/ss.rb +2 -2
- data/lib/active_matrix/railtie.rb +18 -0
- data/lib/{matrix_sdk → active_matrix}/response.rb +2 -2
- data/lib/{matrix_sdk → active_matrix}/room.rb +21 -25
- data/lib/{matrix_sdk → active_matrix}/rooms/space.rb +3 -3
- data/lib/{matrix_sdk → active_matrix}/user.rb +13 -15
- data/lib/{matrix_sdk → active_matrix}/util/account_data_cache.rb +6 -6
- data/lib/{matrix_sdk → active_matrix}/util/events.rb +8 -8
- data/lib/{matrix_sdk → active_matrix}/util/extensions.rb +2 -15
- data/lib/active_matrix/util/rails_cache_adapter.rb +37 -0
- data/lib/{matrix_sdk → active_matrix}/util/state_event_cache.rb +10 -10
- data/lib/{matrix_sdk → active_matrix}/util/tinycache.rb +11 -6
- data/lib/{matrix_sdk → active_matrix}/util/tinycache_adapter.rb +3 -3
- data/lib/{matrix_sdk → active_matrix}/util/uri.rb +4 -4
- data/lib/active_matrix/version.rb +5 -0
- data/lib/active_matrix.rb +33 -0
- metadata +62 -30
- data/lib/matrix_sdk/bot.rb +0 -4
- data/lib/matrix_sdk/version.rb +0 -5
- data/lib/matrix_sdk.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 143ff7d837b5e8c2da0cc48dac7ec9494b625ec4d1f6dfd3d736648c1cf37951
|
4
|
+
data.tar.gz: 9d4d7c69c17c9d07e36b628a69de1e2d759249ea9310e3158f56323982757979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3376d53d35686a0eb5a40a7a8102a1dcd8c5c226a4bb606cf1c8d05f5f568396bd49465b5ca40c7e52dff5fa7569e0e6c39d6cae3b077ce9656bb59f699267db
|
7
|
+
data.tar.gz: c9a3120e5ea6edde56923990609e6ea156c8df500f8cd6955ec98811c622715872bcc3e76bfd740772be491956a5c4b45980d2c9ac8de87bf2f16e301bcad8f9
|
@@ -1,18 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'matrix_sdk'
|
4
|
-
|
5
3
|
require 'erb'
|
6
4
|
require 'net/http'
|
7
5
|
require 'openssl'
|
8
6
|
require 'uri'
|
9
7
|
|
10
|
-
module
|
8
|
+
module ActiveMatrix
|
11
9
|
class Api
|
12
|
-
extend
|
13
|
-
include
|
10
|
+
extend ActiveMatrix::Extensions
|
11
|
+
include ActiveMatrix::Logging
|
14
12
|
|
15
|
-
USER_AGENT = "Ruby Matrix SDK v#{
|
13
|
+
USER_AGENT = "Ruby Matrix SDK v#{ActiveMatrix::VERSION}".freeze
|
16
14
|
DEFAULT_HEADERS = {
|
17
15
|
'accept' => 'application/json',
|
18
16
|
'user-agent' => USER_AGENT
|
@@ -72,7 +70,7 @@ module MatrixSdk
|
|
72
70
|
self.threadsafe = params.fetch(:threadsafe, :multithread)
|
73
71
|
|
74
72
|
([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
|
75
|
-
self.class.include
|
73
|
+
self.class.include ActiveMatrix::Protocols.const_get(proto)
|
76
74
|
end
|
77
75
|
|
78
76
|
login(user: @homeserver.user, password: @homeserver.password) if @homeserver.user && @homeserver.password && !@access_token && !params[:skip_login] && protocol?(:CS)
|
@@ -84,7 +82,7 @@ module MatrixSdk
|
|
84
82
|
# This will follow the server discovery spec for client-server and federation
|
85
83
|
#
|
86
84
|
# @example Opening a Matrix API connection to a homeserver
|
87
|
-
# hs =
|
85
|
+
# hs = ActiveMatrix::API.new_for_domain 'example.com'
|
88
86
|
# hs.connection_address
|
89
87
|
# # => 'matrix.example.com'
|
90
88
|
# hs.connection_port
|
@@ -97,10 +95,10 @@ module MatrixSdk
|
|
97
95
|
# @return [API] The API connection
|
98
96
|
def self.new_for_domain(domain, target: :client, keep_wellknown: false, ssl: true, **params)
|
99
97
|
domain, port = domain.split(':')
|
100
|
-
uri = URI("http#{
|
98
|
+
uri = URI("http#{'s' if ssl}://#{domain}")
|
101
99
|
well_known = nil
|
102
100
|
target_uri = nil
|
103
|
-
logger =
|
101
|
+
logger = ActiveMatrix.logger
|
104
102
|
logger.debug "Resolving #{domain}"
|
105
103
|
|
106
104
|
if !port.nil? && !port.empty?
|
@@ -171,17 +169,15 @@ module MatrixSdk
|
|
171
169
|
|
172
170
|
new(
|
173
171
|
uri,
|
174
|
-
**params.
|
175
|
-
|
176
|
-
port: target_uri.port
|
177
|
-
)
|
172
|
+
**params, address: target_uri.host,
|
173
|
+
port: target_uri.port
|
178
174
|
)
|
179
175
|
end
|
180
176
|
|
181
177
|
# Get a list of enabled protocols on the API client
|
182
178
|
#
|
183
179
|
# @example
|
184
|
-
#
|
180
|
+
# ActiveMatrix::Api.new_for_domain('matrix.org').protocols
|
185
181
|
# # => [:IS, :CS]
|
186
182
|
#
|
187
183
|
# @return [Symbol[]] An array of enabled APIs
|
@@ -189,7 +185,7 @@ module MatrixSdk
|
|
189
185
|
self
|
190
186
|
.class.included_modules
|
191
187
|
.reject { |m| m&.name.nil? }
|
192
|
-
.select { |m| m.name.start_with? '
|
188
|
+
.select { |m| m.name.start_with? 'ActiveMatrix::Protocols::' }
|
193
189
|
.map { |m| m.name.split('::').last.to_sym }
|
194
190
|
end
|
195
191
|
|
@@ -343,7 +339,7 @@ module MatrixSdk
|
|
343
339
|
logger.error "Received non-parsable data in 200 response; #{response.body.inspect}"
|
344
340
|
raise MatrixConnectionError, response
|
345
341
|
end
|
346
|
-
return
|
342
|
+
return ActiveMatrix::Response.new self, data
|
347
343
|
end
|
348
344
|
raise MatrixRequestError.new_by_code(data, response.code) if data
|
349
345
|
|
@@ -394,11 +390,11 @@ module MatrixSdk
|
|
394
390
|
return unless logger.debug?
|
395
391
|
|
396
392
|
if http.is_a? Net::HTTPRequest
|
397
|
-
dir = "#{
|
393
|
+
dir = "#{"#{id} : " if id}>"
|
398
394
|
logger.debug "#{dir} Sending a #{http.method} request to `#{http.path}`:"
|
399
395
|
else
|
400
|
-
dir = "#{
|
401
|
-
logger.debug "#{dir} Received a #{http.code} #{http.message} response:#{
|
396
|
+
dir = "#{"#{id} : " if id}<"
|
397
|
+
logger.debug "#{dir} Received a #{http.code} #{http.message} response:#{" [#{(duration * 1000).to_i}ms]" if duration}"
|
402
398
|
end
|
403
399
|
http.to_hash.map { |k, v| "#{k}: #{k == 'authorization' ? '[ REDACTED ]' : v.join(', ')}" }.each do |h|
|
404
400
|
logger.debug "#{dir} #{h}"
|
@@ -424,8 +420,8 @@ module MatrixSdk
|
|
424
420
|
def http
|
425
421
|
return @http if @http&.active?
|
426
422
|
|
427
|
-
host =
|
428
|
-
port =
|
423
|
+
host = @connection_address || homeserver.host
|
424
|
+
port = @connection_port || homeserver.port
|
429
425
|
|
430
426
|
connection = @http unless @threadsafe == :multithread
|
431
427
|
connection ||= if proxy_uri
|
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'shellwords'
|
4
4
|
|
5
|
-
module
|
5
|
+
module ActiveMatrix::Bot
|
6
6
|
class Base
|
7
|
-
extend
|
7
|
+
extend ActiveMatrix::Extensions
|
8
|
+
include ActiveMatrix::Logging
|
8
9
|
|
9
10
|
RequestHandler = Struct.new('RequestHandler', :command, :type, :proc, :data) do
|
10
11
|
def command?
|
@@ -29,14 +30,14 @@ module MatrixSdk::Bot
|
|
29
30
|
|
30
31
|
def initialize(hs_url, **params)
|
31
32
|
@client = case hs_url
|
32
|
-
when
|
33
|
-
|
34
|
-
when
|
33
|
+
when ActiveMatrix::Api
|
34
|
+
ActiveMatrix::Client.new hs_url
|
35
|
+
when ActiveMatrix::Client
|
35
36
|
hs_url
|
36
37
|
when %r{^https?://.*}
|
37
|
-
|
38
|
+
ActiveMatrix::Client.new hs_url, **params
|
38
39
|
else
|
39
|
-
|
40
|
+
ActiveMatrix::Client.new_for_domain hs_url, **params
|
40
41
|
end
|
41
42
|
|
42
43
|
@client.on_event.add_handler { |ev| _handle_event(ev) }
|
@@ -59,30 +60,23 @@ module MatrixSdk::Bot
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def self.logger
|
62
|
-
|
63
|
-
begin
|
64
|
-
l.level = :debug if MatrixSdk::Bot::PARAMS_CONFIG[:logging]
|
65
|
-
rescue NameError
|
66
|
-
# Not running as instance
|
67
|
-
end
|
68
|
-
l.level = settings.log_level unless settings.logging?
|
69
|
-
end
|
63
|
+
@logger ||= ActiveMatrix.logger
|
70
64
|
end
|
71
65
|
|
72
66
|
# Register a command during runtime
|
73
67
|
#
|
74
68
|
# @param command [String] The command to register
|
75
69
|
# @see Base.command for full parameter information
|
76
|
-
def register_command(command, **params, &
|
77
|
-
self.class.command(command, **params, &
|
70
|
+
def register_command(command, **params, &)
|
71
|
+
self.class.command(command, **params, &)
|
78
72
|
end
|
79
73
|
|
80
74
|
# Register an event during runtime
|
81
75
|
#
|
82
76
|
# @param event [String] The event to register
|
83
77
|
# @see Base.event for full parameter information
|
84
|
-
def register_event(event, **params, &
|
85
|
-
self.class.event(event, **params, &
|
78
|
+
def register_event(event, **params, &)
|
79
|
+
self.class.event(event, **params, &)
|
86
80
|
end
|
87
81
|
|
88
82
|
# Removes a registered command during runtime
|
@@ -149,7 +143,7 @@ module MatrixSdk::Bot
|
|
149
143
|
attr_reader :handlers
|
150
144
|
|
151
145
|
CALLERS_TO_IGNORE = [
|
152
|
-
/\/matrix_sdk\/.+\.rb$/, # all
|
146
|
+
/\/matrix_sdk\/.+\.rb$/, # all ActiveMatrix code
|
153
147
|
/^\(.*\)$/, # generated code
|
154
148
|
/rubygems\/(custom|core_ext\/kernel)_require\.rb$/, # rubygems require hacks
|
155
149
|
/bundler(\/(?:runtime|inline))?\.rb/, # bundler require hacks
|
@@ -252,16 +246,16 @@ module MatrixSdk::Bot
|
|
252
246
|
# @note Due to the way blocks are handled, required parameters won't block execution.
|
253
247
|
# If your command requires all parameters to be valid, you will need to check for nil yourself.
|
254
248
|
#
|
255
|
-
# @note Execution will be performed with a
|
256
|
-
# To access the bot instance, use
|
249
|
+
# @note Execution will be performed with a ActiveMatrix::Bot::Request object as self.
|
250
|
+
# To access the bot instance, use ActiveMatrix::Bot::Request#bot
|
257
251
|
#
|
258
252
|
# @param command [String] The command to register, will be routed based on the prefix and bot NameError
|
259
253
|
# @param desc [String] A human-readable description for the command
|
260
254
|
# @param only [Symbol,Proc,Array[Symbol,Proc]] What limitations does this command have?
|
261
255
|
# Can use :DM, :Admin, :Mod
|
262
256
|
# @option params
|
263
|
-
def command(command, desc: nil, notes: nil, only: nil, **params, &
|
264
|
-
args = params[:args] || convert_to_lambda(&
|
257
|
+
def command(command, desc: nil, notes: nil, only: nil, **params, &)
|
258
|
+
args = params[:args] || convert_to_lambda(&).parameters.map do |type, name|
|
265
259
|
case type
|
266
260
|
when :req
|
267
261
|
name.to_s.upcase
|
@@ -281,7 +275,7 @@ module MatrixSdk::Bot
|
|
281
275
|
desc: desc,
|
282
276
|
notes: notes,
|
283
277
|
only: [only].flatten.compact,
|
284
|
-
&
|
278
|
+
&
|
285
279
|
)
|
286
280
|
end
|
287
281
|
|
@@ -292,14 +286,14 @@ module MatrixSdk::Bot
|
|
292
286
|
# @param event [String] The ID for the event to register
|
293
287
|
# @param only [Symbol,Proc,Array[Symbol,Proc]] The limitations to when the event should be handled
|
294
288
|
# @option params
|
295
|
-
def event(event, only: nil, **_params, &
|
289
|
+
def event(event, only: nil, **_params, &)
|
296
290
|
logger.debug "Registering event #{event}"
|
297
291
|
|
298
292
|
add_handler(
|
299
293
|
event.to_s,
|
300
294
|
type: :event,
|
301
295
|
only: [only].flatten.compact,
|
302
|
-
&
|
296
|
+
&
|
303
297
|
)
|
304
298
|
end
|
305
299
|
|
@@ -404,7 +398,7 @@ module MatrixSdk::Bot
|
|
404
398
|
# Starts the bot up
|
405
399
|
#
|
406
400
|
# @param options [Hash] Settings to apply using Base.set
|
407
|
-
def run!(options = {}, &
|
401
|
+
def run!(options = {}, &)
|
408
402
|
return if running?
|
409
403
|
|
410
404
|
set options
|
@@ -423,7 +417,7 @@ module MatrixSdk::Bot
|
|
423
417
|
end
|
424
418
|
|
425
419
|
begin
|
426
|
-
start_bot(bot_settings, &
|
420
|
+
start_bot(bot_settings, &)
|
427
421
|
ensure
|
428
422
|
quit!
|
429
423
|
end
|
@@ -442,9 +436,9 @@ module MatrixSdk::Bot
|
|
442
436
|
|
443
437
|
def start_bot(bot_settings, &block)
|
444
438
|
cl = if homeserver =~ %r{^https?://}
|
445
|
-
|
439
|
+
ActiveMatrix::Client.new homeserver
|
446
440
|
else
|
447
|
-
|
441
|
+
ActiveMatrix::Client.new_for_domain homeserver
|
448
442
|
end
|
449
443
|
|
450
444
|
auth = bot_settings.delete :auth
|
@@ -476,7 +470,7 @@ module MatrixSdk::Bot
|
|
476
470
|
begin
|
477
471
|
data = bot.client.api.get_account_data(bot.client.mxid, "dev.ananace.ruby-sdk.#{bot_name}")
|
478
472
|
bot.client.sync_token = data[:sync_token]
|
479
|
-
rescue
|
473
|
+
rescue ActiveMatrix::MatrixNotFoundError
|
480
474
|
# Valid
|
481
475
|
rescue StandardError => e
|
482
476
|
bot.logger.error "Failed to restore old sync token, #{e.class}: #{e}"
|
@@ -539,7 +533,7 @@ module MatrixSdk::Bot
|
|
539
533
|
return true if (handler.data[:only] || []).empty?
|
540
534
|
|
541
535
|
# Avoid modifying input data for a checking method
|
542
|
-
@event =
|
536
|
+
@event = ActiveMatrix::Response.new(client.api, event.dup)
|
543
537
|
return false if [handler.data[:only]].flatten.compact.any? do |only|
|
544
538
|
if only.is_a? Proc
|
545
539
|
!instance_exec(&only)
|
@@ -569,7 +563,7 @@ module MatrixSdk::Bot
|
|
569
563
|
return true if (handler.data[:only] || []).empty?
|
570
564
|
|
571
565
|
# Avoid modifying input data for a checking method
|
572
|
-
@event =
|
566
|
+
@event = ActiveMatrix::Response.new(client.api, event.dup)
|
573
567
|
return false if [handler.data[:only]].flatten.compact.any? do |only|
|
574
568
|
if only.is_a? Proc
|
575
569
|
instance_exec(&only)
|
@@ -640,7 +634,7 @@ module MatrixSdk::Bot
|
|
640
634
|
return if in_event?
|
641
635
|
return if settings.ignore_own? && client.mxid == event[:sender]
|
642
636
|
|
643
|
-
event = event.data if event.is_a?
|
637
|
+
event = event.data if event.is_a? ActiveMatrix::MatrixEvent
|
644
638
|
|
645
639
|
logger.debug "Received event #{event}"
|
646
640
|
return _handle_message(event) if event[:type] == 'm.room.message'
|
@@ -651,7 +645,7 @@ module MatrixSdk::Bot
|
|
651
645
|
|
652
646
|
logger.info "Handling event #{event[:sender]}/#{event[:room_id]} => #{event[:type]}"
|
653
647
|
|
654
|
-
@event =
|
648
|
+
@event = ActiveMatrix::Response.new(client.api, event)
|
655
649
|
instance_exec(&handler.proc)
|
656
650
|
# Argument errors are likely to be a "friendly" error, so don't direct the user to the log
|
657
651
|
rescue ArgumentError => e
|
@@ -703,7 +697,7 @@ module MatrixSdk::Bot
|
|
703
697
|
|
704
698
|
logger.info "Handling command #{event[:sender]}/#{event[:room_id]}: #{settings.command_prefix}#{command}"
|
705
699
|
|
706
|
-
@event =
|
700
|
+
@event = ActiveMatrix::Response.new(client.api, event)
|
707
701
|
arity = handler.arity
|
708
702
|
case arity
|
709
703
|
when 0
|
@@ -826,8 +820,17 @@ module MatrixSdk::Bot
|
|
826
820
|
info += "\n #{handler.data[:notes].split("\n").join("\n ")}" if !command.nil? && handler.data[:notes]
|
827
821
|
info = nil if info.empty?
|
828
822
|
|
823
|
+
prefix = if handler.command == 'help'
|
824
|
+
# Help command is always accessible without bot name prefix
|
825
|
+
"#{settings.command_prefix}#{handler.command}"
|
826
|
+
elsif room.dm?
|
827
|
+
"#{settings.command_prefix}#{handler.command}"
|
828
|
+
else
|
829
|
+
"#{expanded_prefix}#{handler.command}"
|
830
|
+
end
|
831
|
+
|
829
832
|
[
|
830
|
-
|
833
|
+
prefix,
|
831
834
|
info
|
832
835
|
].compact
|
833
836
|
end
|
@@ -840,7 +843,7 @@ module MatrixSdk::Bot
|
|
840
843
|
room.send_notice("Help for #{command};\n#{commands}")
|
841
844
|
end
|
842
845
|
else
|
843
|
-
room.send_notice("#{
|
846
|
+
room.send_notice("#{"#{settings.help_preamble}\n\n" if settings.help_preamble?}Usage:\n\n#{commands}")
|
844
847
|
end
|
845
848
|
end
|
846
849
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module ActiveMatrix::Bot
|
4
4
|
PARAMS_CONFIG = {} # rubocop:disable Style/MutableConstant Intended
|
5
5
|
|
6
6
|
require 'optparse'
|
@@ -21,14 +21,13 @@ module MatrixSdk::Bot
|
|
21
21
|
PARAMS_CONFIG[:optparse_error] = e
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
ActiveMatrix.logger.appenders.each do |log|
|
25
25
|
log.layout = Logging::Layouts.pattern(
|
26
26
|
pattern: "%d|%.1l %c : %m\n"
|
27
27
|
)
|
28
28
|
end
|
29
|
-
|
29
|
+
ActiveMatrix.debug! if ENV['MATRIX_DEBUG'] == '1'
|
30
30
|
|
31
|
-
require 'matrix_sdk/bot/base'
|
32
31
|
class Instance < Base
|
33
32
|
set :logging, true
|
34
33
|
set :log_level, :info
|
@@ -76,4 +75,4 @@ module MatrixSdk::Bot
|
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
79
|
-
extend
|
78
|
+
extend ActiveMatrix::Bot::Delegator # rubocop:disable Style/MixinUsage Intended
|
@@ -1,15 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'matrix_sdk'
|
4
|
-
require 'matrix_sdk/util/events'
|
5
|
-
|
6
3
|
require 'English'
|
7
4
|
require 'forwardable'
|
8
5
|
|
9
|
-
module
|
6
|
+
module ActiveMatrix
|
10
7
|
class Client
|
11
|
-
extend
|
12
|
-
include
|
8
|
+
extend ActiveMatrix::Extensions
|
9
|
+
include ActiveMatrix::Logging
|
13
10
|
extend Forwardable
|
14
11
|
|
15
12
|
# @!attribute api [r] The underlying API connection
|
@@ -44,11 +41,11 @@ module MatrixSdk
|
|
44
41
|
# @see Api.new_for_domain
|
45
42
|
# @see #initialize
|
46
43
|
def self.new_for_domain(domain, **params)
|
47
|
-
api =
|
44
|
+
api = ActiveMatrix::Api.new_for_domain(domain, keep_wellknown: true)
|
48
45
|
return new(api, **params) unless api.well_known&.key?('m.identity_server')
|
49
46
|
|
50
|
-
identity_server =
|
51
|
-
new(api, **params
|
47
|
+
identity_server = ActiveMatrix::Api.new(api.well_known['m.identity_server']['base_url'], protocols: %i[IS])
|
48
|
+
new(api, **params, identity_server: identity_server)
|
52
49
|
end
|
53
50
|
|
54
51
|
# @param hs_url [String,URI,Api] The URL to the Matrix homeserver, without the /_matrix/ part, or an existing Api instance
|
@@ -56,7 +53,7 @@ module MatrixSdk
|
|
56
53
|
# @param params [Hash] Additional parameters on creation
|
57
54
|
# @option params [String,MXID] :user_id The user ID of the logged-in user
|
58
55
|
# @option params [Integer] :sync_filter_limit (20) Limit of timeline entries in syncs
|
59
|
-
# @see
|
56
|
+
# @see ActiveMatrix::Api.new for additional usable params
|
60
57
|
def initialize(hs_url, client_cache: :all, **params)
|
61
58
|
event_initialize
|
62
59
|
|
@@ -168,9 +165,9 @@ module MatrixSdk
|
|
168
165
|
|
169
166
|
# Retrieve an account data helper
|
170
167
|
def account_data
|
171
|
-
return
|
168
|
+
return ActiveMatrix::Util::AccountDataCache.new self if cache == :none
|
172
169
|
|
173
|
-
@account_data ||=
|
170
|
+
@account_data ||= ActiveMatrix::Util::AccountDataCache.new self
|
174
171
|
end
|
175
172
|
|
176
173
|
# Gets a direct message room for the given user if one exists
|
@@ -178,7 +175,7 @@ module MatrixSdk
|
|
178
175
|
# @note Will return the oldest room if multiple exist
|
179
176
|
# @return [Room,nil] A direct message room if one exists
|
180
177
|
def direct_room(mxid)
|
181
|
-
mxid =
|
178
|
+
mxid = ActiveMatrix::MXID.new mxid.to_s unless mxid.is_a? ActiveMatrix::MXID
|
182
179
|
raise ArgumentError, 'Must be a valid user ID' unless mxid.user?
|
183
180
|
|
184
181
|
room_id = direct_rooms[mxid.to_s]&.first
|
@@ -365,7 +362,7 @@ module MatrixSdk
|
|
365
362
|
end
|
366
363
|
|
367
364
|
def inspect
|
368
|
-
"#<
|
365
|
+
"#<ActiveMatrix::Response 3pid=#{to_s.inspect} added_at=\"#{added_at}\"#{" validated_at=\"#{validated_at}\"" if validated?}>"
|
369
366
|
end
|
370
367
|
end
|
371
368
|
end
|
@@ -376,13 +373,13 @@ module MatrixSdk
|
|
376
373
|
#
|
377
374
|
# @example Creating a room with an alias
|
378
375
|
# client.create_room('myroom')
|
379
|
-
# #<
|
376
|
+
# #<ActiveMatrix::Room ... >
|
380
377
|
#
|
381
378
|
# @param room_alias [String] A default alias to set on the room, should only be the localpart
|
382
379
|
# @return [Room] The resulting room
|
383
380
|
# @see Protocols::CS#create_room
|
384
381
|
def create_room(room_alias = nil, **params)
|
385
|
-
data = api.create_room(**params
|
382
|
+
data = api.create_room(**params, room_alias: room_alias)
|
386
383
|
ensure_room(data.room_id)
|
387
384
|
end
|
388
385
|
|
@@ -542,7 +539,7 @@ module MatrixSdk
|
|
542
539
|
attempts = 0
|
543
540
|
data = loop do
|
544
541
|
break api.sync(**extra_params)
|
545
|
-
rescue
|
542
|
+
rescue ActiveMatrix::MatrixTimeoutError => e
|
546
543
|
raise e if (attempts += 1) >= params.fetch(:allow_sync_retry, 0)
|
547
544
|
end
|
548
545
|
|
@@ -577,7 +574,7 @@ module MatrixSdk
|
|
577
574
|
orig_bad_sync_timeout = bad_sync_timeout + 0
|
578
575
|
while @should_listen
|
579
576
|
begin
|
580
|
-
sync(**params
|
577
|
+
sync(**params, timeout: timeout)
|
581
578
|
return unless @should_listen
|
582
579
|
|
583
580
|
bad_sync_timeout = orig_bad_sync_timeout
|
@@ -588,7 +585,7 @@ module MatrixSdk
|
|
588
585
|
logger.warn("A #{e.class} occurred during sync")
|
589
586
|
if e.httpstatus >= 500
|
590
587
|
logger.warn("Serverside error, retrying in #{bad_sync_timeout} seconds...")
|
591
|
-
sleep(bad_sync_timeout) if bad_sync_timeout.positive?
|
588
|
+
sleep(bad_sync_timeout) if bad_sync_timeout.positive?
|
592
589
|
bad_sync_timeout = [bad_sync_timeout * 2, @bad_sync_timeout_limit].min
|
593
590
|
end
|
594
591
|
end
|
@@ -681,7 +678,7 @@ module MatrixSdk
|
|
681
678
|
|
682
679
|
unless cache == :none
|
683
680
|
account_data.tinycache_adapter.cleanup if instance_variable_defined?(:@account_data) && @account_data
|
684
|
-
@rooms.
|
681
|
+
@rooms.each_value do |room|
|
685
682
|
# Clean up old cache data after every sync
|
686
683
|
# TODO Run this in a thread?
|
687
684
|
room.tinycache_adapter.cleanup
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
# A generic error raised for issues in the
|
3
|
+
module ActiveMatrix
|
4
|
+
# A generic error raised for issues in the ActiveMatrix
|
5
5
|
class MatrixError < StandardError
|
6
6
|
end
|
7
7
|
|
@@ -30,9 +30,9 @@ module MatrixSdk
|
|
30
30
|
@code = error[:errcode]
|
31
31
|
@httpstatus = status
|
32
32
|
@message = error[:error]
|
33
|
-
@data = error.
|
33
|
+
@data = error.except(:errcode, :error)
|
34
34
|
|
35
|
-
super
|
35
|
+
super(error[:error])
|
36
36
|
end
|
37
37
|
|
38
38
|
def to_s
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveMatrix
|
4
|
+
module Logging
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def logger
|
11
|
+
@logger ||= ActiveMatrix.logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger=(logger)
|
15
|
+
@logger = logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger ||= self.class.logger
|
21
|
+
end
|
22
|
+
|
23
|
+
def logger=(logger)
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def logger
|
30
|
+
@logger ||= if defined?(::Rails) && ::Rails.respond_to?(:logger)
|
31
|
+
::Rails.logger
|
32
|
+
else
|
33
|
+
# Fallback for testing
|
34
|
+
require 'logger'
|
35
|
+
::Logger.new($stdout)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger=(logger)
|
40
|
+
@logger = logger
|
41
|
+
@global_logger = !logger.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def debug!
|
45
|
+
logger.level = if defined?(::Rails)
|
46
|
+
:debug
|
47
|
+
else
|
48
|
+
::Logger::DEBUG
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def global_logger?
|
53
|
+
@global_logger ||= false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module ActiveMatrix
|
4
4
|
class MXID
|
5
5
|
attr_accessor :sigil, :localpart, :domain, :port
|
6
6
|
|
@@ -82,7 +82,7 @@ module MatrixSdk
|
|
82
82
|
# Check if the ID is of a room
|
83
83
|
# @return [Boolean] if the ID is of the room_id or room_alias types
|
84
84
|
def room?
|
85
|
-
|
85
|
+
%i[room_id room_alias].include?(type)
|
86
86
|
end
|
87
87
|
|
88
88
|
# Check if the ID is of a event
|