async-matrix 2.1.0 → 3.0.0
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/Cargo.lock +8 -8
- data/README.md +33 -58
- data/ext/async_matrix_e2ee/Cargo.toml +7 -1
- data/lib/async/matrix/api/chain.rb +120 -94
- data/lib/async/matrix/api/concat.rb +28 -22
- data/lib/async/matrix/api/path_tree.rb +71 -44
- data/lib/async/matrix/api.rb +6 -1
- data/lib/async/matrix/auth_error.rb +20 -0
- data/lib/async/matrix/bad_json_error.rb +20 -0
- data/lib/async/matrix/client.rb +142 -110
- data/lib/async/matrix/config/vivify.rb +107 -0
- data/lib/async/matrix/config.rb +184 -0
- data/lib/async/matrix/content.rb +106 -0
- data/lib/async/matrix/double_puppet_client.rb +1 -1
- data/lib/async/matrix/error.rb +0 -27
- data/lib/async/matrix/{application_service/error_response.rb → error_response.rb} +10 -10
- data/lib/async/matrix/event.rb +197 -0
- data/lib/async/matrix/homeserver_error.rb +20 -0
- data/lib/async/matrix/invalid_endpoint_error.rb +20 -0
- data/lib/async/matrix/media_client.rb +46 -35
- data/lib/async/matrix/not_found_error.rb +20 -0
- data/lib/async/matrix/notifier.rb +7 -3
- data/lib/async/matrix/response_too_large_error.rb +20 -0
- data/lib/async/matrix/schema/registry.rb +367 -340
- data/lib/async/matrix/schema/validation_error.rb +221 -214
- data/lib/async/matrix/schema.rb +161 -161
- data/lib/async/matrix/version.rb +3 -3
- data/lib/async/matrix.rb +0 -7
- metadata +24 -132
- data/lib/async/discord/api/path_tree.rb +0 -127
- data/lib/async/discord/api.rb +0 -151
- data/lib/async/discord/client.rb +0 -283
- data/lib/async/discord/error.rb +0 -84
- data/lib/async/discord/gateway.rb +0 -359
- data/lib/async/discord.rb +0 -15
- data/lib/async/matrix/application_service/bot.rb +0 -232
- data/lib/async/matrix/application_service/config/schema/analytics.json +0 -21
- data/lib/async/matrix/application_service/config/schema/appservice.json +0 -82
- data/lib/async/matrix/application_service/config/schema/backfill.json +0 -91
- data/lib/async/matrix/application_service/config/schema/bridge.json +0 -209
- data/lib/async/matrix/application_service/config/schema/config.json +0 -61
- data/lib/async/matrix/application_service/config/schema/database.json +0 -38
- data/lib/async/matrix/application_service/config/schema/direct_media.json +0 -35
- data/lib/async/matrix/application_service/config/schema/double_puppet.json +0 -24
- data/lib/async/matrix/application_service/config/schema/encryption.json +0 -164
- data/lib/async/matrix/application_service/config/schema/homeserver.json +0 -58
- data/lib/async/matrix/application_service/config/schema/logging.json +0 -50
- data/lib/async/matrix/application_service/config/schema/management_room_texts.json +0 -25
- data/lib/async/matrix/application_service/config/schema/matrix.json +0 -45
- data/lib/async/matrix/application_service/config/schema/permissions.json +0 -54
- data/lib/async/matrix/application_service/config/schema/provisioning.json +0 -23
- data/lib/async/matrix/application_service/config/schema/public_media.json +0 -39
- data/lib/async/matrix/application_service/config/schema/relay.json +0 -43
- data/lib/async/matrix/application_service/config/vivify.rb +0 -109
- data/lib/async/matrix/application_service/config.rb +0 -225
- data/lib/async/matrix/application_service/dispatcher.rb +0 -185
- data/lib/async/matrix/application_service/event.rb +0 -285
- data/lib/async/matrix/application_service/server.rb +0 -430
- data/lib/async/matrix/application_service/transaction.rb +0 -66
- data/lib/async/matrix/application_service/transaction_handler.rb +0 -185
- data/lib/async/matrix/application_service/transaction_store.rb +0 -80
- data/lib/async/matrix/bridge/discord/db/connection.rb +0 -141
- data/lib/async/matrix/bridge/discord/db/file.rb +0 -118
- data/lib/async/matrix/bridge/discord/db/guild.rb +0 -120
- data/lib/async/matrix/bridge/discord/db/message.rb +0 -160
- data/lib/async/matrix/bridge/discord/db/migrations/001_create_users.rb +0 -14
- data/lib/async/matrix/bridge/discord/db/migrations/002_create_guilds.rb +0 -14
- data/lib/async/matrix/bridge/discord/db/migrations/003_create_portals.rb +0 -23
- data/lib/async/matrix/bridge/discord/db/migrations/004_create_puppets.rb +0 -19
- data/lib/async/matrix/bridge/discord/db/migrations/005_create_messages.rb +0 -20
- data/lib/async/matrix/bridge/discord/db/migrations/006_create_reactions.rb +0 -19
- data/lib/async/matrix/bridge/discord/db/migrations/007_create_files.rb +0 -18
- data/lib/async/matrix/bridge/discord/db/portal.rb +0 -150
- data/lib/async/matrix/bridge/discord/db/puppet.rb +0 -128
- data/lib/async/matrix/bridge/discord/db/reaction.rb +0 -165
- data/lib/async/matrix/bridge/discord/db/schema.rb +0 -18
- data/lib/async/matrix/bridge/discord/db/user.rb +0 -112
- data/lib/async/matrix/bridge/discord/db.rb +0 -138
|
@@ -49,19 +49,24 @@ module Async
|
|
|
49
49
|
|
|
50
50
|
Console.debug(self) { "UPLOAD #{method} #{path} (#{content_type}, #{body.bytesize} bytes)" }
|
|
51
51
|
|
|
52
|
-
response = internet.call(
|
|
52
|
+
response = internet.call(
|
|
53
|
+
method,
|
|
54
|
+
url,
|
|
55
|
+
headers,
|
|
56
|
+
body,
|
|
57
|
+
)
|
|
53
58
|
status = response.status
|
|
54
59
|
|
|
55
60
|
unless (200..299).cover?(status)
|
|
56
61
|
payload = read_limited(response, ERROR_RESPONSE_SIZE_LIMIT)
|
|
57
|
-
parsed =
|
|
58
|
-
begin; JSON.parse(payload); rescue; {} end
|
|
62
|
+
parsed = ErrorResponse.new(
|
|
63
|
+
begin; JSON.parse(payload); rescue; {} end,
|
|
59
64
|
)
|
|
60
65
|
Console.error(self) { "Matrix media upload #{status}: #{parsed.errcode} — #{parsed.error}" }
|
|
61
66
|
raise HomeserverError.new(
|
|
62
67
|
parsed.errcode || "UNKNOWN",
|
|
63
68
|
parsed.error || payload.to_s[0..200],
|
|
64
|
-
status: status
|
|
69
|
+
status: status,
|
|
65
70
|
)
|
|
66
71
|
end
|
|
67
72
|
|
|
@@ -87,19 +92,24 @@ module Async
|
|
|
87
92
|
|
|
88
93
|
Console.debug(self) { "DOWNLOAD #{path}" }
|
|
89
94
|
|
|
90
|
-
response = internet.call(
|
|
95
|
+
response = internet.call(
|
|
96
|
+
"GET",
|
|
97
|
+
url,
|
|
98
|
+
@auth_headers,
|
|
99
|
+
nil,
|
|
100
|
+
)
|
|
91
101
|
status = response.status
|
|
92
102
|
|
|
93
103
|
unless (200..299).cover?(status)
|
|
94
104
|
payload = response.read
|
|
95
|
-
parsed =
|
|
96
|
-
begin; JSON.parse(payload); rescue; {} end
|
|
105
|
+
parsed = ErrorResponse.new(
|
|
106
|
+
begin; JSON.parse(payload); rescue; {} end,
|
|
97
107
|
)
|
|
98
108
|
Console.error(self) { "Matrix media download #{status}: #{parsed.errcode} — #{parsed.error}" }
|
|
99
109
|
raise HomeserverError.new(
|
|
100
110
|
parsed.errcode || "UNKNOWN",
|
|
101
111
|
parsed.error || payload.to_s[0..200],
|
|
102
|
-
status: status
|
|
112
|
+
status: status,
|
|
103
113
|
)
|
|
104
114
|
end
|
|
105
115
|
|
|
@@ -113,37 +123,38 @@ module Async
|
|
|
113
123
|
|
|
114
124
|
private
|
|
115
125
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
def internet
|
|
127
|
+
@internet ||= Async::HTTP::Internet.new
|
|
128
|
+
end
|
|
119
129
|
|
|
120
130
|
# Read response body with a size limit. Raises ResponseTooLargeError
|
|
121
131
|
# if the body exceeds the limit.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
def read_limited(response, limit)
|
|
133
|
+
body = response.body
|
|
134
|
+
if body
|
|
135
|
+
if body.respond_to?(:length) && body.length && body.length > limit
|
|
136
|
+
body.close
|
|
137
|
+
raise ResponseTooLargeError.new(
|
|
138
|
+
"M_TOO_LARGE",
|
|
139
|
+
"Response Content-Length #{body.length} bytes exceeds limit of #{limit} bytes",
|
|
140
|
+
)
|
|
141
|
+
end
|
|
142
|
+
buffer = String.new(encoding: Encoding::BINARY)
|
|
143
|
+
body.each do |chunk|
|
|
144
|
+
buffer << chunk
|
|
145
|
+
if buffer.bytesize > limit
|
|
146
|
+
body.close
|
|
147
|
+
raise ResponseTooLargeError.new(
|
|
148
|
+
"M_TOO_LARGE",
|
|
149
|
+
"Response body exceeds limit of #{limit} bytes",
|
|
150
|
+
)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
buffer.empty? ? nil : buffer
|
|
154
|
+
else
|
|
155
|
+
nil
|
|
143
156
|
end
|
|
144
157
|
end
|
|
145
|
-
buffer.empty? ? nil : buffer
|
|
146
|
-
end
|
|
147
158
|
end
|
|
148
159
|
end
|
|
149
160
|
end
|
|
@@ -151,7 +162,7 @@ end
|
|
|
151
162
|
__END__
|
|
152
163
|
describe "Async::Matrix::MediaClient" do
|
|
153
164
|
def make_config
|
|
154
|
-
Async::Matrix::
|
|
165
|
+
Async::Matrix::Config.new({
|
|
155
166
|
"homeserver" => { "address" => "http://localhost:8008", "domain" => "localhost" },
|
|
156
167
|
"appservice" => { "as_token" => "test_token", "hs_token" => "hs_secret", "bot" => { "username" => "bot" } }
|
|
157
168
|
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the Apache License, Version 2.0.
|
|
4
|
+
# Copyright, 2026, by General Intelligence Systems.
|
|
5
|
+
|
|
6
|
+
# Async::Matrix::Error is this class's superclass, so it has to exist before
|
|
7
|
+
# this file finishes loading — the glob in async/matrix.rb sorts
|
|
8
|
+
# alphabetically and would otherwise get here first.
|
|
9
|
+
require_relative "error"
|
|
10
|
+
|
|
11
|
+
module Async
|
|
12
|
+
module Matrix
|
|
13
|
+
class NotFoundError < Error; end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
__END__
|
|
18
|
+
it "NotFoundError inherits from Error" do
|
|
19
|
+
Async::Matrix::NotFoundError.new("M_NOT_FOUND", "gone").should.be.kind_of Async::Matrix::Error
|
|
20
|
+
end
|
|
@@ -37,17 +37,21 @@ module Async
|
|
|
37
37
|
|
|
38
38
|
loop do
|
|
39
39
|
result = yield
|
|
40
|
-
|
|
40
|
+
if result
|
|
41
|
+
break result
|
|
42
|
+
end
|
|
41
43
|
|
|
42
44
|
remaining = deadline - Time.now
|
|
43
|
-
|
|
45
|
+
if remaining <= 0
|
|
46
|
+
break result
|
|
47
|
+
end
|
|
44
48
|
|
|
45
49
|
begin
|
|
46
50
|
Async::Task.current.with_timeout(remaining) do
|
|
47
51
|
@condition.wait
|
|
48
52
|
end
|
|
49
53
|
rescue Async::TimeoutError
|
|
50
|
-
|
|
54
|
+
break yield
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the Apache License, Version 2.0.
|
|
4
|
+
# Copyright, 2026, by General Intelligence Systems.
|
|
5
|
+
|
|
6
|
+
# Async::Matrix::Error is this class's superclass, so it has to exist before
|
|
7
|
+
# this file finishes loading — the glob in async/matrix.rb sorts
|
|
8
|
+
# alphabetically and would otherwise get here first.
|
|
9
|
+
require_relative "error"
|
|
10
|
+
|
|
11
|
+
module Async
|
|
12
|
+
module Matrix
|
|
13
|
+
class ResponseTooLargeError < Error; end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
__END__
|
|
18
|
+
it "ResponseTooLargeError inherits from Error" do
|
|
19
|
+
Async::Matrix::ResponseTooLargeError.new("M_TOO_LARGE", "too big").should.be.kind_of Async::Matrix::Error
|
|
20
|
+
end
|