Compare commits

..

214 Commits

Author SHA1 Message Date
9cd69d1e33 Merge branch 'release/0.3.0' 2019-08-08 16:45:03 +02:00
e216cd15a8 Prepare release 0.3.0 2019-08-08 16:44:53 +02:00
37fde374b3 Merge pull request #469 from vector-im/feature/versionCode_auto
Ensure versionCode is the wanted one for GPlay and F-Droid build
2019-08-08 16:32:10 +02:00
f7b471f141 Stop using BuildConfig.VERSION_CODE, it is not the correct value 2019-08-08 16:31:45 +02:00
93fd56a7ca Ensure versionCode is the wanted one for GPlay and F-Droid build 2019-08-08 16:30:44 +02:00
5a9d88e791 Merge pull request #473 from vector-im/feature/sync_room
Feature/sync room
2019-08-08 16:15:26 +02:00
eaf6a9923a Cancel sync request on pause and timeout to 0 after pause (#404) 2019-08-08 16:04:53 +02:00
9d5433a857 Show sync progress also in room detail screen (#403) 2019-08-08 14:14:10 +02:00
6d4ee83e65 Merge pull request #472 from vector-im/feature/vectorPref
Dagger for VectorPreferences and /markdown command as a bonus
2019-08-08 12:43:22 +02:00
6e44cca17d Handle /markdown command 2019-08-08 12:09:05 +02:00
0a73887c70 Daggerization of VectorPreferences 2019-08-08 11:52:50 +02:00
7fef063e15 Merge pull request #468 from vector-im/feature/fix_realm_issues
Feature/fix realm issues
2019-08-07 18:05:06 +02:00
24f391dac0 Merge pull request #467 from vector-im/feature/playstore_crash
Feature/playstore crash
2019-08-07 17:10:49 +02:00
81c7f694d6 Import Strings form Riot 2019-08-07 16:10:50 +02:00
80e2fc0ca3 Merge pull request #466 from vector-im/feature/edit_history_item
Add "View Edit History" item in the message bottom sheet (#401)
2019-08-07 15:08:26 +02:00
9f53406e99 Fix crash (KotlinNullPointerException) observed on PlayStore 2019-08-07 13:35:44 +02:00
3584658c36 Fix crash (IllegalStateException) observed on PlayStore 2019-08-07 13:24:43 +02:00
12a0cbb400 Fix crash observed on PlayStore 2019-08-07 13:16:04 +02:00
20437446b4 Add "View Edit History" item in the message bottom sheet (#401) 2019-08-07 13:05:22 +02:00
35229882e3 Fix (edited) link can be copied to clipboard (#402) 2019-08-07 12:28:21 +02:00
a04f4421f6 Merge pull request #464 from vector-im/feature/splitApk
Split apk
2019-08-07 12:11:13 +02:00
af1e81f65e Remove unused react native lib, and ensure dependencies lib are explicitly declared 2019-08-07 11:53:59 +02:00
63f6081fa5 Split APK: generate one APK per arch, to reduce APK size of about 30% 2019-08-07 11:46:38 +02:00
ee2e575211 Display VersionCode of the app in the settings, because Android system does not display it anymore 2019-08-07 11:44:51 +02:00
0949d29f9c Let TimelineEvent be queried by SendState 2019-08-07 10:54:54 +02:00
23466fb5a4 Merge pull request #463 from vector-im/feature/fix_theme
Fix theme not well defined at runtime after configurationChange
2019-08-07 10:40:33 +02:00
7f09e64d63 Fix timeline forward loader showing when sending events 2019-08-07 09:59:37 +02:00
585f0ba4b7 Add an identifier method on ChunkEntity 2019-08-06 21:32:45 +02:00
245fbe86d9 Get enum safe with realm entities 2019-08-06 21:32:40 +02:00
b79fdf6a85 Fix theme not well defined at runtime after configurationChange 2019-08-06 18:55:38 +02:00
d9f448c9aa Merge pull request #459 from vector-im/feature/clenup_after_hol
Review of merged PRs
2019-08-06 18:39:37 +02:00
7a6fc4936b Start chain: create extension 2019-08-06 18:15:15 +02:00
d82fd10f3b Start chain: add missing cases 2019-08-06 18:15:15 +02:00
4009f2c176 Add comment to explain why we use a AlwaysSuccessfulWorker 2019-08-06 18:15:15 +02:00
15c4b03340 Event: do not display sendState in View Source and cleanup the class 2019-08-06 18:14:24 +02:00
7b5dff3dcf Mutualize :? part 2019-08-06 18:14:24 +02:00
357123743f Search firstIndexOf, because server url can contains port (This is what JS does, but Riot Android is also bugged) 2019-08-06 18:14:24 +02:00
bb04af1e2c Remove useless code 2019-08-06 18:14:24 +02:00
2f94fbd7eb Use existing method 2019-08-06 18:14:24 +02:00
f2a3bdb68e Kotlin style 2019-08-06 18:14:24 +02:00
097e9714ff Cleaner code 2019-08-06 18:14:24 +02:00
acae0fad3e Better private method name 2019-08-06 18:14:24 +02:00
4deb7eb865 Javadoc for NoMerger 2019-08-06 18:14:24 +02:00
f910cd6f97 More robust SDK: retry only when on failure 2019-08-06 18:14:24 +02:00
652ac81fa1 simple code 2019-08-06 18:14:24 +02:00
99f4196388 More code cleanup/review 2019-08-06 18:14:24 +02:00
c0b94f4111 Typo 2019-08-06 18:14:24 +02:00
1462fa0484 Simple code 2019-08-06 18:14:24 +02:00
dafdc1d3ad Cleaner API 2019-08-06 18:07:35 +02:00
394b89e76b Avoid duplicated code 2019-08-06 18:07:35 +02:00
0db8e7da43 Format 2019-08-06 18:07:35 +02:00
dae8b5c196 Merge pull request #460 from vector-im/feature/fix_cancellations
Feature/fix cancellations
2019-08-06 18:06:05 +02:00
d3ce4c491c Clean code after review 2019-08-06 11:45:06 +02:00
ed6d28bd3b Merge pull request #417 from Dominaezzz/kt-opt
Some optimisations
2019-08-06 11:42:07 +02:00
c2e053b62b Merge pull request #414 from Dominaezzz/kt-leak
Fix potential resource leak
2019-08-06 11:39:51 +02:00
c450849cc3 Merge pull request #425 from Cadair/patch-1
Fix reply fallback prefix
2019-08-06 11:23:37 +02:00
fe884dba2d Update CHANGES.md and fix code quality 2019-08-05 20:28:50 +02:00
3fa4dbaa25 Make async transaction working with suspend method 2019-08-05 20:17:59 +02:00
4a74f58516 Task: use a builder with DSL and introduce Constraints (only boolean connectedToNetwork at the moment) 2019-08-05 20:17:36 +02:00
c413321a22 Remove unnecessary code and fix signout 2019-08-02 13:15:56 +02:00
d696bd2830 Send worker: let LIMIT_EXCEEDED error to be retry 2019-08-02 11:36:32 +02:00
a2b6bd0f62 Fix network reconnection with sync 2019-08-02 11:35:58 +02:00
9cc922a8a2 Optimize imports 2019-08-02 11:35:27 +02:00
c36d1bcd06 Merge pull request #456 from vector-im/feature/fix_image_transition_overlap
Fix / Shared element transition overlap
2019-08-02 10:18:14 +02:00
85499c6b33 fix for background overlaps 2019-08-02 10:00:33 +02:00
8076eab4b5 Fix / Shared element transition overlap
Shared element was overlapping top system bars
2019-08-02 10:00:33 +02:00
d47c0f5ebc Fix / layout res in debug instead of main 2019-08-02 09:59:59 +02:00
fd09a1224e Remove Try from suspending functions 2019-08-01 17:15:17 +02:00
c300c50093 Merge pull request #449 from vector-im/feature/room_update
Feature/room upgrade
2019-07-31 15:34:38 +02:00
77c4355aed Merge branch 'develop' into feature/room_update 2019-07-31 14:27:12 +02:00
1a92562182 Clean code after review 2019-07-31 14:06:10 +02:00
9c390dcc0c Merge pull request #453 from vector-im/feature/fix_code_quality
Fix code quality issues
2019-07-30 21:54:38 +02:00
95089b91b8 UserAccountData: optimize helper and clean code. 2019-07-30 21:41:29 +02:00
eb446d7b49 Fix code quality issues 2019-07-30 21:20:30 +02:00
dc4786ecf0 Room upgrade: add rx flux and handle failures more precisely 2019-07-30 19:13:09 +02:00
e245023add Merge pull request #444 from vector-im/feature/fail_to_send_msg
Basic Message Failure support + Resend (text only)
2019-07-30 18:31:53 +02:00
90fad23493 Fix reply fallback prefix
Plain text reply fallback should be prefixed with "> " not ">" (as per spec).

Signed-off-by: Stuart Mumford <stuart@cadair.com>
2019-07-30 12:09:29 -04:00
000db4b192 Basic Message Failure support + Resend (text only)
+ clean worker inputs when starting new independent task in unique queue
2019-07-30 17:53:43 +02:00
2a16c36a59 Merge pull request #451 from vector-im/feature/fix_user_account_data_direct
User Account Data: fix sync issues with direct invites
2019-07-30 17:39:12 +02:00
ef6c1cfc63 RoomSummaryUpdater: remove unused params 2019-07-30 17:37:16 +02:00
4b4156996d User Account Data: fix sync issues with direct invites 2019-07-30 17:32:31 +02:00
087cc0e6e3 Merge pull request #448 from danteissaias/develop
Fix #447
2019-07-30 17:07:22 +02:00
f4df27c2dc Merge branch 'develop' into feature/room_update 2019-07-30 15:51:56 +02:00
ab25980c4e Merge pull request #437 from vector-im/feature/create_direct_room
Feature/create direct room
2019-07-30 15:13:30 +02:00
77b402ce70 updates CHANGES.md
Signed-off-by: Dante Issaias <dante.issaias@gmail.com>
2019-07-30 14:01:41 +01:00
2763fbb496 fix #447
Signed-off-by: Dante Issaias <dante.issaias@gmail.com>
2019-07-30 13:57:04 +01:00
6deba31111 Direct room: finally use PagedList as we can get a lot of users in DB. 2019-07-30 14:51:14 +02:00
ff6ce8a4b7 Create direct : remove letter headers when filtering 2019-07-29 19:13:06 +02:00
d0cff219aa Merge pull request #446 from vector-im/feature/remove_identity_default
Remove default identity server as we don't use it.
2019-07-29 18:32:07 +02:00
65f0af918f Remove default identity server as we don't use it. 2019-07-29 18:26:26 +02:00
ac38a6461c Tombstone : handle joining viaserver params 2019-07-26 19:17:12 +02:00
9a1e16a170 Tombstone : add notification area and handle links 2019-07-26 14:51:14 +02:00
9e5c70dda3 Room update: start handling tombstone and room create events [WIP] 2019-07-25 19:34:39 +02:00
0255696c88 Update CHANGES 2019-07-25 16:49:15 +02:00
76a9625f25 Direct chat : finalize flow 2019-07-25 16:34:27 +02:00
5af6bf3762 Direct room: finally handle selection with chips (not as Nad design) 2019-07-25 16:34:27 +02:00
507bc2f622 UserEntity: fix not inserted at all 2019-07-23 21:31:58 +02:00
125eacb20b Direct messages: try to handle selecting/deselecting users (WIP) 2019-07-23 19:53:47 +02:00
6176520805 Merge pull request #407 from vector-im/feature/pending_edits_ux
Feature/pending edits ux
2019-07-22 23:53:26 +02:00
3aea0a50ca Merge branch 'develop' into feature/pending_edits_ux 2019-07-22 23:53:16 +02:00
ab87a3caea Merge pull request #397 from vector-im/feature/animation_image_preview
Better image fullscreen preview animation
2019-07-22 23:37:15 +02:00
c58328f94e cleaning / review 2019-07-22 23:36:19 +02:00
03974c8bdf Create Direct Room : fix loading/error state (WIP) 2019-07-22 19:01:17 +02:00
151ae7f4dd Direct chat: handle user account data 2019-07-22 18:58:55 +02:00
a34b053efe Some optimisations
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
2019-07-21 23:35:38 +01:00
b59017938b Fix potential leak
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
2019-07-21 19:11:53 +01:00
2c81e41288 Merge branch 'develop' into feature/create_direct_room 2019-07-19 18:18:22 +02:00
cb44ab547c Create direct room: almost finished, still need to handle showing selected users in search field 2019-07-19 18:12:42 +02:00
6d01a570fd Clear notification for a room left on another client 2019-07-19 16:44:30 +02:00
4a2bf0d6c6 Cleaning Lint 2019-07-19 16:18:47 +02:00
36af8a6a9f Lab / show replace in timeline when show hidden event selected 2019-07-19 16:13:55 +02:00
40a68c3e9f Show pending edits by fading the event body #193
+ Fix issues with edits local echo management in aggregation
2019-07-19 16:13:35 +02:00
1a4ec34bb2 Code cleanup 2019-07-19 16:03:37 +02:00
10490e3aa6 Close detail room screen when the room is left with another client (#256) 2019-07-19 16:00:06 +02:00
cd6624a8a6 Fix issue on setting screen: bad alignment of title 2019-07-19 15:15:29 +02:00
3965218bf9 Cleaning / Review 2019-07-19 12:12:17 +02:00
d78ff7ab08 Fix / can't zoom after rotation 2019-07-19 11:58:24 +02:00
cb274d6a33 Add some cancelable on service methods and start branching Rx 2019-07-19 11:21:16 +02:00
c00dbce536 Fix #390
(edited) string in edited message body
2019-07-19 09:58:53 +02:00
db88caf7fa Better image fullscreen preview animation 2019-07-18 18:53:46 +02:00
c3d945d6bb Version++ 2019-07-18 17:48:56 +02:00
df6080b1da Merge branch 'release/0.2.0' 2019-07-18 17:47:39 +02:00
4c128602b2 Merge branch 'release/0.2.0' into develop 2019-07-18 17:47:39 +02:00
d609c49b31 Prepare release 0.2.0 2019-07-18 17:47:24 +02:00
001603cf9a Create direct room: add filtering and enhance design a bit 2019-07-18 17:42:22 +02:00
d87ee32422 Merge pull request #384 from vector-im/feature/edit_e2e
Feature/edit e2e
2019-07-18 16:44:44 +02:00
f0671b9e73 "Riot X" -> "RiotX" 2019-07-18 14:28:46 +02:00
e218691bf2 Import strings and translation from Riot 2019-07-18 14:25:34 +02:00
9c67036c08 Fix / keyboard won't show when using reply from long tap menu 2019-07-18 12:13:17 +02:00
62657538af Merge pull request #389 from vector-im/feature/cleanup
Do not show invitation in the filtered room list
2019-07-18 12:10:47 +02:00
5438207fba faster animation for quick reply 2019-07-18 12:01:23 +02:00
fe88aaffbd Inject RoomListNameFilter 2019-07-18 11:39:13 +02:00
21ba72e5e7 Do not show invitation in the filtered room list 2019-07-18 11:34:49 +02:00
d48ae967bd Remove dead code 2019-07-18 11:11:42 +02:00
0afde3b021 Rename class member for code clarity 2019-07-18 11:07:09 +02:00
49ae954183 Merge remote-tracking branch 'origin/develop' into develop 2019-07-18 10:58:40 +02:00
64bee91f7a Merge pull request #387 from vector-im/feature/fix_sync_state
Fix sync state progress bar
2019-07-18 10:57:46 +02:00
4341b0d0f5 Merge branch 'develop' into feature/create_direct_room 2019-07-18 09:47:25 +02:00
51fdccb393 cleaning 2019-07-18 09:29:27 +02:00
7e3b300130 Fix sync state progress bar 2019-07-17 19:45:35 +02:00
a98b324c89 Merge pull request #385 from vector-im/feature/invit_notif
Cancel invitation notification when handling the invitation in the application
2019-07-17 18:39:40 +02:00
977721881f Cancel invitation notification when handling the invitation in the application 2019-07-17 18:35:41 +02:00
838003b68a Create direct room: start creating all the required stuff 2019-07-17 18:30:14 +02:00
7d41352918 Fix / edit reply was quoting wrong text
+ e2e reply of edit
2019-07-17 16:46:56 +02:00
077396a832 E2E replies
+ Edit History / support e2e and use original event
2019-07-17 16:20:12 +02:00
32b79bd50e Remove extra space around userId 2019-07-17 15:13:12 +02:00
844f6d16a4 Code quality 2019-07-17 15:05:29 +02:00
fc9ef579ca Merge pull request #381 from vector-im/feature/room_members_perf
Feature/room members perf
2019-07-17 15:01:06 +02:00
77fa5af1b8 Fix compilation issue after merge 2019-07-17 14:58:23 +02:00
90d25ff45e Code cleanup 2019-07-17 14:41:01 +02:00
173452d38c Merge pull request #367 from Dominaezzz/kotlinify-3
Some more kotlinification.
2019-07-17 14:38:16 +02:00
a9f9083745 Merge pull request #374 from vector-im/feature/quick_fix_long_click_link
WIP /  Fix Copying link from a message shouldn't open context menu
2019-07-17 14:37:11 +02:00
22dc2a6790 Fix Copying link from a message shouldn't open context menu 2019-07-17 14:36:47 +02:00
927cd7285d Merge pull request #378 from vector-im/feature/fix_sync_thread_wrong_autostart
Fix / SyncThread was started in background
2019-07-17 14:32:19 +02:00
4d5bdecec6 Merge pull request #382 from vector-im/feature/better_long_tap_menu
Feature/better long tap menu
2019-07-17 14:28:51 +02:00
0be987ac0d Merge branch 'develop' into feature/better_long_tap_menu 2019-07-17 14:28:36 +02:00
4bfaa00be4 Fix / clean bad method name 2019-07-17 14:27:02 +02:00
8e78d8a58d Merge pull request #380 from vector-im/feature/rs_crash_steve
Fix a crash in notificationwhen display name is empty
2019-07-17 14:22:45 +02:00
e3e86c0a41 Merge pull request #383 from vector-im/feature/filter_params
Pass filter to room directory screen or create room screen
2019-07-17 14:20:29 +02:00
8a5fddd952 Merge pull request #379 from vector-im/feature/small_fixes
Fix bad View used for searching in room directory.
2019-07-17 14:19:37 +02:00
208460850e Dagger: activate incremental build 2019-07-17 14:16:20 +02:00
0ddef67cc9 Migrate to rxbinding 3 and fix bad layout for room directory filter (Fixes #349) 2019-07-17 14:16:20 +02:00
896e582a9c Create style VectorSearchView 2019-07-17 14:16:20 +02:00
477920f411 Add some comment 2019-07-17 14:14:02 +02:00
c647648e79 Merge pull request #371 from vector-im/feature/composer_fix_edit_reply
Feature/composer fix edit reply
2019-07-17 14:03:10 +02:00
b654025a3b Fix alignment issue in toolbars 2019-07-17 12:38:35 +02:00
786a7d7560 Rename id 2019-07-17 12:20:11 +02:00
b935b9311e Scroll the list to top after each new filter 2019-07-17 12:18:45 +02:00
8e12f71535 Add top left back button 2019-07-17 12:16:10 +02:00
7eea2ccfb4 Fix infinite opening of room once the room is created 2019-07-17 12:09:09 +02:00
c32ef02a12 Pre fill the room directory filter and and the room name with the already entered string from the user 2019-07-17 12:04:19 +02:00
3651ec4870 Add some doc 2019-07-17 11:58:18 +02:00
87de7bd3e6 fix lint code quality 2019-07-17 11:41:14 +02:00
9494174c33 Swipe to reply in timeline (lab) 2019-07-17 10:54:15 +02:00
9bdea5b325 Change order of actions (and reply on top) 2019-07-16 16:35:57 +02:00
2f01ad99b3 Compact long tap menu 2019-07-16 16:35:36 +02:00
bb3b5788ba Update hint from design 2019-07-16 16:35:10 +02:00
45f7d3e9c4 Kotlin style 2019-07-16 15:59:08 +02:00
0f7a56d005 Use Session.myUserId whereas it's possible 2019-07-16 15:54:00 +02:00
63d2861bc8 Fix / SyncThread was started in background
Upon reception of a push, is the session is instantiated the sync thread was starting to loop
2019-07-16 15:44:08 +02:00
6bbc784c29 Fix crash (from Steve's rageshake) 2019-07-16 15:42:02 +02:00
c6fd625761 code review 2019-07-16 14:56:16 +02:00
d8092abc4e fix / strip reply prefix on history 2019-07-16 14:39:46 +02:00
6effb90361 Fix / edit of reply and edit of edit of reply 2019-07-16 14:39:05 +02:00
42584fc55a Merge pull request #372 from vector-im/feature/room_filtering
Room filtering
2019-07-16 11:41:08 +02:00
30d9ddb3e8 Merge pull request #373 from vector-im/feature/fix_composer_separator_dark
Fix / composer separator color was using a clear theme color
2019-07-15 18:16:06 +02:00
020c32bb1a Fix / composer separator color was using a clear theme color 2019-07-15 17:46:24 +02:00
efd973208f Green close icon 2019-07-15 17:35:51 +02:00
30a6c98c08 Room name in bold 2019-07-15 17:29:37 +02:00
1440080d04 Changes 2019-07-15 17:27:49 +02:00
61bb4c0427 Introduce CreateRoomActivity, a simple container for [CreateRoomFragment] 2019-07-15 17:26:48 +02:00
3c25088243 Filter rooms 2019-07-15 17:26:48 +02:00
fc1c0caea3 Avoid displaying two loaders if there is no elements between them 2019-07-15 17:25:59 +02:00
8901a5e09a Merge pull request #342 from vector-im/feature/edit_history
Feature/edit history
2019-07-15 15:15:45 +02:00
25f1d21bc7 Edit history
Get history from API


cleaning


Updated change log


Missing copyrights


Code review


cleaning
2019-07-15 14:57:12 +02:00
4d2ab9fa31 Merge pull request #344 from vector-im/feature/play_store_crash
Feature/play store crash
2019-07-15 10:49:20 +02:00
0289d2ee87 Simpler code 2019-07-15 10:48:44 +02:00
222201cc64 Fix crash observe on the PlayStore (#341) 2019-07-15 10:48:44 +02:00
b15dea6de3 Merge pull request #338 from vector-im/feature/green_encrypt
Text in green when encrypting
2019-07-15 10:46:44 +02:00
2ba83e456d Merge pull request #343 from vector-im/feature/click_on_redacted_event
Handle click on redacted event
2019-07-15 10:46:06 +02:00
1822fc4fbb Some more kotlinification
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
2019-07-13 15:35:10 +01:00
e6dd1fbfec Use GlobalScope instead of temp scope
Signed-off-by: Dominic Fischer <dominicfischer7@gmail.com>
2019-07-13 15:18:16 +01:00
e2ea76f871 Fix crash reported by PlayStore 2019-07-12 16:48:35 +02:00
34d14eb304 Fix regression on permalink click 2019-07-12 13:51:37 +02:00
3625c462f0 Click on redacted event 2019-07-12 13:51:37 +02:00
fe69206340 Prepare next release 2019-07-12 11:39:26 +02:00
f9885fd04c Update CHANGES.md 2019-07-12 11:38:55 +02:00
316c8ec27e Merge pull request #265 from vector-im/readme_update_for_beta
README: Update it for the beta launch
2019-07-12 11:36:49 +02:00
41465450d8 Code cleanup 2019-07-12 10:45:08 +02:00
bd009caaf1 Code cleanup 2019-07-12 10:22:58 +02:00
33252c3b65 Green text color during encrypting 2019-07-12 10:16:43 +02:00
4b971a9e67 README: Fix develop build links 2019-07-03 10:04:35 +02:00
698fc35704 README: Put back link to #riotx:matrix.org 2019-07-02 18:41:28 +02:00
1c69d8e425 README: Update it for the beta launch 2019-07-02 18:06:43 +02:00
455 changed files with 10749 additions and 3788 deletions

View File

@ -1,11 +1,65 @@
Changes in RiotX 0.3.0 (2019-08-08)
===================================================
Features:
- Create Direct Room flow
- Handle `/markdown` command
Improvements:
- UI for pending edits (#193)
- UX image preview screen transition (#393)
- Basic support for resending failed messages (retry/remove)
- Enable proper cancellation of suspending functions (including db transaction)
- Enhances network connectivity checks in SDK
- Add "View Edit History" item in the message bottom sheet (#401)
- Cancel sync request on pause and timeout to 0 after pause (#404)
Other changes:
- Show sync progress also in room detail screen (#403)
Bugfix:
- Edited message: link confusion when (edited) appears in body (#398)
- Close detail room screen when the room is left with another client (#256)
- Clear notification for a room left on another client
- Fix messages with empty `in_reply_to` not rendering (#447)
- Fix clear cache (#408) and Logout (#205)
- Fix `(edited)` link can be copied to clipboard (#402)
Build:
- Split APK: generate one APK per arch, to reduce APK size of about 30%
Changes in RiotX 0.2.0 (2019-07-18)
===================================================
Features:
- Message Editing: View edit history (#121)
- Rooms filtering (#304)
- Edit in encrypted room
Improvements:
- Handle click on redacted events: view source and create permalink
- Improve long tap menu: reply on top, more compact (#368)
- Quick reply in timeline with swipe gesture (#167)
- Improve edit of replies
- Improve performance on Room Members and Users management (#381)
Other changes:
- migrate from rxbinding 2 to rxbinding 3
Bugfix:
- Fix regression on permalink click
- Fix crash reported by the PlayStore (#341)
- Fix Chat composer separator color in dark/black theme
- Fix bad layout for room directory filter (#349)
- Fix Copying link from a message shouldn't open context menu (#364)
Changes in RiotX 0.1.0 (2019-07-11) Changes in RiotX 0.1.0 (2019-07-11)
=================================================== ===================================================
First release! First release!
Mode details here: https://medium.com/@RiotChat/introducing-the-riotx-beta-for-android-b17952e8f771
======================================================= =======================================================
@ -13,7 +67,7 @@ First release!
======================================================= =======================================================
Changes in RiotX 0.XX (2019-XX-XX) Changes in RiotX 0.0.0 (2019-XX-XX)
=================================================== ===================================================
Features: Features:

View File

@ -1,4 +1,4 @@
[![Buildkite](https://badge.buildkite.com/657d3db27364448d69d54f66c690f7788bc6aa80a7628e37f3.svg?branch=develop)](https://buildkite.com/matrix-dot-org/riotx-android) [![Buildkite](https://badge.buildkite.com/657d3db27364448d69d54f66c690f7788bc6aa80a7628e37f3.svg?branch=develop)](https://buildkite.com/matrix-dot-org/riotx-android/builds?branch=develop)
[![Weblate](https://translate.riot.im/widgets/riot-android/-/svg-badge.svg)](https://translate.riot.im/engage/riot-android/?utm_source=widget) [![Weblate](https://translate.riot.im/widgets/riot-android/-/svg-badge.svg)](https://translate.riot.im/engage/riot-android/?utm_source=widget)
[![RiotX Android Matrix room #riot-android:matrix.org](https://img.shields.io/matrix/riotx:matrix.org.svg?label=%23RiotX:matrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#riotx:matrix.org) [![RiotX Android Matrix room #riot-android:matrix.org](https://img.shields.io/matrix/riotx:matrix.org.svg?label=%23RiotX:matrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#riotx:matrix.org)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=vector.android.riotx&metric=alert_status)](https://sonarcloud.io/dashboard?id=vector.android.riotx) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=vector.android.riotx&metric=alert_status)](https://sonarcloud.io/dashboard?id=vector.android.riotx)
@ -7,14 +7,31 @@
# RiotX Android # RiotX Android
RiotX is an Android Matrix Client currently in development. The application is not yet available on the PlayStore. RiotX is an Android Matrix Client currently in beta but in active development.
It's based on a new Matrix SDK, written in Kotlin. It is a total rewrite of [Riot-Android](https://github.com/vector-im/riot-android) with a new user experience. RiotX will become the official replacement as soon as all features are implemented.
Download nightly build here: [![Buildkite](https://badge.buildkite.com/657d3db27364448d69d54f66c690f7788bc6aa80a7628e37f3.svg?branch=develop)](https://buildkite.com/matrix-dot-org/riotx-android/builds?branch=develop) [<img src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png" alt="Get it on Google Play" height="60">](https://play.google.com/store/apps/details?id=im.vector.riotx)
Nightly build: [![Buildkite](https://badge.buildkite.com/657d3db27364448d69d54f66c690f7788bc6aa80a7628e37f3.svg?branch=develop)](https://buildkite.com/matrix-dot-org/riotx-android/builds?branch=develop)
# New Android SDK
RiotX is based on a new Android SDK fully written in Kotlin (like RiotX). In order to make the early development as fast as possible, RiotX and the new SDK currently share the same git repository. We will make separate repos once the API is stable enough.
# Roadmap
The current target is to release an application out of beta with the same level of features (and even more) as Riot.
The roadmap has 3 phases:
- [phase 0](https://github.com/vector-im/riotX-android/labels/phase0): Prototyping / Project setup
- [phase 1](https://github.com/vector-im/riotX-android/labels/phase1): Beta release to the Play Store
- [phase 2](https://github.com/vector-im/riotX-android/labels/phase2): Out of beta
Matrix Room: [![RiotX Android Matrix room #riot-android:matrix.org](https://img.shields.io/matrix/riotx:matrix.org.svg?label=%23RiotX:matrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#riotx:matrix.org)
## Contributing ## Contributing
Please refer to [CONTRIBUTING.md](https://github.com/vector-im/riotX-android/blob/develop/CONTRIBUTING.md) if you want to contribute the Matrix on Android projects! Please refer to [CONTRIBUTING.md](https://github.com/vector-im/riotX-android/blob/develop/CONTRIBUTING.md) if you want to contribute on Matrix Android projects!
Come chat with the community in the dedicated Matrix [room](https://matrix.to/#/#riotx:matrix.org).

View File

@ -1,3 +1,5 @@
import javax.tools.JavaCompiler
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
@ -45,7 +47,26 @@ allprojects {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
google() google()
jcenter() jcenter()
maven {
url 'https://repo.adobe.com/nexus/content/repositories/public/'
content {
includeGroupByRegex "diff_match_patch"
} }
}
}
tasks.withType(JavaCompile).all {
options.compilerArgs += [
'-Adagger.gradle.incremental=enabled'
]
}
afterEvaluate {
extensions.findByName("kapt")?.arguments {
arg("dagger.gradle.incremental", "enabled")
}
}
} }
task clean(type: Delete) { task clean(type: Delete) {

View File

@ -1,4 +1,4 @@
This document aims to describe how Riot X android displays notifications to the end user. It also clarifies notifications and background settings in the app. This document aims to describe how RiotX android displays notifications to the end user. It also clarifies notifications and background settings in the app.
# Table of Contents # Table of Contents
1. [Prerequisites Knowledge](#prerequisites-knowledge) 1. [Prerequisites Knowledge](#prerequisites-knowledge)
@ -50,7 +50,7 @@ By default, this is 0, so the server will return immediately even if the respons
**delay** is a client preference. When the server responds to a sync request, the client waits for `delay`before calling a new sync. **delay** is a client preference. When the server responds to a sync request, the client waits for `delay`before calling a new sync.
When the Riot X Android app is open (i.e in foreground state), the default timeout is 30 seconds, and delay is 0. When the RiotX Android app is open (i.e in foreground state), the default timeout is 30 seconds, and delay is 0.
## How does a mobile app receives push notification ## How does a mobile app receives push notification
@ -86,7 +86,7 @@ This need some disambiguation, because it is the source of common confusion:
In order to send a push to a mobile, App developers need to have a server that will use the FCM APIs, and these APIs requires authentication! In order to send a push to a mobile, App developers need to have a server that will use the FCM APIs, and these APIs requires authentication!
This server is called a **Push Gateway** in the matrix world This server is called a **Push Gateway** in the matrix world
That means that Riot X Android, a matrix client created by New Vector, is using a **Push Gateway** with the needed credentials (FCM API secret Key) in order to send push to the New Vector client. That means that RiotX Android, a matrix client created by New Vector, is using a **Push Gateway** with the needed credentials (FCM API secret Key) in order to send push to the New Vector client.
If you create your own matrix client, you will also need to deploy an instance of a **Push Gateway** with the credentials needed to use FCM for your app. If you create your own matrix client, you will also need to deploy an instance of a **Push Gateway** with the credentials needed to use FCM for your app.
@ -223,7 +223,7 @@ Upon reception of the FCM push, RiotX will perform a sync call to the Home Serve
* The sync generates additional notifications (e.g an encrypted message where the user is mentioned detected locally) * The sync generates additional notifications (e.g an encrypted message where the user is mentioned detected locally)
* The sync takes too long and the process is killed before completion, or network is not reliable and the sync fails. * The sync takes too long and the process is killed before completion, or network is not reliable and the sync fails.
Riot X implements several strategies in these cases (TODO document) RiotX implements several strategies in these cases (TODO document)
## FCM Fallback mode ## FCM Fallback mode

View File

@ -33,11 +33,12 @@ android {
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":matrix-sdk-android") implementation project(":matrix-sdk-android")
implementation 'androidx.appcompat:appcompat:1.1.0-beta01' implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0' implementation 'io.reactivex.rxjava2:rxkotlin:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// Paging
implementation "androidx.paging:paging-runtime-ktx:2.1.0"
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'

View File

@ -20,6 +20,8 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.android.MainThreadDisposable import io.reactivex.android.MainThreadDisposable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
private class LiveDataObservable<T>( private class LiveDataObservable<T>(
private val liveData: LiveData<T>, private val liveData: LiveData<T>,
@ -57,5 +59,5 @@ private class LiveDataObservable<T>(
} }
fun <T> LiveData<T>.asObservable(): Observable<T> { fun <T> LiveData<T>.asObservable(): Observable<T> {
return LiveDataObservable(this) return LiveDataObservable(this).observeOn(Schedulers.computation())
} }

View File

@ -0,0 +1,39 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.rx
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.util.Cancelable
import io.reactivex.CompletableEmitter
import io.reactivex.SingleEmitter
internal class MatrixCallbackCompletable<T>(private val completableEmitter: CompletableEmitter) : MatrixCallback<T> {
override fun onSuccess(data: T) {
completableEmitter.onComplete()
}
override fun onFailure(failure: Throwable) {
completableEmitter.tryOnError(failure)
}
}
fun Cancelable.toCompletable(completableEmitter: CompletableEmitter) {
completableEmitter.setCancellable {
this.cancel()
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.rx
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.util.Cancelable
import io.reactivex.SingleEmitter
internal class MatrixCallbackSingle<T>(private val singleEmitter: SingleEmitter<T>) : MatrixCallback<T> {
override fun onSuccess(data: T) {
singleEmitter.onSuccess(data)
}
override fun onFailure(failure: Throwable) {
singleEmitter.tryOnError(failure)
}
}
fun <T> Cancelable.toSingle(singleEmitter: SingleEmitter<T>) {
singleEmitter.setCancellable {
this.cancel()
}
}

View File

@ -21,24 +21,32 @@ import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers import io.reactivex.Single
class RxRoom(private val room: Room) { class RxRoom(private val room: Room) {
fun liveRoomSummary(): Observable<RoomSummary> { fun liveRoomSummary(): Observable<RoomSummary> {
return room.liveRoomSummary().asObservable().observeOn(Schedulers.computation()) return room.liveRoomSummary().asObservable()
} }
fun liveRoomMemberIds(): Observable<List<String>> { fun liveRoomMemberIds(): Observable<List<String>> {
return room.getRoomMemberIdsLive().asObservable().observeOn(Schedulers.computation()) return room.getRoomMemberIdsLive().asObservable()
} }
fun liveAnnotationSummary(eventId: String): Observable<EventAnnotationsSummary> { fun liveAnnotationSummary(eventId: String): Observable<EventAnnotationsSummary> {
return room.getEventSummaryLive(eventId).asObservable().observeOn(Schedulers.computation()) return room.getEventSummaryLive(eventId).asObservable()
} }
fun liveTimelineEvent(eventId: String): Observable<TimelineEvent> { fun liveTimelineEvent(eventId: String): Observable<TimelineEvent> {
return room.liveTimeLineEvent(eventId).asObservable().observeOn(Schedulers.computation()) return room.liveTimeLineEvent(eventId).asObservable()
}
fun loadRoomMembersIfNeeded(): Single<Unit> = Single.create {
room.loadRoomMembersIfNeeded(MatrixCallbackSingle(it)).toSingle(it)
}
fun joinRoom(viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
room.join(viaServers, MatrixCallbackSingle(it)).toSingle(it)
} }
} }

View File

@ -16,30 +16,55 @@
package im.vector.matrix.rx package im.vector.matrix.rx
import androidx.paging.PagedList
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.matrix.android.api.session.group.model.GroupSummary
import im.vector.matrix.android.api.session.pushers.Pusher import im.vector.matrix.android.api.session.pushers.Pusher
import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
import im.vector.matrix.android.api.session.sync.SyncState import im.vector.matrix.android.api.session.sync.SyncState
import im.vector.matrix.android.api.session.user.model.User
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers import io.reactivex.Single
class RxSession(private val session: Session) { class RxSession(private val session: Session) {
fun liveRoomSummaries(): Observable<List<RoomSummary>> { fun liveRoomSummaries(): Observable<List<RoomSummary>> {
return session.liveRoomSummaries().asObservable().observeOn(Schedulers.computation()) return session.liveRoomSummaries().asObservable()
} }
fun liveGroupSummaries(): Observable<List<GroupSummary>> { fun liveGroupSummaries(): Observable<List<GroupSummary>> {
return session.liveGroupSummaries().asObservable().observeOn(Schedulers.computation()) return session.liveGroupSummaries().asObservable()
} }
fun liveSyncState(): Observable<SyncState> { fun liveSyncState(): Observable<SyncState> {
return session.syncState().asObservable().observeOn(Schedulers.computation()) return session.syncState().asObservable()
} }
fun livePushers(): Observable<List<Pusher>> { fun livePushers(): Observable<List<Pusher>> {
return session.livePushers().asObservable().observeOn(Schedulers.computation()) return session.livePushers().asObservable()
}
fun liveUsers(): Observable<List<User>> {
return session.liveUsers().asObservable()
}
fun livePagedUsers(filter: String? = null): Observable<PagedList<User>> {
return session.livePagedUsers(filter).asObservable()
}
fun createRoom(roomParams: CreateRoomParams): Single<String> = Single.create {
session.createRoom(roomParams, MatrixCallbackSingle(it)).toSingle(it)
}
fun searchUsersDirectory(search: String,
limit: Int,
excludedUserIds: Set<String>): Single<List<User>> = Single.create {
session.searchUsersDirectory(search, limit, excludedUserIds, MatrixCallbackSingle(it)).toSingle(it)
}
fun joinRoom(roomId: String, viaServers: List<String> = emptyList()): Single<Unit> = Single.create {
session.joinRoom(roomId, viaServers, MatrixCallbackSingle(it)).toSingle(it)
} }
} }

View File

@ -94,7 +94,6 @@ dependencies {
def markwon_version = '3.0.0' def markwon_version = '3.0.0'
def daggerVersion = '2.23.1' def daggerVersion = '2.23.1'
implementation fileTree(dir: 'libs', include: ['*.aar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
@ -110,7 +109,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0' implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.1' implementation 'com.squareup.okhttp3:okhttp:3.14.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.novoda:merlin:1.1.6' implementation 'com.novoda:merlin:1.2.0'
implementation "com.squareup.moshi:moshi-adapters:$moshi_version" implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version" kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
@ -126,9 +125,6 @@ dependencies {
// FP // FP
implementation "io.arrow-kt:arrow-core:$arrow_version" implementation "io.arrow-kt:arrow-core:$arrow_version"
implementation "io.arrow-kt:arrow-instances-core:$arrow_version" implementation "io.arrow-kt:arrow-instances-core:$arrow_version"
implementation "io.arrow-kt:arrow-effects:$arrow_version"
implementation "io.arrow-kt:arrow-effects-instances:$arrow_version"
implementation "io.arrow-kt:arrow-integration-retrofit-adapter:$arrow_version"
// olm lib is now hosted by jitpack: https://jitpack.io/#org.matrix.gitlab.matrix-org/olm // olm lib is now hosted by jitpack: https://jitpack.io/#org.matrix.gitlab.matrix-org/olm
implementation 'org.matrix.gitlab.matrix-org:olm:3.1.2' implementation 'org.matrix.gitlab.matrix-org:olm:3.1.2'

View File

@ -16,10 +16,10 @@
package im.vector.matrix.android; package im.vector.matrix.android;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;

View File

@ -19,11 +19,7 @@ package im.vector.matrix.android.session.room.timeline
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.InstrumentedTest import im.vector.matrix.android.InstrumentedTest
import im.vector.matrix.android.internal.database.helper.add import im.vector.matrix.android.internal.database.helper.*
import im.vector.matrix.android.internal.database.helper.addAll
import im.vector.matrix.android.internal.database.helper.isUnlinked
import im.vector.matrix.android.internal.database.helper.lastStateIndex
import im.vector.matrix.android.internal.database.helper.merge
import im.vector.matrix.android.internal.database.model.ChunkEntity import im.vector.matrix.android.internal.database.model.ChunkEntity
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
import im.vector.matrix.android.session.room.timeline.RoomDataHelper.createFakeListOfEvents import im.vector.matrix.android.session.room.timeline.RoomDataHelper.createFakeListOfEvents

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.session.room.timeline package im.vector.matrix.android.session.room.timeline
import arrow.core.Try
import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEventTask import im.vector.matrix.android.internal.session.room.timeline.GetContextOfEventTask
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
@ -24,7 +23,7 @@ import kotlin.random.Random
internal class FakeGetContextOfEventTask constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask { internal class FakeGetContextOfEventTask constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : GetContextOfEventTask {
override suspend fun execute(params: GetContextOfEventTask.Params): Try<TokenChunkEventPersistor.Result> { override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result {
val fakeEvents = RoomDataHelper.createFakeListOfEvents(30) val fakeEvents = RoomDataHelper.createFakeListOfEvents(30)
val tokenChunkEvent = FakeTokenChunkEvent( val tokenChunkEvent = FakeTokenChunkEvent(
Random.nextLong(System.currentTimeMillis()).toString(), Random.nextLong(System.currentTimeMillis()).toString(),

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.session.room.timeline package im.vector.matrix.android.session.room.timeline
import arrow.core.Try
import im.vector.matrix.android.internal.session.room.timeline.PaginationTask import im.vector.matrix.android.internal.session.room.timeline.PaginationTask
import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor import im.vector.matrix.android.internal.session.room.timeline.TokenChunkEventPersistor
import javax.inject.Inject import javax.inject.Inject
@ -24,7 +23,7 @@ import kotlin.random.Random
internal class FakePaginationTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask { internal class FakePaginationTask @Inject constructor(private val tokenChunkEventPersistor: TokenChunkEventPersistor) : PaginationTask {
override suspend fun execute(params: PaginationTask.Params): Try<TokenChunkEventPersistor.Result> { override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result {
val fakeEvents = RoomDataHelper.createFakeListOfEvents(30) val fakeEvents = RoomDataHelper.createFakeListOfEvents(30)
val tokenChunkEvent = FakeTokenChunkEvent(params.from, Random.nextLong(System.currentTimeMillis()).toString(), fakeEvents) val tokenChunkEvent = FakeTokenChunkEvent(params.from, Random.nextLong(System.currentTimeMillis()).toString(), fakeEvents)
return tokenChunkEventPersistor.insertInDb(tokenChunkEvent, params.roomId, params.direction) return tokenChunkEventPersistor.insertInDb(tokenChunkEvent, params.roomId, params.direction)

View File

@ -28,7 +28,7 @@ object MatrixPatterns {
// regex pattern to find matrix user ids in a string. // regex pattern to find matrix user ids in a string.
// See https://matrix.org/speculator/spec/HEAD/appendices.html#historical-user-ids // See https://matrix.org/speculator/spec/HEAD/appendices.html#historical-user-ids
private const val MATRIX_USER_IDENTIFIER_REGEX = "@[A-Z0-9\\x21-\\x39\\x3B-\\x7F]+$DOMAIN_REGEX" private const val MATRIX_USER_IDENTIFIER_REGEX = "@[A-Z0-9\\x21-\\x39\\x3B-\\x7F]+$DOMAIN_REGEX"
private val PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER = MATRIX_USER_IDENTIFIER_REGEX.toRegex(RegexOption.IGNORE_CASE) val PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER = MATRIX_USER_IDENTIFIER_REGEX.toRegex(RegexOption.IGNORE_CASE)
// regex pattern to find room ids in a string. // regex pattern to find room ids in a string.
private const val MATRIX_ROOM_IDENTIFIER_REGEX = "![A-Z0-9]+$DOMAIN_REGEX" private const val MATRIX_ROOM_IDENTIFIER_REGEX = "![A-Z0-9]+$DOMAIN_REGEX"
@ -137,4 +137,23 @@ object MatrixPatterns {
fun isGroupId(str: String?): Boolean { fun isGroupId(str: String?): Boolean {
return str != null && str matches PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER return str != null && str matches PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER
} }
/**
* Extract server name from a matrix id
*
* @param matrixId
* @return null if not found or if matrixId is null
*/
fun extractServerNameFromId(matrixId: String?): String? {
if (matrixId == null) {
return null
}
val index = matrixId.indexOf(":")
return if (index == -1) {
null
} else matrixId.substring(index + 1)
}
} }

View File

@ -31,7 +31,7 @@ import okhttp3.TlsVersion
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class HomeServerConnectionConfig( data class HomeServerConnectionConfig(
val homeServerUri: Uri, val homeServerUri: Uri,
val identityServerUri: Uri, val identityServerUri: Uri? = null,
val antiVirusServerUri: Uri? = null, val antiVirusServerUri: Uri? = null,
val allowedFingerprints: MutableList<Fingerprint> = ArrayList(), val allowedFingerprints: MutableList<Fingerprint> = ArrayList(),
val shouldPin: Boolean = false, val shouldPin: Boolean = false,
@ -48,7 +48,7 @@ data class HomeServerConnectionConfig(
class Builder { class Builder {
private lateinit var homeServerUri: Uri private lateinit var homeServerUri: Uri
private lateinit var identityServerUri: Uri private var identityServerUri: Uri? = null
private var antiVirusServerUri: Uri? = null private var antiVirusServerUri: Uri? = null
private val allowedFingerprints: MutableList<Fingerprint> = ArrayList() private val allowedFingerprints: MutableList<Fingerprint> = ArrayList()
private var shouldPin: Boolean = false private var shouldPin: Boolean = false

View File

@ -26,8 +26,13 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class MatrixError( data class MatrixError(
@Json(name = "errcode") val code: String, @Json(name = "errcode") val code: String,
@Json(name = "error") val message: String @Json(name = "error") val message: String,
) {
@Json(name = "consent_uri") val consentUri: String? = null,
// RESOURCE_LIMIT_EXCEEDED data
@Json(name = "limit_type") val limitType: String? = null,
@Json(name = "admin_contact") val adminUri: String? = null) {
companion object { companion object {
const val FORBIDDEN = "M_FORBIDDEN" const val FORBIDDEN = "M_FORBIDDEN"
@ -55,5 +60,8 @@ data class MatrixError(
const val M_CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN" const val M_CONSENT_NOT_GIVEN = "M_CONSENT_NOT_GIVEN"
const val RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED" const val RESOURCE_LIMIT_EXCEEDED = "M_RESOURCE_LIMIT_EXCEEDED"
const val WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION" const val WRONG_ROOM_KEYS_VERSION = "M_WRONG_ROOM_KEYS_VERSION"
// Possible value for "limit_type"
const val LIMIT_TYPE_MAU = "monthly_active_user"
} }
} }

View File

@ -42,7 +42,7 @@ object MatrixLinkify {
hasMatch = true hasMatch = true
val startPos = match.range.first val startPos = match.range.first
if (startPos == 0 || text[startPos - 1] != '/') { if (startPos == 0 || text[startPos - 1] != '/') {
val endPos = match.range.last val endPos = match.range.last + 1
val url = text.substring(match.range) val url = text.substring(match.range)
val span = MatrixPermalinkSpan(url, callback) val span = MatrixPermalinkSpan(url, callback)
spannable.setSpan(span, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) spannable.setSpan(span, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.api.permalinks
import android.text.style.ClickableSpan import android.text.style.ClickableSpan
import android.view.View import android.view.View
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan.Callback
/** /**
* This MatrixPermalinkSpan is a clickable span which use a [Callback] to communicate back. * This MatrixPermalinkSpan is a clickable span which use a [Callback] to communicate back.

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.api.pushrules
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.pushrules.rest.PushRule import im.vector.matrix.android.api.pushrules.rest.PushRule
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.util.Cancelable
interface PushRuleService { interface PushRuleService {
@ -31,7 +32,7 @@ interface PushRuleService {
//TODO update rule //TODO update rule
fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>) fun updatePushRuleEnableStatus(kind: String, pushRule: PushRule, enabled: Boolean, callback: MatrixCallback<Unit>): Cancelable
fun addPushRuleListener(listener: PushRuleListener) fun addPushRuleListener(listener: PushRuleListener)
@ -41,6 +42,7 @@ interface PushRuleService {
interface PushRuleListener { interface PushRuleListener {
fun onMatchRule(event: Event, actions: List<Action>) fun onMatchRule(event: Event, actions: List<Action>)
fun onRoomLeft(roomId: String)
fun batchFinish() fun batchFinish()
} }
} }

View File

@ -57,6 +57,9 @@ interface Session :
*/ */
val sessionParams: SessionParams val sessionParams: SessionParams
/**
* Useful shortcut to get access to the userId
*/
val myUserId: String val myUserId: String
get() = sessionParams.credentials.userId get() = sessionParams.credentials.userId
@ -84,7 +87,7 @@ interface Session :
/** /**
* This method start the sync thread. * This method start the sync thread.
*/ */
fun startSync() fun startSync(fromForeground : Boolean)
/** /**
* This method stop the sync thread. * This method stop the sync thread.

View File

@ -26,14 +26,12 @@ import im.vector.matrix.android.api.session.events.model.Content
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
import im.vector.matrix.android.internal.crypto.NewSessionListener import im.vector.matrix.android.internal.crypto.NewSessionListener
import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXEncryptEventContentResult import im.vector.matrix.android.internal.crypto.model.MXEncryptEventContentResult
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse import im.vector.matrix.android.internal.crypto.model.rest.DevicesListResponse
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
import java.io.File
interface CryptoService { interface CryptoService {

View File

@ -20,6 +20,9 @@ import android.text.TextUtils
import com.squareup.moshi.Json import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.model.message.MessageType
import im.vector.matrix.android.api.session.room.send.SendState
import im.vector.matrix.android.api.util.JsonDict import im.vector.matrix.android.api.util.JsonDict
import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult import im.vector.matrix.android.internal.crypto.algorithms.olm.OlmDecryptionResult
import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.di.MoshiProvider
@ -79,9 +82,15 @@ data class Event(
) { ) {
@Transient
var mxDecryptionResult: OlmDecryptionResult? = null var mxDecryptionResult: OlmDecryptionResult? = null
@Transient
var mCryptoError: MXCryptoError.ErrorType? = null var mCryptoError: MXCryptoError.ErrorType? = null
@Transient
var sendState: SendState = SendState.UNKNOWN
/** /**
* Check if event is a state event. * Check if event is a state event.
@ -95,42 +104,6 @@ data class Event(
// Crypto // Crypto
//============================================================================================================== //==============================================================================================================
// /**
// * For encrypted events, the plaintext payload for the event.
// * This is a small MXEvent instance with typically value for `type` and 'content' fields.
// */
// @Transient
// var mClearEvent: Event? = null
// private set
//
// /**
// * Curve25519 key which we believe belongs to the sender of the event.
// * See `senderKey` property.
// */
// @Transient
// private var mSenderCurve25519Key: String? = null
//
// /**
// * Ed25519 key which the sender of this event (for olm) or the creator of the megolm session (for megolm) claims to own.
// * See `claimedEd25519Key` property.
// */
// @Transient
// private var mClaimedEd25519Key: String? = null
//
// /**
// * Curve25519 keys of devices involved in telling us about the senderCurve25519Key and claimedEd25519Key.
// * See `forwardingCurve25519KeyChain` property.
// */
// @Transient
// private var mForwardingCurve25519KeyChain: List<String> = ArrayList()
//
// /**
// * Decryption error
// */
// @Transient
// var mCryptoError: MXCryptoError? = null
// private set
/** /**
* @return true if this event is encrypted. * @return true if this event is encrypted.
*/ */
@ -138,51 +111,11 @@ data class Event(
return TextUtils.equals(type, EventType.ENCRYPTED) return TextUtils.equals(type, EventType.ENCRYPTED)
} }
/**
* Update the clear data on this event.
* This is used after decrypting an event; it should not be used by applications.
*
* @param decryptionResult the decryption result, including the plaintext and some key info.
*/
// internal fun setClearData(decryptionResult: MXEventDecryptionResult?) {
// mClearEvent = null
// if (decryptionResult != null) {
// if (decryptionResult.clearEvent != null) {
// val adapter = MoshiProvider.providesMoshi().adapter(Event::class.java)
// mClearEvent = adapter.fromJsonValue(decryptionResult.clearEvent)
//
// if (mClearEvent != null) {
// mSenderCurve25519Key = decryptionResult.senderCurve25519Key
// mClaimedEd25519Key = decryptionResult.claimedEd25519Key
// mForwardingCurve25519KeyChain = decryptionResult.forwardingCurve25519KeyChain
//
// // For encrypted events with relation, the m.relates_to is kept in clear, so we need to put it back
// // in the clear event
// try {
// content?.get("m.relates_to")?.let { clearRelates ->
// mClearEvent = mClearEvent?.copy(
// content = HashMap(mClearEvent!!.content).apply {
// this["m.relates_to"] = clearRelates
// }
// )
// }
// } catch (e: Exception) {
// Timber.e(e, "Unable to restore 'm.relates_to' the clear event")
// }
// }
//
//
// }
// }
// mCryptoError = null
// }
/** /**
* @return The curve25519 key that sent this event. * @return The curve25519 key that sent this event.
*/ */
fun getSenderKey(): String? { fun getSenderKey(): String? {
return mxDecryptionResult?.senderKey return mxDecryptionResult?.senderKey
// return mClearEvent?.mSenderCurve25519Key ?: mSenderCurve25519Key
} }
/** /**
@ -190,23 +123,13 @@ data class Event(
*/ */
fun getKeysClaimed(): Map<String, String> { fun getKeysClaimed(): Map<String, String> {
return mxDecryptionResult?.keysClaimed ?: HashMap() return mxDecryptionResult?.keysClaimed ?: HashMap()
// val res = HashMap<String, String>()
//
// val claimedEd25519Key = if (null != mClearEvent) mClearEvent!!.mClaimedEd25519Key else mClaimedEd25519Key
//
// if (null != claimedEd25519Key) {
// res["ed25519"] = claimedEd25519Key
// }
//
// return res
} }
//
/** /**
* @return the event type * @return the event type
*/ */
fun getClearType(): String { fun getClearType(): String {
return mxDecryptionResult?.payload?.get("type")?.toString() return mxDecryptionResult?.payload?.get("type")?.toString() ?: type
?: type//get("type")?.toString() ?: type
} }
/** /**
@ -216,30 +139,8 @@ data class Event(
return mxDecryptionResult?.payload?.get("content") as? Content ?: content return mxDecryptionResult?.payload?.get("content") as? Content ?: content
} }
// /**
// * @return the linked crypto error
// */
// fun getCryptoError(): MXCryptoError? {
// return mCryptoError
// }
//
// /**
// * Update the linked crypto error
// *
// * @param error the new crypto error.
// */
// fun setCryptoError(error: MXCryptoError?) {
// mCryptoError = error
// if (null != error) {
// mClearEvent = null
// }
// }
fun toContentStringWithIndent(): String { fun toContentStringWithIndent(): String {
val contentMap = this.toContent()?.toMutableMap() ?: HashMap() val contentMap = toContent()?.toMutableMap() ?: HashMap()
contentMap.remove("mxDecryptionResult")
contentMap.remove("mCryptoError")
return JSONObject(contentMap).toString(4) return JSONObject(contentMap).toString(4)
} }
@ -272,6 +173,7 @@ data class Event(
if (redacts != other.redacts) return false if (redacts != other.redacts) return false
if (mxDecryptionResult != other.mxDecryptionResult) return false if (mxDecryptionResult != other.mxDecryptionResult) return false
if (mCryptoError != other.mCryptoError) return false if (mCryptoError != other.mCryptoError) return false
if (sendState != other.sendState) return false
return true return true
} }
@ -289,6 +191,27 @@ data class Event(
result = 31 * result + (redacts?.hashCode() ?: 0) result = 31 * result + (redacts?.hashCode() ?: 0)
result = 31 * result + (mxDecryptionResult?.hashCode() ?: 0) result = 31 * result + (mxDecryptionResult?.hashCode() ?: 0)
result = 31 * result + (mCryptoError?.hashCode() ?: 0) result = 31 * result + (mCryptoError?.hashCode() ?: 0)
result = 31 * result + sendState.hashCode()
return result return result
} }
}
fun Event.isTextMessage(): Boolean {
return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.type) {
MessageType.MSGTYPE_TEXT,
MessageType.MSGTYPE_EMOTE,
MessageType.MSGTYPE_NOTICE -> true
else -> false
}
}
fun Event.isImageMessage(): Boolean {
return getClearType() == EventType.MESSAGE
&& when (getClearContent()?.toModel<MessageContent>()?.type) {
MessageType.MSGTYPE_IMAGE -> true
else -> false
}
} }

View File

@ -17,7 +17,7 @@ package im.vector.matrix.android.api.session.events.model
/** /**
* Constants defining known event relation types from Matrix specifications. * Constants defining known event relation types from Matrix specifications
*/ */
object RelationType { object RelationType {
@ -25,7 +25,7 @@ object RelationType {
const val ANNOTATION = "m.annotation" const val ANNOTATION = "m.annotation"
/** Lets you define an event which replaces an existing event.*/ /** Lets you define an event which replaces an existing event.*/
const val REPLACE = "m.replace" const val REPLACE = "m.replace"
/** ets you define an event which references an existing event.*/ /** Lets you define an event which references an existing event.*/
const val REFERENCE = "m.reference" const val REFERENCE = "m.reference"
} }

View File

@ -30,20 +30,17 @@ interface RoomDirectoryService {
/** /**
* Get rooms from directory * Get rooms from directory
*/ */
fun getPublicRooms(server: String?, fun getPublicRooms(server: String?, publicRoomsParams: PublicRoomsParams, callback: MatrixCallback<PublicRoomsResponse>): Cancelable
publicRoomsParams: PublicRoomsParams,
callback: MatrixCallback<PublicRoomsResponse>): Cancelable
/** /**
* Join a room by id * Join a room by id
*/ */
fun joinRoom(roomId: String, fun joinRoom(roomId: String, callback: MatrixCallback<Unit>): Cancelable
callback: MatrixCallback<Unit>)
/** /**
* Fetches the overall metadata about protocols supported by the homeserver. * Fetches the overall metadata about protocols supported by the homeserver.
* Includes both the available protocols and all fields required for queries against each protocol. * Includes both the available protocols and all fields required for queries against each protocol.
*/ */
fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>) fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>): Cancelable
} }

View File

@ -20,6 +20,7 @@ import androidx.lifecycle.LiveData
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
import im.vector.matrix.android.api.util.Cancelable
/** /**
* This interface defines methods to get rooms. It's implemented at the session level. * This interface defines methods to get rooms. It's implemented at the session level.
@ -27,10 +28,18 @@ import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
interface RoomService { interface RoomService {
/** /**
* Create a room * Create a room asynchronously
*/ */
fun createRoom(createRoomParams: CreateRoomParams, fun createRoom(createRoomParams: CreateRoomParams, callback: MatrixCallback<String>): Cancelable
callback: MatrixCallback<String>)
/**
* Join a room by id
* @param roomId the roomId of the room to join
* @param viaServers the servers to attempt to join the room through. One of the servers must be participating in the room.
*/
fun joinRoom(roomId: String,
viaServers: List<String> = emptyList(),
callback: MatrixCallback<Unit>): Cancelable
/** /**
* Get a room from a roomId * Get a room from a roomId

View File

@ -0,0 +1,25 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.session.room.failure
import im.vector.matrix.android.api.failure.Failure
sealed class CreateRoomFailure : Failure.FeatureFailure() {
object CreatedWithTimeout: CreateRoomFailure()
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.session.room.failure
import im.vector.matrix.android.api.failure.Failure
sealed class JoinRoomFailure : Failure.FeatureFailure() {
object JoinedWithTimeout : JoinRoomFailure()
}

View File

@ -30,7 +30,7 @@ interface MembershipService {
* This methods load all room members if it was done yet. * This methods load all room members if it was done yet.
* @return a [Cancelable] * @return a [Cancelable]
*/ */
fun loadRoomMembersIfNeeded(): Cancelable fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback<Unit>): Cancelable
/** /**
* Return the roomMember with userId or null. * Return the roomMember with userId or null.
@ -52,16 +52,17 @@ interface MembershipService {
/** /**
* Invite a user in the room * Invite a user in the room
*/ */
fun invite(userId: String, callback: MatrixCallback<Unit>) fun invite(userId: String, callback: MatrixCallback<Unit>): Cancelable
/** /**
* Join the room, or accept an invitation. * Join the room, or accept an invitation.
*/ */
fun join(callback: MatrixCallback<Unit>)
fun join(viaServers: List<String> = emptyList(), callback: MatrixCallback<Unit>): Cancelable
/** /**
* Leave the room, or reject an invitation. * Leave the room, or reject an invitation.
*/ */
fun leave(callback: MatrixCallback<Unit>) fun leave(callback: MatrixCallback<Unit>): Cancelable
} }

View File

@ -34,5 +34,10 @@ data class RoomSummary(
val notificationCount: Int = 0, val notificationCount: Int = 0,
val highlightCount: Int = 0, val highlightCount: Int = 0,
val tags: List<RoomTag> = emptyList(), val tags: List<RoomTag> = emptyList(),
val membership: Membership = Membership.NONE val membership: Membership = Membership.NONE,
) val versioningState: VersioningState = VersioningState.NONE
) {
val isVersioned: Boolean
get() = versioningState != VersioningState.NONE
}

View File

@ -14,8 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package im.vector.riotx.features.home.room package im.vector.matrix.android.api.session.room.model
import im.vector.riotx.core.utils.RxStore enum class VersioningState {
NONE,
class VisibleRoomStore : RxStore<String>() UPGRADED_ROOM_NOT_JOINED,
UPGRADED_ROOM_JOINED
}

View File

@ -223,11 +223,10 @@ class CreateRoomParams {
credentials: Credentials, credentials: Credentials,
ids: List<String>) { ids: List<String>) {
for (id in ids) { for (id in ids) {
if (Patterns.EMAIL_ADDRESS.matcher(id).matches()) { if (Patterns.EMAIL_ADDRESS.matcher(id).matches() && hsConfig.identityServerUri != null) {
if (null == invite3pids) { if (null == invite3pids) {
invite3pids = ArrayList() invite3pids = ArrayList()
} }
val pid = Invite3Pid(idServer = hsConfig.identityServerUri.host!!, val pid = Invite3Pid(idServer = hsConfig.identityServerUri.host!!,
medium = ThreePidMedium.EMAIL, medium = ThreePidMedium.EMAIL,
address = id) address = id)

View File

@ -0,0 +1,28 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.session.room.model.create
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* A link to an old room in case of room versioning
*/
@JsonClass(generateAdapter = true)
data class Predecessor(
@Json(name = "room_id") val roomId: String? = null,
@Json(name = "event_id") val eventId: String? = null
)

View File

@ -0,0 +1,32 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.session.room.model.create
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* Content of a m.room.create type event
*/
@JsonClass(generateAdapter = true)
data class RoomCreateContent(
@Json(name = "creator") val creator: String? = null,
@Json(name = "room_version") val roomVersion: String? = null,
@Json(name = "predecessor") val predecessor: Predecessor? = null
)

View File

@ -26,3 +26,8 @@ interface MessageContent {
val relatesTo: RelationDefaultContent? val relatesTo: RelationDefaultContent?
val newContent: Content? val newContent: Content?
} }
fun MessageContent?.isReply(): Boolean {
return this?.relatesTo?.inReplyTo?.eventId != null
}

View File

@ -16,7 +16,10 @@
package im.vector.matrix.android.api.session.room.model.relation package im.vector.matrix.android.api.session.room.model.relation
import im.vector.matrix.android.api.session.events.model.RelationType
interface RelationContent { interface RelationContent {
/** See [RelationType] for known possible values */
val type: String? val type: String?
val eventId: String? val eventId: String?
val inReplyTo: ReplyToContent? val inReplyTo: ReplyToContent?

View File

@ -16,6 +16,8 @@
package im.vector.matrix.android.api.session.room.model.relation package im.vector.matrix.android.api.session.room.model.relation
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
@ -79,6 +81,25 @@ interface RelationService {
compatibilityBodyText: String = "* $newBodyText"): Cancelable compatibilityBodyText: String = "* $newBodyText"): Cancelable
/**
* Edit a reply. This is a special case because replies contains fallback text as a prefix.
* This method will take the new body (stripped from fallbacks) and re-add them before sending.
* @param replyToEdit The event to edit
* @param originalTimelineEvent the message that this reply (being edited) is relating to
* @param newBodyText The edited body (stripped from in reply to content)
* @param compatibilityBodyText The text that will appear on clients that don't support yet edition
*/
fun editReply(replyToEdit: TimelineEvent,
originalTimelineEvent: TimelineEvent,
newBodyText: String,
compatibilityBodyText: String = "* $newBodyText"): Cancelable
/**
* Get's the edit history of the given event
*/
fun fetchEditHistory(eventId: String, callback: MatrixCallback<List<Event>>)
/** /**
* Reply to an event in the timeline (must be in same room) * Reply to an event in the timeline (must be in same room)
* https://matrix.org/docs/spec/client_server/r0.4.0.html#id350 * https://matrix.org/docs/spec/client_server/r0.4.0.html#id350
@ -91,4 +112,6 @@ interface RelationService {
autoMarkdown: Boolean = false): Cancelable? autoMarkdown: Boolean = false): Cancelable?
fun getEventSummaryLive(eventId: String): LiveData<EventAnnotationsSummary> fun getEventSummaryLive(eventId: String): LiveData<EventAnnotationsSummary>
} }

View File

@ -21,5 +21,5 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class ReplyToContent( data class ReplyToContent(
@Json(name = "event_id") val eventId: String @Json(name = "event_id") val eventId: String? = null
) )

View File

@ -0,0 +1,28 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.session.room.model.tombstone
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
* Class to contains Tombstone information
*/
@JsonClass(generateAdapter = true)
data class RoomTombstoneContent(
@Json(name = "body") val body: String? = null,
@Json(name = "replacement_room") val replacementRoom: String?
)

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.api.session.room.send
import im.vector.matrix.android.api.session.content.ContentAttachmentData import im.vector.matrix.android.api.session.content.ContentAttachmentData
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.model.message.MessageType
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
@ -65,4 +66,31 @@ interface SendService {
*/ */
fun redactEvent(event: Event, reason: String?): Cancelable fun redactEvent(event: Event, reason: String?): Cancelable
/**
* Schedule this message to be resent
* @param localEcho the unsent local echo
*/
fun resendTextMessage(localEcho: TimelineEvent): Cancelable?
/**
* Schedule this message to be resent
* @param localEcho the unsent local echo
*/
fun resendMediaMessage(localEcho: TimelineEvent): Cancelable?
/**
* Remove this failed message from the timeline
* @param localEcho the unsent local echo
*/
fun deleteFailedEcho(localEcho: TimelineEvent)
fun clearSendingQueue()
/**
* Resend all failed messages one by one (and keep order)
*/
fun resendAllFailedMessages()
} }

View File

@ -16,6 +16,7 @@
package im.vector.matrix.android.api.session.room.send package im.vector.matrix.android.api.session.room.send
enum class SendState { enum class SendState {
UNKNOWN, UNKNOWN,
// the event has not been sent // the event has not been sent
@ -33,12 +34,19 @@ enum class SendState {
// the event failed to be sent because some unknown devices have been found while encrypting it // the event failed to be sent because some unknown devices have been found while encrypting it
FAILED_UNKNOWN_DEVICES; FAILED_UNKNOWN_DEVICES;
fun isSent(): Boolean { internal companion object {
return this == SENT || this == SYNCED val HAS_FAILED_STATES = listOf(UNDELIVERED, FAILED_UNKNOWN_DEVICES)
val IS_SENT_STATES = listOf(SENT, SYNCED)
val IS_SENDING_STATES = listOf(UNSENT, ENCRYPTING, SENDING)
val PENDING_STATES = IS_SENDING_STATES + HAS_FAILED_STATES
} }
fun hasFailed(): Boolean { fun isSent() = IS_SENT_STATES.contains(this)
return this == UNDELIVERED || this == FAILED_UNKNOWN_DEVICES
} fun hasFailed() = HAS_FAILED_STATES.contains(this)
fun isSending() = IS_SENDING_STATES.contains(this)
} }

View File

@ -17,6 +17,7 @@
package im.vector.matrix.android.api.session.room.state package im.vector.matrix.android.api.session.room.state
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.events.model.Event
interface StateService { interface StateService {
@ -25,4 +26,6 @@ interface StateService {
*/ */
fun updateTopic(topic: String, callback: MatrixCallback<Unit>) fun updateTopic(topic: String, callback: MatrixCallback<Unit>)
fun getStateEvent(eventType: String): Event?
} }

View File

@ -56,6 +56,9 @@ interface Timeline {
*/ */
fun paginate(direction: Direction, count: Int) fun paginate(direction: Direction, count: Int)
fun pendingEventCount() : Int
fun failedToDeliverEventCount() : Int
interface Listener { interface Listener {
/** /**

View File

@ -21,7 +21,9 @@ import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary import im.vector.matrix.android.api.session.room.model.EventAnnotationsSummary
import im.vector.matrix.android.api.session.room.model.message.MessageContent import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.send.SendState import im.vector.matrix.android.api.session.room.model.message.isReply
import im.vector.matrix.android.api.util.ContentUtils.extractUsefulTextFromReply
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
/** /**
* This data class is a wrapper around an Event. It allows to get useful data in the context of a timeline. * This data class is a wrapper around an Event. It allows to get useful data in the context of a timeline.
@ -35,7 +37,6 @@ data class TimelineEvent(
val senderName: String?, val senderName: String?,
val isUniqueDisplayName: Boolean, val isUniqueDisplayName: Boolean,
val senderAvatar: String?, val senderAvatar: String?,
val sendState: SendState,
val annotations: EventAnnotationsSummary? = null val annotations: EventAnnotationsSummary? = null
) { ) {
@ -83,8 +84,26 @@ data class TimelineEvent(
} }
} }
/**
* Tells if the event has been edited
*/
fun TimelineEvent.hasBeenEdited() = annotations?.editSummary != null
/** /**
* Get last MessageContent, after a possible edition * Get last MessageContent, after a possible edition
*/ */
fun TimelineEvent.getLastMessageContent(): MessageContent? = annotations?.editSummary?.aggregatedContent?.toModel() fun TimelineEvent.getLastMessageContent(): MessageContent? = annotations?.editSummary?.aggregatedContent?.toModel()
?: root.getClearContent().toModel() ?: root.getClearContent().toModel()
fun TimelineEvent.getTextEditableContent(): String? {
val originalContent = root.getClearContent().toModel<MessageContent>() ?: return null
val isReply = originalContent.isReply() || root.content.toModel<EncryptedEventContent>()?.relatesTo?.inReplyTo?.eventId != null
val lastContent = getLastMessageContent()
return if (isReply) {
return extractUsefulTextFromReply(lastContent?.body ?: "")
} else {
lastContent?.body ?: ""
}
}

View File

@ -18,7 +18,7 @@ package im.vector.matrix.android.api.session.sync
sealed class SyncState { sealed class SyncState {
object IDLE : SyncState() object IDLE : SyncState()
data class RUNNING(val catchingUp: Boolean) : SyncState() data class RUNNING(val afterPause: Boolean) : SyncState()
object PAUSED : SyncState() object PAUSED : SyncState()
object KILLING : SyncState() object KILLING : SyncState()
object KILLED : SyncState() object KILLED : SyncState()

View File

@ -17,7 +17,10 @@
package im.vector.matrix.android.api.session.user package im.vector.matrix.android.api.session.user
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.paging.PagedList
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.user.model.User import im.vector.matrix.android.api.session.user.model.User
import im.vector.matrix.android.api.util.Cancelable
/** /**
* This interface defines methods to get users. It's implemented at the session level. * This interface defines methods to get users. It's implemented at the session level.
@ -31,11 +34,34 @@ interface UserService {
*/ */
fun getUser(userId: String): User? fun getUser(userId: String): User?
/**
* Search list of users on server directory.
* @param search the searched term
* @param limit the max number of users to return
* @param excludedUserIds the user ids to filter from the search
* @param callback the async callback
* @return Cancelable
*/
fun searchUsersDirectory(search: String, limit: Int, excludedUserIds: Set<String>, callback: MatrixCallback<List<User>>): Cancelable
/** /**
* Observe a live user from a userId * Observe a live user from a userId
* @param userId the userId to look for. * @param userId the userId to look for.
* @return a Livedata of user with userId * @return a Livedata of user with userId
*/ */
fun observeUser(userId: String): LiveData<User?> fun liveUser(userId: String): LiveData<User?>
/**
* Observe a live list of users sorted alphabetically
* @return a Livedata of users
*/
fun liveUsers(): LiveData<List<User>>
/**
* Observe a live [PagedList] of users sorted alphabetically. You can filter the users.
* @param filter the filter. It will look into userId and displayName.
* @return a Livedata of users
*/
fun livePagedUsers(filter: String? = null): LiveData<PagedList<User>>
} }

View File

@ -19,5 +19,6 @@ package im.vector.matrix.android.api.util
class CancelableBag : Cancelable, MutableList<Cancelable> by ArrayList() { class CancelableBag : Cancelable, MutableList<Cancelable> by ArrayList() {
override fun cancel() { override fun cancel() {
forEach { it.cancel() } forEach { it.cancel() }
clear()
} }
} }

View File

@ -0,0 +1,47 @@
/*
* Copyright 2019 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.matrix.android.api.util
object ContentUtils {
fun extractUsefulTextFromReply(repliedBody: String): String {
val lines = repliedBody.lines()
var wellFormed = repliedBody.startsWith(">")
var endOfPreviousFound = false
val usefullines = ArrayList<String>()
lines.forEach {
if (it == "") {
endOfPreviousFound = true
return@forEach
}
if (!endOfPreviousFound) {
wellFormed = wellFormed && it.startsWith(">")
} else {
usefullines.add(it)
}
}
return usefullines.joinToString("\n").takeIf { wellFormed } ?: repliedBody
}
fun extractUsefulTextFromHtmlReply(repliedBody: String): String {
if (repliedBody.startsWith("<mx-reply>")) {
val closingTagIndex = repliedBody.lastIndexOf("</mx-reply>")
if (closingTagIndex != -1)
return repliedBody.substring(closingTagIndex + "</mx-reply>".length).trim()
}
return repliedBody
}
}

View File

@ -50,16 +50,10 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M
} }
private fun getOrCreateSessionComponent(sessionParams: SessionParams): SessionComponent { private fun getOrCreateSessionComponent(sessionParams: SessionParams): SessionComponent {
val userId = sessionParams.credentials.userId return sessionComponents.getOrPut(sessionParams.credentials.userId) {
if (sessionComponents.containsKey(userId)) { DaggerSessionComponent
return sessionComponents[userId]!!
}
return DaggerSessionComponent
.factory() .factory()
.create(matrixComponent, sessionParams) .create(matrixComponent, sessionParams)
.also {
sessionComponents[sessionParams.credentials.userId] = it
} }
} }
} }

View File

@ -68,7 +68,9 @@ internal class DefaultAuthenticator @Inject constructor(@Unauthenticated
callback: MatrixCallback<Session>): Cancelable { callback: MatrixCallback<Session>): Cancelable {
val job = GlobalScope.launch(coroutineDispatchers.main) { val job = GlobalScope.launch(coroutineDispatchers.main) {
val sessionOrFailure = authenticate(homeServerConnectionConfig, login, password) val sessionOrFailure = runCatching {
authenticate(homeServerConnectionConfig, login, password)
}
sessionOrFailure.foldToCallback(callback) sessionOrFailure.foldToCallback(callback)
} }
return CancelableCoroutine(job) return CancelableCoroutine(job)
@ -85,16 +87,12 @@ internal class DefaultAuthenticator @Inject constructor(@Unauthenticated
} else { } else {
PasswordLoginParams.userIdentifier(login, password, "Mobile") PasswordLoginParams.userIdentifier(login, password, "Mobile")
} }
executeRequest<Credentials> { val credentials = executeRequest<Credentials> {
apiCall = authAPI.login(loginParams) apiCall = authAPI.login(loginParams)
}.map {
val sessionParams = SessionParams(it, homeServerConnectionConfig)
sessionParamsStore.save(sessionParams)
sessionParams
}.map {
sessionManager.getOrCreateSession(it)
} }
val sessionParams = SessionParams(credentials, homeServerConnectionConfig)
sessionParamsStore.save(sessionParams)
sessionManager.getOrCreateSession(sessionParams)
} }
private fun buildAuthAPI(homeServerConnectionConfig: HomeServerConnectionConfig): AuthAPI { private fun buildAuthAPI(homeServerConnectionConfig: HomeServerConnectionConfig): AuthAPI {

View File

@ -27,7 +27,7 @@ internal interface SessionParamsStore {
fun getAll(): List<SessionParams> fun getAll(): List<SessionParams>
fun save(sessionParams: SessionParams): Try<SessionParams> fun save(sessionParams: SessionParams): Try<Unit>
fun delete(userId: String): Try<Unit> fun delete(userId: String): Try<Unit>

View File

@ -62,7 +62,7 @@ internal class RealmSessionParamsStore @Inject constructor(private val mapper: S
return sessionParams return sessionParams
} }
override fun save(sessionParams: SessionParams): Try<SessionParams> { override fun save(sessionParams: SessionParams): Try<Unit> {
return Try { return Try {
val entity = mapper.map(sessionParams) val entity = mapper.map(sessionParams)
if (entity != null) { if (entity != null) {
@ -72,7 +72,6 @@ internal class RealmSessionParamsStore @Inject constructor(private val mapper: S
} }
realm.close() realm.close()
} }
sessionParams
} }
} }

View File

@ -20,7 +20,6 @@ import com.squareup.moshi.Moshi
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.auth.data.SessionParams
import im.vector.matrix.android.internal.di.MatrixScope
import javax.inject.Inject import javax.inject.Inject
internal class SessionParamsMapper @Inject constructor(moshi: Moshi) { internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {

View File

@ -21,7 +21,6 @@ package im.vector.matrix.android.internal.crypto
import android.content.Context import android.content.Context
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.text.TextUtils
import arrow.core.Try import arrow.core.Try
import com.squareup.moshi.Types import com.squareup.moshi.Types
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
@ -73,17 +72,15 @@ import im.vector.matrix.android.internal.session.room.membership.RoomMembers
import im.vector.matrix.android.internal.session.sync.model.SyncResponse import im.vector.matrix.android.internal.session.sync.model.SyncResponse
import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.configureWith import im.vector.matrix.android.internal.task.configureWith
import im.vector.matrix.android.internal.task.toConfigurableTask
import im.vector.matrix.android.internal.util.JsonCanonicalizer import im.vector.matrix.android.internal.util.JsonCanonicalizer
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import im.vector.matrix.android.internal.util.fetchCopied import im.vector.matrix.android.internal.util.fetchCopied
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.matrix.olm.OlmManager import org.matrix.olm.OlmManager
import timber.log.Timber import timber.log.Timber
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.EmptyCoroutineContext import kotlin.math.max
/** /**
* A `CryptoService` class instance manages the end-to-end crypto for a session. * A `CryptoService` class instance manages the end-to-end crypto for a session.
@ -169,22 +166,25 @@ internal class CryptoManager @Inject constructor(
override fun setDeviceName(deviceId: String, deviceName: String, callback: MatrixCallback<Unit>) { override fun setDeviceName(deviceId: String, deviceName: String, callback: MatrixCallback<Unit>) {
setDeviceNameTask setDeviceNameTask
.configureWith(SetDeviceNameTask.Params(deviceId, deviceName)) .configureWith(SetDeviceNameTask.Params(deviceId, deviceName)) {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
override fun deleteDevice(deviceId: String, callback: MatrixCallback<Unit>) { override fun deleteDevice(deviceId: String, callback: MatrixCallback<Unit>) {
deleteDeviceTask deleteDeviceTask
.configureWith(DeleteDeviceTask.Params(deviceId)) .configureWith(DeleteDeviceTask.Params(deviceId)) {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
override fun deleteDeviceWithUserPassword(deviceId: String, authSession: String?, password: String, callback: MatrixCallback<Unit>) { override fun deleteDeviceWithUserPassword(deviceId: String, authSession: String?, password: String, callback: MatrixCallback<Unit>) {
deleteDeviceWithUserPasswordTask deleteDeviceWithUserPasswordTask
.configureWith(DeleteDeviceWithUserPasswordTask.Params(deviceId, authSession, password)) .configureWith(DeleteDeviceWithUserPasswordTask.Params(deviceId, authSession, password)) {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
@ -198,8 +198,9 @@ internal class CryptoManager @Inject constructor(
override fun getDevicesList(callback: MatrixCallback<DevicesListResponse>) { override fun getDevicesList(callback: MatrixCallback<DevicesListResponse>) {
getDevicesTask getDevicesTask
.toConfigurableTask() .configureWith {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
@ -248,7 +249,7 @@ internal class CryptoManager @Inject constructor(
return return
} }
isStarting.set(true) isStarting.set(true)
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
internalStart(isInitialSync) internalStart(isInitialSync)
} }
} }
@ -256,16 +257,9 @@ internal class CryptoManager @Inject constructor(
private suspend fun internalStart(isInitialSync: Boolean) { private suspend fun internalStart(isInitialSync: Boolean) {
// Open the store // Open the store
cryptoStore.open() cryptoStore.open()
runCatching {
uploadDeviceKeys() uploadDeviceKeys()
.flatMap { oneTimeKeysUploader.maybeUploadOneTimeKeys() } oneTimeKeysUploader.maybeUploadOneTimeKeys()
.fold(
{
Timber.e("Start failed: $it")
delay(1000)
isStarting.set(false)
internalStart(isInitialSync)
},
{
outgoingRoomKeyRequestManager.start() outgoingRoomKeyRequestManager.start()
keysBackup.checkAndStartKeysBackup() keysBackup.checkAndStartKeysBackup()
if (isInitialSync) { if (isInitialSync) {
@ -275,8 +269,16 @@ internal class CryptoManager @Inject constructor(
} else { } else {
incomingRoomKeyRequestManager.processReceivedRoomKeyRequests() incomingRoomKeyRequestManager.processReceivedRoomKeyRequests()
} }
}.fold(
{
isStarting.set(false) isStarting.set(false)
isStarted.set(true) isStarted.set(true)
},
{
Timber.e("Start failed: $it")
delay(1000)
isStarting.set(false)
internalStart(isInitialSync)
} }
) )
} }
@ -284,7 +286,7 @@ internal class CryptoManager @Inject constructor(
/** /**
* Close the crypto * Close the crypto
*/ */
fun close() { fun close() = runBlocking(coroutineDispatchers.crypto) {
olmDevice.release() olmDevice.release()
cryptoStore.close() cryptoStore.close()
outgoingRoomKeyRequestManager.stop() outgoingRoomKeyRequestManager.stop()
@ -315,7 +317,7 @@ internal class CryptoManager @Inject constructor(
* @param syncResponse the syncResponse * @param syncResponse the syncResponse
*/ */
fun onSyncCompleted(syncResponse: SyncResponse) { fun onSyncCompleted(syncResponse: SyncResponse) {
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
if (syncResponse.deviceLists != null) { if (syncResponse.deviceLists != null) {
deviceListManager.handleDeviceListsChanges(syncResponse.deviceLists.changed, syncResponse.deviceLists.left) deviceListManager.handleDeviceListsChanges(syncResponse.deviceLists.changed, syncResponse.deviceLists.left)
} }
@ -340,7 +342,7 @@ internal class CryptoManager @Inject constructor(
* @return the device info, or null if not found / unsupported algorithm / crypto released * @return the device info, or null if not found / unsupported algorithm / crypto released
*/ */
override fun deviceWithIdentityKey(senderKey: String, algorithm: String): MXDeviceInfo? { override fun deviceWithIdentityKey(senderKey: String, algorithm: String): MXDeviceInfo? {
return if (!TextUtils.equals(algorithm, MXCRYPTO_ALGORITHM_MEGOLM) && !TextUtils.equals(algorithm, MXCRYPTO_ALGORITHM_OLM)) { return if (algorithm != MXCRYPTO_ALGORITHM_MEGOLM && algorithm != MXCRYPTO_ALGORITHM_OLM) {
// We only deal in olm keys // We only deal in olm keys
null null
} else cryptoStore.deviceWithIdentityKey(senderKey) } else cryptoStore.deviceWithIdentityKey(senderKey)
@ -353,8 +355,8 @@ internal class CryptoManager @Inject constructor(
* @param deviceId the device id * @param deviceId the device id
*/ */
override fun getDeviceInfo(userId: String, deviceId: String?): MXDeviceInfo? { override fun getDeviceInfo(userId: String, deviceId: String?): MXDeviceInfo? {
return if (!TextUtils.isEmpty(userId) && !TextUtils.isEmpty(deviceId)) { return if (userId.isNotEmpty() && !deviceId.isNullOrEmpty()) {
cryptoStore.getUserDevice(deviceId!!, userId) cryptoStore.getUserDevice(deviceId, userId)
} else { } else {
null null
} }
@ -439,7 +441,7 @@ internal class CryptoManager @Inject constructor(
// (for now at least. Maybe we should alert the user somehow?) // (for now at least. Maybe we should alert the user somehow?)
val existingAlgorithm = cryptoStore.getRoomAlgorithm(roomId) val existingAlgorithm = cryptoStore.getRoomAlgorithm(roomId)
if (!TextUtils.isEmpty(existingAlgorithm) && !TextUtils.equals(existingAlgorithm, algorithm)) { if (!existingAlgorithm.isNullOrEmpty() && existingAlgorithm != algorithm) {
Timber.e("## setEncryptionInRoom() : Ignoring m.room.encryption event which requests a change of config in $roomId") Timber.e("## setEncryptionInRoom() : Ignoring m.room.encryption event which requests a change of config in $roomId")
return false return false
} }
@ -535,7 +537,7 @@ internal class CryptoManager @Inject constructor(
eventType: String, eventType: String,
roomId: String, roomId: String,
callback: MatrixCallback<MXEncryptEventContentResult>) { callback: MatrixCallback<MXEncryptEventContentResult>) {
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
if (!isStarted()) { if (!isStarted()) {
Timber.v("## encryptEventContent() : wait after e2e init") Timber.v("## encryptEventContent() : wait after e2e init")
internalStart(false) internalStart(false)
@ -558,13 +560,16 @@ internal class CryptoManager @Inject constructor(
if (safeAlgorithm != null) { if (safeAlgorithm != null) {
val t0 = System.currentTimeMillis() val t0 = System.currentTimeMillis()
Timber.v("## encryptEventContent() starts") Timber.v("## encryptEventContent() starts")
runCatching {
safeAlgorithm.encryptEventContent(eventContent, eventType, userIds) safeAlgorithm.encryptEventContent(eventContent, eventType, userIds)
}
.fold( .fold(
{ callback.onFailure(it) },
{ {
Timber.v("## encryptEventContent() : succeeds after ${System.currentTimeMillis() - t0} ms") Timber.v("## encryptEventContent() : succeeds after ${System.currentTimeMillis() - t0} ms")
callback.onSuccess(MXEncryptEventContentResult(it, EventType.ENCRYPTED)) callback.onSuccess(MXEncryptEventContentResult(it, EventType.ENCRYPTED))
} },
{ callback.onFailure(it) }
) )
} else { } else {
val algorithm = getEncryptionAlgorithm(roomId) val algorithm = getEncryptionAlgorithm(roomId)
@ -586,10 +591,7 @@ internal class CryptoManager @Inject constructor(
@Throws(MXCryptoError::class) @Throws(MXCryptoError::class)
override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult { override fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
return runBlocking { return runBlocking {
internalDecryptEvent(event, timeline).fold( internalDecryptEvent(event, timeline)
{ throw it },
{ it }
)
} }
} }
@ -601,10 +603,12 @@ internal class CryptoManager @Inject constructor(
* @param callback the callback to return data or null * @param callback the callback to return data or null
*/ */
override fun decryptEventAsync(event: Event, timeline: String, callback: MatrixCallback<MXEventDecryptionResult>) { override fun decryptEventAsync(event: Event, timeline: String, callback: MatrixCallback<MXEventDecryptionResult>) {
GlobalScope.launch(EmptyCoroutineContext) { GlobalScope.launch {
val result = withContext(coroutineDispatchers.crypto) { val result = runCatching {
withContext(coroutineDispatchers.crypto) {
internalDecryptEvent(event, timeline) internalDecryptEvent(event, timeline)
} }
}
result.foldToCallback(callback) result.foldToCallback(callback)
} }
} }
@ -614,22 +618,22 @@ internal class CryptoManager @Inject constructor(
* *
* @param event the raw event. * @param event the raw event.
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack. * @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
* @return the MXEventDecryptionResult data, or null in case of error wrapped into [Try] * @return the MXEventDecryptionResult data, or null in case of error
*/ */
private suspend fun internalDecryptEvent(event: Event, timeline: String): Try<MXEventDecryptionResult> { private suspend fun internalDecryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
val eventContent = event.content val eventContent = event.content
return if (eventContent == null) { if (eventContent == null) {
Timber.e("## decryptEvent : empty event content") Timber.e("## decryptEvent : empty event content")
Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON)) throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON)
} else { } else {
val algorithm = eventContent["algorithm"]?.toString() val algorithm = eventContent["algorithm"]?.toString()
val alg = roomDecryptorProvider.getOrCreateRoomDecryptor(event.roomId, algorithm) val alg = roomDecryptorProvider.getOrCreateRoomDecryptor(event.roomId, algorithm)
if (alg == null) { if (alg == null) {
val reason = String.format(MXCryptoError.UNABLE_TO_DECRYPT_REASON, event.eventId, algorithm) val reason = String.format(MXCryptoError.UNABLE_TO_DECRYPT_REASON, event.eventId, algorithm)
Timber.e("## decryptEvent() : $reason") Timber.e("## decryptEvent() : $reason")
Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT, reason)) throw MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT, reason)
} else { } else {
alg.decryptEvent(event, timeline) return alg.decryptEvent(event, timeline)
} }
} }
} }
@ -649,7 +653,7 @@ internal class CryptoManager @Inject constructor(
* @param event the event * @param event the event
*/ */
fun onToDeviceEvent(event: Event) { fun onToDeviceEvent(event: Event) {
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
when (event.getClearType()) { when (event.getClearType()) {
EventType.ROOM_KEY, EventType.FORWARDED_ROOM_KEY -> { EventType.ROOM_KEY, EventType.FORWARDED_ROOM_KEY -> {
onRoomKeyEvent(event) onRoomKeyEvent(event)
@ -671,7 +675,7 @@ internal class CryptoManager @Inject constructor(
*/ */
private fun onRoomKeyEvent(event: Event) { private fun onRoomKeyEvent(event: Event) {
val roomKeyContent = event.getClearContent().toModel<RoomKeyContent>() ?: return val roomKeyContent = event.getClearContent().toModel<RoomKeyContent>() ?: return
if (TextUtils.isEmpty(roomKeyContent.roomId) || TextUtils.isEmpty(roomKeyContent.algorithm)) { if (roomKeyContent.roomId.isNullOrEmpty() || roomKeyContent.algorithm.isNullOrEmpty()) {
Timber.e("## onRoomKeyEvent() : missing fields") Timber.e("## onRoomKeyEvent() : missing fields")
return return
} }
@ -689,13 +693,14 @@ internal class CryptoManager @Inject constructor(
* @param event the encryption event. * @param event the encryption event.
*/ */
private fun onRoomEncryptionEvent(roomId: String, event: Event) { private fun onRoomEncryptionEvent(roomId: String, event: Event) {
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
val params = LoadRoomMembersTask.Params(roomId) val params = LoadRoomMembersTask.Params(roomId)
loadRoomMembersTask try {
.execute(params) loadRoomMembersTask.execute(params)
.map { _ ->
val userIds = getRoomUserIds(roomId) val userIds = getRoomUserIds(roomId)
setEncryptionInRoom(roomId, event.content?.get("algorithm")?.toString(), true, userIds) setEncryptionInRoom(roomId, event.content?.get("algorithm")?.toString(), true, userIds)
} catch (throwable: Throwable) {
Timber.e(throwable)
} }
} }
} }
@ -738,7 +743,7 @@ internal class CryptoManager @Inject constructor(
val membership = roomMember?.membership val membership = roomMember?.membership
if (membership == Membership.JOIN) { if (membership == Membership.JOIN) {
// make sure we are tracking the deviceList for this user. // make sure we are tracking the deviceList for this user.
deviceListManager.startTrackingDeviceList(Arrays.asList(userId)) deviceListManager.startTrackingDeviceList(listOf(userId))
} else if (membership == Membership.INVITE } else if (membership == Membership.INVITE
&& shouldEncryptForInvitedMembers(roomId) && shouldEncryptForInvitedMembers(roomId)
&& cryptoConfig.enableEncryptionForInvitedMembers) { && cryptoConfig.enableEncryptionForInvitedMembers) {
@ -747,7 +752,7 @@ internal class CryptoManager @Inject constructor(
// know what other servers are in the room at the time they've been invited. // know what other servers are in the room at the time they've been invited.
// They therefore will not send device updates if a user logs in whilst // They therefore will not send device updates if a user logs in whilst
// their state is invite. // their state is invite.
deviceListManager.startTrackingDeviceList(Arrays.asList(userId)) deviceListManager.startTrackingDeviceList(listOf(userId))
} }
} }
} }
@ -763,7 +768,7 @@ internal class CryptoManager @Inject constructor(
/** /**
* Upload my user's device keys. * Upload my user's device keys.
*/ */
private suspend fun uploadDeviceKeys(): Try<KeysUploadResponse> { private suspend fun uploadDeviceKeys(): KeysUploadResponse {
// Prepare the device keys data to send // Prepare the device keys data to send
// Sign it // Sign it
val canonicalJson = JsonCanonicalizer.getCanonicalJson(Map::class.java, getMyDevice().signalableJSONDictionary()) val canonicalJson = JsonCanonicalizer.getCanonicalJson(Map::class.java, getMyDevice().signalableJSONDictionary())
@ -782,7 +787,11 @@ internal class CryptoManager @Inject constructor(
* @param callback the exported keys * @param callback the exported keys
*/ */
override fun exportRoomKeys(password: String, callback: MatrixCallback<ByteArray>) { override fun exportRoomKeys(password: String, callback: MatrixCallback<ByteArray>) {
exportRoomKeys(password, MXMegolmExportEncryption.DEFAULT_ITERATION_COUNT, callback) GlobalScope.launch(coroutineDispatchers.main) {
runCatching {
exportRoomKeys(password, MXMegolmExportEncryption.DEFAULT_ITERATION_COUNT)
}.fold(callback::onSuccess, callback::onFailure)
}
} }
/** /**
@ -792,31 +801,17 @@ internal class CryptoManager @Inject constructor(
* @param anIterationCount the encryption iteration count (0 means no encryption) * @param anIterationCount the encryption iteration count (0 means no encryption)
* @param callback the exported keys * @param callback the exported keys
*/ */
private fun exportRoomKeys(password: String, anIterationCount: Int, callback: MatrixCallback<ByteArray>) { private suspend fun exportRoomKeys(password: String, anIterationCount: Int): ByteArray {
GlobalScope.launch(coroutineDispatchers.main) { return withContext(coroutineDispatchers.crypto) {
withContext(coroutineDispatchers.crypto) { val iterationCount = max(0, anIterationCount)
Try {
val iterationCount = Math.max(0, anIterationCount)
val exportedSessions = ArrayList<MegolmSessionData>() val exportedSessions = cryptoStore.getInboundGroupSessions().mapNotNull { it.exportKeys() }
val inboundGroupSessions = cryptoStore.getInboundGroupSessions()
for (session in inboundGroupSessions) {
val megolmSessionData = session.exportKeys()
if (null != megolmSessionData) {
exportedSessions.add(megolmSessionData)
}
}
val adapter = MoshiProvider.providesMoshi() val adapter = MoshiProvider.providesMoshi()
.adapter(List::class.java) .adapter(List::class.java)
MXMegolmExportEncryption.encryptMegolmKeyFile(adapter.toJson(exportedSessions), password, iterationCount) MXMegolmExportEncryption.encryptMegolmKeyFile(adapter.toJson(exportedSessions), password, iterationCount)
} }
}.foldToCallback(callback)
}
} }
/** /**
@ -879,11 +874,9 @@ internal class CryptoManager @Inject constructor(
*/ */
fun checkUnknownDevices(userIds: List<String>, callback: MatrixCallback<Unit>) { fun checkUnknownDevices(userIds: List<String>, callback: MatrixCallback<Unit>) {
// force the refresh to ensure that the devices list is up-to-date // force the refresh to ensure that the devices list is up-to-date
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
deviceListManager runCatching { deviceListManager.downloadKeys(userIds, true) }
.downloadKeys(userIds, true)
.fold( .fold(
{ callback.onFailure(it) },
{ {
val unknownDevices = getUnknownDevices(it) val unknownDevices = getUnknownDevices(it)
if (unknownDevices.map.isEmpty()) { if (unknownDevices.map.isEmpty()) {
@ -892,7 +885,8 @@ internal class CryptoManager @Inject constructor(
// trigger an an unknown devices exception // trigger an an unknown devices exception
callback.onFailure(Failure.CryptoError(MXCryptoError.UnknownDevice(unknownDevices))) callback.onFailure(Failure.CryptoError(MXCryptoError.UnknownDevice(unknownDevices)))
} }
} },
{ callback.onFailure(it) }
) )
} }
} }
@ -944,7 +938,7 @@ internal class CryptoManager @Inject constructor(
val roomIds = cryptoStore.getRoomsListBlacklistUnverifiedDevices().toMutableList() val roomIds = cryptoStore.getRoomsListBlacklistUnverifiedDevices().toMutableList()
if (add) { if (add) {
if (!roomIds.contains(roomId)) { if (roomId !in roomIds) {
roomIds.add(roomId) roomIds.add(roomId)
} }
} else { } else {
@ -1033,8 +1027,7 @@ internal class CryptoManager @Inject constructor(
val unknownDevices = MXUsersDevicesMap<MXDeviceInfo>() val unknownDevices = MXUsersDevicesMap<MXDeviceInfo>()
val userIds = devicesInRoom.userIds val userIds = devicesInRoom.userIds
for (userId in userIds) { for (userId in userIds) {
val deviceIds = devicesInRoom.getUserDeviceIds(userId) devicesInRoom.getUserDeviceIds(userId)?.forEach { deviceId ->
deviceIds?.forEach { deviceId ->
devicesInRoom.getObject(userId, deviceId) devicesInRoom.getObject(userId, deviceId)
?.takeIf { it.isUnknown } ?.takeIf { it.isUnknown }
?.let { ?.let {
@ -1047,17 +1040,18 @@ internal class CryptoManager @Inject constructor(
} }
override fun downloadKeys(userIds: List<String>, forceDownload: Boolean, callback: MatrixCallback<MXUsersDevicesMap<MXDeviceInfo>>) { override fun downloadKeys(userIds: List<String>, forceDownload: Boolean, callback: MatrixCallback<MXUsersDevicesMap<MXDeviceInfo>>) {
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
deviceListManager runCatching {
.downloadKeys(userIds, forceDownload) deviceListManager.downloadKeys(userIds, forceDownload)
.foldToCallback(callback) }.foldToCallback(callback)
} }
} }
override fun clearCryptoCache(callback: MatrixCallback<Unit>) { override fun clearCryptoCache(callback: MatrixCallback<Unit>) {
clearCryptoDataTask clearCryptoDataTask
.toConfigurableTask() .configureWith {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }

View File

@ -18,14 +18,12 @@
package im.vector.matrix.android.internal.crypto package im.vector.matrix.android.internal.crypto
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.MatrixPatterns import im.vector.matrix.android.api.MatrixPatterns
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.crypto.tasks.DownloadKeysForUsersTask import im.vector.matrix.android.internal.crypto.tasks.DownloadKeysForUsersTask
import im.vector.matrix.android.internal.extensions.onError
import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.sync.SyncTokenStore import im.vector.matrix.android.internal.session.sync.SyncTokenStore
import timber.log.Timber import timber.log.Timber
@ -237,7 +235,7 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
* @param forceDownload Always download the keys even if cached. * @param forceDownload Always download the keys even if cached.
* @param callback the asynchronous callback * @param callback the asynchronous callback
*/ */
suspend fun downloadKeys(userIds: List<String>?, forceDownload: Boolean): Try<MXUsersDevicesMap<MXDeviceInfo>> { suspend fun downloadKeys(userIds: List<String>?, forceDownload: Boolean): MXUsersDevicesMap<MXDeviceInfo> {
Timber.v("## downloadKeys() : forceDownload $forceDownload : $userIds") Timber.v("## downloadKeys() : forceDownload $forceDownload : $userIds")
// Map from userId -> deviceId -> MXDeviceInfo // Map from userId -> deviceId -> MXDeviceInfo
val stored = MXUsersDevicesMap<MXDeviceInfo>() val stored = MXUsersDevicesMap<MXDeviceInfo>()
@ -268,15 +266,14 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
} }
return if (downloadUsers.isEmpty()) { return if (downloadUsers.isEmpty()) {
Timber.v("## downloadKeys() : no new user device") Timber.v("## downloadKeys() : no new user device")
Try.just(stored) stored
} else { } else {
Timber.v("## downloadKeys() : starts") Timber.v("## downloadKeys() : starts")
val t0 = System.currentTimeMillis() val t0 = System.currentTimeMillis()
doKeyDownloadForUsers(downloadUsers) val result = doKeyDownloadForUsers(downloadUsers)
.map {
Timber.v("## downloadKeys() : doKeyDownloadForUsers succeeds after " + (System.currentTimeMillis() - t0) + " ms") Timber.v("## downloadKeys() : doKeyDownloadForUsers succeeds after " + (System.currentTimeMillis() - t0) + " ms")
result.also {
it.addEntriesFromMap(stored) it.addEntriesFromMap(stored)
it
} }
} }
} }
@ -286,17 +283,22 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
* *
* @param downloadUsers the user ids list * @param downloadUsers the user ids list
*/ */
private suspend fun doKeyDownloadForUsers(downloadUsers: MutableList<String>): Try<MXUsersDevicesMap<MXDeviceInfo>> { private suspend fun doKeyDownloadForUsers(downloadUsers: MutableList<String>): MXUsersDevicesMap<MXDeviceInfo> {
Timber.v("## doKeyDownloadForUsers() : doKeyDownloadForUsers $downloadUsers") Timber.v("## doKeyDownloadForUsers() : doKeyDownloadForUsers $downloadUsers")
// get the user ids which did not already trigger a keys download // get the user ids which did not already trigger a keys download
val filteredUsers = downloadUsers.filter { MatrixPatterns.isUserId(it) } val filteredUsers = downloadUsers.filter { MatrixPatterns.isUserId(it) }
if (filteredUsers.isEmpty()) { if (filteredUsers.isEmpty()) {
// trigger nothing // trigger nothing
return Try.just(MXUsersDevicesMap()) return MXUsersDevicesMap()
} }
val params = DownloadKeysForUsersTask.Params(filteredUsers, syncTokenStore.getLastToken()) val params = DownloadKeysForUsersTask.Params(filteredUsers, syncTokenStore.getLastToken())
return downloadKeysForUsersTask.execute(params) val response = try {
.map { response -> downloadKeysForUsersTask.execute(params)
} catch (throwable: Throwable) {
Timber.e(throwable, "##doKeyDownloadForUsers(): error")
onKeysDownloadFailed(filteredUsers)
throw throwable
}
Timber.v("## doKeyDownloadForUsers() : Got keys for " + filteredUsers.size + " users") Timber.v("## doKeyDownloadForUsers() : Got keys for " + filteredUsers.size + " users")
for (userId in filteredUsers) { for (userId in filteredUsers) {
val devices = response.deviceKeys?.get(userId) val devices = response.deviceKeys?.get(userId)
@ -334,12 +336,7 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
cryptoStore.storeUserDevices(userId, mutableDevices) cryptoStore.storeUserDevices(userId, mutableDevices)
} }
} }
onKeysDownloadSucceed(filteredUsers, response.failures) return onKeysDownloadSucceed(filteredUsers, response.failures)
}
.onError {
Timber.e(it, "##doKeyDownloadForUsers(): error")
onKeysDownloadFailed(filteredUsers)
}
} }
/** /**
@ -465,13 +462,14 @@ internal class DeviceListManager @Inject constructor(private val cryptoStore: IM
} }
cryptoStore.saveDeviceTrackingStatuses(deviceTrackingStatuses) cryptoStore.saveDeviceTrackingStatuses(deviceTrackingStatuses)
runCatching {
doKeyDownloadForUsers(users) doKeyDownloadForUsers(users)
.fold( }.fold(
{
Timber.e(it, "## refreshOutdatedDeviceLists() : ERROR updating device keys for users $users")
},
{ {
Timber.v("## refreshOutdatedDeviceLists() : done") Timber.v("## refreshOutdatedDeviceLists() : done")
},
{
Timber.e(it, "## refreshOutdatedDeviceLists() : ERROR updating device keys for users $users")
} }
) )
} }

View File

@ -18,7 +18,6 @@
package im.vector.matrix.android.internal.crypto package im.vector.matrix.android.internal.crypto
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.util.JSON_DICT_PARAMETERIZED_TYPE import im.vector.matrix.android.api.util.JSON_DICT_PARAMETERIZED_TYPE
import im.vector.matrix.android.api.util.JsonDict import im.vector.matrix.android.api.util.JsonDict
@ -80,8 +79,7 @@ internal class MXOlmDevice @Inject constructor(
// //
// The first level keys are timeline ids. // The first level keys are timeline ids.
// The second level keys are strings of form "<senderKey>|<session_id>|<message_index>" // The second level keys are strings of form "<senderKey>|<session_id>|<message_index>"
// Values are true. private val inboundGroupSessionMessageIndexes: MutableMap<String, MutableSet<String>> = HashMap()
private val inboundGroupSessionMessageIndexes: MutableMap<String, MutableMap<String, Boolean>> = HashMap()
init { init {
// Retrieve the account from the store // Retrieve the account from the store
@ -506,11 +504,8 @@ internal class MXOlmDevice @Inject constructor(
keysClaimed: Map<String, String>, keysClaimed: Map<String, String>,
exportFormat: Boolean): Boolean { exportFormat: Boolean): Boolean {
val session = OlmInboundGroupSessionWrapper(sessionKey, exportFormat) val session = OlmInboundGroupSessionWrapper(sessionKey, exportFormat)
runCatching { getInboundGroupSession(sessionId, senderKey, roomId) }
getInboundGroupSession(sessionId, senderKey, roomId).fold( .fold(
{
// Nothing to do in case of error
},
{ {
// If we already have this session, consider updating it // If we already have this session, consider updating it
Timber.e("## addInboundGroupSession() : Update for megolm session $senderKey/$sessionId") Timber.e("## addInboundGroupSession() : Update for megolm session $senderKey/$sessionId")
@ -523,6 +518,9 @@ internal class MXOlmDevice @Inject constructor(
session.olmInboundGroupSession?.releaseSession() session.olmInboundGroupSession?.releaseSession()
return false return false
} }
},
{
// Nothing to do in case of error
} }
) )
@ -595,12 +593,8 @@ internal class MXOlmDevice @Inject constructor(
continue continue
} }
getInboundGroupSession(sessionId, senderKey, roomId) runCatching { getInboundGroupSession(sessionId, senderKey, roomId) }
.fold( .fold(
{
// Session does not already exist, add it
sessions.add(session)
},
{ {
// If we already have this session, consider updating it // If we already have this session, consider updating it
Timber.e("## importInboundGroupSession() : Update for megolm session $senderKey/$sessionId") Timber.e("## importInboundGroupSession() : Update for megolm session $senderKey/$sessionId")
@ -613,7 +607,12 @@ internal class MXOlmDevice @Inject constructor(
sessions.add(session) sessions.add(session)
} }
Unit Unit
},
{
// Session does not already exist, add it
sessions.add(session)
} }
) )
} }
@ -648,9 +647,8 @@ internal class MXOlmDevice @Inject constructor(
roomId: String, roomId: String,
timeline: String?, timeline: String?,
sessionId: String, sessionId: String,
senderKey: String): Try<OlmDecryptionResult> { senderKey: String): OlmDecryptionResult {
return getInboundGroupSession(sessionId, senderKey, roomId) val session = getInboundGroupSession(sessionId, senderKey, roomId)
.flatMap { session ->
// Check that the room id matches the original one for the session. This stops // Check that the room id matches the original one for the session. This stops
// the HS pretending a message was targeting a different room. // the HS pretending a message was targeting a different room.
if (roomId == session.roomId) { if (roomId == session.roomId) {
@ -659,23 +657,21 @@ internal class MXOlmDevice @Inject constructor(
decryptResult = session.olmInboundGroupSession!!.decryptMessage(body) decryptResult = session.olmInboundGroupSession!!.decryptMessage(body)
} catch (e: OlmException) { } catch (e: OlmException) {
Timber.e(e, "## decryptGroupMessage () : decryptMessage failed") Timber.e(e, "## decryptGroupMessage () : decryptMessage failed")
return@flatMap Try.Failure(MXCryptoError.OlmError(e)) throw MXCryptoError.OlmError(e)
} }
if (null != timeline) { if (null != timeline) {
if (!inboundGroupSessionMessageIndexes.containsKey(timeline)) { val timelineSet = inboundGroupSessionMessageIndexes.getOrPut(timeline) { mutableSetOf() }
inboundGroupSessionMessageIndexes[timeline] = HashMap()
}
val messageIndexKey = senderKey + "|" + sessionId + "|" + decryptResult.mIndex val messageIndexKey = senderKey + "|" + sessionId + "|" + decryptResult.mIndex
if (inboundGroupSessionMessageIndexes[timeline]?.get(messageIndexKey) != null) { if (timelineSet.contains(messageIndexKey)) {
val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex) val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex)
Timber.e("## decryptGroupMessage() : $reason") Timber.e("## decryptGroupMessage() : $reason")
return@flatMap Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.DUPLICATED_MESSAGE_INDEX, reason)) throw MXCryptoError.Base(MXCryptoError.ErrorType.DUPLICATED_MESSAGE_INDEX, reason)
} }
inboundGroupSessionMessageIndexes[timeline]!!.put(messageIndexKey, true) timelineSet.add(messageIndexKey)
} }
store.storeInboundGroupSessions(listOf(session)) store.storeInboundGroupSessions(listOf(session))
@ -685,23 +681,20 @@ internal class MXOlmDevice @Inject constructor(
adapter.fromJson(payloadString) adapter.fromJson(payloadString)
} catch (e: Exception) { } catch (e: Exception) {
Timber.e("## decryptGroupMessage() : fails to parse the payload") Timber.e("## decryptGroupMessage() : fails to parse the payload")
return@flatMap Try.Failure( throw
MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)) MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)
} }
return@flatMap Try.just( return OlmDecryptionResult(
OlmDecryptionResult(
payload, payload,
session.keysClaimed, session.keysClaimed,
senderKey, senderKey,
session.forwardingCurve25519KeyChain session.forwardingCurve25519KeyChain
) )
)
} else { } else {
val reason = String.format(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_REASON, roomId, session.roomId) val reason = String.format(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_REASON, roomId, session.roomId)
Timber.e("## decryptGroupMessage() : $reason") Timber.e("## decryptGroupMessage() : $reason")
return@flatMap Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.INBOUND_SESSION_MISMATCH_ROOM_ID, reason)) throw MXCryptoError.Base(MXCryptoError.ErrorType.INBOUND_SESSION_MISMATCH_ROOM_ID, reason)
}
} }
} }
@ -766,26 +759,26 @@ internal class MXOlmDevice @Inject constructor(
* @param senderKey the base64-encoded curve25519 key of the sender. * @param senderKey the base64-encoded curve25519 key of the sender.
* @return the inbound group session. * @return the inbound group session.
*/ */
fun getInboundGroupSession(sessionId: String?, senderKey: String?, roomId: String?): Try<OlmInboundGroupSessionWrapper> { fun getInboundGroupSession(sessionId: String?, senderKey: String?, roomId: String?): OlmInboundGroupSessionWrapper {
if (sessionId.isNullOrBlank() || senderKey.isNullOrBlank()) { if (sessionId.isNullOrBlank() || senderKey.isNullOrBlank()) {
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY, MXCryptoError.ERROR_MISSING_PROPERTY_REASON)) throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY, MXCryptoError.ERROR_MISSING_PROPERTY_REASON)
} }
val session = store.getInboundGroupSession(sessionId, senderKey) val session = store.getInboundGroupSession(sessionId, senderKey)
return if (null != session) { if (session != null) {
// Check that the room id matches the original one for the session. This stops // Check that the room id matches the original one for the session. This stops
// the HS pretending a message was targeting a different room. // the HS pretending a message was targeting a different room.
if (!TextUtils.equals(roomId, session.roomId)) { if (!TextUtils.equals(roomId, session.roomId)) {
val errorDescription = String.format(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_REASON, roomId, session.roomId) val errorDescription = String.format(MXCryptoError.INBOUND_SESSION_MISMATCH_ROOM_ID_REASON, roomId, session.roomId)
Timber.e("## getInboundGroupSession() : $errorDescription") Timber.e("## getInboundGroupSession() : $errorDescription")
Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.INBOUND_SESSION_MISMATCH_ROOM_ID, errorDescription)) throw MXCryptoError.Base(MXCryptoError.ErrorType.INBOUND_SESSION_MISMATCH_ROOM_ID, errorDescription)
} else { } else {
Try.just(session) return session
} }
} else { } else {
Timber.e("## getInboundGroupSession() : Cannot retrieve inbound group session $sessionId") Timber.e("## getInboundGroupSession() : Cannot retrieve inbound group session $sessionId")
Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, MXCryptoError.UNKNOWN_INBOUND_SESSION_ID_REASON)) throw MXCryptoError.Base(MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID, MXCryptoError.UNKNOWN_INBOUND_SESSION_ID_REASON)
} }
} }
@ -798,6 +791,6 @@ internal class MXOlmDevice @Inject constructor(
* @return true if the unbound session keys are known. * @return true if the unbound session keys are known.
*/ */
fun hasInboundSessionKeys(roomId: String, senderKey: String, sessionId: String): Boolean { fun hasInboundSessionKeys(roomId: String, senderKey: String, sessionId: String): Boolean {
return getInboundGroupSession(sessionId, senderKey, roomId).isSuccess() return runCatching { getInboundGroupSession(sessionId, senderKey, roomId) }.isSuccess
} }
} }

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.crypto package im.vector.matrix.android.internal.crypto
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.session.SessionScope
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject

View File

@ -16,8 +16,6 @@
package im.vector.matrix.android.internal.crypto package im.vector.matrix.android.internal.crypto
import arrow.core.Try
import arrow.instances.`try`.applicativeError.handleError
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.crypto.model.MXKey import im.vector.matrix.android.internal.crypto.model.MXKey
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadResponse
@ -59,13 +57,13 @@ internal class OneTimeKeysUploader @Inject constructor(
/** /**
* Check if the OTK must be uploaded. * Check if the OTK must be uploaded.
*/ */
suspend fun maybeUploadOneTimeKeys(): Try<Unit> { suspend fun maybeUploadOneTimeKeys() {
if (oneTimeKeyCheckInProgress) { if (oneTimeKeyCheckInProgress) {
return Try.just(Unit) return
} }
if (System.currentTimeMillis() - lastOneTimeKeyCheck < ONE_TIME_KEY_UPLOAD_PERIOD) { if (System.currentTimeMillis() - lastOneTimeKeyCheck < ONE_TIME_KEY_UPLOAD_PERIOD) {
// we've done a key upload recently. // we've done a key upload recently.
return Try.just(Unit) return
} }
lastOneTimeKeyCheck = System.currentTimeMillis() lastOneTimeKeyCheck = System.currentTimeMillis()
@ -81,13 +79,12 @@ internal class OneTimeKeysUploader @Inject constructor(
// discard the oldest private keys first. This will eventually clean // discard the oldest private keys first. This will eventually clean
// out stale private keys that won't receive a message. // out stale private keys that won't receive a message.
val keyLimit = Math.floor(maxOneTimeKeys / 2.0).toInt() val keyLimit = Math.floor(maxOneTimeKeys / 2.0).toInt()
val result = if (oneTimeKeyCount != null) { if (oneTimeKeyCount != null) {
uploadOTK(oneTimeKeyCount!!, keyLimit) uploadOTK(oneTimeKeyCount!!, keyLimit)
} else { } else {
// ask the server how many keys we have // ask the server how many keys we have
val uploadKeysParams = UploadKeysTask.Params(null, null, credentials.deviceId!!) val uploadKeysParams = UploadKeysTask.Params(null, null, credentials.deviceId!!)
uploadKeysTask.execute(uploadKeysParams) val response = uploadKeysTask.execute(uploadKeysParams)
.flatMap {
// We need to keep a pool of one time public keys on the server so that // We need to keep a pool of one time public keys on the server so that
// other devices can start conversations with us. But we can only store // other devices can start conversations with us. But we can only store
// a finite number of private keys in the olm Account object. // a finite number of private keys in the olm Account object.
@ -101,22 +98,13 @@ internal class OneTimeKeysUploader @Inject constructor(
// these factors. // these factors.
// TODO Why we do not set oneTimeKeyCount here? // TODO Why we do not set oneTimeKeyCount here?
// TODO This is not needed anymore, see https://github.com/matrix-org/matrix-js-sdk/pull/493 (TODO on iOS also) // TODO This is not needed anymore, see https://github.com/matrix-org/matrix-js-sdk/pull/493 (TODO on iOS also)
val keyCount = it.oneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE) val keyCount = response.oneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE)
uploadOTK(keyCount, keyLimit) uploadOTK(keyCount, keyLimit)
} }
}
return result
.map {
Timber.v("## uploadKeys() : success") Timber.v("## uploadKeys() : success")
oneTimeKeyCount = null oneTimeKeyCount = null
oneTimeKeyCheckInProgress = false oneTimeKeyCheckInProgress = false
} }
.handleError {
Timber.e(it, "## uploadKeys() : failed")
oneTimeKeyCount = null
oneTimeKeyCheckInProgress = false
}
}
/** /**
* Upload some the OTKs. * Upload some the OTKs.
@ -124,29 +112,26 @@ internal class OneTimeKeysUploader @Inject constructor(
* @param keyCount the key count * @param keyCount the key count
* @param keyLimit the limit * @param keyLimit the limit
*/ */
private suspend fun uploadOTK(keyCount: Int, keyLimit: Int): Try<Unit> { private suspend fun uploadOTK(keyCount: Int, keyLimit: Int) {
if (keyLimit <= keyCount) { if (keyLimit <= keyCount) {
// If we don't need to generate any more keys then we are done. // If we don't need to generate any more keys then we are done.
return Try.just(Unit) return
} }
val keysThisLoop = Math.min(keyLimit - keyCount, ONE_TIME_KEY_GENERATION_MAX_NUMBER) val keysThisLoop = Math.min(keyLimit - keyCount, ONE_TIME_KEY_GENERATION_MAX_NUMBER)
olmDevice.generateOneTimeKeys(keysThisLoop) olmDevice.generateOneTimeKeys(keysThisLoop)
return uploadOneTimeKeys() val response = uploadOneTimeKeys()
.flatMap { if (response.hasOneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE)) {
if (it.hasOneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE)) { uploadOTK(response.oneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE), keyLimit)
uploadOTK(it.oneTimeKeyCountsForAlgorithm(MXKey.KEY_SIGNED_CURVE_25519_TYPE), keyLimit)
} else { } else {
Timber.e("## uploadLoop() : response for uploading keys does not contain one_time_key_counts.signed_curve25519") Timber.e("## uploadLoop() : response for uploading keys does not contain one_time_key_counts.signed_curve25519")
Try.raise(Exception("response for uploading keys does not contain one_time_key_counts.signed_curve25519")) throw Exception("response for uploading keys does not contain one_time_key_counts.signed_curve25519")
}
} }
} }
/** /**
* Upload my user's one time keys. * Upload my user's one time keys.
*/ */
private suspend fun uploadOneTimeKeys(): Try<KeysUploadResponse> { private suspend fun uploadOneTimeKeys(): KeysUploadResponse {
val oneTimeKeys = olmDevice.getOneTimeKeys() val oneTimeKeys = olmDevice.getOneTimeKeys()
val oneTimeJson = HashMap<String, Any>() val oneTimeJson = HashMap<String, Any>()
@ -169,13 +154,10 @@ internal class OneTimeKeysUploader @Inject constructor(
// For now, we set the device id explicitly, as we may not be using the // For now, we set the device id explicitly, as we may not be using the
// same one as used in login. // same one as used in login.
val uploadParams = UploadKeysTask.Params(null, oneTimeJson, credentials.deviceId!!) val uploadParams = UploadKeysTask.Params(null, oneTimeJson, credentials.deviceId!!)
return uploadKeysTask val response = uploadKeysTask.execute(uploadParams)
.execute(uploadParams)
.map {
lastPublishedOneTimeKeys = oneTimeKeys lastPublishedOneTimeKeys = oneTimeKeys
olmDevice.markKeysAsPublished() olmDevice.markKeysAsPublished()
it return response
}
} }
companion object { companion object {

View File

@ -299,10 +299,12 @@ internal class OutgoingRoomKeyRequestManager @Inject constructor(
// TODO Change this two hard coded key to something better // TODO Change this two hard coded key to something better
contentMap.setObject(recipient["userId"], recipient["deviceId"], message) contentMap.setObject(recipient["userId"], recipient["deviceId"], message)
} }
sendToDeviceTask.configureWith(SendToDeviceTask.Params(EventType.ROOM_KEY_REQUEST, contentMap, transactionId)) sendToDeviceTask
.dispatchTo(callback) .configureWith(SendToDeviceTask.Params(EventType.ROOM_KEY_REQUEST, contentMap, transactionId)) {
.executeOn(TaskThread.CALLER) this.callback = callback
.callbackOn(TaskThread.CALLER) this.callbackThread = TaskThread.CALLER
this.executionThread = TaskThread.CALLER
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.crypto.actions package im.vector.matrix.android.internal.crypto.actions
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.MXOlmDevice
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXKey import im.vector.matrix.android.internal.crypto.model.MXKey
@ -32,7 +31,7 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val
private val oneTimeKeysForUsersDeviceTask: ClaimOneTimeKeysForUsersDeviceTask) { private val oneTimeKeysForUsersDeviceTask: ClaimOneTimeKeysForUsersDeviceTask) {
suspend fun handle(devicesByUser: Map<String, List<MXDeviceInfo>>): Try<MXUsersDevicesMap<MXOlmSessionResult>> { suspend fun handle(devicesByUser: Map<String, List<MXDeviceInfo>>): MXUsersDevicesMap<MXOlmSessionResult> {
val devicesWithoutSession = ArrayList<MXDeviceInfo>() val devicesWithoutSession = ArrayList<MXDeviceInfo>()
val results = MXUsersDevicesMap<MXOlmSessionResult>() val results = MXUsersDevicesMap<MXOlmSessionResult>()
@ -58,7 +57,7 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val
} }
if (devicesWithoutSession.size == 0) { if (devicesWithoutSession.size == 0) {
return Try.just(results) return results
} }
// Prepare the request for claiming one-time keys // Prepare the request for claiming one-time keys
@ -79,15 +78,13 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val
Timber.v("## claimOneTimeKeysForUsersDevices() : $usersDevicesToClaim") Timber.v("## claimOneTimeKeysForUsersDevices() : $usersDevicesToClaim")
val claimParams = ClaimOneTimeKeysForUsersDeviceTask.Params(usersDevicesToClaim) val claimParams = ClaimOneTimeKeysForUsersDeviceTask.Params(usersDevicesToClaim)
return oneTimeKeysForUsersDeviceTask val oneTimeKeys = oneTimeKeysForUsersDeviceTask.execute(claimParams)
.execute(claimParams) Timber.v("## claimOneTimeKeysForUsersDevices() : keysClaimResponse.oneTimeKeys: $oneTimeKeys")
.map {
Timber.v("## claimOneTimeKeysForUsersDevices() : keysClaimResponse.oneTimeKeys: $it")
for (userId in userIds) { for (userId in userIds) {
val deviceInfos = devicesByUser[userId] val deviceInfos = devicesByUser[userId]
for (deviceInfo in deviceInfos!!) { for (deviceInfo in deviceInfos!!) {
var oneTimeKey: MXKey? = null var oneTimeKey: MXKey? = null
val deviceIds = it.getUserDeviceIds(userId) val deviceIds = oneTimeKeys.getUserDeviceIds(userId)
if (null != deviceIds) { if (null != deviceIds) {
for (deviceId in deviceIds) { for (deviceId in deviceIds) {
val olmSessionResult = results.getObject(userId, deviceId) val olmSessionResult = results.getObject(userId, deviceId)
@ -95,7 +92,7 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val
// We already have a result for this device // We already have a result for this device
continue continue
} }
val key = it.getObject(userId, deviceId) val key = oneTimeKeys.getObject(userId, deviceId)
if (key?.type == oneTimeKeyAlgorithm) { if (key?.type == oneTimeKeyAlgorithm) {
oneTimeKey = key oneTimeKey = key
} }
@ -110,8 +107,7 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(private val
} }
} }
} }
results return results
}
} }
private fun verifyKeyAndStartSession(oneTimeKey: MXKey, userId: String, deviceInfo: MXDeviceInfo): String? { private fun verifyKeyAndStartSession(oneTimeKey: MXKey, userId: String, deviceInfo: MXDeviceInfo): String? {

View File

@ -17,14 +17,11 @@
package im.vector.matrix.android.internal.crypto.actions package im.vector.matrix.android.internal.crypto.actions
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.MXOlmDevice
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXOlmSessionResult import im.vector.matrix.android.internal.crypto.model.MXOlmSessionResult
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.session.SessionScope
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -37,7 +34,7 @@ internal class EnsureOlmSessionsForUsersAction @Inject constructor(private val o
* Try to make sure we have established olm sessions for the given users. * Try to make sure we have established olm sessions for the given users.
* @param users a list of user ids. * @param users a list of user ids.
*/ */
suspend fun handle(users: List<String>) : Try<MXUsersDevicesMap<MXOlmSessionResult>> { suspend fun handle(users: List<String>) : MXUsersDevicesMap<MXOlmSessionResult> {
Timber.v("## ensureOlmSessionsForUsers() : ensureOlmSessionsForUsers $users") Timber.v("## ensureOlmSessionsForUsers() : ensureOlmSessionsForUsers $users")
val devicesByUser = HashMap<String /* userId */, MutableList<MXDeviceInfo>>() val devicesByUser = HashMap<String /* userId */, MutableList<MXDeviceInfo>>()

View File

@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.crypto.RoomDecryptorProvider
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.session.SessionScope
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject

View File

@ -19,7 +19,6 @@ package im.vector.matrix.android.internal.crypto.actions
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.session.SessionScope
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.crypto.algorithms package im.vector.matrix.android.internal.crypto.algorithms
import arrow.core.Try
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest import im.vector.matrix.android.internal.crypto.IncomingRoomKeyRequest
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
@ -35,7 +34,7 @@ internal interface IMXDecrypting {
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack. * @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
* @return the decryption information, or an error * @return the decryption information, or an error
*/ */
suspend fun decryptEvent(event: Event, timeline: String): Try<MXEventDecryptionResult> suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult
/** /**
* Handle a key event. * Handle a key event.

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.crypto.algorithms package im.vector.matrix.android.internal.crypto.algorithms
import arrow.core.Try
import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Content
/** /**
@ -31,7 +30,7 @@ internal interface IMXEncrypting {
* @param eventContent the content of the event. * @param eventContent the content of the event.
* @param eventType the type of the event. * @param eventType the type of the event.
* @param userIds the room members the event will be sent to. * @param userIds the room members the event will be sent to.
* @return the encrypted content wrapped by [Try] * @return the encrypted content
*/ */
suspend fun encryptEventContent(eventContent: Content, eventType: String, userIds: List<String>): Try<Content> suspend fun encryptEventContent(eventContent: Content, eventType: String, userIds: List<String>): Content
} }

View File

@ -18,7 +18,6 @@
package im.vector.matrix.android.internal.crypto.algorithms.megolm package im.vector.matrix.android.internal.crypto.algorithms.megolm
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
@ -29,7 +28,6 @@ import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevi
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
import im.vector.matrix.android.internal.crypto.algorithms.IMXDecrypting import im.vector.matrix.android.internal.crypto.algorithms.IMXDecrypting
import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup import im.vector.matrix.android.internal.crypto.keysbackup.KeysBackup
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent
import im.vector.matrix.android.internal.crypto.model.event.RoomKeyContent import im.vector.matrix.android.internal.crypto.model.event.RoomKeyContent
@ -38,11 +36,9 @@ import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import timber.log.Timber import timber.log.Timber
import java.util.*
import kotlin.collections.HashMap
internal class MXMegolmDecryption(private val credentials: Credentials, internal class MXMegolmDecryption(private val credentials: Credentials,
private val olmDevice: MXOlmDevice, private val olmDevice: MXOlmDevice,
@ -63,30 +59,46 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
*/ */
private var pendingEvents: MutableMap<String /* senderKey|sessionId */, MutableMap<String /* timelineId */, MutableList<Event>>> = HashMap() private var pendingEvents: MutableMap<String /* senderKey|sessionId */, MutableMap<String /* timelineId */, MutableList<Event>>> = HashMap()
override suspend fun decryptEvent(event: Event, timeline: String): Try<MXEventDecryptionResult> { override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
return decryptEvent(event, timeline, true) return decryptEvent(event, timeline, true)
} }
private fun decryptEvent(event: Event, timeline: String, requestKeysOnFail: Boolean): Try<MXEventDecryptionResult> { private suspend fun decryptEvent(event: Event, timeline: String, requestKeysOnFail: Boolean): MXEventDecryptionResult {
if (event.roomId.isNullOrBlank()) { if (event.roomId.isNullOrBlank()) {
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)) throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)
} }
val encryptedEventContent = event.content.toModel<EncryptedEventContent>() val encryptedEventContent = event.content.toModel<EncryptedEventContent>()
?: return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)) ?: throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)
if (encryptedEventContent.senderKey.isNullOrBlank() if (encryptedEventContent.senderKey.isNullOrBlank()
|| encryptedEventContent.sessionId.isNullOrBlank() || encryptedEventContent.sessionId.isNullOrBlank()
|| encryptedEventContent.ciphertext.isNullOrBlank()) { || encryptedEventContent.ciphertext.isNullOrBlank()) {
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)) throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)
} }
return olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext, return runCatching {
olmDevice.decryptGroupMessage(encryptedEventContent.ciphertext,
event.roomId, event.roomId,
timeline, timeline,
encryptedEventContent.sessionId, encryptedEventContent.sessionId,
encryptedEventContent.senderKey) encryptedEventContent.senderKey)
}
.fold( .fold(
{ olmDecryptionResult ->
// the decryption succeeds
if (olmDecryptionResult.payload != null) {
MXEventDecryptionResult(
clearEvent = olmDecryptionResult.payload,
senderCurve25519Key = olmDecryptionResult.senderKey,
claimedEd25519Key = olmDecryptionResult.keysClaimed?.get("ed25519"),
forwardingCurve25519KeyChain = olmDecryptionResult.forwardingCurve25519KeyChain
?: emptyList()
)
} else {
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)
}
},
{ throwable -> { throwable ->
if (throwable is MXCryptoError.OlmError) { if (throwable is MXCryptoError.OlmError) {
// TODO Check the value of .message // TODO Check the value of .message
@ -100,10 +112,10 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
val reason = String.format(MXCryptoError.OLM_REASON, throwable.olmException.message) val reason = String.format(MXCryptoError.OLM_REASON, throwable.olmException.message)
val detailedReason = String.format(MXCryptoError.DETAILED_OLM_REASON, encryptedEventContent.ciphertext, reason) val detailedReason = String.format(MXCryptoError.DETAILED_OLM_REASON, encryptedEventContent.ciphertext, reason)
Try.Failure(MXCryptoError.Base( throw MXCryptoError.Base(
MXCryptoError.ErrorType.OLM, MXCryptoError.ErrorType.OLM,
reason, reason,
detailedReason)) detailedReason)
} }
if (throwable is MXCryptoError.Base) { if (throwable is MXCryptoError.Base) {
if (throwable.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) { if (throwable.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID) {
@ -113,23 +125,7 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
} }
} }
} }
throw throwable
Try.Failure(throwable)
},
{ olmDecryptionResult ->
// the decryption succeeds
if (olmDecryptionResult.payload != null) {
Try.just(
MXEventDecryptionResult(
clearEvent = olmDecryptionResult.payload,
senderCurve25519Key = olmDecryptionResult.senderKey,
claimedEd25519Key = olmDecryptionResult.keysClaimed?.get("ed25519"),
forwardingCurve25519KeyChain = olmDecryptionResult.forwardingCurve25519KeyChain ?: emptyList()
)
)
} else {
Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON))
}
} }
) )
} }
@ -312,45 +308,41 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
return return
} }
val userId = request.userId ?: return val userId = request.userId ?: return
CoroutineScope(coroutineDispatchers.crypto).launch { GlobalScope.launch(coroutineDispatchers.crypto) {
deviceListManager runCatching { deviceListManager.downloadKeys(listOf(userId), false) }
.downloadKeys(listOf(userId), false) .mapCatching {
.flatMap {
val deviceId = request.deviceId val deviceId = request.deviceId
val deviceInfo = cryptoStore.getUserDevice(deviceId ?: "", userId) val deviceInfo = cryptoStore.getUserDevice(deviceId ?: "", userId)
if (deviceInfo == null) { if (deviceInfo == null) {
throw RuntimeException() throw RuntimeException()
} else { } else {
val devicesByUser = HashMap<String, List<MXDeviceInfo>>() val devicesByUser = mapOf(userId to listOf(deviceInfo))
devicesByUser[userId] = ArrayList(Arrays.asList(deviceInfo)) val usersDeviceMap = ensureOlmSessionsForDevicesAction.handle(devicesByUser)
ensureOlmSessionsForDevicesAction
.handle(devicesByUser)
.flatMap {
val body = request.requestBody val body = request.requestBody
val olmSessionResult = it.getObject(userId, deviceId) val olmSessionResult = usersDeviceMap.getObject(userId, deviceId)
if (olmSessionResult?.sessionId == null) { if (olmSessionResult?.sessionId == null) {
// no session with this device, probably because there // no session with this device, probably because there
// were no one-time keys. // were no one-time keys.
Try.just(Unit) return@mapCatching
} }
Timber.v("## shareKeysWithDevice() : sharing keys for session" + Timber.v("## shareKeysWithDevice() : sharing keys for session" +
" ${body?.senderKey}|${body?.sessionId} with device $userId:$deviceId") " ${body?.senderKey}|${body?.sessionId} with device $userId:$deviceId")
val payloadJson = HashMap<String, Any>() val payloadJson = mutableMapOf<String, Any>("type" to EventType.FORWARDED_ROOM_KEY)
payloadJson["type"] = EventType.FORWARDED_ROOM_KEY runCatching { olmDevice.getInboundGroupSession(body?.sessionId, body?.senderKey, body?.roomId) }
olmDevice.getInboundGroupSession(body?.sessionId, body?.senderKey, body?.roomId)
.fold( .fold(
{ {
// TODO // TODO
payloadJson["content"] = it.exportKeys()
?: ""
}, },
{ {
// TODO // TODO
payloadJson["content"] = it.exportKeys() ?: ""
} }
) )
val encodedPayload = messageEncrypter.encryptMessage(payloadJson, Arrays.asList(deviceInfo)) val encodedPayload = messageEncrypter.encryptMessage(payloadJson, listOf(deviceInfo))
val sendToDeviceMap = MXUsersDevicesMap<Any>() val sendToDeviceMap = MXUsersDevicesMap<Any>()
sendToDeviceMap.setObject(userId, deviceId, encodedPayload) sendToDeviceMap.setObject(userId, deviceId, encodedPayload)
Timber.v("## shareKeysWithDevice() : sending to $userId:$deviceId") Timber.v("## shareKeysWithDevice() : sending to $userId:$deviceId")
@ -360,6 +352,5 @@ internal class MXMegolmDecryption(private val credentials: Credentials,
} }
} }
} }
}
} }

View File

@ -24,7 +24,6 @@ import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForDevi
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask import im.vector.matrix.android.internal.crypto.tasks.SendToDeviceTask
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import javax.inject.Inject import javax.inject.Inject

View File

@ -19,7 +19,6 @@
package im.vector.matrix.android.internal.crypto.algorithms.megolm package im.vector.matrix.android.internal.crypto.algorithms.megolm
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Content
@ -69,12 +68,10 @@ internal class MXMegolmEncryption(
override suspend fun encryptEventContent(eventContent: Content, override suspend fun encryptEventContent(eventContent: Content,
eventType: String, eventType: String,
userIds: List<String>): Try<Content> { userIds: List<String>): Content {
return getDevicesInRoom(userIds) val devices = getDevicesInRoom(userIds)
.flatMap { ensureOutboundSession(it) } val outboundSession = ensureOutboundSession(devices)
.flatMap { return encryptContent(outboundSession, eventType, eventContent)
encryptContent(it, eventType, eventContent)
}
} }
/** /**
@ -101,7 +98,7 @@ internal class MXMegolmEncryption(
* *
* @param devicesInRoom the devices list * @param devicesInRoom the devices list
*/ */
private suspend fun ensureOutboundSession(devicesInRoom: MXUsersDevicesMap<MXDeviceInfo>): Try<MXOutboundSessionInfo> { private suspend fun ensureOutboundSession(devicesInRoom: MXUsersDevicesMap<MXDeviceInfo>): MXOutboundSessionInfo {
var session = outboundSession var session = outboundSession
if (session == null if (session == null
// Need to make a brand new session? // Need to make a brand new session?
@ -126,7 +123,8 @@ internal class MXMegolmEncryption(
} }
} }
} }
return shareKey(safeSession, shareMap).map { safeSession!! } shareKey(safeSession, shareMap)
return safeSession
} }
/** /**
@ -136,11 +134,11 @@ internal class MXMegolmEncryption(
* @param devicesByUsers the devices map * @param devicesByUsers the devices map
*/ */
private suspend fun shareKey(session: MXOutboundSessionInfo, private suspend fun shareKey(session: MXOutboundSessionInfo,
devicesByUsers: Map<String, List<MXDeviceInfo>>): Try<Unit> { devicesByUsers: Map<String, List<MXDeviceInfo>>) {
// nothing to send, the task is done // nothing to send, the task is done
if (devicesByUsers.isEmpty()) { if (devicesByUsers.isEmpty()) {
Timber.v("## shareKey() : nothing more to do") Timber.v("## shareKey() : nothing more to do")
return Try.just(Unit) return
} }
// reduce the map size to avoid request timeout when there are too many devices (Users size * devices per user) // reduce the map size to avoid request timeout when there are too many devices (Users size * devices per user)
val subMap = HashMap<String, List<MXDeviceInfo>>() val subMap = HashMap<String, List<MXDeviceInfo>>()
@ -157,12 +155,10 @@ internal class MXMegolmEncryption(
} }
} }
Timber.v("## shareKey() ; userId $userIds") Timber.v("## shareKey() ; userId $userIds")
return shareUserDevicesKey(session, subMap) shareUserDevicesKey(session, subMap)
.flatMap {
val remainingDevices = devicesByUsers.filterKeys { userIds.contains(it).not() } val remainingDevices = devicesByUsers.filterKeys { userIds.contains(it).not() }
shareKey(session, remainingDevices) shareKey(session, remainingDevices)
} }
}
/** /**
* Share the device keys of a an user * Share the device keys of a an user
@ -172,7 +168,7 @@ internal class MXMegolmEncryption(
* @param callback the asynchronous callback * @param callback the asynchronous callback
*/ */
private suspend fun shareUserDevicesKey(session: MXOutboundSessionInfo, private suspend fun shareUserDevicesKey(session: MXOutboundSessionInfo,
devicesByUser: Map<String, List<MXDeviceInfo>>): Try<Unit> { devicesByUser: Map<String, List<MXDeviceInfo>>) {
val sessionKey = olmDevice.getSessionKey(session.sessionId) val sessionKey = olmDevice.getSessionKey(session.sessionId)
val chainIndex = olmDevice.getMessageIndex(session.sessionId) val chainIndex = olmDevice.getMessageIndex(session.sessionId)
@ -190,17 +186,16 @@ internal class MXMegolmEncryption(
var t0 = System.currentTimeMillis() var t0 = System.currentTimeMillis()
Timber.v("## shareUserDevicesKey() : starts") Timber.v("## shareUserDevicesKey() : starts")
return ensureOlmSessionsForDevicesAction.handle(devicesByUser) val results = ensureOlmSessionsForDevicesAction.handle(devicesByUser)
.flatMap {
Timber.v("## shareUserDevicesKey() : ensureOlmSessionsForDevices succeeds after " Timber.v("## shareUserDevicesKey() : ensureOlmSessionsForDevices succeeds after "
+ (System.currentTimeMillis() - t0) + " ms") + (System.currentTimeMillis() - t0) + " ms")
val contentMap = MXUsersDevicesMap<Any>() val contentMap = MXUsersDevicesMap<Any>()
var haveTargets = false var haveTargets = false
val userIds = it.userIds val userIds = results.userIds
for (userId in userIds) { for (userId in userIds) {
val devicesToShareWith = devicesByUser[userId] val devicesToShareWith = devicesByUser[userId]
for ((deviceID) in devicesToShareWith!!) { for ((deviceID) in devicesToShareWith!!) {
val sessionResult = it.getObject(userId, deviceID) val sessionResult = results.getObject(userId, deviceID)
if (sessionResult?.sessionId == null) { if (sessionResult?.sessionId == null) {
// no session with this device, probably because there // no session with this device, probably because there
// were no one-time keys. // were no one-time keys.
@ -226,7 +221,6 @@ internal class MXMegolmEncryption(
Timber.v("## shareUserDevicesKey() : has target") Timber.v("## shareUserDevicesKey() : has target")
val sendToDeviceParams = SendToDeviceTask.Params(EventType.ENCRYPTED, contentMap) val sendToDeviceParams = SendToDeviceTask.Params(EventType.ENCRYPTED, contentMap)
sendToDeviceTask.execute(sendToDeviceParams) sendToDeviceTask.execute(sendToDeviceParams)
.map {
Timber.v("## shareUserDevicesKey() : sendToDevice succeeds after " Timber.v("## shareUserDevicesKey() : sendToDevice succeeds after "
+ (System.currentTimeMillis() - t0) + " ms") + (System.currentTimeMillis() - t0) + " ms")
@ -241,20 +235,15 @@ internal class MXMegolmEncryption(
session.sharedWithDevices.setObject(userId, deviceId, chainIndex) session.sharedWithDevices.setObject(userId, deviceId, chainIndex)
} }
} }
Unit
}
} else { } else {
Timber.v("## shareUserDevicesKey() : no need to sharekey") Timber.v("## shareUserDevicesKey() : no need to sharekey")
Try.just(Unit)
}
} }
} }
/** /**
* process the pending encryptions * process the pending encryptions
*/ */
private fun encryptContent(session: MXOutboundSessionInfo, eventType: String, eventContent: Content): Try<Content> { private fun encryptContent(session: MXOutboundSessionInfo, eventType: String, eventContent: Content): Content {
return Try<Content> {
// Everything is in place, encrypt all pending events // Everything is in place, encrypt all pending events
val payloadJson = HashMap<String, Any>() val payloadJson = HashMap<String, Any>()
payloadJson["room_id"] = roomId payloadJson["room_id"] = roomId
@ -276,8 +265,7 @@ internal class MXMegolmEncryption(
// m.new_device message if they don't have our session key. // m.new_device message if they don't have our session key.
map["device_id"] = credentials.deviceId!! map["device_id"] = credentials.deviceId!!
session.useCount++ session.useCount++
map return map
}
} }
/** /**
@ -287,24 +275,22 @@ internal class MXMegolmEncryption(
* @param userIds the user ids whose devices must be checked. * @param userIds the user ids whose devices must be checked.
* @param callback the asynchronous callback * @param callback the asynchronous callback
*/ */
private suspend fun getDevicesInRoom(userIds: List<String>): Try<MXUsersDevicesMap<MXDeviceInfo>> { private suspend fun getDevicesInRoom(userIds: List<String>): MXUsersDevicesMap<MXDeviceInfo> {
// We are happy to use a cached version here: we assume that if we already // We are happy to use a cached version here: we assume that if we already
// have a list of the user's devices, then we already share an e2e room // have a list of the user's devices, then we already share an e2e room
// with them, which means that they will have announced any new devices via // with them, which means that they will have announced any new devices via
// an m.new_device. // an m.new_device.
return deviceListManager val keys = deviceListManager.downloadKeys(userIds, false)
.downloadKeys(userIds, false)
.flatMap {
val encryptToVerifiedDevicesOnly = cryptoStore.getGlobalBlacklistUnverifiedDevices() val encryptToVerifiedDevicesOnly = cryptoStore.getGlobalBlacklistUnverifiedDevices()
|| cryptoStore.getRoomsListBlacklistUnverifiedDevices().contains(roomId) || cryptoStore.getRoomsListBlacklistUnverifiedDevices().contains(roomId)
val devicesInRoom = MXUsersDevicesMap<MXDeviceInfo>() val devicesInRoom = MXUsersDevicesMap<MXDeviceInfo>()
val unknownDevices = MXUsersDevicesMap<MXDeviceInfo>() val unknownDevices = MXUsersDevicesMap<MXDeviceInfo>()
for (userId in it.userIds) { for (userId in keys.userIds) {
val deviceIds = it.getUserDeviceIds(userId) ?: continue val deviceIds = keys.getUserDeviceIds(userId) ?: continue
for (deviceId in deviceIds) { for (deviceId in deviceIds) {
val deviceInfo = it.getObject(userId, deviceId) ?: continue val deviceInfo = keys.getObject(userId, deviceId) ?: continue
if (warnOnUnknownDevicesRepository.warnOnUnknownDevices() && deviceInfo.isUnknown) { if (warnOnUnknownDevicesRepository.warnOnUnknownDevices() && deviceInfo.isUnknown) {
// The device is not yet known by the user // The device is not yet known by the user
unknownDevices.setObject(userId, deviceId, deviceInfo) unknownDevices.setObject(userId, deviceId, deviceInfo)
@ -327,10 +313,9 @@ internal class MXMegolmEncryption(
} }
} }
if (unknownDevices.isEmpty) { if (unknownDevices.isEmpty) {
Try.just(devicesInRoom) return devicesInRoom
} else { } else {
Try.Failure(MXCryptoError.UnknownDevice(unknownDevices)) throw MXCryptoError.UnknownDevice(unknownDevices)
}
} }
} }
} }

View File

@ -17,7 +17,6 @@
package im.vector.matrix.android.internal.crypto.algorithms.olm package im.vector.matrix.android.internal.crypto.algorithms.olm
import arrow.core.Try
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.session.crypto.MXCryptoError import im.vector.matrix.android.api.session.crypto.MXCryptoError
import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
@ -41,29 +40,28 @@ internal class MXOlmDecryption(
private val credentials: Credentials) private val credentials: Credentials)
: IMXDecrypting { : IMXDecrypting {
override suspend fun decryptEvent(event: Event, timeline: String): Try<MXEventDecryptionResult> { override suspend fun decryptEvent(event: Event, timeline: String): MXEventDecryptionResult {
val olmEventContent = event.content.toModel<OlmEventContent>() ?: run { val olmEventContent = event.content.toModel<OlmEventContent>() ?: run {
Timber.e("## decryptEvent() : bad event format") Timber.e("## decryptEvent() : bad event format")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_EVENT_FORMAT,
MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON)) MXCryptoError.BAD_EVENT_FORMAT_TEXT_REASON)
} }
val cipherText = olmEventContent.ciphertext ?: run { val cipherText = olmEventContent.ciphertext ?: run {
Timber.e("## decryptEvent() : missing cipher text") Timber.e("## decryptEvent() : missing cipher text")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_CIPHER_TEXT, throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_CIPHER_TEXT,
MXCryptoError.MISSING_CIPHER_TEXT_REASON)) MXCryptoError.MISSING_CIPHER_TEXT_REASON)
} }
val senderKey = olmEventContent.senderKey ?: run { val senderKey = olmEventContent.senderKey ?: run {
Timber.e("## decryptEvent() : missing sender key") Timber.e("## decryptEvent() : missing sender key")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY, throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY,
MXCryptoError.MISSING_SENDER_KEY_TEXT_REASON)) MXCryptoError.MISSING_SENDER_KEY_TEXT_REASON)
} }
val messageAny = cipherText[olmDevice.deviceCurve25519Key] ?: run { val messageAny = cipherText[olmDevice.deviceCurve25519Key] ?: run {
Timber.e("## decryptEvent() : our device ${olmDevice.deviceCurve25519Key} is not included in recipients") Timber.e("## decryptEvent() : our device ${olmDevice.deviceCurve25519Key} is not included in recipients")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.NOT_INCLUDE_IN_RECIPIENTS, throw MXCryptoError.Base(MXCryptoError.ErrorType.NOT_INCLUDE_IN_RECIPIENTS, MXCryptoError.NOT_INCLUDED_IN_RECIPIENT_REASON)
MXCryptoError.NOT_INCLUDED_IN_RECIPIENT_REASON))
} }
// The message for myUser // The message for myUser
@ -73,14 +71,12 @@ internal class MXOlmDecryption(
if (decryptedPayload == null) { if (decryptedPayload == null) {
Timber.e("## decryptEvent() Failed to decrypt Olm event (id= ${event.eventId} from $senderKey") Timber.e("## decryptEvent() Failed to decrypt Olm event (id= ${event.eventId} from $senderKey")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON)
MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON))
} }
val payloadString = convertFromUTF8(decryptedPayload) val payloadString = convertFromUTF8(decryptedPayload)
if (payloadString == null) { if (payloadString == null) {
Timber.e("## decryptEvent() Failed to decrypt Olm event (id= ${event.eventId} from $senderKey") Timber.e("## decryptEvent() Failed to decrypt Olm event (id= ${event.eventId} from $senderKey")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ENCRYPTED_MESSAGE, MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON)
MXCryptoError.BAD_ENCRYPTED_MESSAGE_REASON))
} }
val adapter = MoshiProvider.providesMoshi().adapter<JsonDict>(JSON_DICT_PARAMETERIZED_TYPE) val adapter = MoshiProvider.providesMoshi().adapter<JsonDict>(JSON_DICT_PARAMETERIZED_TYPE)
@ -88,73 +84,70 @@ internal class MXOlmDecryption(
if (payload == null) { if (payload == null) {
Timber.e("## decryptEvent failed : null payload") Timber.e("## decryptEvent failed : null payload")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT, throw MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT, MXCryptoError.MISSING_CIPHER_TEXT_REASON)
MXCryptoError.MISSING_CIPHER_TEXT_REASON))
} }
val olmPayloadContent = OlmPayloadContent.fromJsonString(payloadString) ?: run { val olmPayloadContent = OlmPayloadContent.fromJsonString(payloadString) ?: run {
Timber.e("## decryptEvent() : bad olmPayloadContent format") Timber.e("## decryptEvent() : bad olmPayloadContent format")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_DECRYPTED_FORMAT, MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON)
MXCryptoError.BAD_DECRYPTED_FORMAT_TEXT_REASON))
} }
if (olmPayloadContent.recipient.isNullOrBlank()) { if (olmPayloadContent.recipient.isNullOrBlank()) {
val reason = String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "recipient") val reason = String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "recipient")
Timber.e("## decryptEvent() : $reason") Timber.e("## decryptEvent() : $reason")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, reason)
reason))
} }
if (olmPayloadContent.recipient != credentials.userId) { if (olmPayloadContent.recipient != credentials.userId) {
Timber.e("## decryptEvent() : Event ${event.eventId}:" + Timber.e("## decryptEvent() : Event ${event.eventId}:" +
" Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}") " Intended recipient ${olmPayloadContent.recipient} does not match our id ${credentials.userId}")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT,
String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))) String.format(MXCryptoError.BAD_RECIPIENT_REASON, olmPayloadContent.recipient))
} }
val recipientKeys = olmPayloadContent.recipient_keys ?: run { val recipientKeys = olmPayloadContent.recipient_keys ?: run {
Timber.e("## decryptEvent() : Olm event (id=${event.eventId}) contains no 'recipient_keys' property; cannot prevent unknown-key attack") Timber.e("## decryptEvent() : Olm event (id=${event.eventId}) contains no 'recipient_keys' property; cannot prevent unknown-key attack")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY,
String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "recipient_keys"))) String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "recipient_keys"))
} }
val ed25519 = recipientKeys["ed25519"] val ed25519 = recipientKeys["ed25519"]
if (ed25519 != olmDevice.deviceEd25519Key) { if (ed25519 != olmDevice.deviceEd25519Key) {
Timber.e("## decryptEvent() : Event ${event.eventId}: Intended recipient ed25519 key $ed25519 did not match ours") Timber.e("## decryptEvent() : Event ${event.eventId}: Intended recipient ed25519 key $ed25519 did not match ours")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT_KEY, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_RECIPIENT_KEY,
MXCryptoError.BAD_RECIPIENT_KEY_REASON)) MXCryptoError.BAD_RECIPIENT_KEY_REASON)
} }
if (olmPayloadContent.sender.isNullOrBlank()) { if (olmPayloadContent.sender.isNullOrBlank()) {
Timber.e("## decryptEvent() : Olm event (id=${event.eventId}) contains no 'sender' property; cannot prevent unknown-key attack") Timber.e("## decryptEvent() : Olm event (id=${event.eventId}) contains no 'sender' property; cannot prevent unknown-key attack")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY, throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_PROPERTY,
String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "sender"))) String.format(MXCryptoError.ERROR_MISSING_PROPERTY_REASON, "sender"))
} }
if (olmPayloadContent.sender != event.senderId) { if (olmPayloadContent.sender != event.senderId) {
Timber.e("Event ${event.eventId}: original sender ${olmPayloadContent.sender} does not match reported sender ${event.senderId}") Timber.e("Event ${event.eventId}: original sender ${olmPayloadContent.sender} does not match reported sender ${event.senderId}")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.FORWARDED_MESSAGE, throw MXCryptoError.Base(MXCryptoError.ErrorType.FORWARDED_MESSAGE,
String.format(MXCryptoError.FORWARDED_MESSAGE_REASON, olmPayloadContent.sender))) String.format(MXCryptoError.FORWARDED_MESSAGE_REASON, olmPayloadContent.sender))
} }
if (olmPayloadContent.room_id != event.roomId) { if (olmPayloadContent.room_id != event.roomId) {
Timber.e("## decryptEvent() : Event ${event.eventId}: original room ${olmPayloadContent.room_id} does not match reported room ${event.roomId}") Timber.e("## decryptEvent() : Event ${event.eventId}: original room ${olmPayloadContent.room_id} does not match reported room ${event.roomId}")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ROOM, throw MXCryptoError.Base(MXCryptoError.ErrorType.BAD_ROOM,
String.format(MXCryptoError.BAD_ROOM_REASON, olmPayloadContent.room_id))) String.format(MXCryptoError.BAD_ROOM_REASON, olmPayloadContent.room_id))
} }
val keys = olmPayloadContent.keys ?: run { val keys = olmPayloadContent.keys ?: run {
Timber.e("## decryptEvent failed : null keys") Timber.e("## decryptEvent failed : null keys")
return Try.Failure(MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT, throw MXCryptoError.Base(MXCryptoError.ErrorType.UNABLE_TO_DECRYPT,
MXCryptoError.MISSING_CIPHER_TEXT_REASON)) MXCryptoError.MISSING_CIPHER_TEXT_REASON)
} }
return Try.just(MXEventDecryptionResult( return MXEventDecryptionResult(
clearEvent = payload, clearEvent = payload,
senderCurve25519Key = senderKey, senderCurve25519Key = senderKey,
claimedEd25519Key = keys["ed25519"] claimedEd25519Key = keys["ed25519"]
)) )
} }
/** /**

View File

@ -18,7 +18,6 @@ package im.vector.matrix.android.internal.crypto.algorithms.olm
import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.internal.crypto.MXOlmDevice import im.vector.matrix.android.internal.crypto.MXOlmDevice
import im.vector.matrix.android.internal.session.SessionScope
import javax.inject.Inject import javax.inject.Inject
internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice, internal class MXOlmDecryptionFactory @Inject constructor(private val olmDevice: MXOlmDevice,

View File

@ -19,7 +19,6 @@
package im.vector.matrix.android.internal.crypto.algorithms.olm package im.vector.matrix.android.internal.crypto.algorithms.olm
import android.text.TextUtils import android.text.TextUtils
import arrow.core.Try
import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Content
import im.vector.matrix.android.api.session.events.model.toContent import im.vector.matrix.android.api.session.events.model.toContent
import im.vector.matrix.android.internal.crypto.DeviceListManager import im.vector.matrix.android.internal.crypto.DeviceListManager
@ -40,12 +39,11 @@ internal class MXOlmEncryption(
private val ensureOlmSessionsForUsersAction: EnsureOlmSessionsForUsersAction) private val ensureOlmSessionsForUsersAction: EnsureOlmSessionsForUsersAction)
: IMXEncrypting { : IMXEncrypting {
override suspend fun encryptEventContent(eventContent: Content, eventType: String, userIds: List<String>): Try<Content> { override suspend fun encryptEventContent(eventContent: Content, eventType: String, userIds: List<String>): Content {
// pick the list of recipients based on the membership list. // pick the list of recipients based on the membership list.
// //
// TODO: there is a race condition here! What if a new user turns up // TODO: there is a race condition here! What if a new user turns up
return ensureSession(userIds) ensureSession(userIds)
.map {
val deviceInfos = ArrayList<MXDeviceInfo>() val deviceInfos = ArrayList<MXDeviceInfo>()
for (userId in userIds) { for (userId in userIds) {
val devices = cryptoStore.getUserDevices(userId)?.values ?: emptyList() val devices = cryptoStore.getUserDevices(userId)?.values ?: emptyList()
@ -69,8 +67,7 @@ internal class MXOlmEncryption(
messageMap["content"] = eventContent messageMap["content"] = eventContent
messageEncrypter.encryptMessage(messageMap, deviceInfos) messageEncrypter.encryptMessage(messageMap, deviceInfos)
messageMap.toContent()!! return messageMap.toContent()!!
}
} }
@ -78,13 +75,9 @@ internal class MXOlmEncryption(
* Ensure that the session * Ensure that the session
* *
* @param users the user ids list * @param users the user ids list
* @param callback the asynchronous callback
*/ */
private suspend fun ensureSession(users: List<String>): Try<Unit> { private suspend fun ensureSession(users: List<String>) {
return deviceListManager deviceListManager.downloadKeys(users, false)
.downloadKeys(users, false) ensureOlmSessionsForUsersAction.handle(users)
.flatMap { ensureOlmSessionsForUsersAction.handle(users) }
.map { Unit }
} }
} }

View File

@ -21,7 +21,6 @@ import im.vector.matrix.android.internal.crypto.MXOlmDevice
import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForUsersAction import im.vector.matrix.android.internal.crypto.actions.EnsureOlmSessionsForUsersAction
import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter import im.vector.matrix.android.internal.crypto.actions.MessageEncrypter
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import javax.inject.Inject import javax.inject.Inject

View File

@ -18,8 +18,6 @@ package im.vector.matrix.android.internal.crypto.api
import im.vector.matrix.android.internal.crypto.model.rest.* import im.vector.matrix.android.internal.crypto.model.rest.*
import im.vector.matrix.android.internal.crypto.model.rest.KeysUploadBody
import im.vector.matrix.android.internal.crypto.model.rest.SendToDeviceBody
import im.vector.matrix.android.internal.network.NetworkConstants import im.vector.matrix.android.internal.network.NetworkConstants
import retrofit2.Call import retrofit2.Call
import retrofit2.http.* import retrofit2.http.*

View File

@ -51,7 +51,6 @@ import im.vector.matrix.android.internal.crypto.store.db.model.KeysBackupDataEnt
import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.di.MoshiProvider
import im.vector.matrix.android.internal.extensions.foldToCallback import im.vector.matrix.android.internal.extensions.foldToCallback
import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.*
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.task.TaskThread import im.vector.matrix.android.internal.task.TaskThread
@ -204,8 +203,8 @@ internal class KeysBackup @Inject constructor(
keysBackupStateManager.state = KeysBackupState.Enabling keysBackupStateManager.state = KeysBackupState.Enabling
createKeysBackupVersionTask createKeysBackupVersionTask
.configureWith(createKeysBackupVersionBody) .configureWith(createKeysBackupVersionBody) {
.dispatchTo(object : MatrixCallback<KeysVersion> { this.callback = object : MatrixCallback<KeysVersion> {
override fun onSuccess(info: KeysVersion) { override fun onSuccess(info: KeysVersion) {
// Reset backup markers. // Reset backup markers.
cryptoStore.resetBackupMarkers() cryptoStore.resetBackupMarkers()
@ -228,7 +227,8 @@ internal class KeysBackup @Inject constructor(
keysBackupStateManager.state = KeysBackupState.Disabled keysBackupStateManager.state = KeysBackupState.Disabled
callback.onFailure(failure) callback.onFailure(failure)
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
@ -243,8 +243,9 @@ internal class KeysBackup @Inject constructor(
keysBackupStateManager.state = KeysBackupState.Unknown keysBackupStateManager.state = KeysBackupState.Unknown
} }
deleteBackupTask.configureWith(DeleteBackupTask.Params(version)) deleteBackupTask
.dispatchTo(object : MatrixCallback<Unit> { .configureWith(DeleteBackupTask.Params(version)) {
this.callback = object : MatrixCallback<Unit> {
private fun eventuallyRestartBackup() { private fun eventuallyRestartBackup() {
// Do not stay in KeysBackupState.Unknown but check what is available on the homeserver // Do not stay in KeysBackupState.Unknown but check what is available on the homeserver
if (state == KeysBackupState.Unknown) { if (state == KeysBackupState.Unknown) {
@ -263,7 +264,8 @@ internal class KeysBackup @Inject constructor(
uiHandler.post { callback?.onFailure(failure) } uiHandler.post { callback?.onFailure(failure) }
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
} }
@ -355,15 +357,14 @@ internal class KeysBackup @Inject constructor(
callback: MatrixCallback<KeysBackupVersionTrust>) { callback: MatrixCallback<KeysBackupVersionTrust>) {
// TODO Validate with François that this is correct // TODO Validate with François that this is correct
object : Task<KeysVersionResult, KeysBackupVersionTrust> { object : Task<KeysVersionResult, KeysBackupVersionTrust> {
override suspend fun execute(params: KeysVersionResult): Try<KeysBackupVersionTrust> { override suspend fun execute(params: KeysVersionResult): KeysBackupVersionTrust {
return Try { return getKeysBackupTrustBg(params)
getKeysBackupTrustBg(params)
} }
} }
.configureWith(keysBackupVersion) {
this.callback = callback
this.executionThread = TaskThread.COMPUTATION
} }
.configureWith(keysBackupVersion)
.dispatchTo(callback)
.executeOn(TaskThread.COMPUTATION)
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
@ -454,7 +455,8 @@ internal class KeysBackup @Inject constructor(
val myUserId = credentials.userId val myUserId = credentials.userId
// Get current signatures, or create an empty set // Get current signatures, or create an empty set
val myUserSignatures = authData.signatures?.get(myUserId)?.toMutableMap() ?: HashMap() val myUserSignatures = authData.signatures?.get(myUserId)?.toMutableMap()
?: HashMap()
if (trust) { if (trust) {
// Add current device signature // Add current device signature
@ -492,8 +494,8 @@ internal class KeysBackup @Inject constructor(
// And send it to the homeserver // And send it to the homeserver
updateKeysBackupVersionTask updateKeysBackupVersionTask
.configureWith(UpdateKeysBackupVersionTask.Params(keysBackupVersion.version!!, updateKeysBackupVersionBody)) .configureWith(UpdateKeysBackupVersionTask.Params(keysBackupVersion.version!!, updateKeysBackupVersionBody)) {
.dispatchTo(object : MatrixCallback<Unit> { this.callback = object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) { override fun onSuccess(data: Unit) {
// Relaunch the state machine on this updated backup version // Relaunch the state machine on this updated backup version
val newKeysBackupVersion = KeysVersionResult() val newKeysBackupVersion = KeysVersionResult()
@ -512,7 +514,8 @@ internal class KeysBackup @Inject constructor(
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {
callback.onFailure(failure) callback.onFailure(failure)
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
} }
@ -758,8 +761,8 @@ internal class KeysBackup @Inject constructor(
if (roomId != null && sessionId != null) { if (roomId != null && sessionId != null) {
// Get key for the room and for the session // Get key for the room and for the session
getRoomSessionDataTask getRoomSessionDataTask
.configureWith(GetRoomSessionDataTask.Params(roomId, sessionId, version)) .configureWith(GetRoomSessionDataTask.Params(roomId, sessionId, version)) {
.dispatchTo(object : MatrixCallback<KeyBackupData> { this.callback = object : MatrixCallback<KeyBackupData> {
override fun onSuccess(data: KeyBackupData) { override fun onSuccess(data: KeyBackupData) {
// Convert to KeysBackupData // Convert to KeysBackupData
val keysBackupData = KeysBackupData() val keysBackupData = KeysBackupData()
@ -775,13 +778,14 @@ internal class KeysBackup @Inject constructor(
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {
callback.onFailure(failure) callback.onFailure(failure)
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} else if (roomId != null) { } else if (roomId != null) {
// Get all keys for the room // Get all keys for the room
getRoomSessionsDataTask getRoomSessionsDataTask
.configureWith(GetRoomSessionsDataTask.Params(roomId, version)) .configureWith(GetRoomSessionsDataTask.Params(roomId, version)) {
.dispatchTo(object : MatrixCallback<RoomKeysBackupData> { this.callback = object : MatrixCallback<RoomKeysBackupData> {
override fun onSuccess(data: RoomKeysBackupData) { override fun onSuccess(data: RoomKeysBackupData) {
// Convert to KeysBackupData // Convert to KeysBackupData
val keysBackupData = KeysBackupData() val keysBackupData = KeysBackupData()
@ -794,13 +798,15 @@ internal class KeysBackup @Inject constructor(
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {
callback.onFailure(failure) callback.onFailure(failure)
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} else { } else {
// Get all keys // Get all keys
getSessionsDataTask getSessionsDataTask
.configureWith(GetSessionsDataTask.Params(version)) .configureWith(GetSessionsDataTask.Params(version)) {
.dispatchTo(callback) this.callback = callback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
} }
@ -855,8 +861,8 @@ internal class KeysBackup @Inject constructor(
override fun getVersion(version: String, override fun getVersion(version: String,
callback: MatrixCallback<KeysVersionResult?>) { callback: MatrixCallback<KeysVersionResult?>) {
getKeysBackupVersionTask getKeysBackupVersionTask
.configureWith(version) .configureWith(version) {
.dispatchTo(object : MatrixCallback<KeysVersionResult> { this.callback = object : MatrixCallback<KeysVersionResult> {
override fun onSuccess(data: KeysVersionResult) { override fun onSuccess(data: KeysVersionResult) {
callback.onSuccess(data) callback.onSuccess(data)
} }
@ -871,14 +877,15 @@ internal class KeysBackup @Inject constructor(
callback.onFailure(failure) callback.onFailure(failure)
} }
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
override fun getCurrentVersion(callback: MatrixCallback<KeysVersionResult?>) { override fun getCurrentVersion(callback: MatrixCallback<KeysVersionResult?>) {
getKeysBackupLastVersionTask getKeysBackupLastVersionTask
.toConfigurableTask() .configureWith {
.dispatchTo(object : MatrixCallback<KeysVersionResult> { this.callback = object : MatrixCallback<KeysVersionResult> {
override fun onSuccess(data: KeysVersionResult) { override fun onSuccess(data: KeysVersionResult) {
callback.onSuccess(data) callback.onSuccess(data)
} }
@ -893,7 +900,8 @@ internal class KeysBackup @Inject constructor(
callback.onFailure(failure) callback.onFailure(failure)
} }
} }
}) }
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
@ -1236,10 +1244,7 @@ internal class KeysBackup @Inject constructor(
Timber.v("backupKeys: 4 - Sending request") Timber.v("backupKeys: 4 - Sending request")
// Make the request val sendingRequestCallback = object : MatrixCallback<BackupKeysResult> {
storeSessionDataTask
.configureWith(StoreSessionsDataTask.Params(keysBackupVersion!!.version!!, keysBackupData))
.dispatchTo(object : MatrixCallback<BackupKeysResult> {
override fun onSuccess(data: BackupKeysResult) { override fun onSuccess(data: BackupKeysResult) {
uiHandler.post { uiHandler.post {
Timber.v("backupKeys: 5a - Request complete") Timber.v("backupKeys: 5a - Request complete")
@ -1298,7 +1303,13 @@ internal class KeysBackup @Inject constructor(
} }
} }
} }
}) }
// Make the request
storeSessionDataTask
.configureWith(StoreSessionsDataTask.Params(keysBackupVersion!!.version!!, keysBackupData)){
this.callback = sendingRequestCallback
}
.executeBy(taskExecutor) .executeBy(taskExecutor)
} }
} }

View File

@ -142,12 +142,11 @@ private fun deriveKey(password: String,
* Generate a 32 chars salt * Generate a 32 chars salt
*/ */
private fun generateSalt(): String { private fun generateSalt(): String {
var salt = "" val salt = buildString {
do { do {
salt += UUID.randomUUID().toString() append(UUID.randomUUID().toString())
} while (salt.length < SALT_LENGTH) } while (length < SALT_LENGTH)
}
return salt.substring(0, SALT_LENGTH) return salt.substring(0, SALT_LENGTH)
} }

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersion import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersion
@ -30,7 +29,7 @@ internal class DefaultCreateKeysBackupVersionTask @Inject constructor(private va
: CreateKeysBackupVersionTask { : CreateKeysBackupVersionTask {
override suspend fun execute(params: CreateKeysBackupVersionBody): Try<KeysVersion> { override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.createKeysBackupVersion(params) apiCall = roomKeysApi.createKeysBackupVersion(params)
} }

View File

@ -16,10 +16,8 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -33,10 +31,9 @@ internal interface DeleteBackupTask : Task<DeleteBackupTask.Params, Unit> {
internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultDeleteBackupTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteBackupTask { : DeleteBackupTask {
override suspend fun execute(params: DeleteBackupTask.Params): Try<Unit> { override suspend fun execute(params: DeleteBackupTask.Params) {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.deleteBackup( apiCall = roomKeysApi.deleteBackup(params.version)
params.version)
} }
} }
} }

View File

@ -16,10 +16,8 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -34,7 +32,7 @@ internal interface DeleteRoomSessionDataTask : Task<DeleteRoomSessionDataTask.Pa
internal class DefaultDeleteRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultDeleteRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionDataTask { : DeleteRoomSessionDataTask {
override suspend fun execute(params: DeleteRoomSessionDataTask.Params): Try<Unit> { override suspend fun execute(params: DeleteRoomSessionDataTask.Params) {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.deleteRoomSessionData( apiCall = roomKeysApi.deleteRoomSessionData(
params.roomId, params.roomId,

View File

@ -16,10 +16,8 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -33,7 +31,7 @@ internal interface DeleteRoomSessionsDataTask : Task<DeleteRoomSessionsDataTask.
internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultDeleteRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteRoomSessionsDataTask { : DeleteRoomSessionsDataTask {
override suspend fun execute(params: DeleteRoomSessionsDataTask.Params): Try<Unit> { override suspend fun execute(params: DeleteRoomSessionsDataTask.Params) {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.deleteRoomSessionsData( apiCall = roomKeysApi.deleteRoomSessionsData(
params.roomId, params.roomId,

View File

@ -16,10 +16,8 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -32,10 +30,9 @@ internal interface DeleteSessionsDataTask : Task<DeleteSessionsDataTask.Params,
internal class DefaultDeleteSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultDeleteSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: DeleteSessionsDataTask { : DeleteSessionsDataTask {
override suspend fun execute(params: DeleteSessionsDataTask.Params): Try<Unit> { override suspend fun execute(params: DeleteSessionsDataTask.Params) {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.deleteSessionsData( apiCall = roomKeysApi.deleteSessionsData(params.version)
params.version)
} }
} }
} }

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
@ -29,7 +28,7 @@ internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(private v
: GetKeysBackupLastVersionTask { : GetKeysBackupLastVersionTask {
override suspend fun execute(params: Unit): Try<KeysVersionResult> { override suspend fun execute(params: Unit): KeysVersionResult {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.getKeysBackupLastVersion() apiCall = roomKeysApi.getKeysBackupLastVersion()
} }

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
@ -29,7 +28,7 @@ internal class DefaultGetKeysBackupVersionTask @Inject constructor(private val r
: GetKeysBackupVersionTask { : GetKeysBackupVersionTask {
override suspend fun execute(params: String): Try<KeysVersionResult> { override suspend fun execute(params: String): KeysVersionResult {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.getKeysBackupVersion(params) apiCall = roomKeysApi.getKeysBackupVersion(params)
} }

View File

@ -16,11 +16,9 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -35,7 +33,7 @@ internal interface GetRoomSessionDataTask : Task<GetRoomSessionDataTask.Params,
internal class DefaultGetRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultGetRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionDataTask { : GetRoomSessionDataTask {
override suspend fun execute(params: GetRoomSessionDataTask.Params): Try<KeyBackupData> { override suspend fun execute(params: GetRoomSessionDataTask.Params): KeyBackupData {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.getRoomSessionData( apiCall = roomKeysApi.getRoomSessionData(
params.roomId, params.roomId,

View File

@ -16,11 +16,9 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -35,7 +33,7 @@ internal interface GetRoomSessionsDataTask : Task<GetRoomSessionsDataTask.Params
internal class DefaultGetRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultGetRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetRoomSessionsDataTask { : GetRoomSessionsDataTask {
override suspend fun execute(params: GetRoomSessionsDataTask.Params): Try<RoomKeysBackupData> { override suspend fun execute(params: GetRoomSessionsDataTask.Params): RoomKeysBackupData {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.getRoomSessionsData( apiCall = roomKeysApi.getRoomSessionsData(
params.roomId, params.roomId,

View File

@ -16,11 +16,9 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -33,10 +31,9 @@ internal interface GetSessionsDataTask : Task<GetSessionsDataTask.Params, KeysBa
internal class DefaultGetSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultGetSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: GetSessionsDataTask { : GetSessionsDataTask {
override suspend fun execute(params: GetSessionsDataTask.Params): Try<KeysBackupData> { override suspend fun execute(params: GetSessionsDataTask.Params): KeysBackupData {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.getSessionsData( apiCall = roomKeysApi.getSessionsData(params.version)
params.version)
} }
} }
} }

View File

@ -16,12 +16,10 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeyBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -37,7 +35,7 @@ internal interface StoreRoomSessionDataTask : Task<StoreRoomSessionDataTask.Para
internal class DefaultStoreRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultStoreRoomSessionDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionDataTask { : StoreRoomSessionDataTask {
override suspend fun execute(params: StoreRoomSessionDataTask.Params): Try<BackupKeysResult> { override suspend fun execute(params: StoreRoomSessionDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.storeRoomSessionData( apiCall = roomKeysApi.storeRoomSessionData(
params.roomId, params.roomId,

View File

@ -16,12 +16,10 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.RoomKeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -36,7 +34,7 @@ internal interface StoreRoomSessionsDataTask : Task<StoreRoomSessionsDataTask.Pa
internal class DefaultStoreRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultStoreRoomSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreRoomSessionsDataTask { : StoreRoomSessionsDataTask {
override suspend fun execute(params: StoreRoomSessionsDataTask.Params): Try<BackupKeysResult> { override suspend fun execute(params: StoreRoomSessionsDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.storeRoomSessionsData( apiCall = roomKeysApi.storeRoomSessionsData(
params.roomId, params.roomId,

View File

@ -16,12 +16,10 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.BackupKeysResult
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysBackupData
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.task.Task
import javax.inject.Inject import javax.inject.Inject
@ -35,7 +33,7 @@ internal interface StoreSessionsDataTask : Task<StoreSessionsDataTask.Params, Ba
internal class DefaultStoreSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi) internal class DefaultStoreSessionsDataTask @Inject constructor(private val roomKeysApi: RoomKeysApi)
: StoreSessionsDataTask { : StoreSessionsDataTask {
override suspend fun execute(params: StoreSessionsDataTask.Params): Try<BackupKeysResult> { override suspend fun execute(params: StoreSessionsDataTask.Params): BackupKeysResult {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.storeSessionsData( apiCall = roomKeysApi.storeSessionsData(
params.version, params.version,

View File

@ -16,7 +16,6 @@
package im.vector.matrix.android.internal.crypto.keysbackup.tasks package im.vector.matrix.android.internal.crypto.keysbackup.tasks
import arrow.core.Try
import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi import im.vector.matrix.android.internal.crypto.keysbackup.api.RoomKeysApi
import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.UpdateKeysBackupVersionBody
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
@ -34,7 +33,7 @@ internal class DefaultUpdateKeysBackupVersionTask @Inject constructor(private va
: UpdateKeysBackupVersionTask { : UpdateKeysBackupVersionTask {
override suspend fun execute(params: UpdateKeysBackupVersionTask.Params): Try<Unit> { override suspend fun execute(params: UpdateKeysBackupVersionTask.Params) {
return executeRequest { return executeRequest {
apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody) apiCall = roomKeysApi.updateKeysBackupVersion(params.version, params.keysBackupVersionBody)
} }

View File

@ -63,10 +63,8 @@ data class MXKey(
fun signatureForUserId(userId: String, signkey: String): String? { fun signatureForUserId(userId: String, signkey: String): String? {
// sanity checks // sanity checks
if (userId.isNotBlank() && signkey.isNotBlank()) { if (userId.isNotBlank() && signkey.isNotBlank()) {
if (signatures.containsKey(userId)) {
return signatures[userId]?.get(signkey) return signatures[userId]?.get(signkey)
} }
}
return null return null
} }

View File

@ -17,6 +17,7 @@ package im.vector.matrix.android.internal.crypto.model.event
import com.squareup.moshi.Json import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.session.room.model.relation.RelationDefaultContent
/** /**
* Class representing an encrypted event content * Class representing an encrypted event content
@ -52,5 +53,8 @@ data class EncryptedEventContent(
* The session id * The session id
*/ */
@Json(name = "session_id") @Json(name = "session_id")
val sessionId: String? = null val sessionId: String? = null,
//Relation context is in clear in encrypted message
@Json(name = "m.relates_to") val relatesTo: RelationDefaultContent? = null
) )

View File

@ -16,8 +16,8 @@
package im.vector.matrix.android.internal.crypto.store.db package im.vector.matrix.android.internal.crypto.store.db
import io.realm.annotations.RealmModule
import im.vector.matrix.android.internal.crypto.store.db.model.* import im.vector.matrix.android.internal.crypto.store.db.model.*
import io.realm.annotations.RealmModule
/** /**
* Realm module for Crypto store classes * Realm module for Crypto store classes

View File

@ -16,10 +16,10 @@
package im.vector.matrix.android.internal.crypto.store.db.model package im.vector.matrix.android.internal.crypto.store.db.model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm
import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import org.matrix.olm.OlmAccount import org.matrix.olm.OlmAccount
internal open class CryptoMetadataEntity( internal open class CryptoMetadataEntity(

View File

@ -16,9 +16,9 @@
package im.vector.matrix.android.internal.crypto.store.db.model package im.vector.matrix.android.internal.crypto.store.db.model
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm
import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmResults import io.realm.RealmResults
import io.realm.annotations.LinkingObjects import io.realm.annotations.LinkingObjects

View File

@ -16,11 +16,11 @@
package im.vector.matrix.android.internal.crypto.store.db.model package im.vector.matrix.android.internal.crypto.store.db.model
import io.realm.RealmObject import im.vector.matrix.android.internal.crypto.model.OlmInboundGroupSessionWrapper
import io.realm.annotations.PrimaryKey
import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm
import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm
import im.vector.matrix.android.internal.crypto.model.OlmInboundGroupSessionWrapper import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
internal fun OlmInboundGroupSessionEntity.Companion.createPrimaryKey(sessionId: String?, senderKey: String?) = "$sessionId|$senderKey" internal fun OlmInboundGroupSessionEntity.Companion.createPrimaryKey(sessionId: String?, senderKey: String?) = "$sessionId|$senderKey"

View File

@ -16,10 +16,10 @@
package im.vector.matrix.android.internal.crypto.store.db.model package im.vector.matrix.android.internal.crypto.store.db.model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm
import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import org.matrix.olm.OlmSession import org.matrix.olm.OlmSession
internal fun OlmSessionEntity.Companion.createPrimaryKey(sessionId: String, deviceKey: String) = "$sessionId|$deviceKey" internal fun OlmSessionEntity.Companion.createPrimaryKey(sessionId: String, deviceKey: String) = "$sessionId|$deviceKey"

View File

@ -17,9 +17,9 @@
package im.vector.matrix.android.internal.crypto.store.db.model package im.vector.matrix.android.internal.crypto.store.db.model
import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequest import im.vector.matrix.android.internal.crypto.OutgoingRoomKeyRequest
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm import im.vector.matrix.android.internal.crypto.store.db.deserializeFromRealm
import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm import im.vector.matrix.android.internal.crypto.store.db.serializeForRealm
import im.vector.matrix.android.internal.crypto.model.rest.RoomKeyRequestBody
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.annotations.PrimaryKey import io.realm.annotations.PrimaryKey

View File

@ -16,11 +16,11 @@
package im.vector.matrix.android.internal.crypto.store.db.query package im.vector.matrix.android.internal.crypto.store.db.query
import io.realm.Realm
import io.realm.kotlin.where
import im.vector.matrix.android.internal.crypto.store.db.model.DeviceInfoEntity import im.vector.matrix.android.internal.crypto.store.db.model.DeviceInfoEntity
import im.vector.matrix.android.internal.crypto.store.db.model.DeviceInfoEntityFields import im.vector.matrix.android.internal.crypto.store.db.model.DeviceInfoEntityFields
import im.vector.matrix.android.internal.crypto.store.db.model.createPrimaryKey import im.vector.matrix.android.internal.crypto.store.db.model.createPrimaryKey
import io.realm.Realm
import io.realm.kotlin.where
/** /**
* Get or create a device info * Get or create a device info

Some files were not shown because too many files have changed in this diff Show More