Start importing some classes from the developed SDK... + rename packages

This commit is contained in:
ganfra 2018-10-05 18:14:32 +02:00
parent c4316d5055
commit a7eecdffae
61 changed files with 901 additions and 172 deletions

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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 {

View file

@ -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 {

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -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 <reified T> content(): T? {
val moshi = Moshi.Builder().build()
return moshi.adapter<T>(T::class.java).fromJson(content)
}
inline fun <reified T> prevContent(): T? {
if (prevContent == null) {
return null
}
val moshi = Moshi.Builder().build()
return moshi.adapter<T>(T::class.java).fromJson(prevContent)
}
}

View file

@ -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
}

View file

@ -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
)

View file

@ -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)
}

View file

@ -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
)

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
)

View file

@ -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<String> = emptyList()
)

View file

@ -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
)

View file

@ -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.
* <p>
* There are two kinds of timeline:
* <p>
* - live timelines: they receive live events from the events stream. You can paginate
* backwards but not forwards.
* <p>
* - 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);
}
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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<LoginFlow>)

View file

@ -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"

View file

@ -0,0 +1,5 @@
package im.vector.matrix.android.internal.auth.data
interface LoginParams {
val type: String
}

View file

@ -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

View file

@ -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 {

View file

@ -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<Credentials>) : CredentialsStore {

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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<String, Any>?, isInitialSync: Boolean) {
try {
if (accountData!!.containsKey("events")) {
val events = accountData["events"] as List<Map<String, Any>>
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<Map<String, Any>>) {
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<Map<String, Any>>, 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<Map<String, Any>>): List<String>? {
var ignoredUsers: List<String>? = 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<String, Any>
if (contentDict.containsKey(AccountDataRestClient.ACCOUNT_DATA_KEY_IGNORED_USERS)) {
val ignored_users = contentDict[AccountDataRestClient.ACCOUNT_DATA_KEY_IGNORED_USERS] as Map<String, Any>
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<Map<String, Any>>, 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<String, List<String>>
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<Map<String, Any>>) {
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<String, Any>
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<Map<String, Any>>) {
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<String, Any>
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<String, List<String>>? = 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<String>
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<Void>() {
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}}"
}
}
*/

View file

@ -0,0 +1,11 @@
package im.vector.matrix.android.internal.events.sync
class Synchronizer(private val syncAPI: SyncAPI) {
fun synchronize() {
}
}

View file

@ -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
)

View file

@ -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<String>? = null,
val changed: List<String> = emptyList(),
// List of user ids who are no more tracked.
val left: List<String>? = null)
val left: List<String> = emptyList()
)

View file

@ -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
)

View file

@ -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<DeviceInfo>? = null
val devices: List<DeviceInfo>? = null
)

View file

@ -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
)

View file

@ -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<Event>? = null
val events: List<Event>? = null
)

View file

@ -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<Event>? = null
val events: List<Event> = emptyList()
)

View file

@ -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<Event>? = null,
val messages: TokensChunkResponse<Event>? = null,
// The state events.
var state: List<Event>? = null,
val state: List<Event>? = null,
// The private data that this user has attached to this room.
var accountData: List<Event>? = null,
val accountData: List<Event>? = 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<Event>? = null,
val presence: List<Event>? = null,
// The read receipts (Provided in case of room initial sync).
var receipts: List<Event>? = null
val receipts: List<Event>? = null
)

View file

@ -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
)

View file

@ -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<Event>? = null
val events: List<Event>? = null
)

View file

@ -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<Event>? = null
val events: List<Event>? = null
)

View file

@ -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

View file

@ -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<Event>? = null,
val events: List<Event>? = 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
)

View file

@ -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

View file

@ -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<String, RoomSync>? = null,
val join: Map<String, RoomSync> = emptyMap(),
/**
* Invitations. The rooms that the user has been invited to: keys are rooms ids.
*/
var invite: Map<String, InvitedRoomSync>? = null,
val invite: Map<String, InvitedRoomSync> = emptyMap(),
/**
* Left rooms. The rooms that the user has left or been banned from: keys are rooms ids.
*/
var leave: Map<String, RoomSync>? = null)
val leave: Map<String, RoomSync> = emptyMap()
)

View file

@ -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<String, Any>? = null,
val accountData: Map<String, Any> = 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
)

View file

@ -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<Event>? = null
val events: List<Event>? = null
)

View file

@ -0,0 +1,9 @@
package im.vector.matrix.android.internal.events.sync.data
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class TokensChunkResponse<T>(
val start: String? = null,
val end: String? = null,
val chunk: List<T>? = null)

View file

@ -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<LoginFlow>)

View file

@ -1,5 +0,0 @@
package im.vector.matrix.android.internal.login.data
interface LoginParams {
val type: String
}

View file

@ -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

View file

@ -1,9 +0,0 @@
package im.vector.matrix.android.internal.sync.data
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class TokensChunkResponse<T>(
var start: String? = null,
var end: String? = null,
var chunk: List<T>? = null)

View file

@ -1,4 +1,4 @@
package im.vector.matrix.android.internal
package im.vector.matrix.android.internal.util
import kotlinx.coroutines.CoroutineDispatcher