diff --git a/CHANGES.md b/CHANGES.md
index 579124ce45..3aefa2b2ba 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,15 +1,15 @@
-Changes in Element 1.0.14 (2020-XX-XX)
+Changes in Element 1.0.15 (2020-XX-XX)
===================================================
Features ✨:
- Allow changing nick colors (#2610)
- - Enable url previews for notices (#2562)
+ -
Improvements 🙌:
-
Bugfix 🐛:
- - Url previews sometimes attached to wrong message (#2561)
+ -
Translations 🗣:
-
@@ -23,6 +23,40 @@ Build 🧱:
Test:
-
+Other changes:
+ - Update Dagger to 2.31 version so we can use the embedded AssistedInject feature
+
+Changes in Element 1.0.14 (2020-01-15)
+===================================================
+
+Features ✨:
+ - Enable url previews for notices (#2562)
+ - Edit room permissions (#2471)
+
+Improvements 🙌:
+ - Add System theme option and set as default (#904, #2387)
+ - Store megolm outbound session to improve send time of first message after app launch.
+ - Warn user when they are leaving a not public room (#1460)
+ - Option to disable emoji keyboard (#2563)
+
+Bugfix 🐛:
+ - Unspecced msgType field in m.sticker (#2580)
+ - Wait for all room members to be known before sending a message to a e2e room (#2518)
+ - Url previews sometimes attached to wrong message (#2561)
+ - Room Topic not displayed correctly after visiting a link (#2551)
+ - Hiding membership events works the exact opposite (#2603)
+ - Tapping drawer having more than 1 room in notifications gives "malformed link" error (#2605)
+ - Sent image not displayed when opened immediately after sending (#409)
+ - Initial sync is not retried correctly when there is some network error. (#2632)
+ - Fix switch theme issue, and white field issue (#2599, #2528)
+ - Fix request too large Uri error when joining a room
+
+Translations 🗣:
+ - New language supported: Hebrew
+
+Build 🧱:
+ - Remove dependency to org.greenrobot.eventbus library
+
Other changes:
- Migrate to ViewBindings (#1072)
diff --git a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt
index ae095be41a..9b1345cd39 100644
--- a/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt
+++ b/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt
@@ -40,13 +40,16 @@ import kotlin.math.abs
abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventListener {
- lateinit var pager2: ViewPager2
- lateinit var imageTransitionView: ImageView
- lateinit var transitionImageContainer: ViewGroup
+ protected val pager2: ViewPager2
+ get() = views.attachmentPager
+ protected val imageTransitionView: ImageView
+ get() = views.transitionImageView
+ protected val transitionImageContainer: ViewGroup
+ get() = views.transitionImageContainer
- var topInset = 0
- var bottomInset = 0
- var systemUiVisibility = true
+ private var topInset = 0
+ private var bottomInset = 0
+ private var systemUiVisibility = true
private var overlayView: View? = null
set(value) {
@@ -65,14 +68,16 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
private lateinit var gestureDetector: GestureDetectorCompat
var currentPosition = 0
+ private set
private var swipeDirection: SwipeDirection? = null
private fun isScaled() = attachmentsAdapter.isScaled(currentPosition)
+ private val attachmentsAdapter = AttachmentsAdapter()
+
private var wasScaled: Boolean = false
private var isSwipeToDismissAllowed: Boolean = true
- private lateinit var attachmentsAdapter: AttachmentsAdapter
private var isOverlayWasClicked = false
// private val shouldDismissToBottom: Boolean
@@ -101,10 +106,7 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi
views = ActivityAttachmentViewerBinding.inflate(layoutInflater)
setContentView(views.root)
views.attachmentPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
- attachmentsAdapter = AttachmentsAdapter()
views.attachmentPager.adapter = attachmentsAdapter
- imageTransitionView = views.transitionImageView
- pager2 = views.attachmentPager
directionDetector = createSwipeDirectionDetector()
gestureDetector = createGestureDetector()
diff --git a/docs/ui-tests.md b/docs/ui-tests.md
index ff01da0b31..6ebb52abe8 100644
--- a/docs/ui-tests.md
+++ b/docs/ui-tests.md
@@ -27,7 +27,6 @@ $ source env/bin/activate
Every time you want to launch these test homeservers, type:
```shell script
-$ virtualenv -p python3 env
$ source env/bin/activate
(env) $ demo/start.sh --no-rate-limit
```
diff --git a/fastlane/metadata/android/de/changelogs/40100100.txt b/fastlane/metadata/android/de/changelogs/40100100.txt
index 70b786d12e..2faf4b5d39 100644
--- a/fastlane/metadata/android/de/changelogs/40100100.txt
+++ b/fastlane/metadata/android/de/changelogs/40100100.txt
@@ -1 +1,2 @@
-// TODO
+Diese neue Version enthält hauptsächlich Fehlerkorrekturen und Verbesserungen. Nachrichten verschicken geht jetzt viel schneller.
+Vollständige Versionshinweise: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/de/changelogs/40100110.txt b/fastlane/metadata/android/de/changelogs/40100110.txt
new file mode 100644
index 0000000000..e70007b5d7
--- /dev/null
+++ b/fastlane/metadata/android/de/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Diese neue Version enthält hauptsächlich Verbesserungen der Benutzer*innenoberfläche und der Handhabung. Du kannst jetzt ganz schnell Freund*innen einladen und DMs erstellen, indem du schlicht einen QR-Code scannst.
+Vollständige Versionshinweise: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/en-US/changelogs/40100130.txt b/fastlane/metadata/android/en-US/changelogs/40100130.txt
index 39715c2910..dc517fac48 100644
--- a/fastlane/metadata/android/en-US/changelogs/40100130.txt
+++ b/fastlane/metadata/android/en-US/changelogs/40100130.txt
@@ -1,2 +1,2 @@
Main changes in this version: URL Preview, new Emoji keyboard, new room settings capabilities, and snow for Christmas!
-Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.12
\ No newline at end of file
+Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.13
\ No newline at end of file
diff --git a/fastlane/metadata/android/en-US/changelogs/40100140.txt b/fastlane/metadata/android/en-US/changelogs/40100140.txt
new file mode 100644
index 0000000000..74f609fa15
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/40100140.txt
@@ -0,0 +1,2 @@
+Main changes in this version: Edit room permissions, automatic light/dark theme, and a bunch of bug fixes.
+Full changelog: https://github.com/vector-im/element-android/releases/tag/v1.0.14
\ No newline at end of file
diff --git a/fastlane/metadata/android/et/changelogs/40100100.txt b/fastlane/metadata/android/et/changelogs/40100100.txt
new file mode 100644
index 0000000000..11a040ceb0
--- /dev/null
+++ b/fastlane/metadata/android/et/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Selles uues versioonis leidub põhiliselt veaparandusi ja pisikohendusi. Sõnumite saatmine on nüüd märkatavalt kiirem.
+Kogu ingliskeelne muudatuste logi: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/et/changelogs/40100110.txt b/fastlane/metadata/android/et/changelogs/40100110.txt
new file mode 100644
index 0000000000..019a84a2be
--- /dev/null
+++ b/fastlane/metadata/android/et/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Uues versioonis leidub põhiliselt kasutajaliidese ning kasutajakogemuse parandusi. Nüüd saad sõpradele kutseid saata ning otsevestlusi alustada QR-koodi lugemise abil.
+Kõik muudatused: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/fa/changelogs/40100100.txt b/fastlane/metadata/android/fa/changelogs/40100100.txt
index 6123bfc7fc..080d80a3ad 100644
--- a/fastlane/metadata/android/fa/changelogs/40100100.txt
+++ b/fastlane/metadata/android/fa/changelogs/40100100.txt
@@ -1 +1,2 @@
-// برای انجام
+این نگارش جدید به طور عمده شامل رفع اشکالها و بهبودها است. ارسال پیام اکنون بسیار سریعتر است.
+گزارش دگرگونی کامل: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/fa/changelogs/40100110.txt b/fastlane/metadata/android/fa/changelogs/40100110.txt
new file mode 100644
index 0000000000..c95922e2d7
--- /dev/null
+++ b/fastlane/metadata/android/fa/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+این نگارش جدید به طور عمده شامل رابط کاربری و بهبود تجربه کاربر است. اکنون میتوانید با پویش کدهای QR دوستانتان را دعوت کرده و بسیار سریع پیام مستقیم ایجاد کنید.
+گزارش دگرگونی کامل: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/fa/short_description.txt b/fastlane/metadata/android/fa/short_description.txt
index 4cfa767649..aba229f959 100644
--- a/fastlane/metadata/android/fa/short_description.txt
+++ b/fastlane/metadata/android/fa/short_description.txt
@@ -1 +1 @@
-گپ و تماس نامتمرکز امن. دادههایتان را از شرکتها امن نگه دارید.
+گپ و تماس نامتمرکز امن. دادههایتان را از اشخاص سوم امن نگه دارید.
diff --git a/fastlane/metadata/android/fa/title.txt b/fastlane/metadata/android/fa/title.txt
index fb4ea4125e..899b3d6adb 100644
--- a/fastlane/metadata/android/fa/title.txt
+++ b/fastlane/metadata/android/fa/title.txt
@@ -1 +1 @@
-المنت (ریوت سابق)
+Element (پیشتر Riot.im)
diff --git a/fastlane/metadata/android/fi/changelogs/40100110.txt b/fastlane/metadata/android/fi/changelogs/40100110.txt
new file mode 100644
index 0000000000..356eabd29b
--- /dev/null
+++ b/fastlane/metadata/android/fi/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Tämä versio sisältää pääosin käyttöliittymä- ja käyttökokemusparannuksia. Voit nyt kutsua kavereita ja luoda yksityisviestejä nopeasti QR-koodeja lukemalla.
+Täysi muutosloki: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/fi/full_description.txt b/fastlane/metadata/android/fi/full_description.txt
index 70def518da..947d19ce3d 100644
--- a/fastlane/metadata/android/fi/full_description.txt
+++ b/fastlane/metadata/android/fi/full_description.txt
@@ -1,30 +1,30 @@
Element on uudenlainen viestinsovellus, joka:
-1. Antaa sinun päättää yksityisyydestäsi.
+1. Antaa sinun päättää yksityisyydestäsi
2. Antaa sinun kommunikoida kenen tahansa kanssa Matrix-verkossa ja jopa sen ulkopuolella siltaamalla sovelluksiin, kuten Slack
3. Suojaa sinua mainonnalta, tietojen keräämiseltä ja suljetuilta alustoilta
4. Suojaa sinut päästä päähän -salauksella sekä ristiin varmentamisella muiden todentamiseksi
Element eroaa täysin muista viestintäsovelluksista, koska se on hajautettu ja avointa lähdekoodia.
-Element antaa sinun isännöidä itse - valita isännän - jotta sinulla on yksityisyys ja voit hallita tietojasi sekä keskustelujasi. Se antaa sinulle pääsyn avoimeen verkkoon; joten et ole jumissa Elementin käyttäjissä.
+Element antaa sinun isännöidä itse - tai valita palveluntarjoajan - jotta sinulla on yksityisyys ja voit hallita tietojasi sekä keskustelujasi. Se antaa sinulle pääsyn avoimeen verkkoon, joten et jää juttelemaan vain toisten Elementin käyttäjien kanssa. Se on myös hyvin turvallinen.
Element pystyy tekemään kaiken tämän, koska se toimii Matrixilla - avoimella, hajautetun viestinnän standardilla.
-Element antaa sinulle hallinnan antamalla sinun valita, kuka isännöi keskustelujasi. Element-sovelluksessa voit valita isännän eri tavoin:
+Element antaa sinulle päätösvallan antamalla sinun valita, kuka isännöi keskustelujasi. Element-sovelluksessa voit valita isännän eri tavoin:
1. Hanki ilmainen tili Matrix-kehittäjien ylläpitämällä matrix.org-palvelimella tai valitse tuhansista vapaaehtoisten ylläpitämistä julkisista palvelimista.
-2. Isännöi tiliäsi itse suorittamalla palvelinta omalla laitteellasi
-3. Luo tili mukautetulla palvelimella yksinkertaisesti tilaamalla Element Matrix Services -palvelu
+2. Isännöi tiliäsi itse ylläpitämällä palvelinta omalla laitteellasi
+3. Luo tili sinua varten tehdyllä palvelimella tilaamalla Element Matrix Services -palvelu
Miksi valita Element?
-OMAT TIEDOT: Sinä päätät, missä tietosi ja viestisi säilytetään. Hallitset sitä itse, eikä jokin MEGAYHTIÖ, joka tutkii tietojasi tai antaa niitä kolmansille osapuolille.
+OMAT TIEDOT: Sinä päätät, missä tietosi ja viestisi säilytetään. Sinä määräät, ei jokin jättiyhtiö, joka tutkii tietojasi tai antaa niitä kolmansille osapuolille.
-AVOIN KOMMUNIKOINYI JA YHTEISTYÖ: Voit keskustella kaikkien muiden Matrix-verkon käyttäjien kanssa, riippumatta siitä käyttävätkö he Elementiä tai muuta Matrix-sovellusta, ja vaikka he käyttäisivät eri viestijärjestelmiä, kuten Slack, IRC tai XMPP.
+AVOINTA VIESTINTÄÄ JA YHTEISTYÖTÄ: Voit keskustella kaikkien muiden Matrix-verkon käyttäjien kanssa, riippumatta siitä käyttävätkö he Elementiä tai muuta Matrix-sovellusta, ja vaikka he käyttäisivät eri viestijärjestelmiä, kuten Slack, IRC tai XMPP.
ERITTÄIN TURVALLINEN: Vahva päästä päähän -salaus (vain keskustelussa olevat voivat purkaa viestien salauksen), ja ristiin varmentaminen keskustelun osallistujien laitteiden tarkistamiseksi.
-TÄYDELLISTÄ VIESTINTÄÄ: Viestit, ääni- ja videopuhelut, tiedostojen jakaminen, näytön jakaminen ja koko joukko integraatioita, botteja ja widgettejä. Rakenna huoneita, yhteisöjä, pidä yhteyttä ja tee asioita.
+KATTAVAA VIESTINTÄÄ: Viestit, ääni- ja videopuhelut, tiedostojen jakaminen, näytön jakaminen ja koko joukko integraatioita, botteja ja sovelmia. Rakenna huoneita ja yhteisöjä, pidä yhteyttä ja hoida asiasi.
MISSÄ TAHANSA OLETKIN: Pidä yhteyttä missä tahansa, täysin synkronoidun viestihistorian kautta kaikilla laitteillasi ja verkossa osoitteessa https://app.element.io.
diff --git a/fastlane/metadata/android/fi/short_description.txt b/fastlane/metadata/android/fi/short_description.txt
index 5573ac1cb9..64f35a7dff 100644
--- a/fastlane/metadata/android/fi/short_description.txt
+++ b/fastlane/metadata/android/fi/short_description.txt
@@ -1 +1 @@
-Turvallista, hajautettua, keskusteluja ja VoIP-puheluita. Pidä tietosi turvassa.
+Turvallista, hajautettua keskustelua ja VoIP-puheluita. Pidä tietosi turvassa.
diff --git a/fastlane/metadata/android/fr/changelogs/40100100.txt b/fastlane/metadata/android/fr/changelogs/40100100.txt
new file mode 100644
index 0000000000..36ca3016b6
--- /dev/null
+++ b/fastlane/metadata/android/fr/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Cette nouvelle version contient principalement des corrections de bogues et des améliorations. Envoyer un message est maintenant plus rapide.
+Liste complète des changements : https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/hu/changelogs/40100100.txt b/fastlane/metadata/android/hu/changelogs/40100100.txt
new file mode 100644
index 0000000000..87a00efded
--- /dev/null
+++ b/fastlane/metadata/android/hu/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Ez az új verzió főképp hibajavításokat, és teljesítménybeli fejlesztéseket tartalmaz. Most már sokkal gyorsabb az üzenetek elküldése.
+A változtatások teljes listája itt található: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/hu/changelogs/40100110.txt b/fastlane/metadata/android/hu/changelogs/40100110.txt
new file mode 100644
index 0000000000..c14ed73aeb
--- /dev/null
+++ b/fastlane/metadata/android/hu/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Ez az új verzió főleg a felhasználói felülettel és a felhasználói élménnyel kapcsolatos javításokat tartalmaz. Mostantól már sokkal gyorsabban hívhatsz meg új ismerősöket a QR kód beolvasás által.
+A változtatások teljes listája itt található: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/hu/full_description.txt b/fastlane/metadata/android/hu/full_description.txt
index dfc842594d..b75f259d02 100644
--- a/fastlane/metadata/android/hu/full_description.txt
+++ b/fastlane/metadata/android/hu/full_description.txt
@@ -17,7 +17,7 @@ Az Element a te kezedbe adja az irányítást azáltal, hogy eldöntheted, ki t
2. A saját számítógépeden is futtathatsz szervert
3. Előfizethetsz egy saját szerverre az Element Matrix Szolgáltatások platformon
-Miért válaszd az Element-et?
+Miért jó az Element-et választani?
ADATAID MEGVÉDÉSE: Eldöntheted, hol tárold az adataid és üzeneteid. A te tulajdonodban van, nem valami megacégnél, ami bányássza az adataid, vagy továbbadja másoknak.
diff --git a/fastlane/metadata/android/it/changelogs/40100110.txt b/fastlane/metadata/android/it/changelogs/40100110.txt
new file mode 100644
index 0000000000..897dda36d2
--- /dev/null
+++ b/fastlane/metadata/android/it/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Questa nuova versione contiene principalmente miglioramenti di interfaccia ed esperienza utente. Ora puoi invitare amici e iniziare messaggi diretti rapidamente tramite codici QR.
+Cronologia completa: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/nb_NO/changelogs/40100100.txt b/fastlane/metadata/android/nb_NO/changelogs/40100100.txt
new file mode 100644
index 0000000000..7ef80a2532
--- /dev/null
+++ b/fastlane/metadata/android/nb_NO/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Denne nye versjonen inneholder hovedsakelig feilrettinger og forbedringer. Å sende en melding er nå mye raskere.
+Full endringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/nb_NO/changelogs/40100110.txt b/fastlane/metadata/android/nb_NO/changelogs/40100110.txt
new file mode 100644
index 0000000000..c2f5e03845
--- /dev/null
+++ b/fastlane/metadata/android/nb_NO/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Denne nye versjonen inneholder hovedsakelig forbedringer av brukergrensesnittet og brukeropplevelsen. Nå kan du invitere venner og opprette DM veldig raskt ved å skanne QR-koder.
+Full endringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/nb_NO/short_description.txt b/fastlane/metadata/android/nb_NO/short_description.txt
new file mode 100644
index 0000000000..b7cad4c849
--- /dev/null
+++ b/fastlane/metadata/android/nb_NO/short_description.txt
@@ -0,0 +1 @@
+Sikker desentralisert chat & VoIP. Beskytt dataene dine fra tredjeparter.
diff --git a/fastlane/metadata/android/nb_NO/title.txt b/fastlane/metadata/android/nb_NO/title.txt
new file mode 100644
index 0000000000..aacee5be54
--- /dev/null
+++ b/fastlane/metadata/android/nb_NO/title.txt
@@ -0,0 +1 @@
+Element (tidligere Riot.im)
diff --git a/fastlane/metadata/android/pt_BR/changelogs/40100110.txt b/fastlane/metadata/android/pt_BR/changelogs/40100110.txt
new file mode 100644
index 0000000000..2e9aef1c4a
--- /dev/null
+++ b/fastlane/metadata/android/pt_BR/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Esta nova versão contém principalmente melhorias na interface do usuário e na experiência do usuário. Agora você pode convidar amigos e criar conversas rapidamente, digitalizando códigos QR.
+Registro completo de alterações: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/ru/changelogs/40100100.txt b/fastlane/metadata/android/ru/changelogs/40100100.txt
new file mode 100644
index 0000000000..326562fb32
--- /dev/null
+++ b/fastlane/metadata/android/ru/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Эта новая версия в основном содержит исправления ошибок и улучшения. Отправка сообщения стала намного быстрее.
+Полный список изменений: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/ru/changelogs/40100110.txt b/fastlane/metadata/android/ru/changelogs/40100110.txt
new file mode 100644
index 0000000000..166e5b701c
--- /dev/null
+++ b/fastlane/metadata/android/ru/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Эта новая версия в основном содержит улучшения пользовательского интерфейса и взаимодействия с пользователем. Теперь вы можете приглашать друзей и очень быстро создавать чаты, сканируя QR-коды.
+Полный список изменений: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/sk/changelogs/40100100.txt b/fastlane/metadata/android/sk/changelogs/40100100.txt
new file mode 100644
index 0000000000..b5fe2085ca
--- /dev/null
+++ b/fastlane/metadata/android/sk/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Táto verzia obsahuje predovšetkým opravy chýb. Odosielanie správ je odteraz omnoho rýchlejšie.
+Kompletný zoznam zmien: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/sk/changelogs/40100110.txt b/fastlane/metadata/android/sk/changelogs/40100110.txt
new file mode 100644
index 0000000000..ae68eee15e
--- /dev/null
+++ b/fastlane/metadata/android/sk/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Táto verzia obsahuje najmä vylepšenia používateľského rozhrania. Pozývať priateľov alebo vytvárať priame konverzácie môžete veľmi rýchlo naskenovaním QR kódov.
+Kompletný zoznam zmien: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/sv/changelogs/40100110.txt b/fastlane/metadata/android/sv/changelogs/40100110.txt
new file mode 100644
index 0000000000..e3ed460f17
--- /dev/null
+++ b/fastlane/metadata/android/sv/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Den här nya versionen innehåller mest förbättringar för användargränssnittet och användarupplevelsen. Du kan nu bjuda in vänner och skapa direktmeddelanden väldigt snabbt genom att skanna QR-koder.
+Full ändringslogg: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/uk/changelogs/40100110.txt b/fastlane/metadata/android/uk/changelogs/40100110.txt
new file mode 100644
index 0000000000..32f220e75d
--- /dev/null
+++ b/fastlane/metadata/android/uk/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Ця нова версія містить переважно поліпшення інтерфейсу та зручності користування. Тепер ви можете запросити друзів і створити прямі повідомлення дуже швидко, скануючи QR-коди.
+Повний перелік змін: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/vi/changelogs/40100100.txt b/fastlane/metadata/android/vi/changelogs/40100100.txt
new file mode 100644
index 0000000000..7125bbde9a
--- /dev/null
+++ b/fastlane/metadata/android/vi/changelogs/40100100.txt
@@ -0,0 +1,2 @@
+Phiên bản mới này chủ yếu bao gồm sửa lỗi và một số cải thiện. Gửi tin nhắn trở nên nhanh chóng hơn trước.
+Danh sách đầy đủ các thay đổi: https://github.com/vector-im/element-android/releases/tag/v1.0.10
diff --git a/fastlane/metadata/android/vi/changelogs/40100110.txt b/fastlane/metadata/android/vi/changelogs/40100110.txt
new file mode 100644
index 0000000000..fce5eff648
--- /dev/null
+++ b/fastlane/metadata/android/vi/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+Phiên bản mới này chủ yếu bao gồm các cải thiện về giao diện và trải nghiệm người dùng. Bây giờ bạn có thể mời bạn bè và bắt đầu nói chuyện nhanh chóng bằng cách quét mã QR.
+Danh sách đầy đủ các thay đổi: https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/vi/short_description.txt b/fastlane/metadata/android/vi/short_description.txt
new file mode 100644
index 0000000000..b41ac0ce82
--- /dev/null
+++ b/fastlane/metadata/android/vi/short_description.txt
@@ -0,0 +1 @@
+Ứng dụng chat và gọi phân tán bảo mật. Bảo vệ dữ liệu của bạn khỏi bên thứ ba.
diff --git a/fastlane/metadata/android/vi/title.txt b/fastlane/metadata/android/vi/title.txt
new file mode 100644
index 0000000000..2a3bef31df
--- /dev/null
+++ b/fastlane/metadata/android/vi/title.txt
@@ -0,0 +1 @@
+Element (trước là Riot.im)
diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt
new file mode 100644
index 0000000000..22dfe07097
--- /dev/null
+++ b/fastlane/metadata/android/zh_Hant/changelogs/40100110.txt
@@ -0,0 +1,2 @@
+這個新版本主要包含使用者介面與使用者體驗改善。現在您可以邀請朋友,並透過掃描 QR code 來快速建立直接訊息了。
+完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.11
diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt
new file mode 100644
index 0000000000..846126af63
--- /dev/null
+++ b/fastlane/metadata/android/zh_Hant/changelogs/40100120.txt
@@ -0,0 +1,2 @@
+此版本中的主要變更:URL 預覽、新的表情符號鍵盤、新的聊天室設定功能以及聖誕節降雪!
+完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.12
diff --git a/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt b/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt
new file mode 100644
index 0000000000..846126af63
--- /dev/null
+++ b/fastlane/metadata/android/zh_Hant/changelogs/40100130.txt
@@ -0,0 +1,2 @@
+此版本中的主要變更:URL 預覽、新的表情符號鍵盤、新的聊天室設定功能以及聖誕節降雪!
+完整變更紀錄:https://github.com/vector-im/element-android/releases/tag/v1.0.12
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index cdc95ef6eb..247e2b90ad 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,7 @@
+#Fri Jan 15 11:30:47 CET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionSha256Sum=22449f5231796abd892c98b2a07c9ceebe4688d192cd2d6763f8e3bf8acbedeb
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
+distributionSha256Sum=a7ca23b3ccf265680f2bfd35f1f00b1424f4466292c7337c85d46c9641b3f053
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle
index d72e5bda41..7d5432ebb8 100644
--- a/matrix-sdk-android/build.gradle
+++ b/matrix-sdk-android/build.gradle
@@ -112,7 +112,7 @@ dependencies {
def lifecycle_version = '2.2.0'
def arch_version = '2.1.0'
def markwon_version = '3.1.0'
- def daggerVersion = '2.29.1'
+ def daggerVersion = '2.31'
def work_version = '2.4.0'
def retrofit_version = '2.6.2'
@@ -160,16 +160,11 @@ dependencies {
// DI
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
- compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.5.0'
- kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.5.0'
// Logging
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
- // Bus
- implementation 'org.greenrobot:eventbus:3.1.1'
-
// Phone number https://github.com/google/libphonenumber
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.23'
diff --git a/matrix-sdk-android/proguard-rules.pro b/matrix-sdk-android/proguard-rules.pro
index fa860d8049..182f9473e8 100644
--- a/matrix-sdk-android/proguard-rules.pro
+++ b/matrix-sdk-android/proguard-rules.pro
@@ -20,14 +20,8 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-
-### EVENT BUS ###
-
+# BMA: Not sure I can delete this one without side effect
-keepattributes *Annotation*
--keepclassmembers class * {
- @org.greenrobot.eventbus.Subscribe ;
-}
--keep enum org.greenrobot.eventbus.ThreadMode { *; }
### MOSHI ###
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt
index 0e7088a6a5..cb49ee8818 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CommonTestHelper.kt
@@ -86,7 +86,7 @@ class CommonTestHelper(context: Context) {
*
* @param session the session to sync
*/
- fun syncSession(session: Session) {
+ fun syncSession(session: Session, timeout: Long = TestConstants.timeOutMillis) {
val lock = CountDownLatch(1)
val job = GlobalScope.launch(Dispatchers.Main) {
@@ -109,7 +109,7 @@ class CommonTestHelper(context: Context) {
}
GlobalScope.launch(Dispatchers.Main) { syncLiveData.observeForever(syncObserver) }
- await(lock)
+ await(lock, timeout)
}
/**
@@ -119,7 +119,7 @@ class CommonTestHelper(context: Context) {
* @param message the message to send
* @param nbOfMessages the number of time the message will be sent
*/
- fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List {
+ fun sendTextMessage(room: Room, message: String, nbOfMessages: Int, timeout: Long = TestConstants.timeOutMillis): List {
val timeline = room.createTimeline(null, TimelineSettings(10))
val sentEvents = ArrayList(nbOfMessages)
val latch = CountDownLatch(1)
@@ -151,7 +151,7 @@ class CommonTestHelper(context: Context) {
room.sendTextMessage(message + " #" + (i + 1))
}
// Wait 3 second more per message
- await(latch, timeout = TestConstants.timeOutMillis + 3_000L * nbOfMessages)
+ await(latch, timeout = timeout + 3_000L * nbOfMessages)
timeline.dispose()
// Check that all events has been created
@@ -215,14 +215,14 @@ class CommonTestHelper(context: Context) {
.getLoginFlow(hs, it)
}
- doSync {
+ doSync(timeout = 60_000) {
matrix.authenticationService
.getRegistrationWizard()
.createAccount(userName, password, null, it)
}
// Perform dummy step
- val registrationResult = doSync {
+ val registrationResult = doSync(timeout = 60_000) {
matrix.authenticationService
.getRegistrationWizard()
.dummy(it)
@@ -231,7 +231,7 @@ class CommonTestHelper(context: Context) {
assertTrue(registrationResult is RegistrationResult.Success)
val session = (registrationResult as RegistrationResult.Success).session
if (sessionTestParams.withInitialSync) {
- syncSession(session)
+ syncSession(session, 60_000)
}
return session
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt
index 76e59d9a90..b6bedbd719 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestData.kt
@@ -18,14 +18,21 @@ package org.matrix.android.sdk.common
import org.matrix.android.sdk.api.session.Session
-data class CryptoTestData(val firstSession: Session,
- val roomId: String,
- val secondSession: Session? = null,
- val thirdSession: Session? = null) {
+data class CryptoTestData(val roomId: String,
+ val sessions: List) {
+
+ val firstSession: Session
+ get() = sessions.first()
+
+ val secondSession: Session?
+ get() = sessions.getOrNull(1)
+
+ val thirdSession: Session?
+ get() = sessions.getOrNull(2)
fun cleanUp(testHelper: CommonTestHelper) {
- testHelper.signOutAndClose(firstSession)
- secondSession?.let { testHelper.signOutAndClose(it) }
- thirdSession?.let { testHelper.signOutAndClose(it) }
+ sessions.forEach {
+ testHelper.signOutAndClose(it)
+ }
}
}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt
index cbb22daf0f..3d5856fc64 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/CryptoTestHelper.kt
@@ -73,7 +73,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
}
}
- return CryptoTestData(aliceSession, roomId)
+ return CryptoTestData(roomId, listOf(aliceSession))
}
/**
@@ -139,7 +139,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
// assertNotNull(roomFromBobPOV.powerLevels)
// assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId))
- return CryptoTestData(aliceSession, aliceRoomId, bobSession)
+ return CryptoTestData(aliceRoomId, listOf(aliceSession, bobSession))
}
/**
@@ -157,7 +157,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
// wait the initial sync
SystemClock.sleep(1000)
- return CryptoTestData(aliceSession, aliceRoomId, cryptoTestData.secondSession, samSession)
+ return CryptoTestData(aliceRoomId, listOf(aliceSession, cryptoTestData.secondSession!!, samSession))
}
/**
@@ -381,4 +381,30 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
}
}
}
+
+ fun doE2ETestWithManyMembers(numberOfMembers: Int): CryptoTestData {
+ val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams)
+ aliceSession.cryptoService().setWarnOnUnknownDevices(false)
+
+ val roomId = mTestHelper.doSync {
+ aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, it)
+ }
+ val room = aliceSession.getRoom(roomId)!!
+
+ mTestHelper.runBlockingTest {
+ room.enableEncryption()
+ }
+
+ val sessions = mutableListOf(aliceSession)
+ for (index in 1 until numberOfMembers) {
+ val session = mTestHelper.createAccount("User_$index", defaultSessionParams)
+ mTestHelper.doSync(timeout = 600_000) { room.invite(session.myUserId, null, it) }
+ println("TEST -> " + session.myUserId + " invited")
+ mTestHelper.doSync { session.joinRoom(room.roomId, null, emptyList(), it) }
+ println("TEST -> " + session.myUserId + " joined")
+ sessions.add(session)
+ }
+
+ return CryptoTestData(roomId, sessions)
+ }
}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt
index 197e36df06..2c4d89b070 100644
--- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/KeyShareTests.kt
@@ -50,6 +50,8 @@ import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
+import org.matrix.android.sdk.api.extensions.tryOrNull
+import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import java.util.concurrent.CountDownLatch
@RunWith(AndroidJUnit4::class)
@@ -296,4 +298,77 @@ class KeyShareTests : InstrumentedTest {
mTestHelper.signOutAndClose(aliceSession1)
mTestHelper.signOutAndClose(aliceSession2)
}
+
+ @Test
+ fun test_ImproperKeyShareBug() {
+ val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(true))
+
+ mTestHelper.doSync {
+ aliceSession.cryptoService().crossSigningService()
+ .initializeCrossSigning(UserPasswordAuth(
+ user = aliceSession.myUserId,
+ password = TestConstants.PASSWORD
+ ), it)
+ }
+
+ // Create an encrypted room and send a couple of messages
+ val roomId = mTestHelper.doSync {
+ aliceSession.createRoom(
+ CreateRoomParams().apply {
+ visibility = RoomDirectoryVisibility.PRIVATE
+ enableEncryption()
+ },
+ it
+ )
+ }
+ val roomAlicePov = aliceSession.getRoom(roomId)
+ assertNotNull(roomAlicePov)
+ Thread.sleep(1_000)
+ assertTrue(roomAlicePov?.isEncrypted() == true)
+ val secondEventId = mTestHelper.sendTextMessage(roomAlicePov!!, "Message", 3)[1].eventId
+
+ // Create bob session
+
+ val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, SessionTestParams(true))
+ mTestHelper.doSync {
+ bobSession.cryptoService().crossSigningService()
+ .initializeCrossSigning(UserPasswordAuth(
+ user = bobSession.myUserId,
+ password = TestConstants.PASSWORD
+ ), it)
+ }
+
+ // Let alice invite bob
+ mTestHelper.doSync {
+ roomAlicePov.invite(bobSession.myUserId, null, it)
+ }
+
+ mTestHelper.doSync {
+ bobSession.joinRoom(roomAlicePov.roomId, null, emptyList(), it)
+ }
+
+ // we want to discard alice outbound session
+ aliceSession.cryptoService().discardOutboundSession(roomAlicePov.roomId)
+
+ // and now resend a new message to reset index to 0
+ mTestHelper.sendTextMessage(roomAlicePov, "After", 1)
+
+ val roomRoomBobPov = aliceSession.getRoom(roomId)
+ val beforeJoin = roomRoomBobPov!!.getTimeLineEvent(secondEventId)
+
+ var dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin!!.root, "") }
+
+ assert(dRes == null)
+
+ // Try to re-ask the keys
+
+ bobSession.cryptoService().reRequestRoomKeyForEvent(beforeJoin!!.root)
+
+ Thread.sleep(3_000)
+
+ // With the bug the first session would have improperly reshare that key :/
+ dRes = tryOrNull { bobSession.cryptoService().decryptEvent(beforeJoin.root, "") }
+ Log.d("#TEST", "KS: sgould not decrypt that ${beforeJoin.root.getClearContent().toModel()?.body}")
+ assert(dRes?.clearEvent == null)
+ }
}
diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt
new file mode 100644
index 0000000000..ff07cf1d1d
--- /dev/null
+++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/room/timeline/TimelineWithManyMembersTest.kt
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2020 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.session.room.timeline
+
+import org.junit.FixMethodOrder
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.runners.MethodSorters
+import org.matrix.android.sdk.InstrumentedTest
+import org.matrix.android.sdk.api.extensions.orFalse
+import org.matrix.android.sdk.api.session.events.model.toModel
+import org.matrix.android.sdk.api.session.room.model.message.MessageContent
+import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
+import org.matrix.android.sdk.common.CommonTestHelper
+import org.matrix.android.sdk.common.CryptoTestHelper
+import java.util.concurrent.CountDownLatch
+import kotlin.test.fail
+
+@RunWith(JUnit4::class)
+@FixMethodOrder(MethodSorters.JVM)
+class TimelineWithManyMembersTest : InstrumentedTest {
+
+ companion object {
+ private const val NUMBER_OF_MEMBERS = 6
+ }
+
+ private val commonTestHelper = CommonTestHelper(context())
+ private val cryptoTestHelper = CryptoTestHelper(commonTestHelper)
+
+ /**
+ * Ensures when someone sends a message to a crowded room, everyone can decrypt the message.
+ */
+ @Test
+ fun everyone_should_decrypt_message_in_a_crowded_room() {
+ val cryptoTestData = cryptoTestHelper.doE2ETestWithManyMembers(NUMBER_OF_MEMBERS)
+
+ val sessionForFirstMember = cryptoTestData.firstSession
+ val roomForFirstMember = sessionForFirstMember.getRoom(cryptoTestData.roomId)!!
+
+ val firstMessage = "First messages from Alice"
+ commonTestHelper.sendTextMessage(
+ roomForFirstMember,
+ firstMessage,
+ 1,
+ 600_000
+ )
+
+ for (index in 1 until cryptoTestData.sessions.size) {
+ val session = cryptoTestData.sessions[index]
+ val roomForCurrentMember = session.getRoom(cryptoTestData.roomId)!!
+ val timelineForCurrentMember = roomForCurrentMember.createTimeline(null, TimelineSettings(30))
+ timelineForCurrentMember.start()
+
+ session.startSync(true)
+
+ run {
+ val lock = CountDownLatch(1)
+ val eventsListener = commonTestHelper.createEventListener(lock) { snapshot ->
+ snapshot
+ .find { it.isEncrypted() }
+ ?.let {
+ val body = it.root.getClearContent()?.toModel()?.body
+ if (body?.startsWith(firstMessage).orFalse()) {
+ println("User " + session.myUserId + " decrypted as " + body)
+ return@createEventListener true
+ } else {
+ fail("User " + session.myUserId + " decrypted as " + body + " CryptoError: " + it.root.mCryptoError)
+ }
+ } ?: return@createEventListener false
+ }
+ timelineForCurrentMember.addListener(eventsListener)
+ commonTestHelper.await(lock, 600_000)
+ }
+ session.stopSync()
+ }
+ }
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt
index 360b955869..bf21941e0c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/AuthenticationService.kt
@@ -41,6 +41,16 @@ interface AuthenticationService {
*/
fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback): Cancelable
+ /**
+ * Get a SSO url
+ */
+ fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String?
+
+ /**
+ * Get the sign in or sign up fallback URL
+ */
+ fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String?
+
/**
* Return a LoginWizard, to login to the homeserver. The login flow has to be retrieved first.
*/
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt
index 4f9c84a47c..6675fb0ff5 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/pushrules/SenderNotificationPermissionCondition.kt
@@ -37,6 +37,6 @@ class SenderNotificationPermissionCondition(
fun isSatisfied(event: Event, powerLevels: PowerLevelsContent): Boolean {
val powerLevelsHelper = PowerLevelsHelper(powerLevels)
- return event.senderId != null && powerLevelsHelper.getUserPowerLevelValue(event.senderId) >= powerLevelsHelper.notificationLevel(key)
+ return event.senderId != null && powerLevelsHelper.getUserPowerLevelValue(event.senderId) >= powerLevels.notificationLevel(key)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt
index aefc086b43..ac1d726d03 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt
@@ -25,7 +25,6 @@ interface PermalinkService {
companion object {
const val MATRIX_TO_URL_BASE = "https://matrix.to/#/"
- const val MATRIX_TO_CUSTOM_SCHEME_URL_BASE = "element://"
}
/**
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt
index 696b612389..e778f5740d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PowerLevelsContent.kt
@@ -25,28 +25,85 @@ import org.matrix.android.sdk.api.session.room.powerlevels.Role
*/
@JsonClass(generateAdapter = true)
data class PowerLevelsContent(
+ /**
+ * The level required to ban a user. Defaults to 50 if unspecified.
+ */
@Json(name = "ban") val ban: Int = Role.Moderator.value,
+ /**
+ * The level required to kick a user. Defaults to 50 if unspecified.
+ */
@Json(name = "kick") val kick: Int = Role.Moderator.value,
+ /**
+ * The level required to invite a user. Defaults to 50 if unspecified.
+ */
@Json(name = "invite") val invite: Int = Role.Moderator.value,
+ /**
+ * The level required to redact an event. Defaults to 50 if unspecified.
+ */
@Json(name = "redact") val redact: Int = Role.Moderator.value,
+ /**
+ * The default level required to send message events. Can be overridden by the events key. Defaults to 0 if unspecified.
+ */
@Json(name = "events_default") val eventsDefault: Int = Role.Default.value,
- @Json(name = "events") val events: MutableMap = HashMap(),
+ /**
+ * The level required to send specific event types. This is a mapping from event type to power level required.
+ */
+ @Json(name = "events") val events: Map = emptyMap(),
+ /**
+ * The default power level for every user in the room, unless their user_id is mentioned in the users key. Defaults to 0 if unspecified.
+ */
@Json(name = "users_default") val usersDefault: Int = Role.Default.value,
- @Json(name = "users") val users: MutableMap = HashMap(),
+ /**
+ * The power levels for specific users. This is a mapping from user_id to power level for that user.
+ */
+ @Json(name = "users") val users: Map = emptyMap(),
+ /**
+ * The default level required to send state events. Can be overridden by the events key. Defaults to 50 if unspecified.
+ */
@Json(name = "state_default") val stateDefault: Int = Role.Moderator.value,
- @Json(name = "notifications") val notifications: Map = HashMap()
+ /**
+ * The power level requirements for specific notification types. This is a mapping from key to power level for that notifications key.
+ */
+ @Json(name = "notifications") val notifications: Map = emptyMap()
) {
/**
- * Alter this content with a new power level for the specified user
+ * Return a copy of this content with a new power level for the specified user
*
* @param userId the userId to alter the power level of
* @param powerLevel the new power level, or null to set the default value.
*/
- fun setUserPowerLevel(userId: String, powerLevel: Int?) {
- if (powerLevel == null || powerLevel == usersDefault) {
- users.remove(userId)
- } else {
- users[userId] = powerLevel
+ fun setUserPowerLevel(userId: String, powerLevel: Int?): PowerLevelsContent {
+ return copy(
+ users = users.toMutableMap().apply {
+ if (powerLevel == null || powerLevel == usersDefault) {
+ remove(userId)
+ } else {
+ put(userId, powerLevel)
+ }
+ }
+ )
+ }
+
+ /**
+ * Get the notification level for a dedicated key.
+ *
+ * @param key the notification key
+ * @return the level, default to Moderator if the key is not found
+ */
+ fun notificationLevel(key: String): Int {
+ return when (val value = notifications[key]) {
+ // the first implementation was a string value
+ is String -> value.toInt()
+ is Double -> value.toInt()
+ is Int -> value
+ else -> Role.Moderator.value
}
}
+
+ companion object {
+ /**
+ * Key to use for content.notifications and get the level required to trigger an @room notification. Defaults to 50 if unspecified.
+ */
+ const val NOTIFICATIONS_ROOM_KEY = "room"
+ }
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt
index 00fa68c0ac..280316d4b5 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/message/MessageStickerContent.kt
@@ -27,6 +27,7 @@ data class MessageStickerContent(
/**
* Set in local, not from server
*/
+ @Transient
override val msgType: String = MessageType.MSGTYPE_STICKER_LOCAL,
/**
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt
index 47922f6968..4f1253c6df 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/powerlevels/PowerLevelsHelper.kt
@@ -108,19 +108,4 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) {
val powerLevel = getUserPowerLevelValue(userId)
return powerLevel >= powerLevelsContent.redact
}
-
- /**
- * Get the notification level for a dedicated key.
- *
- * @param key the notification key
- * @return the level
- */
- fun notificationLevel(key: String): Int {
- return when (val value = powerLevelsContent.notifications[key]) {
- // the first implementation was a string value
- is String -> value.toInt()
- is Int -> value
- else -> Role.Moderator.value
- }
- }
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt
new file mode 100644
index 0000000000..c625a7f088
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/state/StateServiceExtension.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2020 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.api.session.room.state
+
+import org.matrix.android.sdk.api.query.QueryStringValue
+import org.matrix.android.sdk.api.session.events.model.EventType
+import org.matrix.android.sdk.api.session.events.model.toModel
+import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
+import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
+
+/**
+ * Return true if a room can be joined by anyone (RoomJoinRules.PUBLIC)
+ */
+fun StateService.isPublic(): Boolean {
+ return getStateEvent(EventType.STATE_ROOM_JOIN_RULES, QueryStringValue.NoCondition)
+ ?.content
+ ?.toModel()
+ ?.joinRules == RoomJoinRules.PUBLIC
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt
similarity index 58%
rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt
rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt
index 2cbd7ba7f0..17f27b2514 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/eventbus/EventBusTimberLogger.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/UrlExtensions.kt
@@ -14,18 +14,24 @@
* limitations under the License.
*/
-package org.matrix.android.sdk.internal.eventbus
+package org.matrix.android.sdk.api.util
-import org.greenrobot.eventbus.Logger
-import timber.log.Timber
-import java.util.logging.Level
+import java.net.URLEncoder
-class EventBusTimberLogger : Logger {
- override fun log(level: Level, msg: String) {
- Timber.d(msg)
+/**
+ * Append param and value to a Url, using "?" or "&". Value parameter will be encoded
+ * Return this for chaining purpose
+ */
+fun StringBuilder.appendParamToUrl(param: String, value: String): StringBuilder {
+ if (contains("?")) {
+ append("&")
+ } else {
+ append("?")
}
- override fun log(level: Level, msg: String, th: Throwable) {
- Timber.e(th, msg)
- }
+ append(param)
+ append("=")
+ append(URLEncoder.encode(value, "utf-8"))
+
+ return this
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt
similarity index 69%
rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt
rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt
index 7d18aba627..642279cc27 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/Constants.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/Constants.kt
@@ -14,25 +14,25 @@
* limitations under the License.
*/
-package org.matrix.android.sdk.api.auth
+package org.matrix.android.sdk.internal.auth
/**
* Path to use when the client does not supported any or all login flows
* Ref: https://matrix.org/docs/spec/client_server/latest#login-fallback
*/
-const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/"
+internal const val LOGIN_FALLBACK_PATH = "/_matrix/static/client/login/"
/**
* Path to use when the client does not supported any or all registration flows
* Not documented
*/
-const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/"
+internal const val REGISTER_FALLBACK_PATH = "/_matrix/static/client/register/"
/**
* Path to use when the client want to connect using SSO
* Ref: https://matrix.org/docs/spec/client_server/latest#sso-client-login
*/
-const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect"
-const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect"
+internal const val SSO_REDIRECT_PATH = "/_matrix/client/r0/login/sso/redirect"
+internal const val MSC2858_SSO_REDIRECT_PATH = "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect"
-const val SSO_REDIRECT_URL_PARAM = "redirectUrl"
+internal const val SSO_REDIRECT_URL_PARAM = "redirectUrl"
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt
index 55f053de8d..c99e9bd81c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/DefaultAuthenticationService.kt
@@ -34,6 +34,7 @@ import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Cancelable
import org.matrix.android.sdk.api.util.NoOpCancellable
+import org.matrix.android.sdk.api.util.appendParamToUrl
import org.matrix.android.sdk.internal.SessionManager
import org.matrix.android.sdk.internal.auth.data.LoginFlowResponse
import org.matrix.android.sdk.internal.auth.data.RiotConfig
@@ -99,6 +100,52 @@ internal class DefaultAuthenticationService @Inject constructor(
}
}
+ override fun getSsoUrl(redirectUrl: String, deviceId: String?, providerId: String?): String? {
+ val homeServerUrlBase = getHomeServerUrlBase() ?: return null
+
+ return buildString {
+ append(homeServerUrlBase)
+ if (providerId != null) {
+ append(MSC2858_SSO_REDIRECT_PATH)
+ append("/$providerId")
+ } else {
+ append(SSO_REDIRECT_PATH)
+ }
+ // Set the redirect url
+ appendParamToUrl(SSO_REDIRECT_URL_PARAM, redirectUrl)
+ deviceId?.takeIf { it.isNotBlank() }?.let {
+ // But https://github.com/matrix-org/synapse/issues/5755
+ appendParamToUrl("device_id", it)
+ }
+ }
+ }
+
+ override fun getFallbackUrl(forSignIn: Boolean, deviceId: String?): String? {
+ val homeServerUrlBase = getHomeServerUrlBase() ?: return null
+
+ return buildString {
+ append(homeServerUrlBase)
+ if (forSignIn) {
+ append(LOGIN_FALLBACK_PATH)
+ deviceId?.takeIf { it.isNotBlank() }?.let {
+ // But https://github.com/matrix-org/synapse/issues/5755
+ appendParamToUrl("device_id", it)
+ }
+ } else {
+ // For sign up
+ append(REGISTER_FALLBACK_PATH)
+ }
+ }
+ }
+
+ private fun getHomeServerUrlBase(): String? {
+ return pendingSessionData
+ ?.homeServerConnectionConfig
+ ?.homeServerUri
+ ?.toString()
+ ?.trim { it == '/' }
+ }
+
override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback): Cancelable {
pendingSessionData = null
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt
index c2c81894fb..7e92ff3e88 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/CancelGossipRequestWorker.kt
@@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event
@@ -60,7 +59,6 @@ internal class CancelGossipRequestWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore
- @Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials
override fun injectWith(injector: SessionComponent) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt
index 4f94a27bbd..c075c90eb9 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt
@@ -32,6 +32,7 @@ import org.matrix.android.sdk.internal.crypto.crosssigning.toBase64NoPadding
import org.matrix.android.sdk.internal.crypto.keysbackup.util.extractCurveKeyFromRecoveryKey
import org.matrix.android.sdk.internal.crypto.model.rest.GossipingDefaultContent
import org.matrix.android.sdk.internal.crypto.model.rest.GossipingToDeviceObject
+import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyRequestBody
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.session.SessionScope
@@ -206,34 +207,7 @@ internal class IncomingGossipingRequestManager @Inject constructor(
Timber.v("## CRYPTO | GOSSIP processIncomingRoomKeyRequest from $userId:$deviceId for $roomId / ${body.sessionId} id ${request.requestId}")
if (credentials.userId != userId) {
- Timber.w("## CRYPTO | GOSSIP processReceivedGossipingRequests() : room key request from other user")
- val senderKey = body.senderKey ?: return Unit
- .also { Timber.w("missing senderKey") }
- .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
- val sessionId = body.sessionId ?: return Unit
- .also { Timber.w("missing sessionId") }
- .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
-
- if (alg != MXCRYPTO_ALGORITHM_MEGOLM) {
- return Unit
- .also { Timber.w("Only megolm is accepted here") }
- .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
- }
-
- val roomEncryptor = roomEncryptorsStore.get(roomId) ?: return Unit
- .also { Timber.w("no room Encryptor") }
- .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
-
- cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
- val isSuccess = roomEncryptor.reshareKey(sessionId, userId, deviceId, senderKey)
-
- if (isSuccess) {
- cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTED)
- } else {
- cryptoStore.updateGossipingRequestState(request, GossipingRequestState.UNABLE_TO_PROCESS)
- }
- }
- cryptoStore.updateGossipingRequestState(request, GossipingRequestState.RE_REQUESTED)
+ handleKeyRequestFromOtherUser(body, request, alg, roomId, userId, deviceId)
return
}
// TODO: should we queue up requests we don't yet have keys for, in case they turn up later?
@@ -291,6 +265,42 @@ internal class IncomingGossipingRequestManager @Inject constructor(
onRoomKeyRequest(request)
}
+ private fun handleKeyRequestFromOtherUser(body: RoomKeyRequestBody,
+ request: IncomingRoomKeyRequest,
+ alg: String,
+ roomId: String,
+ userId: String,
+ deviceId: String) {
+ Timber.w("## CRYPTO | GOSSIP processReceivedGossipingRequests() : room key request from other user")
+ val senderKey = body.senderKey ?: return Unit
+ .also { Timber.w("missing senderKey") }
+ .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
+ val sessionId = body.sessionId ?: return Unit
+ .also { Timber.w("missing sessionId") }
+ .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
+
+ if (alg != MXCRYPTO_ALGORITHM_MEGOLM) {
+ return Unit
+ .also { Timber.w("Only megolm is accepted here") }
+ .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
+ }
+
+ val roomEncryptor = roomEncryptorsStore.get(roomId) ?: return Unit
+ .also { Timber.w("no room Encryptor") }
+ .also { cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED) }
+
+ cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
+ val isSuccess = roomEncryptor.reshareKey(sessionId, userId, deviceId, senderKey)
+
+ if (isSuccess) {
+ cryptoStore.updateGossipingRequestState(request, GossipingRequestState.ACCEPTED)
+ } else {
+ cryptoStore.updateGossipingRequestState(request, GossipingRequestState.UNABLE_TO_PROCESS)
+ }
+ }
+ cryptoStore.updateGossipingRequestState(request, GossipingRequestState.RE_REQUESTED)
+ }
+
private fun processIncomingSecretShareRequest(request: IncomingSecretShareRequest) {
val secretName = request.secretName ?: return Unit.also {
cryptoStore.updateGossipingRequestState(request, GossipingRequestState.REJECTED)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
index c952602d93..b1e91e8d50 100755
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
@@ -19,6 +19,8 @@ package org.matrix.android.sdk.internal.crypto
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
import org.matrix.android.sdk.api.util.JSON_DICT_PARAMETERIZED_TYPE
import org.matrix.android.sdk.api.util.JsonDict
+import org.matrix.android.sdk.internal.crypto.algorithms.megolm.MXOutboundSessionInfo
+import org.matrix.android.sdk.internal.crypto.algorithms.megolm.SharedWithHelper
import org.matrix.android.sdk.internal.crypto.algorithms.olm.OlmDecryptionResult
import org.matrix.android.sdk.internal.crypto.model.OlmInboundGroupSessionWrapper2
import org.matrix.android.sdk.internal.crypto.model.OlmSessionWrapper
@@ -46,7 +48,7 @@ internal class MXOlmDevice @Inject constructor(
*/
private val store: IMXCryptoStore,
private val inboundGroupSessionStore: InboundGroupSessionStore
- ) {
+) {
/**
* @return the Curve25519 key for the account.
@@ -63,11 +65,15 @@ internal class MXOlmDevice @Inject constructor(
// The OLM lib utility instance.
private var olmUtility: OlmUtility? = null
+ private data class GroupSessionCacheItem(
+ val groupId: String,
+ val groupSession: OlmOutboundGroupSession
+ )
+
// The outbound group session.
- // They are not stored in 'store' to avoid to remember to which devices we sent the session key.
- // Plus, in cryptography, it is good to refresh sessions from time to time.
- // The key is the session id, the value the outbound group session.
- private val outboundGroupSessionStore: MutableMap = HashMap()
+ // Caches active outbound session to avoid to sync with DB before read
+ // The key is the session id, the value the .
+ private val outboundGroupSessionCache: MutableMap = HashMap()
// Store a set of decrypted message indexes for each group session.
// This partially mitigates a replay attack where a MITM resends a group
@@ -135,6 +141,10 @@ internal class MXOlmDevice @Inject constructor(
*/
fun release() {
olmUtility?.releaseUtility()
+ outboundGroupSessionCache.values.forEach {
+ it.groupSession.releaseSession()
+ }
+ outboundGroupSessionCache.clear()
}
/**
@@ -406,11 +416,12 @@ internal class MXOlmDevice @Inject constructor(
*
* @return the session id for the outbound session.
*/
- fun createOutboundGroupSession(): String? {
+ fun createOutboundGroupSessionForRoom(roomId: String): String? {
var session: OlmOutboundGroupSession? = null
try {
session = OlmOutboundGroupSession()
- outboundGroupSessionStore[session.sessionIdentifier()] = session
+ outboundGroupSessionCache[session.sessionIdentifier()] = GroupSessionCacheItem(roomId, session)
+ store.storeCurrentOutboundGroupSessionForRoom(roomId, session)
return session.sessionIdentifier()
} catch (e: Exception) {
Timber.e(e, "createOutboundGroupSession")
@@ -421,6 +432,39 @@ internal class MXOlmDevice @Inject constructor(
return null
}
+ fun storeOutboundGroupSessionForRoom(roomId: String, sessionId: String) {
+ outboundGroupSessionCache[sessionId]?.let {
+ store.storeCurrentOutboundGroupSessionForRoom(roomId, it.groupSession)
+ }
+ }
+
+ fun restoreOutboundGroupSessionForRoom(roomId: String): MXOutboundSessionInfo? {
+ val restoredOutboundGroupSession = store.getCurrentOutboundGroupSessionForRoom(roomId)
+ if (restoredOutboundGroupSession != null) {
+ val sessionId = restoredOutboundGroupSession.outboundGroupSession.sessionIdentifier()
+ // cache it
+ outboundGroupSessionCache[sessionId] = GroupSessionCacheItem(roomId, restoredOutboundGroupSession.outboundGroupSession)
+
+ return MXOutboundSessionInfo(
+ sessionId = sessionId,
+ sharedWithHelper = SharedWithHelper(roomId, sessionId, store),
+ restoredOutboundGroupSession.creationTime
+ )
+ }
+ return null
+ }
+
+ fun discardOutboundGroupSessionForRoom(roomId: String) {
+ val toDiscard = outboundGroupSessionCache.filter {
+ it.value.groupId == roomId
+ }
+ toDiscard.forEach { (sessionId, cacheItem) ->
+ cacheItem.groupSession.releaseSession()
+ outboundGroupSessionCache.remove(sessionId)
+ }
+ store.storeCurrentOutboundGroupSessionForRoom(roomId, null)
+ }
+
/**
* Get the current session key of an outbound group session.
*
@@ -430,7 +474,7 @@ internal class MXOlmDevice @Inject constructor(
fun getSessionKey(sessionId: String): String? {
if (sessionId.isNotEmpty()) {
try {
- return outboundGroupSessionStore[sessionId]!!.sessionKey()
+ return outboundGroupSessionCache[sessionId]!!.groupSession.sessionKey()
} catch (e: Exception) {
Timber.e(e, "## getSessionKey() : failed")
}
@@ -446,7 +490,7 @@ internal class MXOlmDevice @Inject constructor(
*/
fun getMessageIndex(sessionId: String): Int {
return if (sessionId.isNotEmpty()) {
- outboundGroupSessionStore[sessionId]!!.messageIndex()
+ outboundGroupSessionCache[sessionId]!!.groupSession.messageIndex()
} else 0
}
@@ -460,7 +504,7 @@ internal class MXOlmDevice @Inject constructor(
fun encryptGroupMessage(sessionId: String, payloadString: String): String? {
if (sessionId.isNotEmpty() && payloadString.isNotEmpty()) {
try {
- return outboundGroupSessionStore[sessionId]!!.encryptMessage(payloadString)
+ return outboundGroupSessionCache[sessionId]!!.groupSession.encryptMessage(payloadString)
} catch (e: Exception) {
Timber.e(e, "## encryptGroupMessage() : failed")
}
@@ -747,7 +791,7 @@ internal class MXOlmDevice @Inject constructor(
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_SENDER_KEY, MXCryptoError.ERROR_MISSING_PROPERTY_REASON)
}
- val session = inboundGroupSessionStore.getInboundGroupSession(sessionId, senderKey)
+ val session = inboundGroupSessionStore.getInboundGroupSession(sessionId, senderKey)
if (session != null) {
// Check that the room id matches the original one for the session. This stops
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt
index 085469e9d9..e8d567b944 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipRequestWorker.kt
@@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event
@@ -52,7 +51,6 @@ internal class SendGossipRequestWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore
- @Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials
override fun injectWith(injector: SessionComponent) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt
index bcaa16f356..8c68057056 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/SendGossipWorker.kt
@@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.events.model.Event
@@ -54,7 +53,6 @@ internal class SendGossipWorker(context: Context,
@Inject lateinit var sendToDeviceTask: SendToDeviceTask
@Inject lateinit var cryptoStore: IMXCryptoStore
- @Inject lateinit var eventBus: EventBus
@Inject lateinit var credentials: Credentials
@Inject lateinit var messageEncrypter: MessageEncrypter
@Inject lateinit var ensureOlmSessionsForDevicesAction: EnsureOlmSessionsForDevicesAction
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
index fd431ce735..fa8acafb83 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
@@ -68,6 +68,10 @@ internal class MXMegolmEncryption(
// case outboundSession.shareOperation will be non-null.)
private var outboundSession: MXOutboundSessionInfo? = null
+ init {
+ // restore existing outbound session if any
+ outboundSession = olmDevice.restoreOutboundGroupSessionForRoom(roomId)
+ }
// Default rotation periods
// TODO: Make it configurable via parameters
// Session rotation periods
@@ -86,6 +90,9 @@ internal class MXMegolmEncryption(
return encryptContent(outboundSession, eventType, eventContent)
.also {
notifyWithheldForSession(devices.withHeldDevices, outboundSession)
+ // annoyingly we have to serialize again the saved outbound session to store message index :/
+ // if not we would see duplicate message index errors
+ olmDevice.storeOutboundGroupSessionForRoom(roomId, outboundSession.sessionId)
}
}
@@ -107,6 +114,7 @@ internal class MXMegolmEncryption(
override fun discardSessionKey() {
outboundSession = null
+ olmDevice.discardOutboundGroupSessionForRoom(roomId)
}
/**
@@ -116,7 +124,7 @@ internal class MXMegolmEncryption(
*/
private fun prepareNewSessionInRoom(): MXOutboundSessionInfo {
Timber.v("## CRYPTO | prepareNewSessionInRoom() ")
- val sessionId = olmDevice.createOutboundGroupSession()
+ val sessionId = olmDevice.createOutboundGroupSessionForRoom(roomId)
val keysClaimedMap = HashMap()
keysClaimedMap["ed25519"] = olmDevice.deviceEd25519Key!!
@@ -152,7 +160,7 @@ internal class MXMegolmEncryption(
val deviceIds = devicesInRoom.getUserDeviceIds(userId)
for (deviceId in deviceIds!!) {
val deviceInfo = devicesInRoom.getObject(userId, deviceId)
- if (deviceInfo != null && !cryptoStore.wasSessionSharedWithUser(roomId, safeSession.sessionId, userId, deviceId).found) {
+ if (deviceInfo != null && !cryptoStore.getSharedSessionInfo(roomId, safeSession.sessionId, userId, deviceId).found) {
val devices = shareMap.getOrPut(userId) { ArrayList() }
devices.add(deviceInfo)
}
@@ -401,11 +409,18 @@ internal class MXMegolmEncryption(
.also { Timber.w("## Crypto reshareKey: Device not found") }
// Get the chain index of the key we previously sent this device
- val chainIndex = outboundSession?.sharedWithHelper?.wasSharedWith(userId, deviceId) ?: return false
+ val wasSessionSharedWithUser = cryptoStore.getSharedSessionInfo(roomId, sessionId, userId, deviceId)
+ if (!wasSessionSharedWithUser.found) {
+ // This session was never shared with this user
+ // Send a room key with held
+ notifyKeyWithHeld(listOf(UserDevice(userId, deviceId)), sessionId, senderKey, WithHeldCode.UNAUTHORISED)
+ Timber.w("## Crypto reshareKey: ERROR : Never shared megolm with this device")
+ return false
+ }
+ // if found chain index should not be null
+ val chainIndex = wasSessionSharedWithUser.chainIndex ?: return false
.also {
- // Send a room key with held
- notifyKeyWithHeld(listOf(UserDevice(userId, deviceId)), sessionId, senderKey, WithHeldCode.UNAUTHORISED)
- Timber.w("## Crypto reshareKey: ERROR : Never share megolm with this device")
+ Timber.w("## Crypto reshareKey: Null chain index")
}
val devicesByUser = mapOf(userId to listOf(deviceInfo))
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt
index 9244b4d5e7..5a68937868 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXOutboundSessionInfo.kt
@@ -23,9 +23,9 @@ import timber.log.Timber
internal class MXOutboundSessionInfo(
// The id of the session
val sessionId: String,
- val sharedWithHelper: SharedWithHelper) {
- // When the session was created
- private val creationTime = System.currentTimeMillis()
+ val sharedWithHelper: SharedWithHelper,
+ // When the session was created
+ private val creationTime: Long = System.currentTimeMillis()) {
// Number of times this session has been used
var useCount: Int = 0
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt
index 921f9b2cdc..f17168a6d2 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/SharedWithHelper.kt
@@ -28,10 +28,6 @@ internal class SharedWithHelper(
return cryptoStore.getSharedWithInfo(roomId, sessionId)
}
- fun wasSharedWith(userId: String, deviceId: String): Int? {
- return cryptoStore.wasSessionSharedWithUser(roomId, sessionId, userId, deviceId).chainIndex
- }
-
fun markedSessionAsShared(userId: String, deviceId: String, chainIndex: Int) {
cryptoStore.markedSessionAsShared(roomId, sessionId, userId, deviceId, chainIndex)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt
index 36b667911d..5c59cfd80e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/CreateKeysBackupVersionTask.kt
@@ -19,20 +19,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersion
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface CreateKeysBackupVersionTask : Task
internal class DefaultCreateKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : CreateKeysBackupVersionTask {
override suspend fun execute(params: CreateKeysBackupVersionBody): KeysVersion {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.createKeysBackupVersion(params)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt
index d174be20a2..ec09da7240 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteBackupTask.kt
@@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteBackupTask : Task {
@@ -30,11 +30,11 @@ internal interface DeleteBackupTask : Task {
internal class DefaultDeleteBackupTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteBackupTask {
override suspend fun execute(params: DeleteBackupTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.deleteBackup(params.version)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt
index 6826596ba4..9c477efb78 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/DeleteRoomSessionDataTask.kt
@@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteRoomSessionDataTask : Task {
@@ -32,11 +32,11 @@ internal interface DeleteRoomSessionDataTask : Task {
@@ -31,11 +31,11 @@ internal interface DeleteRoomSessionsDataTask : Task {
@@ -30,11 +30,11 @@ internal interface DeleteSessionsDataTask : Task
internal class DefaultGetKeysBackupLastVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetKeysBackupLastVersionTask {
override suspend fun execute(params: Unit): KeysVersionResult {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getKeysBackupLastVersion()
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt
index dd2dd70e4d..13c99fb0f4 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetKeysBackupVersionTask.kt
@@ -18,20 +18,20 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysVersionResult
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetKeysBackupVersionTask : Task
internal class DefaultGetKeysBackupVersionTask @Inject constructor(
private val roomKeysApi: RoomKeysApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetKeysBackupVersionTask {
override suspend fun execute(params: String): KeysVersionResult {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomKeysApi.getKeysBackupVersion(params)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt
index 8ca03491a1..168020d9cd 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/tasks/GetRoomSessionDataTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.keysbackup.tasks
import org.matrix.android.sdk.internal.crypto.keysbackup.api.RoomKeysApi
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeyBackupData
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetRoomSessionDataTask : Task {
@@ -33,11 +33,11 @@ internal interface GetRoomSessionDataTask : Task {
@@ -32,11 +32,11 @@ internal interface GetRoomSessionsDataTask : Task {
@@ -31,11 +31,11 @@ internal interface GetSessionsDataTask : Task {
@@ -35,11 +35,11 @@ internal interface StoreRoomSessionDataTask : Task {
@@ -34,11 +34,11 @@ internal interface StoreRoomSessionsDataTask : Task {
@@ -33,11 +33,11 @@ internal interface StoreSessionsDataTask : Task {
@@ -32,11 +32,11 @@ internal interface UpdateKeysBackupVersionTask : Task
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt
index 6b83c4f7d1..369a4976c9 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt
@@ -47,6 +47,7 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.OlmInboundGroupSessionWrapper2
import org.matrix.android.sdk.internal.crypto.model.OlmSessionWrapper
+import org.matrix.android.sdk.internal.crypto.model.OutboundGroupSessionWrapper
import org.matrix.android.sdk.internal.crypto.model.event.RoomKeyWithHeldContent
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
import org.matrix.android.sdk.internal.crypto.model.rest.RoomKeyRequestBody
@@ -73,6 +74,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSess
import org.matrix.android.sdk.internal.crypto.store.db.model.OlmInboundGroupSessionEntityFields
import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.OlmSessionEntityFields
+import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingGossipingRequestEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.OutgoingGossipingRequestEntityFields
import org.matrix.android.sdk.internal.crypto.store.db.model.SharedSessionEntity
@@ -95,6 +97,7 @@ import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.session.SessionScope
import org.matrix.olm.OlmAccount
import org.matrix.olm.OlmException
+import org.matrix.olm.OlmOutboundGroupSession
import timber.log.Timber
import javax.inject.Inject
import kotlin.collections.set
@@ -756,6 +759,42 @@ internal class RealmCryptoStore @Inject constructor(
return inboundGroupSessionToRelease[key]
}
+ override fun getCurrentOutboundGroupSessionForRoom(roomId: String): OutboundGroupSessionWrapper? {
+ return doWithRealm(realmConfiguration) { realm ->
+ realm.where()
+ .equalTo(CryptoRoomEntityFields.ROOM_ID, roomId)
+ .findFirst()?.outboundSessionInfo?.let { entity ->
+ entity.getOutboundGroupSession()?.let {
+ OutboundGroupSessionWrapper(
+ it,
+ entity.creationTime ?: 0
+ )
+ }
+ }
+ }
+ }
+
+ override fun storeCurrentOutboundGroupSessionForRoom(roomId: String, outboundGroupSession: OlmOutboundGroupSession?) {
+ // we can do this async, as it's just for restoring on next launch
+ // the olmdevice is caching the active instance
+ // this is called for each sent message (so not high frequency), thus we can use basic realm async without
+ // risk of reaching max async operation limit?
+ doRealmTransactionAsync(realmConfiguration) { realm ->
+ CryptoRoomEntity.getById(realm, roomId)?.let { entity ->
+ // we should delete existing outbound session info if any
+ entity.outboundSessionInfo?.deleteFromRealm()
+
+ if (outboundGroupSession != null) {
+ val info = realm.createObject(OutboundGroupSessionInfoEntity::class.java).apply {
+ creationTime = System.currentTimeMillis()
+ putOutboundGroupSession(outboundGroupSession)
+ }
+ entity.outboundSessionInfo = info
+ }
+ }
+ }
+ }
+
/**
* Note: the result will be only use to export all the keys and not to use the OlmInboundGroupSessionWrapper2,
* so there is no need to use or update `inboundGroupSessionToRelease` for native memory management
@@ -1645,7 +1684,7 @@ internal class RealmCryptoStore @Inject constructor(
}
}
- override fun wasSessionSharedWithUser(roomId: String?, sessionId: String, userId: String, deviceId: String): IMXCryptoStore.SharedSessionResult {
+ override fun getSharedSessionInfo(roomId: String?, sessionId: String, userId: String, deviceId: String): IMXCryptoStore.SharedSessionResult {
return doWithRealm(realmConfiguration) { realm ->
SharedSessionEntity.get(realm, roomId, sessionId, userId, deviceId)?.let {
IMXCryptoStore.SharedSessionResult(true, it.chainIndex)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
index 08806b0627..bca7914388 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt
@@ -44,6 +44,7 @@ import org.matrix.android.sdk.internal.di.SerializeNulls
import io.realm.DynamicRealm
import io.realm.RealmMigration
import io.realm.RealmObjectSchema
+import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntityFields
import org.matrix.androidsdk.crypto.data.MXOlmInboundGroupSession2
import timber.log.Timber
import javax.inject.Inject
@@ -55,7 +56,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi
// 0, 1, 2: legacy Riot-Android
// 3: migrate to RiotX schema
// 4, 5, 6, 7, 8, 9: migrations from RiotX (which was previously 1, 2, 3, 4, 5, 6)
- const val CRYPTO_STORE_SCHEMA_VERSION = 11L
+ const val CRYPTO_STORE_SCHEMA_VERSION = 12L
}
private fun RealmObjectSchema.addFieldIfNotExists(fieldName: String, fieldType: Class<*>): RealmObjectSchema {
@@ -93,6 +94,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi
if (oldVersion <= 8) migrateTo9(realm)
if (oldVersion <= 9) migrateTo10(realm)
if (oldVersion <= 10) migrateTo11(realm)
+ if (oldVersion <= 11) migrateTo12(realm)
}
private fun migrateTo1Legacy(realm: DynamicRealm) {
@@ -483,4 +485,16 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi
realm.schema.get("CryptoMetadataEntity")
?.addField(CryptoMetadataEntityFields.DEVICE_KEYS_SENT_TO_SERVER, Boolean::class.java)
}
+
+ // Version 12L added outbound group session persistence
+ private fun migrateTo12(realm: DynamicRealm) {
+ Timber.d("Step 11 -> 12")
+ val outboundEntitySchema = realm.schema.create("OutboundGroupSessionInfoEntity")
+ .addField(OutboundGroupSessionInfoEntityFields.SERIALIZED_OUTBOUND_SESSION_DATA, String::class.java)
+ .addField(OutboundGroupSessionInfoEntityFields.CREATION_TIME, Long::class.java)
+ .setNullable(OutboundGroupSessionInfoEntityFields.CREATION_TIME, true)
+
+ realm.schema.get("CryptoRoomEntity")
+ ?.addRealmObjectField(CryptoRoomEntityFields.OUTBOUND_SESSION_INFO.`$`, outboundEntitySchema)
+ }
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
index a453fc3ed0..6aae68c83e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreModule.kt
@@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.crypto.store.db.model.TrustLevelEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.UserEntity
import org.matrix.android.sdk.internal.crypto.store.db.model.WithHeldSessionEntity
import io.realm.annotations.RealmModule
+import org.matrix.android.sdk.internal.crypto.store.db.model.OutboundGroupSessionInfoEntity
/**
* Realm module for Crypto store classes
@@ -54,6 +55,7 @@ import io.realm.annotations.RealmModule
OutgoingGossipingRequestEntity::class,
MyDeviceLastSeenInfoEntity::class,
WithHeldSessionEntity::class,
- SharedSessionEntity::class
+ SharedSessionEntity::class,
+ OutboundGroupSessionInfoEntity::class
])
internal class RealmCryptoStoreModule
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt
index 4c19b5eb0e..e226f3eaa8 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/CryptoRoomEntity.kt
@@ -23,7 +23,12 @@ internal open class CryptoRoomEntity(
@PrimaryKey var roomId: String? = null,
var algorithm: String? = null,
var shouldEncryptForInvitedMembers: Boolean? = null,
- var blacklistUnverifiedDevices: Boolean = false)
+ var blacklistUnverifiedDevices: Boolean = false,
+ // Store the current outbound session for this room,
+ // to avoid re-create and re-share at each startup (if rotation not needed..)
+ // This is specific to megolm but not sure how to model it better
+ var outboundSessionInfo: OutboundGroupSessionInfoEntity? = null
+ )
: RealmObject() {
companion object
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt
new file mode 100644
index 0000000000..d50db78415
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutboundGroupSessionInfoEntity.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2020 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.internal.crypto.store.db.model
+
+import io.realm.RealmObject
+import org.matrix.android.sdk.internal.crypto.store.db.deserializeFromRealm
+import org.matrix.android.sdk.internal.crypto.store.db.serializeForRealm
+import org.matrix.olm.OlmOutboundGroupSession
+import timber.log.Timber
+
+internal open class OutboundGroupSessionInfoEntity(
+ var serializedOutboundSessionData: String? = null,
+ var creationTime: Long? = null
+) : RealmObject() {
+
+ fun getOutboundGroupSession(): OlmOutboundGroupSession? {
+ return try {
+ deserializeFromRealm(serializedOutboundSessionData)
+ } catch (failure: Throwable) {
+ Timber.e(failure, "## getOutboundGroupSession() Deserialization failure")
+ return null
+ }
+ }
+
+ fun putOutboundGroupSession(olmOutboundGroupSession: OlmOutboundGroupSession?) {
+ serializedOutboundSessionData = serializeForRealm(olmOutboundGroupSession)
+ }
+
+ companion object
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt
index ae72c7198a..3df6312adb 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/ClaimOneTimeKeysForUsersDeviceTask.kt
@@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.model.MXKey
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysClaimResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@@ -36,13 +36,13 @@ internal interface ClaimOneTimeKeysForUsersDeviceTask : Task {
val body = KeysClaimBody(oneTimeKeys = params.usersDevicesKeyTypesMap.map)
- val keysClaimResponse = executeRequest(eventBus) {
+ val keysClaimResponse = executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.claimOneTimeKeysForUsersDevices(body)
}
val map = MXUsersDevicesMap()
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt
index e5078d5b4e..8f1569a037 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceTask.kt
@@ -20,9 +20,9 @@ import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteDeviceTask : Task {
@@ -33,12 +33,12 @@ internal interface DeleteDeviceTask : Task {
internal class DefaultDeleteDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteDeviceTask {
override suspend fun execute(params: DeleteDeviceTask.Params) {
try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.deleteDevice(params.deviceId, DeleteDeviceParams())
}
} catch (throwable: Throwable) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt
index 38eee7f932..b4c1e6d27c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/DeleteDeviceWithUserPasswordTask.kt
@@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeleteDeviceParams
import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteDeviceWithUserPasswordTask : Task {
@@ -37,11 +37,11 @@ internal interface DeleteDeviceWithUserPasswordTask : Task {
@@ -35,7 +35,7 @@ internal interface DownloadKeysForUsersTask : Task {
@@ -29,11 +29,11 @@ internal interface GetDeviceInfoTask : Task
internal class DefaultGetDevicesTask @Inject constructor(
private val cryptoApi: CryptoApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetDevicesTask {
override suspend fun execute(params: Unit): DevicesListResponse {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.getDevices()
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt
index 289a5226f5..4cc9ab2fcb 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/GetKeyChangesTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.KeyChangesResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetKeyChangesTask : Task {
@@ -34,11 +34,11 @@ internal interface GetKeyChangesTask : Task {
internal class DefaultRedactEventTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus) : RedactEventTask {
+ private val globalErrorReceiver: GlobalErrorReceiver) : RedactEventTask {
override suspend fun execute(params: RedactEventTask.Params): String {
- val executeRequest = executeRequest(eventBus) {
+ val executeRequest = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.redactEvent(
txId = params.txID,
roomId = params.roomId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt
index 8b739c4b64..b772bfbce2 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt
@@ -15,11 +15,12 @@
*/
package org.matrix.android.sdk.internal.crypto.tasks
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.send.SendState
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
+import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository
import org.matrix.android.sdk.internal.session.room.send.SendResponse
import org.matrix.android.sdk.internal.task.Task
@@ -35,16 +36,24 @@ internal interface SendEventTask : Task {
internal class DefaultSendEventTask @Inject constructor(
private val localEchoRepository: LocalEchoRepository,
private val encryptEventTask: DefaultEncryptEventTask,
+ private val loadRoomMembersTask: LoadRoomMembersTask,
private val roomAPI: RoomAPI,
- private val eventBus: EventBus) : SendEventTask {
+ private val globalErrorReceiver: GlobalErrorReceiver) : SendEventTask {
override suspend fun execute(params: SendEventTask.Params): String {
try {
+ // Make sure to load all members in the room before sending the event.
+ params.event.roomId
+ ?.takeIf { params.encrypt }
+ ?.let { roomId ->
+ loadRoomMembersTask.execute(LoadRoomMembersTask.Params(roomId))
+ }
+
val event = handleEncryption(params)
val localId = event.eventId!!
localEchoRepository.updateSendState(localId, params.event.roomId, SendState.SENDING)
- val executeRequest = executeRequest(eventBus) {
+ val executeRequest = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.send(
localId,
roomId = event.roomId ?: "",
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt
index 37e0bbc887..d2af91601b 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendToDeviceTask.kt
@@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap
import org.matrix.android.sdk.internal.crypto.model.rest.SendToDeviceBody
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
import kotlin.random.Random
@@ -38,7 +38,7 @@ internal interface SendToDeviceTask : Task {
internal class DefaultSendToDeviceTask @Inject constructor(
private val cryptoApi: CryptoApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : SendToDeviceTask {
override suspend fun execute(params: SendToDeviceTask.Params) {
@@ -46,7 +46,7 @@ internal class DefaultSendToDeviceTask @Inject constructor(
messages = params.contentMap.map
)
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.sendToDevice(
params.eventType,
params.transactionId ?: Random.nextInt(Integer.MAX_VALUE).toString(),
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt
index cedb7a6618..c39dfb1016 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendVerificationMessageTask.kt
@@ -15,10 +15,10 @@
*/
package org.matrix.android.sdk.internal.crypto.tasks
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.internal.crypto.CryptoSessionInfoProvider
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.session.room.send.LocalEchoRepository
@@ -37,7 +37,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor(
private val encryptEventTask: DefaultEncryptEventTask,
private val roomAPI: RoomAPI,
private val cryptoSessionInfoProvider: CryptoSessionInfoProvider,
- private val eventBus: EventBus) : SendVerificationMessageTask {
+ private val globalErrorReceiver: GlobalErrorReceiver) : SendVerificationMessageTask {
override suspend fun execute(params: SendVerificationMessageTask.Params): String {
val event = handleEncryption(params)
@@ -45,7 +45,7 @@ internal class DefaultSendVerificationMessageTask @Inject constructor(
try {
localEchoRepository.updateSendState(localId, event.roomId, SendState.SENDING)
- val executeRequest = executeRequest(eventBus) {
+ val executeRequest = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.send(
localId,
roomId = event.roomId ?: "",
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt
index 51b9624554..b835d46236 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SetDeviceNameTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.UpdateDeviceInfoBody
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SetDeviceNameTask : Task {
@@ -34,14 +34,14 @@ internal interface SetDeviceNameTask : Task {
internal class DefaultSetDeviceNameTask @Inject constructor(
private val cryptoApi: CryptoApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : SetDeviceNameTask {
override suspend fun execute(params: SetDeviceNameTask.Params) {
val body = UpdateDeviceInfoBody(
displayName = params.deviceName
)
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.updateDeviceInfo(params.deviceId, body)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt
index 6216a3a305..eb53bbbf8d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadKeysTask.kt
@@ -21,9 +21,9 @@ import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceKeys
import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadBody
import org.matrix.android.sdk.internal.crypto.model.rest.KeysUploadResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@@ -38,7 +38,7 @@ internal interface UploadKeysTask : Task $body")
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.uploadKeys(body)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt
index a4e10ddbfc..c50faf37b1 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSignaturesTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.crypto.tasks
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.internal.crypto.api.CryptoApi
import org.matrix.android.sdk.internal.crypto.model.rest.SignatureUploadResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UploadSignaturesTask : Task {
@@ -31,12 +31,12 @@ internal interface UploadSignaturesTask : Task(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
this.isRetryable = true
this.maxRetryCount = 10
this.apiCall = cryptoApi.uploadSignatures(params.signatures)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt
index 038ef9dbd3..cceff355bb 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/UploadSigningKeysTask.kt
@@ -25,9 +25,9 @@ import org.matrix.android.sdk.internal.crypto.model.rest.KeysQueryResponse
import org.matrix.android.sdk.internal.crypto.model.rest.UploadSigningKeysBody
import org.matrix.android.sdk.internal.crypto.model.rest.UserPasswordAuth
import org.matrix.android.sdk.internal.crypto.model.toRest
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UploadSigningKeysTask : Task {
@@ -55,7 +55,7 @@ data class UploadSigningKeys(val failures: Map?) : Failure.FeatureF
internal class DefaultUploadSigningKeysTask @Inject constructor(
private val cryptoApi: CryptoApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : UploadSigningKeysTask {
override suspend fun execute(params: UploadSigningKeysTask.Params) {
@@ -87,7 +87,7 @@ internal class DefaultUploadSigningKeysTask @Inject constructor(
}
private suspend fun doRequest(uploadQuery: UploadSigningKeysBody) {
- val keysQueryResponse = executeRequest(eventBus) {
+ val keysQueryResponse = executeRequest(globalErrorReceiver) {
apiCall = cryptoApi.uploadSigningKeys(uploadQuery)
}
if (keysQueryResponse.failures?.isNotEmpty() == true) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt
index b970ec60e2..57002b5a60 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt
@@ -21,6 +21,8 @@ import io.realm.RealmMigration
import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEntityFields
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntityFields
+import org.matrix.android.sdk.internal.database.model.RoomEntityFields
+import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import timber.log.Timber
import javax.inject.Inject
@@ -28,7 +30,7 @@ import javax.inject.Inject
class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
companion object {
- const val SESSION_STORE_SCHEMA_VERSION = 6L
+ const val SESSION_STORE_SCHEMA_VERSION = 7L
}
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
@@ -40,6 +42,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
if (oldVersion <= 3) migrateTo4(realm)
if (oldVersion <= 4) migrateTo5(realm)
if (oldVersion <= 5) migrateTo6(realm)
+ if (oldVersion <= 6) migrateTo7(realm)
}
private fun migrateTo1(realm: DynamicRealm) {
@@ -105,4 +108,18 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
.addField(PreviewUrlCacheEntityFields.MXC_URL, String::class.java)
.addField(PreviewUrlCacheEntityFields.LAST_UPDATED_TIMESTAMP, Long::class.java)
}
+
+ private fun migrateTo7(realm: DynamicRealm) {
+ Timber.d("Step 6 -> 7")
+ realm.schema.get("RoomEntity")
+ ?.addField(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, String::class.java)
+ ?.transform { obj ->
+ if (obj.getBoolean("areAllMembersLoaded")) {
+ obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.LOADED.name)
+ } else {
+ obj.setString("membersLoadStatusStr", RoomMembersLoadStatusType.NONE.name)
+ }
+ }
+ ?.removeField("areAllMembersLoaded")
+ }
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt
index 9af1646a4c..3ff2532604 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomEntity.kt
@@ -23,8 +23,7 @@ import io.realm.annotations.PrimaryKey
internal open class RoomEntity(@PrimaryKey var roomId: String = "",
var chunks: RealmList = RealmList(),
- var sendingTimelineEvents: RealmList = RealmList(),
- var areAllMembersLoaded: Boolean = false
+ var sendingTimelineEvents: RealmList = RealmList()
) : RealmObject() {
private var membershipStr: String = Membership.NONE.name
@@ -36,5 +35,14 @@ internal open class RoomEntity(@PrimaryKey var roomId: String = "",
membershipStr = value.name
}
+ private var membersLoadStatusStr: String = RoomMembersLoadStatusType.NONE.name
+ var membersLoadStatus: RoomMembersLoadStatusType
+ get() {
+ return RoomMembersLoadStatusType.valueOf(membersLoadStatusStr)
+ }
+ set(value) {
+ membersLoadStatusStr = value.name
+ }
+
companion object
}
diff --git a/vector/src/main/java/im/vector/app/core/di/VectorAssistedModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt
similarity index 68%
rename from vector/src/main/java/im/vector/app/core/di/VectorAssistedModule.kt
rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt
index 78a935a1d4..79fe17253b 100644
--- a/vector/src/main/java/im/vector/app/core/di/VectorAssistedModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomMembersLoadStatusType.kt
@@ -1,11 +1,11 @@
/*
- * Copyright 2019 New Vector Ltd
+ * Copyright 2020 The Matrix.org Foundation C.I.C.
*
* 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
+ * 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,
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-package im.vector.app.core.di
+package org.matrix.android.sdk.internal.database.model
-/*
-@Module(includes = [AssistedInject_VectorAssistedModule::class])
-@AssistedModule
-class VectorAssistedModule*/
+internal enum class RoomMembersLoadStatusType {
+ NONE,
+ LOADING,
+ LOADED
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt
new file mode 100644
index 0000000000..9afdb40ed1
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorHandler.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2021 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.internal.network
+
+import org.matrix.android.sdk.api.failure.GlobalError
+import org.matrix.android.sdk.internal.auth.SessionParamsStore
+import org.matrix.android.sdk.internal.di.SessionId
+import org.matrix.android.sdk.internal.session.SessionScope
+import org.matrix.android.sdk.internal.task.TaskExecutor
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import timber.log.Timber
+import javax.inject.Inject
+
+@SessionScope
+internal class GlobalErrorHandler @Inject constructor(
+ private val taskExecutor: TaskExecutor,
+ private val sessionParamsStore: SessionParamsStore,
+ @SessionId private val sessionId: String
+) : GlobalErrorReceiver {
+
+ var listener: Listener? = null
+
+ override fun handleGlobalError(globalError: GlobalError) {
+ Timber.e("Global error received: $globalError")
+
+ if (globalError is GlobalError.InvalidToken && globalError.softLogout) {
+ // Mark the token has invalid
+ taskExecutor.executorScope.launch(Dispatchers.IO) {
+ sessionParamsStore.setTokenInvalid(sessionId)
+ }
+ }
+
+ listener?.onGlobalError(globalError)
+ }
+
+ internal interface Listener {
+ fun onGlobalError(globalError: GlobalError)
+ }
+}
diff --git a/vector/src/main/java/im/vector/app/core/di/AssistedInjectModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt
similarity index 63%
rename from vector/src/main/java/im/vector/app/core/di/AssistedInjectModule.kt
rename to matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt
index 0ba4bedb92..47607ba893 100644
--- a/vector/src/main/java/im/vector/app/core/di/AssistedInjectModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/GlobalErrorReceiver.kt
@@ -1,11 +1,11 @@
/*
- * Copyright 2019 New Vector Ltd
+ * Copyright 2021 The Matrix.org Foundation C.I.C.
*
* 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
+ * 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,
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-package im.vector.app.core.di
+package org.matrix.android.sdk.internal.network
-import com.squareup.inject.assisted.dagger2.AssistedModule
-import dagger.Module
+import org.matrix.android.sdk.api.failure.GlobalError
-@AssistedModule
-@Module(includes = [AssistedInject_AssistedInjectModule::class])
-interface AssistedInjectModule
+internal interface GlobalErrorReceiver {
+ fun handleGlobalError(globalError: GlobalError)
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt
index 2535a5347a..442029127d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/Request.kt
@@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.network
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.internal.network.ssl.CertUtil
@@ -27,10 +26,10 @@ import retrofit2.awaitResponse
import timber.log.Timber
import java.io.IOException
-internal suspend inline fun executeRequest(eventBus: EventBus?,
- block: Request.() -> Unit) = Request(eventBus).apply(block).execute()
+internal suspend inline fun executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
+ block: Request.() -> Unit) = Request(globalErrorReceiver).apply(block).execute()
-internal class Request(private val eventBus: EventBus?) {
+internal class Request(private val globalErrorReceiver: GlobalErrorReceiver?) {
var isRetryable = false
var initialDelay: Long = 100L
@@ -47,7 +46,7 @@ internal class Request(private val eventBus: EventBus?) {
response.body()
?: throw IllegalStateException("The request returned a null body")
} else {
- throw response.toFailure(eventBus)
+ throw response.toFailure(globalErrorReceiver)
}
} catch (exception: Throwable) {
// Log some details about the request which has failed
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt
index c54af571d8..dd5a69dd3c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/RetrofitExtensions.kt
@@ -25,7 +25,6 @@ import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.internal.di.MoshiProvider
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.ResponseBody
-import org.greenrobot.eventbus.EventBus
import retrofit2.Response
import timber.log.Timber
import java.io.IOException
@@ -54,18 +53,18 @@ internal suspend fun okhttp3.Call.awaitResponse(): okhttp3.Response {
/**
* Convert a retrofit Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/
-internal fun Response.toFailure(eventBus: EventBus?): Failure {
- return toFailure(errorBody(), code(), eventBus)
+internal fun Response.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure {
+ return toFailure(errorBody(), code(), globalErrorReceiver)
}
/**
* Convert a okhttp3 Response to a Failure, and eventually parse errorBody to convert it to a MatrixError
*/
-internal fun okhttp3.Response.toFailure(eventBus: EventBus?): Failure {
- return toFailure(body, code, eventBus)
+internal fun okhttp3.Response.toFailure(globalErrorReceiver: GlobalErrorReceiver?): Failure {
+ return toFailure(body, code, globalErrorReceiver)
}
-private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBus?): Failure {
+private fun toFailure(errorBody: ResponseBody?, httpCode: Int, globalErrorReceiver: GlobalErrorReceiver?): Failure {
if (errorBody == null) {
return Failure.Unknown(RuntimeException("errorBody should not be null"))
}
@@ -79,12 +78,12 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int, eventBus: EventBu
if (matrixError != null) {
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) {
- // Also send this error to the bus, for a global management
- eventBus?.post(GlobalError.ConsentNotGivenError(matrixError.consentUri))
+ // Also send this error to the globalErrorReceiver, for a global management
+ globalErrorReceiver?.handleGlobalError(GlobalError.ConsentNotGivenError(matrixError.consentUri))
} else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) {
- // Also send this error to the bus, for a global management
- eventBus?.post(GlobalError.InvalidToken(matrixError.isSoftLogout))
+ // Also send this error to the globalErrorReceiver, for a global management
+ globalErrorReceiver?.handleGlobalError(GlobalError.InvalidToken(matrixError.isSoftLogout))
}
return Failure.ServerError(matrixError, httpCode)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt
index c5f3f65a34..fa07b16c32 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultSession.kt
@@ -19,12 +19,7 @@ package org.matrix.android.sdk.internal.session
import androidx.annotation.MainThread
import dagger.Lazy
import io.realm.RealmConfiguration
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
-import org.greenrobot.eventbus.EventBus
-import org.greenrobot.eventbus.Subscribe
-import org.greenrobot.eventbus.ThreadMode
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.failure.GlobalError
@@ -65,13 +60,12 @@ import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.SessionId
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
import org.matrix.android.sdk.internal.di.WorkManagerProvider
+import org.matrix.android.sdk.internal.network.GlobalErrorHandler
import org.matrix.android.sdk.internal.session.identity.DefaultIdentityService
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
import org.matrix.android.sdk.internal.session.sync.job.SyncThread
import org.matrix.android.sdk.internal.session.sync.job.SyncWorker
-import org.matrix.android.sdk.internal.task.TaskExecutor
-import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
import org.matrix.android.sdk.internal.util.createUIHandler
import timber.log.Timber
import javax.inject.Inject
@@ -81,7 +75,7 @@ import javax.inject.Provider
internal class DefaultSession @Inject constructor(
override val sessionParams: SessionParams,
private val workManagerProvider: WorkManagerProvider,
- private val eventBus: EventBus,
+ private val globalErrorHandler: GlobalErrorHandler,
@SessionId
override val sessionId: String,
@SessionDatabase private val realmConfiguration: RealmConfiguration,
@@ -117,10 +111,8 @@ internal class DefaultSession @Inject constructor(
private val accountDataService: Lazy,
private val _sharedSecretStorageService: Lazy,
private val accountService: Lazy,
- private val coroutineDispatchers: MatrixCoroutineDispatchers,
private val defaultIdentityService: DefaultIdentityService,
private val integrationManagerService: IntegrationManagerService,
- private val taskExecutor: TaskExecutor,
private val callSignalingService: Lazy,
@UnauthenticatedWithCertificate
private val unauthenticatedWithCertificateOkHttpClient: Lazy,
@@ -140,7 +132,8 @@ internal class DefaultSession @Inject constructor(
HomeServerCapabilitiesService by homeServerCapabilitiesService.get(),
ProfileService by profileService.get(),
AccountDataService by accountDataService.get(),
- AccountService by accountService.get() {
+ AccountService by accountService.get(),
+ GlobalErrorHandler.Listener {
override val sharedSecretStorageService: SharedSecretStorageService
get() = _sharedSecretStorageService.get()
@@ -162,7 +155,7 @@ internal class DefaultSession @Inject constructor(
uiHandler.post {
lifecycleObservers.forEach { it.onStart() }
}
- eventBus.register(this)
+ globalErrorHandler.listener = this
eventSenderProcessor.start()
}
@@ -206,7 +199,7 @@ internal class DefaultSession @Inject constructor(
}
cryptoService.get().close()
isOpen = false
- eventBus.unregister(this)
+ globalErrorHandler.listener = null
eventSenderProcessor.interrupt()
}
@@ -234,16 +227,7 @@ internal class DefaultSession @Inject constructor(
workManagerProvider.cancelAllWorks()
}
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onGlobalError(globalError: GlobalError) {
- if (globalError is GlobalError.InvalidToken
- && globalError.softLogout) {
- // Mark the token has invalid
- taskExecutor.executorScope.launch(Dispatchers.IO) {
- sessionParamsStore.setTokenInvalid(sessionId)
- }
- }
-
+ override fun onGlobalError(globalError: GlobalError) {
sessionListeners.dispatchGlobalError(globalError)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionComponent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionComponent.kt
index 659fcc8f5c..f5eade1704 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionComponent.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionComponent.kt
@@ -27,7 +27,6 @@ import org.matrix.android.sdk.internal.crypto.SendGossipWorker
import org.matrix.android.sdk.internal.crypto.crosssigning.UpdateTrustWorker
import org.matrix.android.sdk.internal.crypto.verification.SendVerificationMessageWorker
import org.matrix.android.sdk.internal.di.MatrixComponent
-import org.matrix.android.sdk.internal.di.SessionAssistedInjectModule
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
import org.matrix.android.sdk.internal.session.account.AccountModule
import org.matrix.android.sdk.internal.session.cache.CacheModule
@@ -86,7 +85,6 @@ import org.matrix.android.sdk.internal.util.MatrixCoroutineDispatchers
TermsModule::class,
AccountDataModule::class,
ProfileModule::class,
- SessionAssistedInjectModule::class,
AccountModule::class,
CallModule::class,
SearchModule::class
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt
index 96b44917bd..468c193ad3 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/SessionModule.kt
@@ -26,7 +26,6 @@ import dagger.Provides
import dagger.multibindings.IntoSet
import io.realm.RealmConfiguration
import okhttp3.OkHttpClient
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.MatrixConfiguration
import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
@@ -61,9 +60,10 @@ import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificate
import org.matrix.android.sdk.internal.di.UnauthenticatedWithCertificateWithProgress
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.di.UserMd5
-import org.matrix.android.sdk.internal.eventbus.EventBusTimberLogger
import org.matrix.android.sdk.internal.network.DefaultNetworkConnectivityChecker
import org.matrix.android.sdk.internal.network.FallbackNetworkCallbackStrategy
+import org.matrix.android.sdk.internal.network.GlobalErrorHandler
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.NetworkCallbackStrategy
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
import org.matrix.android.sdk.internal.network.PreferredNetworkCallbackStrategy
@@ -256,16 +256,6 @@ internal abstract class SessionModule {
.create(okHttpClient, sessionParams.homeServerConnectionConfig.homeServerUri.toString())
}
- @JvmStatic
- @Provides
- @SessionScope
- fun providesEventBus(): EventBus {
- return EventBus
- .builder()
- .logger(EventBusTimberLogger())
- .build()
- }
-
@JvmStatic
@Provides
@SessionScope
@@ -294,6 +284,9 @@ internal abstract class SessionModule {
@Binds
abstract fun bindSession(session: DefaultSession): Session
+ @Binds
+ abstract fun bindGlobalErrorReceiver(handler: GlobalErrorHandler): GlobalErrorReceiver
+
@Binds
abstract fun bindNetworkConnectivityChecker(checker: DefaultNetworkConnectivityChecker): NetworkConnectivityChecker
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt
index 869d3f516c..1f043b0a9d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/ChangePasswordTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.account
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface ChangePasswordTask : Task {
@@ -32,14 +32,14 @@ internal interface ChangePasswordTask : Task {
internal class DefaultChangePasswordTask @Inject constructor(
private val accountAPI: AccountAPI,
- private val eventBus: EventBus,
+ private val globalErrorReceiver: GlobalErrorReceiver,
@UserId private val userId: String
) : ChangePasswordTask {
override suspend fun execute(params: ChangePasswordTask.Params) {
val changePasswordParams = ChangePasswordParams.create(userId, params.password, params.newPassword)
try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = accountAPI.changePassword(changePasswordParams)
}
} catch (throwable: Throwable) {
@@ -49,7 +49,7 @@ internal class DefaultChangePasswordTask @Inject constructor(
/* Avoid infinite loop */
&& changePasswordParams.auth?.session == null) {
// Retry with authentication
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = accountAPI.changePassword(
changePasswordParams.copy(auth = changePasswordParams.auth?.copy(session = registrationFlowResponse.session))
)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt
index ac5febcdae..9fb1cbb7d7 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/account/DeactivateAccountTask.kt
@@ -17,11 +17,11 @@
package org.matrix.android.sdk.internal.session.account
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.cleanup.CleanupSession
import org.matrix.android.sdk.internal.session.identity.IdentityDisconnectTask
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@@ -34,7 +34,7 @@ internal interface DeactivateAccountTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = accountAPI.deactivate(deactivateAccountParams)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt
index 1cedee3374..b21ec1113a 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/GetTurnServerTask.kt
@@ -17,9 +17,9 @@
package org.matrix.android.sdk.internal.session.call
import org.matrix.android.sdk.api.session.call.TurnServerResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal abstract class GetTurnServerTask : Task {
@@ -27,10 +27,10 @@ internal abstract class GetTurnServerTask : Task
if (!response.isSuccessful) {
- throw response.toFailure(eventBus)
+ throw response.toFailure(globalErrorReceiver)
} else {
response.body?.source()?.let {
responseAdapter.fromJson(it)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt
index 69ced92fe5..da747934e2 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/SaveFilterTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.filter
import org.matrix.android.sdk.api.session.sync.FilterService
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
/**
@@ -37,7 +37,7 @@ internal class DefaultSaveFilterTask @Inject constructor(
@UserId private val userId: String,
private val filterAPI: FilterApi,
private val filterRepository: FilterRepository,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : SaveFilterTask {
override suspend fun execute(params: SaveFilterTask.Params) {
@@ -59,7 +59,7 @@ internal class DefaultSaveFilterTask @Inject constructor(
}
val updated = filterRepository.storeFilter(filterBody, roomFilter)
if (updated) {
- val filterResponse = executeRequest(eventBus) {
+ val filterResponse = executeRequest(globalErrorReceiver) {
// TODO auto retry
apiCall = filterAPI.uploadFilter(userId, filterBody)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt
index dd703a5e93..9836164aec 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/group/GetGroupDataTask.kt
@@ -23,13 +23,13 @@ import org.matrix.android.sdk.internal.database.model.GroupSummaryEntity
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.group.model.GroupRooms
import org.matrix.android.sdk.internal.session.group.model.GroupSummaryResponse
import org.matrix.android.sdk.internal.session.group.model.GroupUsers
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
-import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@@ -43,7 +43,7 @@ internal interface GetGroupDataTask : Task {
internal class DefaultGetGroupDataTask @Inject constructor(
private val groupAPI: GroupAPI,
@SessionDatabase private val monarchy: Monarchy,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetGroupDataTask {
private data class GroupData(
@@ -64,13 +64,13 @@ internal class DefaultGetGroupDataTask @Inject constructor(
}
Timber.v("Fetch data for group with ids: ${groupIds.joinToString(";")}")
val data = groupIds.map { groupId ->
- val groupSummary = executeRequest(eventBus) {
+ val groupSummary = executeRequest(globalErrorReceiver) {
apiCall = groupAPI.getSummary(groupId)
}
- val groupRooms = executeRequest(eventBus) {
+ val groupRooms = executeRequest(globalErrorReceiver) {
apiCall = groupAPI.getRooms(groupId)
}
- val groupUsers = executeRequest(eventBus) {
+ val groupUsers = executeRequest(globalErrorReceiver) {
apiCall = groupAPI.getUsers(groupId)
}
GroupData(groupId, groupSummary, groupRooms, groupUsers)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt
index f3686b02d3..845cfb392e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/homeserver/GetHomeServerCapabilitiesTask.kt
@@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.homeserver
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
@@ -27,6 +26,7 @@ import org.matrix.android.sdk.internal.database.model.HomeServerCapabilitiesEnti
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationManagerConfigExtractor
import org.matrix.android.sdk.internal.session.media.GetMediaConfigResult
@@ -44,7 +44,7 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
private val capabilitiesAPI: CapabilitiesAPI,
private val mediaAPI: MediaAPI,
@SessionDatabase private val monarchy: Monarchy,
- private val eventBus: EventBus,
+ private val globalErrorReceiver: GlobalErrorReceiver,
private val getWellknownTask: GetWellknownTask,
private val configExtractor: IntegrationManagerConfigExtractor,
private val homeServerConnectionConfig: HomeServerConnectionConfig,
@@ -65,13 +65,13 @@ internal class DefaultGetHomeServerCapabilitiesTask @Inject constructor(
}
val capabilities = runCatching {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = capabilitiesAPI.getCapabilities()
}
}.getOrNull()
val mediaConfig = runCatching {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = mediaAPI.getMediaConfig()
}
}.getOrNull()
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt
index 69cdfa8faa..a218f3f93c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetPreviewUrlTask.kt
@@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.media
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.cache.CacheStrategy
import org.matrix.android.sdk.api.session.media.PreviewUrlData
import org.matrix.android.sdk.api.util.JsonDict
@@ -25,6 +24,7 @@ import org.matrix.android.sdk.internal.database.model.PreviewUrlCacheEntity
import org.matrix.android.sdk.internal.database.query.get
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
@@ -41,7 +41,7 @@ internal interface GetPreviewUrlTask : Task(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = mediaAPI.getPreviewUrlData(url, timestamp)
}
.toPreviewUrlData(url)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt
index 6c5dad2422..32305cd4e4 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/GetRawPreviewUrlTask.kt
@@ -16,8 +16,8 @@
package org.matrix.android.sdk.internal.session.media
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.util.JsonDict
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject
@@ -31,11 +31,11 @@ internal interface GetRawPreviewUrlTask : Task
@@ -27,10 +27,10 @@ internal interface GetOpenIdTokenTask : Task
internal class DefaultGetOpenIdTokenTask @Inject constructor(
@UserId private val userId: String,
private val openIdAPI: OpenIdAPI,
- private val eventBus: EventBus) : GetOpenIdTokenTask {
+ private val globalErrorReceiver: GlobalErrorReceiver) : GetOpenIdTokenTask {
override suspend fun execute(params: Unit): RequestOpenIdTokenResponse {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = openIdAPI.openIdToken(userId)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt
index 2e8a0b3884..6d6d70bb0d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/AddThreePidTask.kt
@@ -18,9 +18,9 @@ package org.matrix.android.sdk.internal.session.profile
import com.google.i18n.phonenumbers.PhoneNumberUtil
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
@@ -37,7 +37,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
private val profileAPI: ProfileAPI,
@SessionDatabase private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper,
- private val eventBus: EventBus) : AddThreePidTask() {
+ private val globalErrorReceiver: GlobalErrorReceiver) : AddThreePidTask() {
override suspend fun execute(params: Params) {
when (params.threePid) {
@@ -50,7 +50,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
val clientSecret = UUID.randomUUID().toString()
val sendAttempt = 1
- val result = executeRequest(eventBus) {
+ val result = executeRequest(globalErrorReceiver) {
val body = AddEmailBody(
clientSecret = clientSecret,
email = threePid.email,
@@ -84,7 +84,7 @@ internal class DefaultAddThreePidTask @Inject constructor(
val countryCode = parsedNumber.countryCode
val country = phoneNumberUtil.getRegionCodeForCountryCode(countryCode)
- val result = executeRequest(eventBus) {
+ val result = executeRequest(globalErrorReceiver) {
val body = AddMsisdnBody(
clientSecret = clientSecret,
country = country,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt
index dbe6bff508..a37e5380bc 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidsTask.kt
@@ -19,12 +19,12 @@ package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.di.AuthenticatedIdentity
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.network.token.AccessTokenProvider
import org.matrix.android.sdk.internal.session.identity.data.IdentityStore
import org.matrix.android.sdk.internal.session.identity.data.getIdentityServerUrlWithoutProtocol
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal abstract class BindThreePidsTask : Task {
@@ -37,13 +37,13 @@ internal class DefaultBindThreePidsTask @Inject constructor(private val profileA
private val identityStore: IdentityStore,
@AuthenticatedIdentity
private val accessTokenProvider: AccessTokenProvider,
- private val eventBus: EventBus) : BindThreePidsTask() {
+ private val globalErrorReceiver: GlobalErrorReceiver) : BindThreePidsTask() {
override suspend fun execute(params: Params) {
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured
val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured
val identityPendingBinding = identityStore.getPendingBinding(params.threePid) ?: throw IdentityServiceError.NoCurrentBindingError
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = profileAPI.bindThreePid(
BindThreePidBody(
clientSecret = identityPendingBinding.clientSecret,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt
index 3f43cbe599..3549f3613f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DeleteThreePidTask.kt
@@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.session.identity.toMedium
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject
@@ -31,10 +31,10 @@ internal abstract class DeleteThreePidTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
val body = DeleteThreePidBody(
medium = params.threePid.toMedium(),
address = params.threePid.value
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt
index 0b1bf88280..1e3a2cb501 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/FinalizeAddingThreePidTask.kt
@@ -17,7 +17,6 @@
package org.matrix.android.sdk.internal.session.profile
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.toRegistrationFlowResponse
import org.matrix.android.sdk.api.session.identity.ThreePid
@@ -26,6 +25,7 @@ import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntityFields
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
@@ -45,7 +45,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
@SessionDatabase private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper,
@UserId private val userId: String,
- private val eventBus: EventBus) : FinalizeAddingThreePidTask() {
+ private val globalErrorReceiver: GlobalErrorReceiver) : FinalizeAddingThreePidTask() {
override suspend fun execute(params: Params) {
if (params.userWantsToCancel.not()) {
@@ -58,7 +58,7 @@ internal class DefaultFinalizeAddingThreePidTask @Inject constructor(
?: throw IllegalArgumentException("unknown threepid")
try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
val body = FinalizeAddThreePidBody(
clientSecret = pendingThreePids.clientSecret,
sid = pendingThreePids.sid,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt
index 5f1f621ddb..ed60c4a368 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/GetProfileInfoTask.kt
@@ -18,9 +18,9 @@
package org.matrix.android.sdk.internal.session.profile
import org.matrix.android.sdk.api.util.JsonDict
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal abstract class GetProfileInfoTask : Task {
@@ -30,10 +30,10 @@ internal abstract class GetProfileInfoTask : Task
internal class DefaultRefreshUserThreePidsTask @Inject constructor(private val profileAPI: ProfileAPI,
@SessionDatabase private val monarchy: Monarchy,
- private val eventBus: EventBus) : RefreshUserThreePidsTask() {
+ private val globalErrorReceiver: GlobalErrorReceiver) : RefreshUserThreePidsTask() {
override suspend fun execute(params: Unit) {
- val accountThreePidsResponse = executeRequest(eventBus) {
+ val accountThreePidsResponse = executeRequest(globalErrorReceiver) {
apiCall = profileAPI.getThreePIDs()
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt
index 4b863c2098..b29153d665 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetAvatarUrlTask.kt
@@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal abstract class SetAvatarUrlTask : Task {
@@ -30,10 +30,10 @@ internal abstract class SetAvatarUrlTask : Task {
internal class DefaultSetAvatarUrlTask @Inject constructor(
private val profileAPI: ProfileAPI,
- private val eventBus: EventBus) : SetAvatarUrlTask() {
+ private val globalErrorReceiver: GlobalErrorReceiver) : SetAvatarUrlTask() {
override suspend fun execute(params: Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
val body = SetAvatarUrlBody(
avatarUrl = params.newAvatarUrl
)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt
index 1fa84f98c1..3f236bc589 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/SetDisplayNameTask.kt
@@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.profile
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal abstract class SetDisplayNameTask : Task {
@@ -30,10 +30,10 @@ internal abstract class SetDisplayNameTask : Task {
@@ -34,12 +34,12 @@ internal abstract class UnbindThreePidsTask : Task(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = profileAPI.unbindThreePid(
UnbindThreePidBody(
identityServerUrlWithoutProtocol,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt
index 36804e06fe..efb6c6e836 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/ValidateSmsCodeTask.kt
@@ -17,13 +17,13 @@
package org.matrix.android.sdk.internal.session.profile
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.internal.auth.registration.SuccessResult
import org.matrix.android.sdk.internal.auth.registration.ValidationCodeBody
import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import javax.inject.Inject
@@ -40,7 +40,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor(
@SessionDatabase
private val monarchy: Monarchy,
private val pendingThreePidMapper: PendingThreePidMapper,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : ValidateSmsCodeTask {
override suspend fun execute(params: ValidateSmsCodeTask.Params) {
@@ -58,7 +58,7 @@ internal class DefaultValidateSmsCodeTask @Inject constructor(
sid = pendingThreePids.sid,
code = params.code
)
- val result = executeRequest(eventBus) {
+ val result = executeRequest(globalErrorReceiver) {
apiCall = profileAPI.validateMsisdn(url, body)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt
index 31c5cda5ec..d0f7cbfca3 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddHttpPusherWorker.kt
@@ -19,13 +19,13 @@ import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
import com.zhuinden.monarchy.Monarchy
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.pushers.PusherState
import org.matrix.android.sdk.internal.database.mapper.toEntity
import org.matrix.android.sdk.internal.database.model.PusherEntity
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.util.awaitTransaction
@@ -45,7 +45,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
@Inject lateinit var pushersAPI: PushersAPI
@Inject @SessionDatabase lateinit var monarchy: Monarchy
- @Inject lateinit var eventBus: EventBus
+ @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
override fun injectWith(injector: SessionComponent) {
injector.inject(this)
@@ -81,7 +81,7 @@ internal class AddHttpPusherWorker(context: Context, params: WorkerParameters)
}
private suspend fun setPusher(pusher: JsonPusher) {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = pushersAPI.setPusher(pusher)
}
monarchy.awaitTransaction { realm ->
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt
index 28ac5db52e..03748b1528 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPushRuleTask.kt
@@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface AddPushRuleTask : Task {
@@ -31,11 +31,11 @@ internal interface AddPushRuleTask : Task {
internal class DefaultAddPushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : AddPushRuleTask {
override suspend fun execute(params: AddPushRuleTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.addRule(params.kind.value, params.pushRule.ruleId, params.pushRule)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt
index 0c532cedbc..9fb2d51664 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushRulesTask.kt
@@ -16,9 +16,9 @@
package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.rest.GetPushRulesResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPushRulesTask : Task {
@@ -31,11 +31,11 @@ internal interface GetPushRulesTask : Task {
internal class DefaultGetPushRulesTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
private val savePushRulesTask: SavePushRulesTask,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetPushRulesTask {
override suspend fun execute(params: GetPushRulesTask.Params) {
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.getAllRules()
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt
index 39e970f4a8..4c7d370446 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/GetPushersTask.kt
@@ -20,10 +20,10 @@ import org.matrix.android.sdk.api.session.pushers.PusherState
import org.matrix.android.sdk.internal.database.mapper.toEntity
import org.matrix.android.sdk.internal.database.model.PusherEntity
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPushersTask : Task
@@ -31,11 +31,11 @@ internal interface GetPushersTask : Task
internal class DefaultGetPushersTask @Inject constructor(
private val pushersAPI: PushersAPI,
@SessionDatabase private val monarchy: Monarchy,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetPushersTask {
override suspend fun execute(params: Unit) {
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
apiCall = pushersAPI.getPushers()
}
monarchy.awaitTransaction { realm ->
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt
index 2fc97cf023..ff3122f566 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePushRuleTask.kt
@@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface RemovePushRuleTask : Task {
@@ -31,11 +31,11 @@ internal interface RemovePushRuleTask : Task {
internal class DefaultRemovePushRuleTask @Inject constructor(
private val pushRulesApi: PushRulesApi,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : RemovePushRuleTask {
override suspend fun execute(params: RemovePushRuleTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.deleteRule(params.kind.value, params.pushRule.ruleId)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt
index 1f10863799..e3f4fdb789 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/RemovePusherTask.kt
@@ -26,7 +26,7 @@ import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
import io.realm.Realm
-import org.greenrobot.eventbus.EventBus
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import javax.inject.Inject
internal interface RemovePusherTask : Task {
@@ -37,7 +37,7 @@ internal interface RemovePusherTask : Task {
internal class DefaultRemovePusherTask @Inject constructor(
private val pushersAPI: PushersAPI,
@SessionDatabase private val monarchy: Monarchy,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : RemovePusherTask {
override suspend fun execute(params: RemovePusherTask.Params) {
@@ -62,7 +62,7 @@ internal class DefaultRemovePusherTask @Inject constructor(
data = JsonPusherData(existing.data.url, existing.data.format),
append = false
)
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = pushersAPI.setPusher(deleteBody)
}
monarchy.awaitTransaction {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt
index c2dca8a9a5..a5c220e662 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleActionsTask.kt
@@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdatePushRuleActionsTask : Task {
@@ -32,13 +32,13 @@ internal interface UpdatePushRuleActionsTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.updateEnableRuleStatus(params.kind.value, params.newPushRule.ruleId, params.newPushRule.enabled)
}
}
@@ -47,7 +47,7 @@ internal class DefaultUpdatePushRuleActionsTask @Inject constructor(
// Also ensure the actions are up to date
val body = mapOf("actions" to params.newPushRule.actions)
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = pushRulesApi.updateRuleActions(params.kind.value, params.newPushRule.ruleId, body)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt
index 4100071c90..f36b5c55fb 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/UpdatePushRuleEnableStatusTask.kt
@@ -17,9 +17,9 @@ package org.matrix.android.sdk.internal.session.pushers
import org.matrix.android.sdk.api.pushrules.RuleKind
import org.matrix.android.sdk.api.pushrules.rest.PushRule
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface UpdatePushRuleEnableStatusTask : Task {
@@ -30,11 +30,11 @@ internal interface UpdatePushRuleEnableStatusTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.addRoomAlias(
roomAlias = params.aliasLocalPart.toFullLocalAlias(userId),
body = AddRoomAliasBody(
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DefaultAliasService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DefaultAliasService.kt
index b6c69224e6..8f58094a2a 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DefaultAliasService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DefaultAliasService.kt
@@ -16,8 +16,9 @@
package org.matrix.android.sdk.internal.session.room.alias
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import org.matrix.android.sdk.api.session.room.alias.AliasService
internal class DefaultAliasService @AssistedInject constructor(
@@ -26,9 +27,9 @@ internal class DefaultAliasService @AssistedInject constructor(
private val addRoomAliasTask: AddRoomAliasTask
) : AliasService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): AliasService
+ fun create(roomId: String): DefaultAliasService
}
override suspend fun getRoomAliases(): List {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt
index 3400fd994c..6ad3db90a9 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/DeleteRoomAliasTask.kt
@@ -16,7 +16,7 @@
package org.matrix.android.sdk.internal.session.room.alias
-import org.greenrobot.eventbus.EventBus
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.task.Task
@@ -30,11 +30,11 @@ internal interface DeleteRoomAliasTask : Task
internal class DefaultDeleteRoomAliasTask @Inject constructor(
private val directoryAPI: DirectoryAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : DeleteRoomAliasTask {
override suspend fun execute(params: DeleteRoomAliasTask.Params) {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.deleteRoomAlias(
roomAlias = params.roomAlias
)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt
index 543d605707..a53ffc4fcd 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomIdByAliasTask.kt
@@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.alias
import com.zhuinden.monarchy.Monarchy
import io.realm.Realm
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.query.findByAlias
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.task.Task
@@ -39,7 +39,7 @@ internal interface GetRoomIdByAliasTask : Task {
@@ -52,7 +52,7 @@ internal class DefaultGetRoomIdByAliasTask @Inject constructor(
Optional.from(null)
} else {
val description = tryOrNull("## Failed to get roomId from alias") {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.getRoomIdByAlias(params.roomAlias)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt
index 7cfce4ecdc..202cb1f6de 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/GetRoomLocalAliasesTask.kt
@@ -16,7 +16,7 @@
package org.matrix.android.sdk.internal.session.room.alias
-import org.greenrobot.eventbus.EventBus
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
@@ -30,12 +30,12 @@ internal interface GetRoomLocalAliasesTask : Task {
// We do not check for "org.matrix.msc2432", so the API may be missing
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.getAliases(roomId = params.roomId)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt
index 25ba493891..51a849a35e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/alias/RoomAliasAvailabilityChecker.kt
@@ -16,10 +16,10 @@
package org.matrix.android.sdk.internal.session.room.alias
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.room.alias.RoomAliasError
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import javax.inject.Inject
@@ -27,7 +27,7 @@ import javax.inject.Inject
internal class RoomAliasAvailabilityChecker @Inject constructor(
@UserId private val userId: String,
private val directoryAPI: DirectoryAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) {
/**
* @param aliasLocalPart the local part of the alias.
@@ -41,7 +41,7 @@ internal class RoomAliasAvailabilityChecker @Inject constructor(
// Check alias availability
val fullAlias = aliasLocalPart.toFullLocalAlias(userId)
try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.getRoomIdByAlias(fullAlias)
}
} catch (throwable: Throwable) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/call/DefaultRoomCallService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/call/DefaultRoomCallService.kt
index 205a085df6..9bde5054f6 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/call/DefaultRoomCallService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/call/DefaultRoomCallService.kt
@@ -16,8 +16,9 @@
package org.matrix.android.sdk.internal.session.room.call
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.room.call.RoomCallService
import org.matrix.android.sdk.internal.session.room.RoomGetter
@@ -27,9 +28,9 @@ internal class DefaultRoomCallService @AssistedInject constructor(
private val roomGetter: RoomGetter
) : RoomCallService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): RoomCallService
+ fun create(roomId: String): DefaultRoomCallService
}
override fun canStartCall(): Boolean {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt
index ef792ab98e..9c16bd1b0f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateRoomTask.kt
@@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.room.create
import com.zhuinden.monarchy.Monarchy
import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.failure.MatrixError
import org.matrix.android.sdk.api.session.room.alias.RoomAliasError
@@ -32,6 +31,7 @@ import org.matrix.android.sdk.internal.database.model.RoomEntityFields
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.session.room.alias.RoomAliasAvailabilityChecker
@@ -55,7 +55,7 @@ internal class DefaultCreateRoomTask @Inject constructor(
@SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val createRoomBodyBuilder: CreateRoomBodyBuilder,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : CreateRoomTask {
override suspend fun execute(params: CreateRoomParams): String {
@@ -75,7 +75,7 @@ internal class DefaultCreateRoomTask @Inject constructor(
val createRoomBody = createRoomBodyBuilder.build(params)
val createRoomResponse = try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.createRoom(createRoomBody)
}
} catch (throwable: Throwable) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt
index f2bd0c5f69..edd8ae9b0d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetPublicRoomTask.kt
@@ -18,10 +18,10 @@ package org.matrix.android.sdk.internal.session.room.directory
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsParams
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoomsResponse
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetPublicRoomTask : Task {
@@ -33,11 +33,11 @@ internal interface GetPublicRoomTask : Task(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.getRoomDirectoryVisibility(params.roomId)
}
.visibility
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt
index 5e08284706..3477aa671e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/GetThirdPartyProtocolsTask.kt
@@ -17,21 +17,21 @@
package org.matrix.android.sdk.internal.session.room.directory
import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetThirdPartyProtocolsTask : Task>
internal class DefaultGetThirdPartyProtocolsTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetThirdPartyProtocolsTask {
override suspend fun execute(params: Unit): Map {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomAPI.thirdPartyProtocols()
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt
index 33b12aa1ca..cbb0b6d5d1 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/directory/SetRoomDirectoryVisibilityTask.kt
@@ -16,8 +16,8 @@
package org.matrix.android.sdk.internal.session.room.directory
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.directory.DirectoryAPI
import org.matrix.android.sdk.internal.session.directory.RoomDirectoryVisibilityJson
@@ -33,11 +33,11 @@ internal interface SetRoomDirectoryVisibilityTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = directoryAPI.setRoomDirectoryVisibility(
params.roomId,
RoomDirectoryVisibilityJson(visibility = params.roomDirectoryVisibility)
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/draft/DefaultDraftService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/draft/DefaultDraftService.kt
index 93fbfb4df0..1d4ab6d516 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/draft/DefaultDraftService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/draft/DefaultDraftService.kt
@@ -17,8 +17,9 @@
package org.matrix.android.sdk.internal.session.room.draft
import androidx.lifecycle.LiveData
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.session.room.send.DraftService
import org.matrix.android.sdk.api.session.room.send.UserDraft
@@ -30,9 +31,9 @@ internal class DefaultDraftService @AssistedInject constructor(@Assisted private
private val coroutineDispatchers: MatrixCoroutineDispatchers
) : DraftService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): DraftService
+ fun create(roomId: String): DefaultDraftService
}
/**
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/DefaultMembershipService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/DefaultMembershipService.kt
index 4fc865304b..cd1c9bbbdd 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/DefaultMembershipService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/DefaultMembershipService.kt
@@ -17,8 +17,9 @@
package org.matrix.android.sdk.internal.session.room.membership
import androidx.lifecycle.LiveData
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.identity.ThreePid
@@ -58,9 +59,9 @@ internal class DefaultMembershipService @AssistedInject constructor(
private val userId: String
) : MembershipService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): MembershipService
+ fun create(roomId: String): DefaultMembershipService
}
override fun loadRoomMembersIfNeeded(matrixCallback: MatrixCallback): Cancelable {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt
index 627f927ad8..2be90bf8e3 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt
@@ -17,25 +17,30 @@
package org.matrix.android.sdk.internal.session.room.membership
import com.zhuinden.monarchy.Monarchy
+import io.realm.Realm
+import io.realm.kotlin.createObject
+import kotlinx.coroutines.TimeoutCancellationException
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.send.SendState
+import org.matrix.android.sdk.internal.database.awaitNotEmptyResult
import org.matrix.android.sdk.internal.database.mapper.toEntity
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
import org.matrix.android.sdk.internal.database.model.EventInsertType
import org.matrix.android.sdk.internal.database.model.RoomEntity
+import org.matrix.android.sdk.internal.database.model.RoomEntityFields
+import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore
import org.matrix.android.sdk.internal.database.query.getOrCreate
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
-import io.realm.Realm
-import io.realm.kotlin.createObject
-import org.greenrobot.eventbus.EventBus
+import java.util.concurrent.TimeUnit
import javax.inject.Inject
internal interface LoadRoomMembersTask : Task {
@@ -52,17 +57,44 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
private val syncTokenStore: SyncTokenStore,
private val roomSummaryUpdater: RoomSummaryUpdater,
private val roomMemberEventHandler: RoomMemberEventHandler,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : LoadRoomMembersTask {
override suspend fun execute(params: LoadRoomMembersTask.Params) {
- if (areAllMembersAlreadyLoaded(params.roomId)) {
- return
+ when (getRoomMembersLoadStatus(params.roomId)) {
+ RoomMembersLoadStatusType.NONE -> doRequest(params)
+ RoomMembersLoadStatusType.LOADING -> waitPreviousRequestToFinish(params)
+ RoomMembersLoadStatusType.LOADED -> Unit
}
+ }
+
+ private suspend fun waitPreviousRequestToFinish(params: LoadRoomMembersTask.Params) {
+ try {
+ awaitNotEmptyResult(monarchy.realmConfiguration, TimeUnit.MINUTES.toMillis(1L)) { realm ->
+ realm.where(RoomEntity::class.java)
+ .equalTo(RoomEntityFields.ROOM_ID, params.roomId)
+ .equalTo(RoomEntityFields.MEMBERS_LOAD_STATUS_STR, RoomMembersLoadStatusType.LOADED.name)
+ }
+ } catch (exception: TimeoutCancellationException) {
+ // Timeout, do the request anyway (?)
+ doRequest(params)
+ }
+ }
+
+ private suspend fun doRequest(params: LoadRoomMembersTask.Params) {
+ setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.LOADING)
+
val lastToken = syncTokenStore.getLastToken()
- val response = executeRequest(eventBus) {
- apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
+ val response = try {
+ executeRequest(globalErrorReceiver) {
+ apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
+ }
+ } catch (throwable: Throwable) {
+ // Revert status to NONE
+ setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.NONE)
+ throw throwable
}
+ // This will also set the status to LOADED
insertInDb(response, params.roomId)
}
@@ -84,14 +116,23 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
}
roomMemberEventHandler.handle(realm, roomId, roomMemberEvent)
}
- roomEntity.areAllMembersLoaded = true
+ roomEntity.membersLoadStatus = RoomMembersLoadStatusType.LOADED
roomSummaryUpdater.update(realm, roomId, updateMembers = true)
}
}
- private fun areAllMembersAlreadyLoaded(roomId: String): Boolean {
- return Realm.getInstance(monarchy.realmConfiguration).use {
- RoomEntity.where(it, roomId).findFirst()?.areAllMembersLoaded ?: false
+ private fun getRoomMembersLoadStatus(roomId: String): RoomMembersLoadStatusType {
+ var result: RoomMembersLoadStatusType?
+ Realm.getInstance(monarchy.realmConfiguration).use {
+ result = RoomEntity.where(it, roomId).findFirst()?.membersLoadStatus
+ }
+ return result ?: RoomMembersLoadStatusType.NONE
+ }
+
+ private suspend fun setRoomMembersLoadStatus(roomId: String, status: RoomMembersLoadStatusType) {
+ monarchy.awaitTransaction { realm ->
+ val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId)
+ roomEntity.membersLoadStatus = status
}
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt
index 854a332679..05503bd643 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/InviteTask.kt
@@ -16,10 +16,10 @@
package org.matrix.android.sdk.internal.session.room.membership.joining
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface InviteTask : Task {
@@ -32,11 +32,11 @@ internal interface InviteTask : Task {
internal class DefaultInviteTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : InviteTask {
override suspend fun execute(params: InviteTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
val body = InviteBody(params.userId, params.reason)
apiCall = roomAPI.invite(params.roomId, body)
isRetryable = true
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt
index dd1dc5fa8a..3b7639d42f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/joining/JoinRoomTask.kt
@@ -30,7 +30,7 @@ import org.matrix.android.sdk.internal.session.room.read.SetReadMarkersTask
import org.matrix.android.sdk.internal.task.Task
import io.realm.RealmConfiguration
import kotlinx.coroutines.TimeoutCancellationException
-import org.greenrobot.eventbus.EventBus
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -48,14 +48,18 @@ internal class DefaultJoinRoomTask @Inject constructor(
@SessionDatabase
private val realmConfiguration: RealmConfiguration,
private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : JoinRoomTask {
override suspend fun execute(params: JoinRoomTask.Params) {
roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.Joining)
val joinRoomResponse = try {
- executeRequest(eventBus) {
- apiCall = roomAPI.join(params.roomIdOrAlias, params.viaServers, mapOf("reason" to params.reason))
+ executeRequest(globalErrorReceiver) {
+ apiCall = roomAPI.join(
+ roomIdOrAlias = params.roomIdOrAlias,
+ viaServers = params.viaServers.take(3),
+ params = mapOf("reason" to params.reason)
+ )
}
} catch (failure: Throwable) {
roomChangeMembershipStateDataSource.updateState(params.roomIdOrAlias, ChangeMembershipState.FailedJoining(failure))
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt
index 58e34a15ec..37bb7570d1 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/leaving/LeaveRoomTask.kt
@@ -21,13 +21,13 @@ import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
import org.matrix.android.sdk.api.session.room.model.create.RoomCreateContent
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.session.room.membership.RoomChangeMembershipStateDataSource
import org.matrix.android.sdk.internal.session.room.state.StateEventDataSource
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryDataSource
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import timber.log.Timber
import javax.inject.Inject
@@ -40,7 +40,7 @@ internal interface LeaveRoomTask : Task {
internal class DefaultLeaveRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus,
+ private val globalErrorReceiver: GlobalErrorReceiver,
private val stateEventDataSource: StateEventDataSource,
private val roomSummaryDataSource: RoomSummaryDataSource,
private val roomChangeMembershipStateDataSource: RoomChangeMembershipStateDataSource
@@ -68,7 +68,7 @@ internal class DefaultLeaveRoomTask @Inject constructor(
leaveRoom(predecessorRoomId, reason)
}
try {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.leave(roomId, mapOf("reason" to reason))
}
} catch (failure: Throwable) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt
index 80af00fc78..d237ec795e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/threepid/InviteThreePidTask.kt
@@ -16,11 +16,11 @@
package org.matrix.android.sdk.internal.session.room.membership.threepid
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.identity.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.ThreePid
import org.matrix.android.sdk.api.session.identity.toMedium
import org.matrix.android.sdk.internal.di.AuthenticatedIdentity
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.network.token.AccessTokenProvider
import org.matrix.android.sdk.internal.session.identity.EnsureIdentityTokenTask
@@ -39,7 +39,7 @@ internal interface InviteThreePidTask : Task {
internal class DefaultInviteThreePidTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus,
+ private val globalErrorReceiver: GlobalErrorReceiver,
private val identityStore: IdentityStore,
private val ensureIdentityTokenTask: EnsureIdentityTokenTask,
@AuthenticatedIdentity
@@ -52,7 +52,7 @@ internal class DefaultInviteThreePidTask @Inject constructor(
val identityServerUrlWithoutProtocol = identityStore.getIdentityServerUrlWithoutProtocol() ?: throw IdentityServiceError.NoIdentityServerConfigured
val identityServerAccessToken = accessTokenProvider.getToken() ?: throw IdentityServiceError.NoIdentityServerConfigured
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
val body = ThreePidInviteBody(
idServer = identityServerUrlWithoutProtocol,
idAccessToken = identityServerAccessToken,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/notification/DefaultRoomPushRuleService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/notification/DefaultRoomPushRuleService.kt
index 67ae55c066..5486d96e28 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/notification/DefaultRoomPushRuleService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/notification/DefaultRoomPushRuleService.kt
@@ -18,8 +18,9 @@ package org.matrix.android.sdk.internal.session.room.notification
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.pushrules.RuleScope
import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState
@@ -33,9 +34,9 @@ internal class DefaultRoomPushRuleService @AssistedInject constructor(@Assisted
@SessionDatabase private val monarchy: Monarchy)
: RoomPushRuleService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): RoomPushRuleService
+ fun create(roomId: String): DefaultRoomPushRuleService
}
override fun getLiveRoomNotificationState(): LiveData {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt
index 03ea2408f0..dbec6b555c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/peeking/ResolveRoomStateTask.kt
@@ -16,8 +16,8 @@
package org.matrix.android.sdk.internal.session.room.peeking
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
@@ -31,11 +31,11 @@ internal interface ResolveRoomStateTask : Task {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomAPI.getRoomState(params.roomId)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt
index 025bea09f4..3cf8cfe5ee 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/DefaultReadService.kt
@@ -18,8 +18,9 @@ package org.matrix.android.sdk.internal.session.room.read
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.room.model.ReadReceipt
@@ -46,9 +47,9 @@ internal class DefaultReadService @AssistedInject constructor(
@UserId private val userId: String
) : ReadService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): ReadService
+ fun create(roomId: String): DefaultReadService
}
override fun markAsRead(params: ReadService.MarkAsReadParams, callback: MatrixCallback) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt
index a98bb02c83..c7f962a699 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt
@@ -33,7 +33,7 @@ import org.matrix.android.sdk.internal.session.sync.RoomFullyReadHandler
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
import io.realm.Realm
-import org.greenrobot.eventbus.EventBus
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import timber.log.Timber
import javax.inject.Inject
import kotlin.collections.set
@@ -58,7 +58,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
private val roomFullyReadHandler: RoomFullyReadHandler,
private val readReceiptHandler: ReadReceiptHandler,
@UserId private val userId: String,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : SetReadMarkersTask {
override suspend fun execute(params: SetReadMarkersTask.Params) {
@@ -96,7 +96,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
updateDatabase(params.roomId, markers, shouldUpdateRoomSummary)
}
if (markers.isNotEmpty()) {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
isRetryable = true
apiCall = roomAPI.sendReadMarker(params.roomId, markers)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/DefaultRelationService.kt
index a7f3f83980..b27cbbb0b2 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/DefaultRelationService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/DefaultRelationService.kt
@@ -17,8 +17,9 @@ package org.matrix.android.sdk.internal.session.room.relation
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.events.model.Event
@@ -56,9 +57,9 @@ internal class DefaultRelationService @AssistedInject constructor(
private val taskExecutor: TaskExecutor)
: RelationService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): RelationService
+ fun create(roomId: String): DefaultRelationService
}
override fun sendReaction(targetEventId: String, reaction: String): Cancelable {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt
index 51eecb8c2a..99d02b50da 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/FetchEditHistoryTask.kt
@@ -18,10 +18,10 @@ package org.matrix.android.sdk.internal.session.room.relation
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.RelationType
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface FetchEditHistoryTask : Task> {
@@ -35,11 +35,11 @@ internal interface FetchEditHistoryTask : Task {
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.getRelations(params.roomId,
params.eventId,
RelationType.REPLACE,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt
index 25dfe32cbb..c12597bea0 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/relation/SendRelationWorker.kt
@@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.relation
import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.relation.ReactionContent
import org.matrix.android.sdk.api.session.room.model.relation.ReactionInfo
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.session.room.RoomAPI
@@ -47,7 +47,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters)
) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI
- @Inject lateinit var eventBus: EventBus
+ @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
@Inject lateinit var localEchoRepository: LocalEchoRepository
override fun injectWith(injector: SessionComponent) {
@@ -84,7 +84,7 @@ internal class SendRelationWorker(context: Context, params: WorkerParameters)
}
private suspend fun sendRelation(roomId: String, relationType: String, relatedEventId: String, localEvent: Event) {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.sendRelation(
roomId = roomId,
parentId = relatedEventId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/DefaultReportingService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/DefaultReportingService.kt
index cac87a9d30..add17a9fa5 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/DefaultReportingService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/DefaultReportingService.kt
@@ -16,17 +16,18 @@
package org.matrix.android.sdk.internal.session.room.reporting
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import org.matrix.android.sdk.api.session.room.reporting.ReportingService
internal class DefaultReportingService @AssistedInject constructor(@Assisted private val roomId: String,
private val reportContentTask: ReportContentTask
) : ReportingService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): ReportingService
+ fun create(roomId: String): DefaultReportingService
}
override suspend fun reportContent(eventId: String, score: Int, reason: String) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt
index bd11937676..9c6e9907a4 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/reporting/ReportContentTask.kt
@@ -16,10 +16,10 @@
package org.matrix.android.sdk.internal.session.room.reporting
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface ReportContentTask : Task {
@@ -33,11 +33,11 @@ internal interface ReportContentTask : Task {
internal class DefaultReportContentTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : ReportContentTask {
override suspend fun execute(params: ReportContentTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomAPI.reportContent(params.roomId, params.eventId, ReportContentBody(params.score, params.reason))
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt
index 8828f3dfed..a12962b51f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt
@@ -21,8 +21,9 @@ import androidx.work.BackoffPolicy
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.Operation
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
import org.matrix.android.sdk.api.session.events.model.Event
@@ -71,9 +72,9 @@ internal class DefaultSendService @AssistedInject constructor(
private val cancelSendTracker: CancelSendTracker
) : SendService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): SendService
+ fun create(roomId: String): DefaultSendService
}
private val workerFutureListenerExecutor = Executors.newSingleThreadExecutor()
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt
index f4871ab35d..f742271fa7 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoRepository.kt
@@ -18,7 +18,6 @@ package org.matrix.android.sdk.internal.session.room.send
import com.zhuinden.monarchy.Monarchy
import io.realm.Realm
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
@@ -42,7 +41,7 @@ import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater
-import org.matrix.android.sdk.internal.session.room.timeline.DefaultTimeline
+import org.matrix.android.sdk.internal.session.room.timeline.TimelineInput
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.util.awaitTransaction
import timber.log.Timber
@@ -52,7 +51,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private
private val taskExecutor: TaskExecutor,
private val realmSessionProvider: RealmSessionProvider,
private val roomSummaryUpdater: RoomSummaryUpdater,
- private val eventBus: EventBus,
+ private val timelineInput: TimelineInput,
private val timelineEventMapper: TimelineEventMapper) {
fun createLocalEcho(event: Event) {
@@ -76,7 +75,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private
}
}
val timelineEvent = timelineEventMapper.map(timelineEventEntity)
- eventBus.post(DefaultTimeline.OnLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent))
+ timelineInput.onLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent)
taskExecutor.executorScope.asyncTransaction(monarchy) { realm ->
val eventInsertEntity = EventInsertEntity(event.eventId, event.type).apply {
this.insertType = EventInsertType.LOCAL_ECHO
@@ -90,7 +89,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private
fun updateSendState(eventId: String, roomId: String?, sendState: SendState) {
Timber.v("## SendEvent: [${System.currentTimeMillis()}] Update local state of $eventId to ${sendState.name}")
- eventBus.post(DefaultTimeline.OnLocalEchoUpdated(roomId ?: "", eventId, sendState))
+ timelineInput.onLocalEchoUpdated(roomId = roomId ?: "", eventId = eventId, sendState = sendState)
updateEchoAsync(eventId) { realm, sendingEventEntity ->
if (sendState == SendState.SENT && sendingEventEntity.sendState == SendState.SYNCED) {
// If already synced, do not put as sent
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt
index 682865eaee..c901c7e18e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/RedactEventWorker.kt
@@ -18,8 +18,8 @@ package org.matrix.android.sdk.internal.session.room.send
import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.Failure
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.SessionComponent
import org.matrix.android.sdk.internal.session.room.RoomAPI
@@ -46,7 +46,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters)
) : SessionWorkerParams
@Inject lateinit var roomAPI: RoomAPI
- @Inject lateinit var eventBus: EventBus
+ @Inject lateinit var globalErrorReceiver: GlobalErrorReceiver
override fun injectWith(injector: SessionComponent) {
injector.inject(this)
@@ -55,7 +55,7 @@ internal class RedactEventWorker(context: Context, params: WorkerParameters)
override suspend fun doSafeWork(params: Params): Result {
val eventId = params.eventId
return runCatching {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.redactEvent(
params.txID,
params.roomId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt
index 37a429d242..c1fc2fd9fe 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/SendEventWorker.kt
@@ -20,7 +20,6 @@ import android.content.Context
import androidx.work.WorkerParameters
import com.squareup.moshi.JsonClass
import io.realm.RealmConfiguration
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.failure.shouldBeRetried
import org.matrix.android.sdk.api.session.crypto.CryptoService
import org.matrix.android.sdk.api.session.room.send.SendState
@@ -54,7 +53,6 @@ internal class SendEventWorker(context: Context,
@Inject lateinit var localEchoRepository: LocalEchoRepository
@Inject lateinit var sendEventTask: SendEventTask
@Inject lateinit var cryptoService: CryptoService
- @Inject lateinit var eventBus: EventBus
@Inject lateinit var cancelSendTracker: CancelSendTracker
@SessionDatabase @Inject lateinit var realmConfiguration: RealmConfiguration
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt
index b546584450..f2640fd1e7 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/DefaultStateService.kt
@@ -18,8 +18,9 @@ package org.matrix.android.sdk.internal.session.room.state
import android.net.Uri
import androidx.lifecycle.LiveData
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType
@@ -35,18 +36,16 @@ import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.api.util.MimeTypes
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.internal.session.content.FileUploader
-import org.matrix.android.sdk.internal.session.room.alias.AddRoomAliasTask
internal class DefaultStateService @AssistedInject constructor(@Assisted private val roomId: String,
private val stateEventDataSource: StateEventDataSource,
private val sendStateTask: SendStateTask,
- private val fileUploader: FileUploader,
- private val addRoomAliasTask: AddRoomAliasTask
+ private val fileUploader: FileUploader
) : StateService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): StateService
+ fun create(roomId: String): DefaultStateService
}
override fun getStateEvent(eventType: String, stateKey: QueryStringValue): Event? {
@@ -74,11 +73,19 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
roomId = roomId,
stateKey = stateKey,
eventType = eventType,
- body = body
+ body = body.toSafeJson(eventType)
)
sendStateTask.execute(params)
}
+ private fun JsonDict.toSafeJson(eventType: String): JsonDict {
+ // Safe treatment for PowerLevelContent
+ return when (eventType) {
+ EventType.STATE_ROOM_POWER_LEVELS -> toSafePowerLevelsContentDict()
+ else -> this
+ }
+ }
+
override suspend fun updateTopic(topic: String) {
sendStateEvent(
eventType = EventType.STATE_ROOM_TOPIC,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt
new file mode 100644
index 0000000000..a97709e38b
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SafePowerLevelContent.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.internal.session.room.state
+
+import com.squareup.moshi.Json
+import com.squareup.moshi.JsonClass
+import org.matrix.android.sdk.api.session.events.model.toContent
+import org.matrix.android.sdk.api.session.events.model.toModel
+import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
+import org.matrix.android.sdk.api.session.room.powerlevels.Role
+import org.matrix.android.sdk.api.util.JsonDict
+
+@JsonClass(generateAdapter = true)
+internal data class SerializablePowerLevelsContent(
+ @Json(name = "ban") val ban: Int = Role.Moderator.value,
+ @Json(name = "kick") val kick: Int = Role.Moderator.value,
+ @Json(name = "invite") val invite: Int = Role.Moderator.value,
+ @Json(name = "redact") val redact: Int = Role.Moderator.value,
+ @Json(name = "events_default") val eventsDefault: Int = Role.Default.value,
+ @Json(name = "events") val events: Map = emptyMap(),
+ @Json(name = "users_default") val usersDefault: Int = Role.Default.value,
+ @Json(name = "users") val users: Map = emptyMap(),
+ @Json(name = "state_default") val stateDefault: Int = Role.Moderator.value,
+ // `Int` is the diff here (instead of `Any`)
+ @Json(name = "notifications") val notifications: Map = emptyMap()
+)
+
+internal fun JsonDict.toSafePowerLevelsContentDict(): JsonDict {
+ return toModel()
+ ?.let { content ->
+ SerializablePowerLevelsContent(
+ ban = content.ban,
+ kick = content.kick,
+ invite = content.invite,
+ redact = content.redact,
+ eventsDefault = content.eventsDefault,
+ events = content.events,
+ usersDefault = content.usersDefault,
+ users = content.users,
+ stateDefault = content.stateDefault,
+ notifications = content.notifications.mapValues { content.notificationLevel(it.key) }
+ )
+ }
+ ?.toContent()
+ ?: emptyMap()
+}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt
index 642f68c15b..63691d9207 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/state/SendStateTask.kt
@@ -17,10 +17,10 @@
package org.matrix.android.sdk.internal.session.room.state
import org.matrix.android.sdk.api.util.JsonDict
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface SendStateTask : Task {
@@ -34,11 +34,11 @@ internal interface SendStateTask : Task {
internal class DefaultSendStateTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : SendStateTask {
override suspend fun execute(params: SendStateTask.Params) {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = if (params.stateKey == null) {
roomAPI.sendStateEvent(
roomId = params.roomId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt
index 013fc86d5c..c3b5c3f78f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/AddTagToRoomTask.kt
@@ -17,10 +17,10 @@
package org.matrix.android.sdk.internal.session.room.tags
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface AddTagToRoomTask : Task {
@@ -35,11 +35,11 @@ internal interface AddTagToRoomTask : Task {
internal class DefaultAddTagToRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
@UserId private val userId: String,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : AddTagToRoomTask {
override suspend fun execute(params: AddTagToRoomTask.Params) {
- executeRequest(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.putTag(
userId = userId,
roomId = params.roomId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DefaultTagsService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DefaultTagsService.kt
index d6c02f0a49..02acaa0570 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DefaultTagsService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DefaultTagsService.kt
@@ -16,8 +16,9 @@
package org.matrix.android.sdk.internal.session.room.tags
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import org.matrix.android.sdk.api.session.room.tags.TagsService
internal class DefaultTagsService @AssistedInject constructor(
@@ -26,9 +27,9 @@ internal class DefaultTagsService @AssistedInject constructor(
private val deleteTagFromRoomTask: DeleteTagFromRoomTask
) : TagsService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): TagsService
+ fun create(roomId: String): DefaultTagsService
}
override suspend fun addTag(tag: String, order: Double?) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt
index b22355d431..d578d21fde 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/tags/DeleteTagFromRoomTask.kt
@@ -17,10 +17,10 @@
package org.matrix.android.sdk.internal.session.room.tags
import org.matrix.android.sdk.internal.di.UserId
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface DeleteTagFromRoomTask : Task {
@@ -34,11 +34,11 @@ internal interface DeleteTagFromRoomTask : Task(eventBus) {
+ executeRequest(globalErrorReceiver) {
apiCall = roomAPI.deleteTag(
userId = userId,
roomId = params.roomId,
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt
index 86b0497bd0..ae90282d52 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimeline.kt
@@ -23,10 +23,8 @@ import io.realm.RealmConfiguration
import io.realm.RealmQuery
import io.realm.RealmResults
import io.realm.Sort
-import org.greenrobot.eventbus.EventBus
-import org.greenrobot.eventbus.Subscribe
-import org.greenrobot.eventbus.ThreadMode
import org.matrix.android.sdk.api.MatrixCallback
+import org.matrix.android.sdk.api.NoOpMatrixCallback
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.events.model.EventType
@@ -53,6 +51,7 @@ import org.matrix.android.sdk.internal.database.query.filterEvents
import org.matrix.android.sdk.internal.database.query.findAllInRoomWithSendStates
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.database.query.whereRoomId
+import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
import org.matrix.android.sdk.internal.util.Debouncer
@@ -79,14 +78,13 @@ internal class DefaultTimeline(
private val timelineEventMapper: TimelineEventMapper,
private val settings: TimelineSettings,
private val hiddenReadReceipts: TimelineHiddenReadReceipts,
- private val eventBus: EventBus,
+ private val timelineInput: TimelineInput,
private val eventDecryptor: TimelineEventDecryptor,
- private val realmSessionProvider: RealmSessionProvider
-) : Timeline, TimelineHiddenReadReceipts.Delegate {
-
- data class OnNewTimelineEvents(val roomId: String, val eventIds: List)
- data class OnLocalEchoCreated(val roomId: String, val timelineEvent: TimelineEvent)
- data class OnLocalEchoUpdated(val roomId: String, val eventId: String, val sendState: SendState)
+ private val realmSessionProvider: RealmSessionProvider,
+ private val loadRoomMembersTask: LoadRoomMembersTask
+) : Timeline,
+ TimelineHiddenReadReceipts.Delegate,
+ TimelineInput.Listener {
companion object {
val BACKGROUND_HANDLER = createBackgroundHandler("TIMELINE_DB_THREAD")
@@ -158,7 +156,7 @@ internal class DefaultTimeline(
override fun start() {
if (isStarted.compareAndSet(false, true)) {
Timber.v("Start timeline for roomId: $roomId and eventId: $initialEventId")
- eventBus.register(this)
+ timelineInput.listeners.add(this)
BACKGROUND_HANDLER.post {
eventDecryptor.start()
val realm = Realm.getInstance(realmConfiguration)
@@ -184,6 +182,13 @@ internal class DefaultTimeline(
if (settings.shouldHandleHiddenReadReceipts()) {
hiddenReadReceipts.start(realm, filteredEvents, nonFilteredEvents, this)
}
+
+ loadRoomMembersTask
+ .configureWith(LoadRoomMembersTask.Params(roomId)) {
+ this.callback = NoOpMatrixCallback()
+ }
+ .executeBy(taskExecutor)
+
isReady.set(true)
}
}
@@ -196,7 +201,7 @@ internal class DefaultTimeline(
override fun dispose() {
if (isStarted.compareAndSet(true, false)) {
isReady.set(false)
- eventBus.unregister(this)
+ timelineInput.listeners.remove(this)
Timber.v("Dispose timeline for roomId: $roomId and eventId: $initialEventId")
cancelableBag.cancel()
BACKGROUND_HANDLER.removeCallbacksAndMessages(null)
@@ -313,25 +318,22 @@ internal class DefaultTimeline(
postSnapshot()
}
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onNewTimelineEvents(onNewTimelineEvents: OnNewTimelineEvents) {
- if (isLive && onNewTimelineEvents.roomId == roomId) {
+ override fun onNewTimelineEvents(roomId: String, eventIds: List) {
+ if (isLive && this.roomId == roomId) {
listeners.forEach {
- it.onNewTimelineEvents(onNewTimelineEvents.eventIds)
+ it.onNewTimelineEvents(eventIds)
}
}
}
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated) {
- if (uiEchoManager.onLocalEchoCreated(onLocalEchoCreated)) {
+ override fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent) {
+ if (uiEchoManager.onLocalEchoCreated(roomId, timelineEvent)) {
postSnapshot()
}
}
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onLocalEchoUpdated(onLocalEchoUpdated: OnLocalEchoUpdated) {
- if (uiEchoManager.onLocalEchoUpdated(onLocalEchoUpdated)) {
+ override fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState) {
+ if (uiEchoManager.onLocalEchoUpdated(roomId, eventId, sendState)) {
postSnapshot()
}
}
@@ -848,11 +850,11 @@ internal class DefaultTimeline(
}
}
- fun onLocalEchoUpdated(onLocalEchoUpdated: OnLocalEchoUpdated): Boolean {
- if (isLive && onLocalEchoUpdated.roomId == roomId) {
- val existingState = inMemorySendingStates[onLocalEchoUpdated.eventId]
- inMemorySendingStates[onLocalEchoUpdated.eventId] = onLocalEchoUpdated.sendState
- if (existingState != onLocalEchoUpdated.sendState) {
+ fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState): Boolean {
+ if (isLive && roomId == this@DefaultTimeline.roomId) {
+ val existingState = inMemorySendingStates[eventId]
+ inMemorySendingStates[eventId] = sendState
+ if (existingState != sendState) {
return true
}
}
@@ -860,22 +862,22 @@ internal class DefaultTimeline(
}
// return true if should update
- fun onLocalEchoCreated(onLocalEchoCreated: OnLocalEchoCreated): Boolean {
+ fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent): Boolean {
var postSnapshot = false
- if (isLive && onLocalEchoCreated.roomId == roomId) {
+ if (isLive && roomId == this@DefaultTimeline.roomId) {
// Manage some ui echos (do it before filter because actual event could be filtered out)
- when (onLocalEchoCreated.timelineEvent.root.getClearType()) {
+ when (timelineEvent.root.getClearType()) {
EventType.REDACTION -> {
}
EventType.REACTION -> {
- val content = onLocalEchoCreated.timelineEvent.root.content?.toModel()
+ val content = timelineEvent.root.content?.toModel()
if (RelationType.ANNOTATION == content?.relatesTo?.type) {
val reaction = content.relatesTo.key
val relatedEventID = content.relatesTo.eventId
inMemoryReactions.getOrPut(relatedEventID) { mutableListOf() }
.add(
ReactionUiEchoData(
- localEchoId = onLocalEchoCreated.timelineEvent.eventId,
+ localEchoId = timelineEvent.eventId,
reactedOnEventId = relatedEventID,
reaction = reaction
)
@@ -888,12 +890,12 @@ internal class DefaultTimeline(
}
// do not add events that would have been filtered
- if (listOf(onLocalEchoCreated.timelineEvent).filterEventsWithSettings().isNotEmpty()) {
+ if (listOf(timelineEvent).filterEventsWithSettings().isNotEmpty()) {
listeners.forEach {
- it.onNewTimelineEvents(listOf(onLocalEchoCreated.timelineEvent.eventId))
+ it.onNewTimelineEvents(listOf(timelineEvent.eventId))
}
- Timber.v("On local echo created: ${onLocalEchoCreated.timelineEvent.eventId}")
- inMemorySendingEvents.add(0, onLocalEchoCreated.timelineEvent)
+ Timber.v("On local echo created: ${timelineEvent.eventId}")
+ inMemorySendingEvents.add(0, timelineEvent)
postSnapshot = true
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt
index 783aa53ddf..ef890db79e 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/DefaultTimelineService.kt
@@ -18,12 +18,12 @@ package org.matrix.android.sdk.internal.session.room.timeline
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
-import com.squareup.inject.assisted.Assisted
-import com.squareup.inject.assisted.AssistedInject
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedInject
+import dagger.assisted.AssistedFactory
import com.zhuinden.monarchy.Monarchy
import io.realm.Sort
import io.realm.kotlin.where
-import org.greenrobot.eventbus.EventBus
import org.matrix.android.sdk.api.session.events.model.isImageMessage
import org.matrix.android.sdk.api.session.events.model.isVideoMessage
import org.matrix.android.sdk.api.session.room.timeline.Timeline
@@ -39,24 +39,26 @@ import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
import org.matrix.android.sdk.internal.task.TaskExecutor
internal class DefaultTimelineService @AssistedInject constructor(@Assisted private val roomId: String,
@SessionDatabase private val monarchy: Monarchy,
private val realmSessionProvider: RealmSessionProvider,
- private val eventBus: EventBus,
+ private val timelineInput: TimelineInput,
private val taskExecutor: TaskExecutor,
private val contextOfEventTask: GetContextOfEventTask,
private val eventDecryptor: TimelineEventDecryptor,
private val paginationTask: PaginationTask,
private val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask,
private val timelineEventMapper: TimelineEventMapper,
- private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper
+ private val readReceiptsSummaryMapper: ReadReceiptsSummaryMapper,
+ private val loadRoomMembersTask: LoadRoomMembersTask
) : TimelineService {
- @AssistedInject.Factory
+ @AssistedFactory
interface Factory {
- fun create(roomId: String): TimelineService
+ fun create(roomId: String): DefaultTimelineService
}
override fun createTimeline(eventId: String?, settings: TimelineSettings): Timeline {
@@ -70,10 +72,11 @@ internal class DefaultTimelineService @AssistedInject constructor(@Assisted priv
timelineEventMapper = timelineEventMapper,
settings = settings,
hiddenReadReceipts = TimelineHiddenReadReceipts(readReceiptsSummaryMapper, roomId, settings),
- eventBus = eventBus,
+ timelineInput = timelineInput,
eventDecryptor = eventDecryptor,
fetchTokenAndPaginateTask = fetchTokenAndPaginateTask,
- realmSessionProvider = realmSessionProvider
+ realmSessionProvider = realmSessionProvider,
+ loadRoomMembersTask = loadRoomMembersTask
)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt
index d1bfa1adcb..76c4b3812c 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/FetchTokenAndPaginateTask.kt
@@ -20,12 +20,12 @@ import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.internal.database.model.ChunkEntity
import org.matrix.android.sdk.internal.database.query.findIncludingEvent
import org.matrix.android.sdk.internal.di.SessionDatabase
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.filter.FilterRepository
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface FetchTokenAndPaginateTask : Task {
@@ -43,12 +43,12 @@ internal class DefaultFetchTokenAndPaginateTask @Inject constructor(
@SessionDatabase private val monarchy: Monarchy,
private val filterRepository: FilterRepository,
private val paginationTask: PaginationTask,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : FetchTokenAndPaginateTask {
override suspend fun execute(params: FetchTokenAndPaginateTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter()
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
apiCall = roomAPI.getContextOfEvent(params.roomId, params.lastKnownEventId, 0, filter)
}
val fromToken = if (params.direction == PaginationDirection.FORWARDS) {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt
index 7a611dd350..d02a7bafe9 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetContextOfEventTask.kt
@@ -16,11 +16,11 @@
package org.matrix.android.sdk.internal.session.room.timeline
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.filter.FilterRepository
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface GetContextOfEventTask : Task {
@@ -35,12 +35,12 @@ internal class DefaultGetContextOfEventTask @Inject constructor(
private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : GetContextOfEventTask {
override suspend fun execute(params: GetContextOfEventTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter()
- val response = executeRequest(eventBus) {
+ val response = executeRequest(globalErrorReceiver) {
// We are limiting the response to the event with eventId to be sure we don't have any issue with potential merging process.
apiCall = roomAPI.getContextOfEvent(params.roomId, params.eventId, 0, filter)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt
index acac3929ae..b8585b1e74 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/GetEventTask.kt
@@ -17,17 +17,17 @@
package org.matrix.android.sdk.internal.session.room.timeline
import org.matrix.android.sdk.api.session.events.model.Event
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
// TODO Add parent task
internal class GetEventTask @Inject constructor(
private val roomAPI: RoomAPI,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : Task {
internal data class Params(
@@ -36,7 +36,7 @@ internal class GetEventTask @Inject constructor(
)
override suspend fun execute(params: Params): Event {
- return executeRequest(eventBus) {
+ return executeRequest(globalErrorReceiver) {
apiCall = roomAPI.getEvent(params.roomId, params.eventId)
}
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt
index b663d03bd7..1f99893e17 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/PaginationTask.kt
@@ -16,11 +16,11 @@
package org.matrix.android.sdk.internal.session.room.timeline
+import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.executeRequest
import org.matrix.android.sdk.internal.session.filter.FilterRepository
import org.matrix.android.sdk.internal.session.room.RoomAPI
import org.matrix.android.sdk.internal.task.Task
-import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
internal interface PaginationTask : Task {
@@ -37,12 +37,12 @@ internal class DefaultPaginationTask @Inject constructor(
private val roomAPI: RoomAPI,
private val filterRepository: FilterRepository,
private val tokenChunkEventPersistor: TokenChunkEventPersistor,
- private val eventBus: EventBus
+ private val globalErrorReceiver: GlobalErrorReceiver
) : PaginationTask {
override suspend fun execute(params: PaginationTask.Params): TokenChunkEventPersistor.Result {
val filter = filterRepository.getRoomFilter()
- val chunk = executeRequest(eventBus) {
+ val chunk = executeRequest(globalErrorReceiver) {
isRetryable = true
apiCall = roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter)
}
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt
new file mode 100644
index 0000000000..002ab1dd8a
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TimelineInput.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2021 The Matrix.org Foundation C.I.C.
+ *
+ * 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 org.matrix.android.sdk.internal.session.room.timeline
+
+import org.matrix.android.sdk.api.session.room.send.SendState
+import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
+import org.matrix.android.sdk.internal.session.SessionScope
+import javax.inject.Inject
+
+@SessionScope
+internal class TimelineInput @Inject constructor() {
+ fun onLocalEchoCreated(roomId: String, timelineEvent: TimelineEvent) {
+ listeners.toSet().forEach { it.onLocalEchoCreated(roomId, timelineEvent) }
+ }
+
+ fun onLocalEchoUpdated(roomId: String, eventId: String, sendState: SendState) {
+ listeners.toSet().forEach { it.onLocalEchoUpdated(roomId, eventId, sendState) }
+ }
+
+ fun onNewTimelineEvents(roomId: String, eventIds: List) {
+ listeners.toSet().forEach { it.onNewTimelineEvents(roomId, eventIds) }
+ }
+
+ val listeners = mutableSetOf