diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 63418f7077..b6dd91a10d 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt b/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt index 29bfc97e8c..70078f580f 100644 --- a/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt +++ b/app/src/main/java/im/vector/riotredesign/features/login/LoginActivity.kt @@ -6,8 +6,8 @@ import android.widget.Toast import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.failure.Failure -import im.vector.matrix.android.api.login.data.Credentials -import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig +import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.riotredesign.R import im.vector.riotredesign.core.platform.RiotActivity import im.vector.riotredesign.features.home.HomeActivity diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index e0a9b48293..d8c5b24631 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -4,6 +4,7 @@ apply plugin: 'kotlin-kapt' apply plugin: 'io.objectbox' ext.support_version = '28.0.0' +ext.moshi_version = '1.7.0' buildscript { @@ -55,8 +56,11 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' implementation 'com.squareup.okio:okio:1.15.0' - implementation 'com.squareup.moshi:moshi-kotlin:1.7.0' - kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.7.0' + + implementation "com.squareup.moshi:moshi-kotlin:$moshi_version" + implementation "com.squareup.moshi:moshi-adapters:$moshi_version" + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version" + // Paging implementation "android.arch.paging:runtime:1.0.1" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt index f8410be8ad..622a7c0f71 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt @@ -1,6 +1,6 @@ package im.vector.matrix.android.api -import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig +import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.internal.DefaultSession import im.vector.matrix.android.internal.di.MatrixModule import im.vector.matrix.android.internal.di.NetworkModule diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Session.kt index f47e37700b..c356a8add0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Session.kt @@ -1,6 +1,6 @@ package im.vector.matrix.android.api -import im.vector.matrix.android.api.login.Authenticator +import im.vector.matrix.android.api.auth.Authenticator interface Session { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/Authenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt similarity index 69% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/Authenticator.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt index 6d28f162c9..143824bbdb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/Authenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/Authenticator.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.api.login +package im.vector.matrix.android.api.auth import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.api.login.data.Credentials +import im.vector.matrix.android.api.auth.data.Credentials interface Authenticator { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/CredentialsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/CredentialsStore.kt new file mode 100644 index 0000000000..7e095fd8e2 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/CredentialsStore.kt @@ -0,0 +1,11 @@ +package im.vector.matrix.android.api.auth + +import im.vector.matrix.android.api.auth.data.Credentials + +interface CredentialsStore { + + fun get(): Credentials? + + fun save(credentials: Credentials) + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/Credentials.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Credentials.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/Credentials.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Credentials.kt index 3b8e83c927..6002d9c918 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/Credentials.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/Credentials.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.login.data +package im.vector.matrix.android.api.auth.data import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/HomeServerConnectionConfig.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt similarity index 77% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/HomeServerConnectionConfig.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt index 8d8955b628..89d26bb54e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/data/HomeServerConnectionConfig.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.login.data +package im.vector.matrix.android.api.auth.data import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/Event.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/Event.kt index f26ae839b8..cda35ff109 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/Event.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/Event.kt @@ -1,4 +1,31 @@ package im.vector.matrix.android.api.events -data class Event(val sender: String, - val eventType: EventType) +import com.squareup.moshi.Json +import com.squareup.moshi.Moshi + +data class Event( + @Json(name = "event_id") val eventId: String, + @Json(name = "type") val type: EventType, + @Json(name = "content") val content: String, + @Json(name = "origin_server_ts") val originServerTs: Long, + @Json(name = "prev_content") val prevContent: String? = null, + @Json(name = "sender") val sender: String? = null, + @Json(name = "state_key") val stateKey: String? = null, + @Json(name = "room_id") val roomId: String? = null, + @Json(name = "unsigned_data") val unsignedData: UnsignedData? = null +) { + + inline fun content(): T? { + val moshi = Moshi.Builder().build() + return moshi.adapter(T::class.java).fromJson(content) + } + + inline fun prevContent(): T? { + if (prevContent == null) { + return null + } + val moshi = Moshi.Builder().build() + return moshi.adapter(T::class.java).fromJson(prevContent) + } + +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventType.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventType.kt index 55d8f44650..9d3f3967ac 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventType.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventType.kt @@ -1,41 +1,44 @@ package im.vector.matrix.android.api.events -sealed class EventType(val str: String) { +import com.squareup.moshi.Json - object Presence : EventType("m.presence") - object Message : EventType("m.room.message") - object Sticker : EventType("m.sticker") - object Encrypted : EventType("m.room.encrypted") - object Encryption : EventType("m.room.encryption") - object Feedback : EventType("m.room.message.feedback") - object Typing : EventType("m.typing") - object Redaction : EventType("m.room.redaction") - object Receipt : EventType("m.receipt") - object Tag : EventType("m.tag") - object RoomKey : EventType("m.room_key") - object FullyRead : EventType("m.fully_read") - object Plumbing : EventType("m.room.plumbing") - object BotOptions : EventType("m.room.bot.options") - object KeyRequest : EventType("m.room_key_request") - object ForwardedRoomKey : EventType("m.forwarded_room_key") - object PreviewUrls : EventType("org.matrix.room.preview_urls") - class StateEvents { - object RoomName : EventType("m.room.name") - object Topic : EventType("m.room.topic") - object Avatar : EventType("m.room.avatar") - object Member : EventType("m.room.member") - object ThirdPartyInvite : EventType("m.room.third_party_invite") - object Create : EventType("m.room.userIdentifier") - object JoinRules : EventType("m.room.join_rules") - object GuestAccess : EventType("m.room.guest_access") - object PowerLevels : EventType("m.room.power_levels") - object Aliases : EventType("m.room.aliases") - object Tombstone : EventType("m.room.tombstone") - object CanonicalAlias : EventType("m.room.canonical_alias") - object HistoryVisibility : EventType("m.room.history_visibility") - object RelatedGroups : EventType("m.room.related_groups") - } +enum class EventType { + + @Json(name ="m.presence") PRESENCE, + @Json(name ="m.room.message") MESSAGE, + @Json(name ="m.sticker") STICKER, + @Json(name ="m.room.encrypted") ENCRYPTED, + @Json(name ="m.room.encryption") ENCRYPTION, + @Json(name ="m.room.message.feedback") FEEDBACK, + @Json(name ="m.typing") TYPING, + @Json(name ="m.room.redaction") REDACTION, + @Json(name ="m.receipt") RECEIPT, + @Json(name ="m.tag") TAG, + @Json(name ="m.room_key") ROOM_KEY, + @Json(name ="m.fully_read") FULLY_READ, + @Json(name ="m.room.plumbing") PLUMBING, + @Json(name ="m.room.bot.options") BOT_OPTIONS, + @Json(name ="m.room_key_request") KEY_REQUEST, + @Json(name ="m.forwarded_room_key") FORWARDED_ROOM_KEY, + @Json(name ="org.matrix.room.preview_urls") PREVIEW_URLS, + + // State Events + @Json(name ="m.room.name") STATE_ROOM_NAME, + @Json(name ="m.room.topic") STATE_ROOM_TOPIC, + @Json(name ="m.room.avatar") STATE_ROOM_AVATAR, + @Json(name ="m.room.member") STATE_ROOM_MEMBER, + @Json(name ="m.room.third_party_invite") STATE_ROOM_THIRD_PARTY_INVITE, + @Json(name ="m.room.create") STATE_ROOM_CREATE, + @Json(name ="m.room.join_rules") STATE_ROOM_JOIN_RULES, + @Json(name ="m.room.guest_access") STATE_ROOM_GUEST_ACCESS, + @Json(name ="m.room.power_levels") STATE_ROOM_POWER_LEVELS, + @Json(name ="m.room.aliases") STATE_ROOM_ALIASES, + @Json(name ="m.room.tombstone") STATE_ROOM_TOMBSTONE, + @Json(name ="m.room.canonical_alias") STATE_CANONICAL_ALIAS, + @Json(name ="m.room.history_visibility") STATE_HISTORY_VISIBILITY, + @Json(name ="m.room.related_groups") STATE_RELATED_GROUPS, + @Json(name ="m.room.pinned_events") STATE_PINNED_EVENT } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/UnsignedData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/UnsignedData.kt new file mode 100644 index 0000000000..d3aff57821 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/UnsignedData.kt @@ -0,0 +1,9 @@ +package im.vector.matrix.android.api.events + +import com.squareup.moshi.Json + +data class UnsignedData( + @Json(name = "age") val age: Int, + @Json(name = "redacted_because") val redactedEvent: Event? = null, + @Json(name = "transaction_id") val transactionId: String +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/CredentialsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/CredentialsStore.kt deleted file mode 100644 index cae096949b..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/login/CredentialsStore.kt +++ /dev/null @@ -1,11 +0,0 @@ -package im.vector.matrix.android.api.login - -import im.vector.matrix.android.api.login.data.Credentials - -interface CredentialsStore { - - fun get(): Credentials? - - fun save(credentials: Credentials) - -} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Invite.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Invite.kt new file mode 100644 index 0000000000..de1d4046e9 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Invite.kt @@ -0,0 +1,8 @@ +package im.vector.matrix.android.api.rooms + +import com.squareup.moshi.Json + +data class Invite( + @Json(name = "display_name") val displayName: String, + @Json(name = "signed") val signed: Signed +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Membership.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Membership.kt new file mode 100644 index 0000000000..c7657acbf9 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Membership.kt @@ -0,0 +1,11 @@ +package im.vector.matrix.android.api.rooms + +import com.squareup.moshi.Json + +enum class Membership { + @Json(name = "invite") INVITE, + @Json(name = "join") JOIN, + @Json(name = "knock") KNOCK, + @Json(name = "leave") LEAVE, + @Json(name = "ban") BAN +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Room.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Room.kt new file mode 100644 index 0000000000..6c273e13fc --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Room.kt @@ -0,0 +1,9 @@ +package im.vector.matrix.android.api.rooms + +import im.vector.matrix.android.api.rooms.timeline.EventTimeline + +interface Room { + + fun timeline(): EventTimeline + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomDirectoryVisibility.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomDirectoryVisibility.kt new file mode 100644 index 0000000000..0741634573 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomDirectoryVisibility.kt @@ -0,0 +1,10 @@ +package im.vector.matrix.android.api.rooms + +import com.squareup.moshi.Json + +enum class RoomDirectoryVisibility { + + @Json(name = "private") PRIVATE, + @Json(name = "public") PUBLIC + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomHistoryVisibility.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomHistoryVisibility.kt new file mode 100644 index 0000000000..e6aae1ab4b --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomHistoryVisibility.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.rooms + +import com.squareup.moshi.Json + +enum class RoomHistoryVisibility { + @Json(name = "shared") SHARED, + @Json(name = "invited") INVITED, + @Json(name = "joined") JOINED, + @Json(name = "word_readable") WORLD_READABLE + + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomMember.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomMember.kt new file mode 100644 index 0000000000..7083cb2430 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomMember.kt @@ -0,0 +1,12 @@ +package im.vector.matrix.android.api.rooms + +import im.vector.matrix.android.api.events.UnsignedData + +data class RoomMember( + val membership: Membership, + val displayDame: String? = null, + val avatarUrl: String? = null, + val isDirect: Boolean = false, + val thirdPartyInvite: Invite? = null, + val unsignedData: UnsignedData? = null +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomState.kt new file mode 100644 index 0000000000..30a9eedd33 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomState.kt @@ -0,0 +1,13 @@ +package im.vector.matrix.android.api.rooms + +data class RoomState( + var name: String? = null, + var topic: String? = null, + var url: String? = null, + var avatar_url: String? = null, + var join_rule: String? = null, + var guest_access: String? = null, + var history_visibility: RoomHistoryVisibility? = null, + var visibility: RoomDirectoryVisibility? = null, + var groups: List = emptyList() +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Signed.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Signed.kt new file mode 100644 index 0000000000..0f7aa5a95b --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Signed.kt @@ -0,0 +1,9 @@ +package im.vector.matrix.android.api.rooms + +import com.squareup.moshi.Json + +data class Signed( + @Json(name = "token") val token: String, + @Json(name = "signatures") val signatures: Any, + @Json(name = "mxid") val mxid: String +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/timeline/EventTimeline.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/timeline/EventTimeline.java new file mode 100644 index 0000000000..a7ab1035a9 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/timeline/EventTimeline.java @@ -0,0 +1,52 @@ +package im.vector.matrix.android.api.rooms.timeline; + +import im.vector.matrix.android.api.events.Event; +import im.vector.matrix.android.api.rooms.RoomState; + +/** + * A `EventTimeline` instance represents a contiguous sequence of events in a room. + *

+ * There are two kinds of timeline: + *

+ * - live timelines: they receive live events from the events stream. You can paginate + * backwards but not forwards. + *

+ * - past timelines: they start in the past from an `initialEventId`. They are filled + * with events on calls of [MXEventTimeline paginate] in backwards or forwards direction. + */ +public interface EventTimeline { + + /** + * @return The state of the room at the top most recent event of the timeline. + */ + RoomState getState(); + + /** + * The direction from which an incoming event is considered. + */ + enum Direction { + /** + * Forwards when the event is added to the end of the timeline. + * These events come from the /sync stream or from forwards pagination. + */ + FORWARDS, + + /** + * Backwards when the event is added to the start of the timeline. + * These events come from a back pagination. + */ + BACKWARDS + } + + interface Listener { + + /** + * Call when an event has been handled in the timeline. + * + * @param event the event. + * @param direction the direction. + * @param roomState the room state + */ + void onEvent(Event event, Direction direction, RoomState roomState); + } +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/DefaultSession.kt index c909bd610f..9de27345f1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/DefaultSession.kt @@ -1,9 +1,9 @@ package im.vector.matrix.android.internal import im.vector.matrix.android.api.Session -import im.vector.matrix.android.api.login.Authenticator -import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig -import im.vector.matrix.android.internal.login.LoginModule +import im.vector.matrix.android.api.auth.Authenticator +import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig +import im.vector.matrix.android.internal.auth.LoginModule import org.koin.core.scope.Scope import org.koin.standalone.KoinComponent import org.koin.standalone.StandAloneContext diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/DefaultAuthenticator.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt similarity index 79% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/DefaultAuthenticator.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt index e429c3de50..6ef7269d3b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/DefaultAuthenticator.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/DefaultAuthenticator.kt @@ -1,14 +1,14 @@ -package im.vector.matrix.android.internal.login +package im.vector.matrix.android.internal.auth import com.squareup.moshi.Moshi import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.login.Authenticator -import im.vector.matrix.android.api.login.CredentialsStore -import im.vector.matrix.android.api.login.data.Credentials +import im.vector.matrix.android.api.auth.Authenticator +import im.vector.matrix.android.api.auth.CredentialsStore +import im.vector.matrix.android.api.auth.data.Credentials import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.internal.MatrixCoroutineDispatchers +import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.map -import im.vector.matrix.android.internal.login.data.PasswordLoginParams +import im.vector.matrix.android.internal.auth.data.PasswordLoginParams import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.util.CancelableCoroutine import kotlinx.coroutines.GlobalScope diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginApi.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginApi.kt similarity index 74% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginApi.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginApi.kt index f618be5584..7d7a909c0f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginApi.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginApi.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.login +package im.vector.matrix.android.internal.auth -import im.vector.matrix.android.api.login.data.Credentials -import im.vector.matrix.android.internal.login.data.PasswordLoginParams +import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.internal.auth.data.PasswordLoginParams import im.vector.matrix.android.internal.network.NetworkConstants import kotlinx.coroutines.Deferred import retrofit2.Response diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginModule.kt similarity index 83% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginModule.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginModule.kt index 3589b849b1..950bc8830b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/LoginModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/LoginModule.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.login +package im.vector.matrix.android.internal.auth -import im.vector.matrix.android.api.login.Authenticator -import im.vector.matrix.android.api.login.data.HomeServerConnectionConfig +import im.vector.matrix.android.api.auth.Authenticator +import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig import im.vector.matrix.android.internal.DefaultSession import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.module.Module diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlow.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlow.kt similarity index 53% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlow.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlow.kt index 46915c435a..978f343824 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlow.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlow.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.login.data +package im.vector.matrix.android.internal.auth.data import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowResponse.kt new file mode 100644 index 0000000000..f8d524a437 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowResponse.kt @@ -0,0 +1,6 @@ +package im.vector.matrix.android.internal.auth.data + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class LoginFlowResponse(val flows: List) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowTypes.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowTypes.kt similarity index 87% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowTypes.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowTypes.kt index b7c23dd650..1c5e8fb74f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowTypes.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginFlowTypes.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.login.data +package im.vector.matrix.android.internal.auth.data object LoginFlowTypes { const val PASSWORD = "m.login.password" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginParams.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginParams.kt new file mode 100644 index 0000000000..d57fffa34b --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/LoginParams.kt @@ -0,0 +1,5 @@ +package im.vector.matrix.android.internal.auth.data + +interface LoginParams { + val type: String +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/PasswordLoginParams.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/PasswordLoginParams.kt similarity index 97% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/PasswordLoginParams.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/PasswordLoginParams.kt index be896976fc..461a54b87d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/PasswordLoginParams.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/data/PasswordLoginParams.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.login.data +package im.vector.matrix.android.internal.auth.data import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/InMemoryCredentialsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/InMemoryCredentialsStore.kt similarity index 61% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/InMemoryCredentialsStore.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/InMemoryCredentialsStore.kt index 7610344014..16f629373b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/InMemoryCredentialsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/InMemoryCredentialsStore.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.login.db +package im.vector.matrix.android.internal.auth.db -import im.vector.matrix.android.api.login.CredentialsStore -import im.vector.matrix.android.api.login.data.Credentials +import im.vector.matrix.android.api.auth.CredentialsStore +import im.vector.matrix.android.api.auth.data.Credentials class InMemoryCredentialsStore : CredentialsStore { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/ObjectBoxCredentialsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/ObjectBoxCredentialsStore.kt similarity index 62% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/ObjectBoxCredentialsStore.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/ObjectBoxCredentialsStore.kt index d6468c2624..fe962519d8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/db/ObjectBoxCredentialsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/ObjectBoxCredentialsStore.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.login.db +package im.vector.matrix.android.internal.auth.db -import im.vector.matrix.android.api.login.CredentialsStore -import im.vector.matrix.android.api.login.data.Credentials +import im.vector.matrix.android.api.auth.CredentialsStore +import im.vector.matrix.android.api.auth.data.Credentials import io.objectbox.Box class ObjectBoxCredentialsStore(private val box: Box) : CredentialsStore { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt index a61253101a..f1a7e724cc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MatrixModule.kt @@ -1,11 +1,11 @@ package im.vector.matrix.android.internal.di import im.vector.matrix.android.api.MatrixOptions -import im.vector.matrix.android.api.login.CredentialsStore -import im.vector.matrix.android.api.login.data.Credentials -import im.vector.matrix.android.api.login.data.MyObjectBox -import im.vector.matrix.android.internal.MatrixCoroutineDispatchers -import im.vector.matrix.android.internal.login.db.ObjectBoxCredentialsStore +import im.vector.matrix.android.api.auth.CredentialsStore +import im.vector.matrix.android.api.auth.data.Credentials +import im.vector.matrix.android.api.auth.data.MyObjectBox +import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers +import im.vector.matrix.android.internal.auth.db.ObjectBoxCredentialsStore import io.objectbox.Box import io.objectbox.BoxStore import kotlinx.coroutines.Dispatchers diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt index 5a7a6a2824..15f2a84851 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/NetworkModule.kt @@ -2,7 +2,6 @@ package im.vector.matrix.android.internal.di import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory import com.squareup.moshi.Moshi -import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import im.vector.matrix.android.internal.network.AccessTokenInterceptor import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor @@ -32,7 +31,7 @@ class NetworkModule() : Module { .build() } - single { Moshi.Builder().add(KotlinJsonAdapterFactory()).build() } + single { Moshi.Builder().build() } single { MoshiConverterFactory.create(get()) as Converter.Factory diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/SyncAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt similarity index 73% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/SyncAPI.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt index dcb1c4049e..c80c1de7bf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/SyncAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.sync +package im.vector.matrix.android.internal.events.sync import im.vector.matrix.android.internal.network.NetworkConstants -import im.vector.matrix.android.internal.sync.data.SyncResponse +import im.vector.matrix.android.internal.events.sync.data.SyncResponse import kotlinx.coroutines.Deferred import retrofit2.Response import retrofit2.http.GET diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncResponseHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncResponseHandler.kt new file mode 100644 index 0000000000..4ac521ec66 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncResponseHandler.kt @@ -0,0 +1,538 @@ +/* + * Copyright 2014 OpenMarket Ltd + * Copyright 2017 Vector Creations Ltd + * Copyright 2018 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *//* + +package im.vector.matrix.android.internal.events.sync + +import android.text.TextUtils +import android.util.Log +import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.events.EventType +import im.vector.matrix.android.internal.events.sync.data.SyncResponse +import java.util.* + +class SyncResponseHandler { + + */ +/** + * Manage the sync accountData field + * + * @param accountData the account data + * @param isInitialSync true if it is an initial sync response + *//* + + private fun manageAccountData(accountData: Map?, isInitialSync: Boolean) { + try { + if (accountData!!.containsKey("events")) { + val events = accountData["events"] as List> + + if (!events.isEmpty()) { + // ignored users list + manageIgnoredUsers(events, isInitialSync) + // push rules + managePushRulesUpdate(events) + // direct messages rooms + manageDirectChatRooms(events, isInitialSync) + // URL preview + manageUrlPreview(events) + // User widgets + manageUserWidgets(events) + } + } + } catch (e: Exception) { + + } + + } + + */ +/** + * Refresh the push rules from the account data events list + * + * @param events the account data events. + *//* + + private fun managePushRulesUpdate(events: List>) { + for (event in events) { + val type = event["type"] as String + if (TextUtils.equals(type, "m.push_rules")) { + if (event.containsKey("content")) { + val gson = JsonUtils.getGson(false) + // convert the data to PushRulesResponse + // because BingRulesManager supports only PushRulesResponse + val element = gson.toJsonTree(event["content"]) + getBingRulesManager().buildRules(gson.fromJson(element, PushRulesResponse::class.java)) + // warn the client that the push rules have been updated + onBingRulesUpdate() + } + return + } + } + } + + */ +/** + * Check if the ignored users list is updated + * + * @param events the account data events list + *//* + + private fun manageIgnoredUsers(events: List>, isInitialSync: Boolean) { + val newIgnoredUsers = ignoredUsers(events) + + if (null != newIgnoredUsers) { + val curIgnoredUsers = getIgnoredUserIds() + + // the both lists are not empty + if (0 != newIgnoredUsers.size || 0 != curIgnoredUsers.size) { + // check if the ignored users list has been updated + if (newIgnoredUsers.size != curIgnoredUsers.size || !newIgnoredUsers.containsAll(curIgnoredUsers)) { + // update the store + mStore.setIgnoredUserIdsList(newIgnoredUsers) + mIgnoredUserIdsList = newIgnoredUsers + + if (!isInitialSync) { + // warn there is an update + onIgnoredUsersListUpdate() + } + } + } + } + } + + */ +/** + * Extract the ignored users list from the account data events list.. + * + * @param events the account data events list. + * @return the ignored users list. null means that there is no defined user ids list. + *//* + + private fun ignoredUsers(events: List>): List? { + var ignoredUsers: List? = null + + if (0 != events.size) { + for (event in events) { + val type = event["type"] as String + + if (TextUtils.equals(type, AccountDataRestClient.ACCOUNT_DATA_TYPE_IGNORED_USER_LIST)) { + if (event.containsKey("content")) { + val contentDict = event["content"] as Map + + if (contentDict.containsKey(AccountDataRestClient.ACCOUNT_DATA_KEY_IGNORED_USERS)) { + val ignored_users = contentDict[AccountDataRestClient.ACCOUNT_DATA_KEY_IGNORED_USERS] as Map + + if (null != ignored_users) { + ignoredUsers = ArrayList(ignored_users.keys) + } + } + } + } + } + + } + + return ignoredUsers + } + + + */ +/** + * Extract the direct chat rooms list from the dedicated events. + * + * @param events the account data events list. + *//* + + private fun manageDirectChatRooms(events: List>, isInitialSync: Boolean) { + if (0 != events.size) { + for (event in events) { + val type = event["type"] as String + + if (TextUtils.equals(type, AccountDataRestClient.ACCOUNT_DATA_TYPE_DIRECT_MESSAGES)) { + if (event.containsKey("content")) { + val contentDict = event["content"] as Map> + + Log.d(LOG_TAG, "## manageDirectChatRooms() : update direct chats map$contentDict") + + mStore.setDirectChatRoomsDict(contentDict) + + // reset the current list of the direct chat roomIDs + // to update it + mLocalDirectChatRoomIdsList = null + + if (!isInitialSync) { + // warn there is an update + onDirectMessageChatRoomsListUpdate() + } + } + } + } + } + } + + */ +/** + * Manage the URL preview flag + * + * @param events the events list + *//* + + private fun manageUrlPreview(events: List>) { + if (0 != events.size) { + for (event in events) { + val type = event["type"] as String + + if (TextUtils.equals(type, AccountDataRestClient.ACCOUNT_DATA_TYPE_PREVIEW_URLS)) { + if (event.containsKey("content")) { + val contentDict = event["content"] as Map + + Log.d(LOG_TAG, "## manageUrlPreview() : $contentDict") + var enable = true + if (contentDict.containsKey(AccountDataRestClient.ACCOUNT_DATA_KEY_URL_PREVIEW_DISABLE)) { + enable = !(contentDict[AccountDataRestClient.ACCOUNT_DATA_KEY_URL_PREVIEW_DISABLE] as Boolean) + } + + mStore.setURLPreviewEnabled(enable) + } + } + } + } + } + + */ +/** + * Manage the user widgets + * + * @param events the events list + *//* + + private fun manageUserWidgets(events: List>) { + if (0 != events.size) { + for (event in events) { + val type = event["type"] as String + + if (TextUtils.equals(type, AccountDataRestClient.ACCOUNT_DATA_TYPE_WIDGETS)) { + if (event.containsKey("content")) { + val contentDict = event["content"] as Map + + Log.d(LOG_TAG, "## manageUserWidgets() : $contentDict") + + mStore.setUserWidgets(contentDict) + } + } + } + } + } + + //================================================================================ + // Sync V2 + //================================================================================ + + */ +/** + * Handle a presence event. + * + * @param presenceEvent the presence event. + *//* + + private fun handlePresenceEvent(presenceEvent: Event) { + // Presence event + if (presenceEvent.type == EventType.PRESENCE) { + val userPresence = presenceEvent.content<>() + // use the sender by default + if (!TextUtils.isEmpty(presenceEvent.sender)) { + userPresence.user_id = presenceEvent.sender + } + var user = mStore.getUser(userPresence.user_id) + + if (user == null) { + user = userPresence + user!!.setDataHandler(this) + } else { + user!!.currently_active = userPresence.currently_active + user!!.presence = userPresence.presence + user!!.lastActiveAgo = userPresence.lastActiveAgo + } + + user!!.setLatestPresenceTs(System.currentTimeMillis()) + + // check if the current user has been updated + if (mCredentials.userId.equals(user!!.user_id)) { + // always use the up-to-date information + getMyUser().displayname = user!!.displayname + getMyUser().avatar_url = user!!.getAvatarUrl() + + mStore.setAvatarURL(user!!.getAvatarUrl(), presenceEvent.getOriginServerTs()) + mStore.setDisplayName(user!!.displayname, presenceEvent.getOriginServerTs()) + } + + mStore.storeUser(user) + onPresenceUpdate(presenceEvent, user) + } + } + + + private fun manageResponse(syncResponse: SyncResponse?, fromToken: String?, isCatchingUp: Boolean) { + val isInitialSync = fromToken == null + var isEmptyResponse = true + if (syncResponse == null) { + return + } + // Handle the to device events before the room ones + // to ensure to decrypt them properly + if (syncResponse.toDevice?.events?.isNotEmpty() == true) { + for (toDeviceEvent in syncResponse.toDevice.events) { + handleToDeviceEvent(toDeviceEvent) + } + } + // Handle account data before the room events + // to be able to update direct chats dictionary during invites handling. + manageAccountData(syncResponse.accountData, isInitialSync) + // joined rooms events + if (syncResponse.rooms?.join?.isNotEmpty() == true) { + Log.d(LOG_TAG, "Received " + syncResponse.rooms.join.size + " joined rooms") + val roomIds = syncResponse.rooms.join.keys + // Handle first joined rooms + for (roomId in roomIds) { + try { + if (null != mLeftRoomsStore.getRoom(roomId)) { + Log.d(LOG_TAG, "the room $roomId moves from left to the joined ones") + mLeftRoomsStore.deleteRoom(roomId) + } + + getRoom(roomId).handleJoinedRoomSync(syncResponse.rooms.join[roomId], isInitialSync) + } catch (e: Exception) { + Log.e(LOG_TAG, "## manageResponse() : handleJoinedRoomSync failed " + e.message + " for room " + roomId, e) + } + + } + + isEmptyResponse = false + } + + // invited room management + if (syncResponse.rooms?.invite?.isNotEmpty() == true) { + Log.d(LOG_TAG, "Received " + syncResponse.rooms.invite.size + " invited rooms") + + val roomIds = syncResponse.rooms.invite.keys + + var updatedDirectChatRoomsDict: MutableMap>? = null + var hasChanged = false + + for (roomId in roomIds) { + try { + Log.d(LOG_TAG, "## manageResponse() : the user has been invited to $roomId") + val room = getRoom(roomId) + val invitedRoomSync = syncResponse.rooms.invite[roomId] + room.handleInvitedRoomSync(invitedRoomSync) + // Handle here the invites to a direct chat. + if (room.isDirectChatInvitation()) { + // Retrieve the inviter user id. + var participantUserId: String? = null + for (event in invitedRoomSync.inviteState.events) { + if (null != event.sender) { + participantUserId = event.sender + break + } + } + if (null != participantUserId) { + // Prepare the updated dictionary. + if (null == updatedDirectChatRoomsDict) { + if (null != getStore().getDirectChatRoomsDict()) { + // Consider the current dictionary. + updatedDirectChatRoomsDict = HashMap(getStore().getDirectChatRoomsDict()) + } else { + updatedDirectChatRoomsDict = HashMap() + } + } + + val roomIdsList: MutableList + if (updatedDirectChatRoomsDict!!.containsKey(participantUserId)) { + roomIdsList = ArrayList(updatedDirectChatRoomsDict[participantUserId]) + } else { + roomIdsList = ArrayList() + } + + // Check whether the room was not yet seen as direct chat + if (roomIdsList.indexOf(roomId) < 0) { + Log.d(LOG_TAG, "## manageResponse() : add this new invite in direct chats") + + roomIdsList.add(roomId) // update room list with the new room + updatedDirectChatRoomsDict[participantUserId] = roomIdsList + hasChanged = true + } + } + } + } catch (e: Exception) { + Log.e(LOG_TAG, "## manageResponse() : handleInvitedRoomSync failed " + e.message + " for room " + roomId, e) + } + + } + + isEmptyResponse = false + + if (hasChanged) { + // Update account data to add new direct chat room(s) + mAccountDataRestClient.setAccountData(mCredentials.userId, AccountDataRestClient.ACCOUNT_DATA_TYPE_DIRECT_MESSAGES, + updatedDirectChatRoomsDict, object : ApiCallback() { + fun onSuccess(info: Void) { + Log.d(LOG_TAG, "## manageResponse() : succeeds") + } + + fun onNetworkError(e: Exception) { + Log.e(LOG_TAG, "## manageResponse() : update account data failed " + e.message, e) + // TODO: we should try again. + } + + fun onMatrixError(e: MatrixError) { + Log.e(LOG_TAG, "## manageResponse() : update account data failed " + e.getMessage()) + } + + fun onUnexpectedError(e: Exception) { + Log.e(LOG_TAG, "## manageResponse() : update account data failed " + e.message, e) + } + }) + } + + // left room management + // it should be done at the end but it seems there is a server issue + // when inviting after leaving a room, the room is defined in the both leave & invite rooms list. + if (null != syncResponse.rooms.leave && syncResponse.rooms.leave.size > 0) { + Log.d(LOG_TAG, "Received " + syncResponse.rooms.leave.size + " left rooms") + + val roomIds = syncResponse.rooms.leave.keys + + for (roomId in roomIds) { + // RoomSync leftRoomSync = syncResponse.rooms.leave.get(roomId); + + // Presently we remove the existing room from the rooms list. + // FIXME SYNC V2 Archive/Display the left rooms! + // For that create 'handleArchivedRoomSync' method + + var membership = RoomMember.MEMBERSHIP_LEAVE + val room = getRoom(roomId) + + // Retrieve existing room + // check if the room still exists. + if (null != room) { + // use 'handleJoinedRoomSync' to pass the last events to the room before leaving it. + // The room will then be able to notify its listeners. + room!!.handleJoinedRoomSync(syncResponse.rooms.leave[roomId], isInitialSync) + + val member = room!!.getMember(getUserId()) + if (null != member) { + membership = member!!.membership + } + + Log.d(LOG_TAG, "## manageResponse() : leave the room $roomId") + } + + if (!TextUtils.equals(membership, RoomMember.MEMBERSHIP_KICK) && !TextUtils.equals(membership, RoomMember.MEMBERSHIP_BAN)) { + // ensure that the room data are properly deleted + getStore().deleteRoom(roomId) + onLeaveRoom(roomId) + } else { + onRoomKick(roomId) + } + + // don't add to the left rooms if the user has been kicked / banned + if (mAreLeftRoomsSynced && TextUtils.equals(membership, RoomMember.MEMBERSHIP_LEAVE)) { + val leftRoom = getRoom(mLeftRoomsStore, roomId, true) + leftRoom.handleJoinedRoomSync(syncResponse.rooms.leave[roomId], isInitialSync) + } + } + + isEmptyResponse = false + } + } + + // groups + if (null != syncResponse.groups) { + // Handle invited groups + if (null != syncResponse.groups.invite && !syncResponse.groups.invite.isEmpty()) { + // Handle invited groups + for (groupId in syncResponse.groups.invite.keySet()) { + val invitedGroupSync = syncResponse.groups.invite.get(groupId) + mGroupsManager.onNewGroupInvitation(groupId, invitedGroupSync.profile, invitedGroupSync.inviter, !isInitialSync) + } + } + + // Handle joined groups + if (null != syncResponse.groups.join && !syncResponse.groups.join.isEmpty()) { + for (groupId in syncResponse.groups.join.keySet()) { + mGroupsManager.onJoinGroup(groupId, !isInitialSync) + } + } + // Handle left groups + if (null != syncResponse.groups.leave && !syncResponse.groups.leave.isEmpty()) { + // Handle joined groups + for (groupId in syncResponse.groups.leave.keySet()) { + mGroupsManager.onLeaveGroup(groupId, !isInitialSync) + } + } + } + + // Handle presence of other users + if (null != syncResponse.presence && null != syncResponse.presence.events) { + Log.d(LOG_TAG, "Received " + syncResponse.presence.events.size + " presence events") + for (presenceEvent in syncResponse.presence.events) { + handlePresenceEvent(presenceEvent) + } + } + + if (null != mCrypto) { + mCrypto.onSyncCompleted(syncResponse, fromToken, isCatchingUp) + } + + val store = getStore() + + if (!isEmptyResponse && null != store) { + store!!.setEventStreamToken(syncResponse.nextBatch) + store!!.commit() + } + + } + + */ +/* + * Handle a 'toDevice' event + * @param event the event + *//* + + private fun handleToDeviceEvent(event: Event) { + // Decrypt event if necessary + decryptEvent(event, null) + + if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE) + && null != event.getContent() + && TextUtils.equals(JsonUtils.getMessageMsgType(event.getContent()), "m.bad.encrypted")) { + Log.e(LOG_TAG, "## handleToDeviceEvent() : Warning: Unable to decrypt to-device event : " + event.getContent()) + } else { + onToDeviceEvent(event) + } + } + + companion object { + + private val LOG_TAG = MXDataHandler::class.java!!.getSimpleName() + + private val LEFT_ROOMS_FILTER = "{\"room\":{\"timeline\":{\"limit\":1},\"include_leave\":true}}" + } + + +} +*/ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/Synchronizer.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/Synchronizer.kt new file mode 100644 index 0000000000..9c89ef03a7 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/Synchronizer.kt @@ -0,0 +1,11 @@ +package im.vector.matrix.android.internal.events.sync + +class Synchronizer(private val syncAPI: SyncAPI) { + + fun synchronize() { + + + } + + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt similarity index 81% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceInfo.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt index 2a3742df20..331bce6b87 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -28,26 +28,26 @@ data class DeviceInfo( /** * The owner user id */ - var user_id: String? = null, + val user_id: String? = null, /** * The device id */ - var device_id: String? = null, + val device_id: String? = null, /** * The device display name */ - var display_name: String? = null, + val display_name: String? = null, /** * The last time this device has been seen. */ - var last_seen_ts: Long = 0, + val last_seen_ts: Long = 0, /** * The last ip address */ - var last_seen_ip: String? = null + val last_seen_ip: String? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceListResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt similarity index 85% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceListResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt index b5e65035f6..598e67287b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceListResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -23,7 +23,8 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class DeviceListResponse( // user ids list which have new crypto devices - val changed: List? = null, + val changed: List = emptyList(), // List of user ids who are no more tracked. - val left: List? = null) + val left: List = emptyList() +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceOneTimeKeysCountSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt similarity index 54% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceOneTimeKeysCountSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt index 54e21736ca..13fd826342 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DeviceOneTimeKeysCountSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class DeviceOneTimeKeysCountSyncResponse( - var signed_curve25519: Int? = null + val signed_curve25519: Int? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DevicesListResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt similarity index 87% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DevicesListResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt index fba71794d3..5b57c7ad3e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/DevicesListResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -22,5 +22,5 @@ import com.squareup.moshi.JsonClass */ @JsonClass(generateAdapter = true) data class DevicesListResponse( - var devices: List? = null + val devices: List? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/InvitedRoomSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/InvitedRoomSync.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt index ea126737f9..288a5e6df5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/InvitedRoomSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -28,5 +28,5 @@ data class InvitedRoomSync( * and one from the archived 'state'. If the client joins the room then the current state will be given as a delta against the * archived 'state' not the 'invite_state'. */ - var inviteState: RoomInviteState? = null + val inviteState: RoomInviteState? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/PresenceSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt similarity index 78% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/PresenceSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt index a43e7241f9..251b9b4508 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/PresenceSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.events.Event @@ -10,5 +10,5 @@ data class PresenceSyncResponse( /** * List of presence events (array of Event with type m.presence). */ - var events: List? = null + val events: List? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomInviteState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt similarity index 89% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomInviteState.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt index f79daf4386..986d30d96a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomInviteState.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -26,5 +26,5 @@ data class RoomInviteState( /** * List of state events (array of MXEvent). */ - var events: List? = null + val events: List = emptyList() ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt similarity index 65% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt index 5bd6cffef5..05cd35594f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -10,32 +10,32 @@ import im.vector.matrix.android.api.events.Event @JsonClass(generateAdapter = true) data class RoomResponse( // The room identifier. - var roomId: String? = null, + val roomId: String? = null, // The last recent messages of the room. - var messages: TokensChunkResponse? = null, + val messages: TokensChunkResponse? = null, // The state events. - var state: List? = null, + val state: List? = null, // The private data that this user has attached to this room. - var accountData: List? = null, + val accountData: List? = null, // The current user membership in this room. - var membership: String? = null, + val membership: String? = null, // The room visibility (public/private). - var visibility: String? = null, + val visibility: String? = null, // The matrix id of the inviter in case of pending invitation. - var inviter: String? = null, + val inviter: String? = null, // The invite event if membership is invite. - var invite: Event? = null, + val invite: Event? = null, // The presence status of other users (Provided in case of room initial sync @see http://matrix.org/docs/api/client-server/#!/-rooms/get_room_sync_data)). - var presence: List? = null, + val presence: List? = null, // The read receipts (Provided in case of room initial sync). - var receipts: List? = null + val receipts: List? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt similarity index 79% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSync.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt index 694f1a7ea3..200e1c62a8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -23,26 +23,26 @@ data class RoomSync( /** * The state updates for the room. */ - var state: RoomSyncState? = null, + val state: RoomSyncState? = null, /** * The timeline of messages and state changes in the room. */ - var timeline: RoomSyncTimeline? = null, + val timeline: RoomSyncTimeline? = null, /** * The ephemeral events in the room that aren't recorded in the timeline or state of the room (e.g. typing, receipts). */ - var ephemeral: RoomSyncEphemeral? = null, + val ephemeral: RoomSyncEphemeral? = null, /** * The account data events for the room (e.g. tags). */ - var accountData: RoomSyncAccountData? = null, + val accountData: RoomSyncAccountData? = null, /** * The notification counts for the room. */ - var unreadNotifications: RoomSyncUnreadNotifications? = null + val unreadNotifications: RoomSyncUnreadNotifications? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncAccountData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt similarity index 70% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncAccountData.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt index d520211e81..c7d3f887eb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncAccountData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass import im.vector.matrix.android.api.events.Event @@ -8,5 +8,5 @@ data class RoomSyncAccountData( /** * List of account data events (array of Event). */ - var events: List? = null + val events: List? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncEphemeral.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt similarity index 78% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncEphemeral.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt index 0b7e6bf3d4..a010177c70 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncEphemeral.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -10,5 +10,5 @@ data class RoomSyncEphemeral( /** * List of ephemeral events (array of Event). */ - var events: List? = null + val events: List? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncState.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt index da3f441781..6477d798c7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncState.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncTimeline.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt similarity index 76% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncTimeline.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt index 5354695172..08d2361782 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncTimeline.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -11,15 +11,15 @@ data class RoomSyncTimeline( /** * List of events (array of Event). */ - var events: List? = null, + val events: List? = null, /** * Boolean which tells whether there are more events on the server */ - var limited: Boolean = false, + val limited: Boolean = false, /** * If the batch was limited then this is a token that can be supplied to the server to retrieve more events */ - var prevBatch: String? = null + val prevBatch: String? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncUnreadNotifications.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt similarity index 86% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncUnreadNotifications.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt index 872a35b693..3c4ad4c798 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomSyncUnreadNotifications.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomsSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt similarity index 82% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomsSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt index a79ea4e2c2..b6a35b7387 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/RoomsSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -23,14 +23,15 @@ data class RoomsSyncResponse( /** * Joined rooms: keys are rooms ids. */ - var join: Map? = null, + val join: Map = emptyMap(), /** * Invitations. The rooms that the user has been invited to: keys are rooms ids. */ - var invite: Map? = null, + val invite: Map = emptyMap(), /** * Left rooms. The rooms that the user has left or been banned from: keys are rooms ids. */ - var leave: Map? = null) \ No newline at end of file + val leave: Map = emptyMap() +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/SyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt similarity index 60% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/SyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt index 015e1c8bdb..defc6c8319 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/SyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -9,36 +9,36 @@ data class SyncResponse( /** * The user private data. */ - var accountData: Map? = null, + val accountData: Map = emptyMap(), /** * The opaque token for the end. */ - var nextBatch: String? = null, + val nextBatch: String? = null, /** * The updates to the presence status of other users. */ - var presence: PresenceSyncResponse? = null, + val presence: PresenceSyncResponse? = null, /* * Data directly sent to one of user's devices. */ - var toDevice: ToDeviceSyncResponse? = null, + val toDevice: ToDeviceSyncResponse? = null, /** * List of rooms. */ - var rooms: RoomsSyncResponse? = null, + val rooms: RoomsSyncResponse? = null, /** * Devices list update */ - var deviceLists: DeviceListResponse? = null, + val deviceLists: DeviceListResponse? = null, /** * One time keys management */ - var deviceOneTimeKeysCount: DeviceOneTimeKeysCountSyncResponse? = null + val deviceOneTimeKeysCount: DeviceOneTimeKeysCountSyncResponse? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/ToDeviceSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt similarity index 75% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/ToDeviceSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt index 83024b4d9d..fa81b354fe 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/ToDeviceSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.sync.data +package im.vector.matrix.android.internal.events.sync.data import com.squareup.moshi.JsonClass @@ -11,5 +11,5 @@ data class ToDeviceSyncResponse( /** * List of direct-to-device events. */ - var events: List? = null + val events: List? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/TokensChunkResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/TokensChunkResponse.kt new file mode 100644 index 0000000000..55b8064315 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/TokensChunkResponse.kt @@ -0,0 +1,9 @@ +package im.vector.matrix.android.internal.events.sync.data + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class TokensChunkResponse( + val start: String? = null, + val end: String? = null, + val chunk: List? = null) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowResponse.kt deleted file mode 100644 index 341c6a32e9..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginFlowResponse.kt +++ /dev/null @@ -1,6 +0,0 @@ -package im.vector.matrix.android.internal.login.data - -import com.squareup.moshi.JsonClass - -@JsonClass(generateAdapter = true) -data class LoginFlowResponse(val flows: List) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginParams.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginParams.kt deleted file mode 100644 index 35a1e8a089..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/login/data/LoginParams.kt +++ /dev/null @@ -1,5 +0,0 @@ -package im.vector.matrix.android.internal.login.data - -interface LoginParams { - val type: String -} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/AccessTokenInterceptor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/AccessTokenInterceptor.kt index cb961644ea..ab30a02a4d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/AccessTokenInterceptor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/AccessTokenInterceptor.kt @@ -1,6 +1,6 @@ package im.vector.matrix.android.internal.network -import im.vector.matrix.android.api.login.CredentialsStore +import im.vector.matrix.android.api.auth.CredentialsStore import okhttp3.Interceptor import okhttp3.Response diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/TokensChunkResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/TokensChunkResponse.kt deleted file mode 100644 index aab839da1d..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/sync/data/TokensChunkResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package im.vector.matrix.android.internal.sync.data - -import com.squareup.moshi.JsonClass - -@JsonClass(generateAdapter = true) -data class TokensChunkResponse( - var start: String? = null, - var end: String? = null, - var chunk: List? = null) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixCoroutineDispatchers.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/MatrixCoroutineDispatchers.kt similarity index 81% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixCoroutineDispatchers.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/MatrixCoroutineDispatchers.kt index 9663725025..2b25129ced 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/MatrixCoroutineDispatchers.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/util/MatrixCoroutineDispatchers.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal +package im.vector.matrix.android.internal.util import kotlinx.coroutines.CoroutineDispatcher