diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventContent.kt deleted file mode 100644 index b1c2c28492..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventContent.kt +++ /dev/null @@ -1,36 +0,0 @@ -package im.vector.matrix.android.api.events - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import im.vector.matrix.android.internal.legacy.rest.model.pid.RoomThirdPartyInvite - -/** - * Class representing an event content - */ -@JsonClass(generateAdapter = true) -data class EventContent( - /** - * The display name for this user, if any. - */ - @Json(name = "displayname") val displayName: String? = null, - - /** - * The avatar URL for this user, if any. - */ - @Json(name = "avatar_url") val avatarUrl: String? = null, - - /** - * The membership state of the user. One of: ["invite", "join", "knock", "leave", "ban"] - */ - @Json(name = "membership") val membership: String? = null, - - /** - * the third party invite - */ - @Json(name = "third_party_invite") val thirdPartyInvite: RoomThirdPartyInvite? = null, - - /* - * e2e encryption format - */ - @Json(name = "algorithm") val algorithm: String? = null -) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/LightEvent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/LightEvent.kt deleted file mode 100644 index ead9d541d4..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/LightEvent.kt +++ /dev/null @@ -1,2 +0,0 @@ -package im.vector.matrix.android.api.events - 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 deleted file mode 100644 index 6c273e13fc..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Room.kt +++ /dev/null @@ -1,9 +0,0 @@ -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/RoomState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomState.kt deleted file mode 100644 index 29ce205544..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomState.kt +++ /dev/null @@ -1,749 +0,0 @@ -package im.vector.matrix.android.api.rooms - -import android.text.TextUtils -import im.vector.matrix.android.api.events.Event -import im.vector.matrix.android.api.events.EventType -import im.vector.matrix.android.api.rooms.timeline.EventTimeline -import im.vector.matrix.android.internal.legacy.MXDataHandler -import im.vector.matrix.android.internal.legacy.call.MXCallsManager -import im.vector.matrix.android.internal.legacy.data.store.IMXStore -import im.vector.matrix.android.internal.legacy.rest.callback.ApiCallback -import im.vector.matrix.android.internal.legacy.rest.callback.SimpleApiCallback -import im.vector.matrix.android.internal.legacy.rest.model.* -import im.vector.matrix.android.internal.legacy.rest.model.RoomDirectoryVisibility -import im.vector.matrix.android.internal.legacy.rest.model.RoomMember -import im.vector.matrix.android.internal.legacy.rest.model.pid.RoomThirdPartyInvite -import im.vector.matrix.android.internal.legacy.util.JsonUtils -import im.vector.matrix.android.internal.legacy.util.Log -import timber.log.Timber -import java.util.* -import kotlin.collections.ArrayList - -/** - * The state of a room. - */ -data class RoomState( - var roomId: String? = null, - var powerLevels: PowerLevels? = null, - var canonicalAlias: String? = null, - var name: String? = null, - var topic: String? = null, - var roomTombstoneContent: RoomTombstoneContent? = null, - var url: String? = null, - var avatarUrl: String? = null, - var roomCreateContent: RoomCreateContent? = null, - var roomPinnedEventsContent: RoomPinnedEventsContent? = null, - var joinRule: String? = null, - var guestAccess: String = RoomState.GUEST_ACCESS_FORBIDDEN, - var historyVisibility: String? = RoomState.HISTORY_VISIBILITY_SHARED, - var visibility: String? = null, - var algorithm: String? = null, - var groups: List = emptyList(), - var token: String? = null, - - private var mergedAliasesList: MutableList? = null, - private var currentAliases: MutableList = ArrayList(), - private var roomAliases: MutableMap = HashMap(), - private var aliasesByDomain_: MutableMap> = HashMap(), - private var stateEvents: MutableMap> = HashMap(), - private var notificationCount_: Int = 0, - private var highlightCount_: Int = 0, - private val members: HashMap = HashMap(), - private var allMembersAreLoaded: Boolean = false, - private val getAllMembersCallbacks: ArrayList>> = ArrayList(), - private val thirdPartyInvites: HashMap = HashMap(), - private val membersWithThirdPartyInviteTokenCache: HashMap = HashMap(), - private var isLive: Boolean = false, - private var memberDisplayNameByUserId: MutableMap = HashMap() -) { - - lateinit var dataHandler: MXDataHandler - - /** - * @return a copy of the room members list. May be incomplete if the full list is not loaded yet - */ - // make a copy to avoid concurrency modifications - val loadedMembers: List - get() { - val res: List - synchronized(this) { - res = ArrayList(members.values) - } - return res - } - - /** - * @return a copy of the displayable members list. May be incomplete if the full list is not loaded yet - */ - val displayableLoadedMembers: List - get() { - val conferenceUserId = getMember(MXCallsManager.getConferenceUserId(roomId)) - return loadedMembers.filter { it != conferenceUserId } - } - - /** - * Tells if the room is a call conference one - * i.e. this room has been created to manage the call conference - * - * @return true if it is a call conference room. - */ - /** - * Set this room as a conference user room - * - * @param isConferenceUserRoom true when it is an user conference room. - */ - var isConferenceUserRoom: Boolean - get() = dataHandler.store.getSummary(roomId)?.isConferenceUserRoom ?: false - set(isConferenceUserRoom) = dataHandler.store!!.getSummary(roomId)!!.setIsConferenceUserRoom(isConferenceUserRoom) - - /** - * @return the notified messages count. - */ - /** - * Update the notified messages count. - * - * @param notificationCount the new notified messages count. - */ - var notificationCount: Int - get() = notificationCount_ - set(notificationCount) { - Timber.d("## setNotificationCount() : $notificationCount room id $roomId") - notificationCount_ = notificationCount - } - - /** - * @return the highlighted messages count. - */ - /** - * Update the highlighted messages count. - * - * @param highlightCount the new highlighted messages count. - */ - var highlightCount: Int - get() = highlightCount_ - set(highlightCount) { - Timber.d("## setHighlightCount() : $highlightCount room id $roomId") - highlightCount_ = highlightCount - } - - /** - * Provides the currentAliases by domain - * - * @return the currentAliases list map - */ - val aliasesByDomain: Map> - get() = HashMap(aliasesByDomain_) - - /** - * @return true if the room is encrypted - */ - // When a client receives an m.room.encryption event as above, it should set a flag to indicate that messages sent in the room should be encrypted. - // This flag should not be cleared if a later m.room.encryption event changes the configuration. This is to avoid a situation where a MITM can simply - // ask participants to disable encryption. In short: once encryption is enabled in a room, it can never be disabled. - val isEncrypted: Boolean - get() = null != algorithm - - /** - * @return true if the room is versioned, it means that the room is obsolete. - * You can't interact with it anymore, but you can still browse the past messages. - */ - val isVersioned: Boolean - get() = roomTombstoneContent != null - - /** - * @return true if the room is a public one - */ - val isPublic: Boolean - get() = TextUtils.equals(if (null != visibility) visibility else joinRule, RoomDirectoryVisibility.DIRECTORY_VISIBILITY_PUBLIC) - - /** - * Get the list of all the room members. Fetch from server if the full list is not loaded yet. - * - * @param callback The callback to get a copy of the room members list. - */ - fun getMembersAsync(callback: ApiCallback>) { - if (areAllMembersLoaded()) { - val res: List - - synchronized(this) { - // make a copy to avoid concurrency modifications - res = ArrayList(members.values) - } - - callback.onSuccess(res) - } else { - val doTheRequest: Boolean - - synchronized(getAllMembersCallbacks) { - getAllMembersCallbacks.add(callback) - - doTheRequest = getAllMembersCallbacks.size == 1 - } - - if (doTheRequest) { - // Load members from server - dataHandler.getMembersAsync(roomId, object : SimpleApiCallback>(callback) { - override fun onSuccess(info: List) { - Timber.d("getMembers has returned " + info.size + " users.") - - val store = (dataHandler as MXDataHandler).store - var res: List - - for (member in info) { - // Do not erase already known members form the sync - if (getMember(member.userId) == null) { - setMember(member.userId, member) - - // Also create a User - store?.updateUserWithRoomMemberEvent(member) - } - } - - synchronized(getAllMembersCallbacks) { - for (apiCallback in getAllMembersCallbacks) { - // make a copy to avoid concurrency modifications - res = ArrayList(members.values) - - apiCallback.onSuccess(res) - } - - getAllMembersCallbacks.clear() - } - - allMembersAreLoaded = true - } - }) - } - } - } - - /** - * Tell if all members has been loaded - * - * @return true if LazyLoading is Off, or if all members has been loaded - */ - private fun areAllMembersLoaded(): Boolean { - return !dataHandler.isLazyLoadingEnabled || allMembersAreLoaded - } - - /** - * Force a fetch of the loaded members the next time they will be requested - */ - fun forceMembersRequest() { - allMembersAreLoaded = false - } - - /** - * Provides the loaded states event list. - * The room member events are NOT included. - * - * @param types the allowed event types. - * @return the filtered state events list. - */ - fun getStateEvents(types: Set?): List { - val filteredStateEvents = ArrayList() - val stateEvents = ArrayList() - - // merge the values lists - val currentStateEvents = this.stateEvents.values - for (eventsList in currentStateEvents) { - stateEvents.addAll(eventsList) - } - - if (null != types && !types.isEmpty()) { - for (stateEvent in stateEvents) { - if (types.contains(stateEvent.type)) { - filteredStateEvents.add(stateEvent) - } - } - } else { - filteredStateEvents.addAll(stateEvents) - } - - return filteredStateEvents - } - - - /** - * Provides the state events list. - * It includes the room member creation events (they are not loaded in memory by default). - * - * @param store the store in which the state events must be retrieved - * @param types the allowed event types. - * @param callback the asynchronous callback. - */ - fun getStateEvents(store: IMXStore?, types: Set?, callback: ApiCallback>) { - if (null != store) { - val stateEvents = ArrayList() - - val currentStateEvents = this.stateEvents.values - - for (eventsList in currentStateEvents) { - stateEvents.addAll(eventsList) - } - - // retrieve the roomMember creation events - store.getRoomStateEvents(roomId, object : SimpleApiCallback>() { - override fun onSuccess(events: List) { - stateEvents.addAll(events) - - val filteredStateEvents = ArrayList() - - if (null != types && !types.isEmpty()) { - for (stateEvent in stateEvents) { - if (types.contains(stateEvent.type)) { - filteredStateEvents.add(stateEvent) - } - } - } else { - filteredStateEvents.addAll(stateEvents) - } - - callback.onSuccess(filteredStateEvents) - } - }) - } - } - - /** - * Provides a list of displayable members. - * Some dummy members are created to internal stuff. - * - * @param callback The callback to get a copy of the displayable room members list. - */ - fun getDisplayableMembersAsync(callback: ApiCallback>) { - getMembersAsync(object : SimpleApiCallback>(callback) { - override fun onSuccess(members: List) { - val conferenceUserId = getMember(MXCallsManager.getConferenceUserId(roomId)) - - if (null != conferenceUserId) { - val membersList = ArrayList(members) - membersList.remove(conferenceUserId) - callback.onSuccess(membersList) - } else { - callback.onSuccess(members) - } - } - }) - } - - /** - * Update the room member from its user id. - * - * @param userId the user id. - * @param member the new member value. - */ - private fun setMember(userId: String, member: RoomMember) { - // Populate a basic user object if there is none - if (member.userId == null) { - member.userId = userId - } - synchronized(this) { - if (null != memberDisplayNameByUserId) { - memberDisplayNameByUserId!!.remove(userId) - } - members.put(userId, member) - } - } - - /** - * Retrieve a room member from its user id. - * - * @param userId the user id. - * @return the linked member it exists. - */ - // TODO Change this? Can return null if all members are not loaded yet - fun getMember(userId: String): RoomMember? { - val member: RoomMember? - - synchronized(this) { - member = members[userId] - } - - if (member == null) { - // TODO LazyLoading - Log.e(LOG_TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Null member '$userId' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - - if (TextUtils.equals(dataHandler.userId, userId)) { - // This should never happen - Log.e(LOG_TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Null current user '$userId' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - } - } - - return member - } - - /** - * Retrieve a room member from its original event id. - * It can return null if the lazy loading is enabled and if the member is not loaded yet. - * - * @param eventId the event id. - * @return the linked member if it exists and if it is loaded. - */ - fun getMemberByEventId(eventId: String): RoomMember? { - var member: RoomMember? = null - - synchronized(this) { - for (aMember in members.values) { - if (aMember.originalEventId == eventId) { - member = aMember - break - } - } - } - - return member - } - - /** - * Remove a member defines by its user id. - * - * @param userId the user id. - */ - fun removeMember(userId: String) { - synchronized(this) { - members.remove(userId) - // remove the cached display name - if (null != memberDisplayNameByUserId) { - memberDisplayNameByUserId!!.remove(userId) - } - } - } - - /** - * Retrieve a member from an invitation token. - * - * @param thirdPartyInviteToken the third party invitation token. - * @return the member it exists. - */ - fun memberWithThirdPartyInviteToken(thirdPartyInviteToken: String): RoomMember? { - return membersWithThirdPartyInviteTokenCache[thirdPartyInviteToken] - } - - /** - * Retrieve a RoomThirdPartyInvite from its token. - * - * @param thirdPartyInviteToken the third party invitation token. - * @return the linked RoomThirdPartyInvite if it exists - */ - fun thirdPartyInviteWithToken(thirdPartyInviteToken: String): RoomThirdPartyInvite? { - return thirdPartyInvites[thirdPartyInviteToken] - } - - /** - * @return the third party invite list. - */ - fun thirdPartyInvites(): Collection { - return thirdPartyInvites.values - } - - /** - * Check if the user userId can back paginate. - * - * @param isJoined true is user is in the room - * @param isInvited true is user is invited to the room - * @return true if the user can back paginate. - */ - fun canBackPaginate(isJoined: Boolean, isInvited: Boolean): Boolean { - val visibility = if (TextUtils.isEmpty(historyVisibility)) HISTORY_VISIBILITY_SHARED else historyVisibility - return (isJoined - || visibility == HISTORY_VISIBILITY_WORLD_READABLE - || visibility == HISTORY_VISIBILITY_SHARED - || visibility == HISTORY_VISIBILITY_INVITED && isInvited) - } - - /** - * Provides the currentAliases for any known domains - * - * @return the currentAliases list - */ - fun getAliases(): List { - if (mergedAliasesList != null) { - return mergedAliasesList as List - } - val merged = ArrayList() - for (url in aliasesByDomain.keys) { - merged.addAll(aliasesByDomain[url] ?: emptyList()) - } - // ensure that the current currentAliases have been added. - // for example for the public rooms because there is no applystate call. - for (anAlias in currentAliases) { - if (merged.indexOf(anAlias) < 0) { - merged.add(anAlias) - } - } - mergedAliasesList = merged - return merged - } - - /** - * Remove an alias. - * - * @param alias the alias to remove - */ - fun removeAlias(alias: String) { - if (getAliases().indexOf(alias) >= 0) { - currentAliases.remove(alias) - for (host in aliasesByDomain.keys) { - aliasesByDomain_[host]?.remove(alias) - } - } - mergedAliasesList = null - } - - /** - * Add an alias. - * - * @param alias the alias to add - */ - fun addAlias(alias: String) { - if (getAliases().indexOf(alias) < 0) { - // patch until the server echoes the alias addition. - mergedAliasesList?.add(alias) - } - } - - /** - * @return true if the room has a predecessor - */ - fun hasPredecessor(): Boolean { - return roomCreateContent != null && roomCreateContent!!.hasPredecessor() - } - - /** - * @return the encryption algorithm - */ - fun encryptionAlgorithm(): String? { - return if (TextUtils.isEmpty(algorithm)) null else algorithm - } - - /** - * Apply the given event (relevant for state changes) to our state. - * - * @param store the store to use - * @param event the event - * @param direction how the event should affect the state: Forwards for applying, backwards for un-applying (applying the previous state) - * @return true if the event is managed - */ - fun applyState(store: IMXStore?, event: Event, direction: EventTimeline.Direction): Boolean { - if (event.stateKey == null) { - return false - } - val contentToConsider = if (direction == EventTimeline.Direction.FORWARDS) event.contentAsJsonObject else event.prevContentAsJsonObject - val dataToConsider = if (direction == EventTimeline.Direction.FORWARDS) event.content else event.prevContent - - - val eventType = event.type - try { - if (EventType.STATE_ROOM_NAME == eventType) { - name = JsonUtils.toStateEvent(contentToConsider).name - } else if (EventType.STATE_ROOM_TOPIC == eventType) { - topic = JsonUtils.toStateEvent(contentToConsider).topic - } else if (EventType.STATE_ROOM_CREATE == eventType) { - roomCreateContent = JsonUtils.toRoomCreateContent(contentToConsider) - } else if (EventType.STATE_ROOM_JOIN_RULES == eventType) { - joinRule = JsonUtils.toStateEvent(contentToConsider).joinRule - } else if (EventType.STATE_ROOM_GUEST_ACCESS == eventType) { - guestAccess = JsonUtils.toStateEvent(contentToConsider).guestAccess - } else if (EventType.STATE_ROOM_ALIASES == eventType) { - if (!TextUtils.isEmpty(event.stateKey)) { - // backward compatibility - currentAliases = JsonUtils.toStateEvent(contentToConsider).aliases - // sanity check - if (null != currentAliases) { - aliasesByDomain_[event.stateKey] = currentAliases - roomAliases[event.stateKey] = event - } else { - aliasesByDomain_[event.stateKey] = ArrayList() - } - } - } else if (EventType.ENCRYPTION == eventType) { - algorithm = JsonUtils.toStateEvent(contentToConsider).algorithm - // When a client receives an m.room.encryption event as above, it should set a flag to indicate that messages sent - // in the room should be encrypted. - // This flag should not be cleared if a later m.room.encryption event changes the configuration. This is to avoid - // a situation where a MITM can simply ask participants to disable encryption. In short: once encryption is enabled - // in a room, it can never be disabled. - if (algorithm == null) { - algorithm = "" - } - } else if (EventType.STATE_CANONICAL_ALIAS == eventType) { - // SPEC-125 - canonicalAlias = JsonUtils.toStateEvent(contentToConsider).canonicalAlias - } else if (EventType.STATE_HISTORY_VISIBILITY == eventType) { - // SPEC-134 - historyVisibility = JsonUtils.toStateEvent(contentToConsider).historyVisibility - } else if (EventType.STATE_ROOM_AVATAR == eventType) { - url = JsonUtils.toStateEvent(contentToConsider).url - } else if (EventType.STATE_RELATED_GROUPS == eventType) { - groups = JsonUtils.toStateEvent(contentToConsider).groups - } else if (EventType.STATE_ROOM_MEMBER == eventType) { - val member = JsonUtils.toRoomMember(contentToConsider) - val userId = event.stateKey - if (member == null) { - // the member has already been removed - if (getMember(userId) == null) { - Log.e(LOG_TAG, "## applyState() : the user $userId is not anymore a member of $roomId") - return false - } - removeMember(userId) - } else { - try { - member.userId = userId - member.originServerTs = event.originServerTs ?: -1 - member.originalEventId = event.eventId - member.mSender = event.sender - if (null != store && direction == EventTimeline.Direction.FORWARDS) { - store.storeRoomStateEvent(roomId, event) - } - val currentMember = getMember(userId) - // check if the member is the same - // duplicated message ? - if (member.equals(currentMember)) { - Log.e(LOG_TAG, "## applyState() : seems being a duplicated event for $userId in room $roomId") - return false - } - - // when a member leaves a room, his avatar / display name is not anymore provided - if (currentMember != null && (TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_LEAVE) || TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_BAN))) { - if (member.getAvatarUrl() == null) { - member.setAvatarUrl(currentMember.getAvatarUrl()) - } - if (member.displayname == null) { - member.displayname = currentMember.displayname - } - // remove the cached display name - memberDisplayNameByUserId.remove(userId) - - // test if the user has been kicked - if (!TextUtils.equals(event.sender, event.stateKey) - && TextUtils.equals(currentMember.membership, RoomMember.MEMBERSHIP_JOIN) - && TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_LEAVE)) { - member.membership = RoomMember.MEMBERSHIP_KICK - } - } - - if (direction == EventTimeline.Direction.FORWARDS && null != store) { - store.updateUserWithRoomMemberEvent(member) - } - - // Cache room member event that is successor of a third party invite event - if (!TextUtils.isEmpty(member.thirdPartyInviteToken)) { - membersWithThirdPartyInviteTokenCache[member.thirdPartyInviteToken] = member - } - } catch (e: Exception) { - Log.e(LOG_TAG, "## applyState() - EVENT_TYPE_STATE_ROOM_MEMBER failed " + e.message, e) - } - - setMember(userId, member) - } - } else if (EventType.STATE_ROOM_POWER_LEVELS == eventType) { - powerLevels = event.toModel(dataToConsider) - } else if (EventType.STATE_ROOM_THIRD_PARTY_INVITE == eventType) { - val thirdPartyInvite = JsonUtils.toRoomThirdPartyInvite(contentToConsider) - thirdPartyInvite.token = event.stateKey - if (direction == EventTimeline.Direction.FORWARDS && null != store) { - store.storeRoomStateEvent(roomId, event) - } - if (!TextUtils.isEmpty(thirdPartyInvite.token)) { - thirdPartyInvites[thirdPartyInvite.token] = thirdPartyInvite - } - } else if (EventType.STATE_ROOM_TOMBSTONE == eventType) { - roomTombstoneContent = JsonUtils.toRoomTombstoneContent(contentToConsider) - } else if (EventType.STATE_PINNED_EVENT == eventType) { - roomPinnedEventsContent = JsonUtils.toRoomPinnedEventsContent(contentToConsider) - } - // same the latest room state events - // excepts the membership ones - // they are saved elsewhere - if (!TextUtils.isEmpty(eventType) && EventType.STATE_ROOM_MEMBER != eventType) { - var eventsList: MutableList? = stateEvents[eventType] - if (eventsList == null) { - eventsList = ArrayList() - stateEvents[eventType] = eventsList - } - eventsList.add(event) - } - - } catch (e: Exception) { - Log.e(LOG_TAG, "applyState failed with error " + e.message, e) - } - - return true - } - - /** - * Return an unique display name of the member userId. - * - * @param userId the user id - * @return unique display name - */ - fun getMemberName(userId: String?): String? { - // sanity check - if (userId == null) { - return null - } - var displayName: String? - synchronized(this) { - displayName = memberDisplayNameByUserId[userId] - } - if (displayName != null) { - return displayName - } - // Get the user display name from the member list of the room - val member = getMember(userId) - // Do not consider null display name - if (null != member && !TextUtils.isEmpty(member.displayname)) { - displayName = member.displayname - synchronized(this) { - val matrixIds = ArrayList() - // Disambiguate users who have the same display name in the room - for (aMember in members.values) { - if (displayName == aMember.displayname) { - matrixIds.add(aMember.userId) - } - } - // if several users have the same display name - // index it i.e bob () - if (matrixIds.size > 1) { - displayName += " ($userId)" - } - } - } else if (null != member && TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_INVITE)) { - val user = dataHandler.getUser(userId) - if (null != user) { - displayName = user.displayname - } - } - if (displayName == null) { - // By default, use the user ID - displayName = userId - } - displayName?.let { - memberDisplayNameByUserId[userId] = it - } - return displayName - } - - companion object { - private val LOG_TAG = RoomState::class.java.simpleName - private val serialVersionUID = -6019932024524988201L - - val JOIN_RULE_PUBLIC = "public" - val JOIN_RULE_INVITE = "invite" - - /** - * room access is granted to guests - */ - val GUEST_ACCESS_CAN_JOIN = "can_join" - /** - * room access is denied to guests - */ - val GUEST_ACCESS_FORBIDDEN = "forbidden" - - val HISTORY_VISIBILITY_SHARED = "shared" - val HISTORY_VISIBILITY_INVITED = "invited" - val HISTORY_VISIBILITY_JOINED = "joined" - val HISTORY_VISIBILITY_WORLD_READABLE = "world_readable" - } -} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomSummary.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomSummary.kt deleted file mode 100644 index 3affc2a25e..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomSummary.kt +++ /dev/null @@ -1,517 +0,0 @@ -package im.vector.matrix.android.api.rooms - - -import android.text.TextUtils -import im.vector.matrix.android.api.events.Event -import im.vector.matrix.android.api.events.EventContent -import im.vector.matrix.android.api.events.EventType -import im.vector.matrix.android.internal.legacy.call.MXCallsManager -import im.vector.matrix.android.internal.legacy.data.RoomState -import im.vector.matrix.android.internal.legacy.rest.model.RoomMember -import im.vector.matrix.android.internal.legacy.rest.model.message.Message -import im.vector.matrix.android.internal.legacy.rest.model.sync.RoomSyncSummary -import timber.log.Timber -import java.util.* - -/** - * Stores summarised information about the room. - */ -class RoomSummary() { - - private var mRoomId: String? = null - /** - * @return the topic. - */ - var roomTopic: String? = null - private set - private var mLatestReceivedEvent: Event? = null - - // the room state is only used to check - // 1- the invitation status - // 2- the members display name - @Transient private var mLatestRoomState: RoomState? = null - - // defines the latest read message - /** - * @return the read receipt event id - */ - /** - * Set the read receipt event Id - * - * @param eventId the read receipt event id. - */ - var readReceiptEventId: String? = null - set(eventId) { - Timber.d("## setReadReceiptEventId() : " + eventId + " roomId " + getRoomId()) - field = eventId - } - - // the read marker event id - private var mReadMarkerEventId: String? = null - - /** - * @return the room tags - */ - /** - * Update the room tags - * - * @param roomTags the room tags - */ - // wraps the set into a serializable one - var roomTags: Set? = null - set(roomTags) = if (roomTags != null) { - field = HashSet(roomTags) - } else { - field = HashSet() - } - - // counters - var mUnreadEventsCount: Int = 0 - var mNotificationCount: Int = 0 - var mHighlightsCount: Int = 0 - - // invitation status - // retrieved at initial sync - // the roomstate is not always known - /** - * @return the inviter user id. - */ - var inviterUserId: String? = null - private set - - // retrieved from the roomState - private var mInviterName: String? = null - - /** - * @return the user id - */ - var userId: String? = null - - // Info from sync, depending on the room position in the sync - private var mUserMembership: String? = null - - /** - * Tell if the room is a user conference user one - */ - private var mIsConferenceUserRoom: Boolean? = null - - /** - * Data from RoomSyncSummary - */ - private val mHeroes = ArrayList() - - var numberOfJoinedMembers: Int = 0 - private set - - var numberOfInvitedMembers: Int = 0 - private set - - /** - * @return true if the current user is invited - */ - val isInvited: Boolean - get() = RoomMember.MEMBERSHIP_INVITE == mUserMembership - - /** - * @return true if the current user is invited - */ - val isJoined: Boolean - get() = RoomMember.MEMBERSHIP_JOIN == mUserMembership - - /** - * @return the read receipt event id - */ - /** - * Set the read marker event Id - * - * @param eventId the read marker event id. - */ - var readMarkerEventId: String? - get() { - if (TextUtils.isEmpty(mReadMarkerEventId)) { - Timber.e("## getReadMarkerEventId') : null mReadMarkerEventId, in " + getRoomId()!!) - mReadMarkerEventId = readReceiptEventId - } - - return mReadMarkerEventId - } - set(eventId) { - Timber.d("## setReadMarkerEventId() : " + eventId + " roomId " + getRoomId()) - - if (TextUtils.isEmpty(eventId)) { - Timber.e("## setReadMarkerEventId') : null mReadMarkerEventId, in " + getRoomId()!!) - } - - mReadMarkerEventId = eventId - } - - /** - * @return the unread events count - */ - /** - * Update the unread message counter - * - * @param count the unread events count. - */ - var unreadEventsCount: Int - get() = mUnreadEventsCount - set(count) { - Timber.d("## setUnreadEventsCount() : " + count + " roomId " + getRoomId()) - mUnreadEventsCount = count - } - - /** - * @return the notification count - */ - /** - * Update the notification counter - * - * @param count the notification counter - */ - var notificationCount: Int - get() = mNotificationCount - set(count) { - Timber.d("## setNotificationCount() : " + count + " roomId " + getRoomId()) - mNotificationCount = count - } - - /** - * @return the highlight count - */ - /** - * Update the highlight counter - * - * @param count the highlight counter - */ - var highlightCount: Int - get() = mHighlightsCount - set(count) { - Timber.d("## setHighlightCount() : " + count + " roomId " + getRoomId()) - mHighlightsCount = count - } - - // test if it is not yet initialized - // FIXME LazyLoading Heroes does not contains me - // FIXME I'ms not sure this code will work anymore - // works only with 1:1 room - var isConferenceUserRoom: Boolean - get() { - if (null == mIsConferenceUserRoom) { - - mIsConferenceUserRoom = false - - val membersId = heroes - if (2 == membersId.size) { - for (userId in membersId) { - if (MXCallsManager.isConferenceUserId(userId)) { - mIsConferenceUserRoom = true - break - } - } - } - } - - return mIsConferenceUserRoom!! - } - set(isConferenceUserRoom) { - mIsConferenceUserRoom = isConferenceUserRoom - } - - val heroes: List - get() = mHeroes - - /** - * Create a room summary - * - * @param fromSummary the summary source - * @param event the latest event of the room - * @param roomState the room state - used to display the event - * @param userId our own user id - used to display the room name - */ - constructor(fromSummary: RoomSummary?, - event: Event?, - roomState: RoomState?, - userId: String) : this() { - this.userId = userId - if (roomState != null) { - setRoomId(roomState.roomId) - } - if (mRoomId == null) { - event?.roomId?.let { setRoomId(it) } - } - setLatestReceivedEvent(event, roomState) - - // if no summary is provided - if (fromSummary == null) { - event?.let { - readMarkerEventId = it.eventId - readReceiptEventId = it.eventId - } - roomState?.let { - highlightCount = it.highlightCount - notificationCount = it.highlightCount - } - unreadEventsCount = Math.max(highlightCount, notificationCount) - } else { - // else use the provided summary data - readMarkerEventId = fromSummary.readMarkerEventId - readReceiptEventId = fromSummary.readReceiptEventId - unreadEventsCount = fromSummary.unreadEventsCount - highlightCount = fromSummary.highlightCount - notificationCount = fromSummary.notificationCount - mHeroes.addAll(fromSummary.mHeroes) - numberOfJoinedMembers = fromSummary.numberOfJoinedMembers - numberOfInvitedMembers = fromSummary.numberOfInvitedMembers - mUserMembership = fromSummary.mUserMembership - } - } - - /** - * @return the room id - */ - fun getRoomId(): String? { - return mRoomId - } - - /** - * @return the room summary event. - */ - fun getLatestReceivedEvent(): Event? { - return mLatestReceivedEvent - } - - /** - * @return the dedicated room state. - */ - fun getLatestRoomState(): RoomState? { - return mLatestRoomState - } - - /** - * To call when the room is in the invited section of the sync response - */ - fun setIsInvited() { - mUserMembership = RoomMember.MEMBERSHIP_INVITE - } - - /** - * To call when the room is in the joined section of the sync response - */ - fun setIsJoined() { - mUserMembership = RoomMember.MEMBERSHIP_JOIN - } - - /** - * Set the room's [org.matrix.androidsdk.rest.model.Event.EVENT_TYPE_STATE_ROOM_TOPIC]. - * - * @param topic The topic - * @return This summary for chaining calls. - */ - fun setTopic(topic: String): RoomSummary { - roomTopic = topic - return this - } - - /** - * Set the room's ID.. - * - * @param roomId The room ID - * @return This summary for chaining calls. - */ - fun setRoomId(roomId: String): RoomSummary { - mRoomId = roomId - return this - } - - /** - * Set the latest tracked event (e.g. the latest m.room.message) - * - * @param event The most-recent event. - * @param roomState The room state - * @return This summary for chaining calls. - */ - fun setLatestReceivedEvent(event: Event?, roomState: RoomState?): RoomSummary { - setLatestReceivedEvent(event) - setLatestRoomState(roomState) - - if (null != roomState) { - setTopic(roomState.topic) - } - return this - } - - /** - * Set the latest tracked event (e.g. the latest m.room.message) - * - * @param event The most-recent event. - * @return This summary for chaining calls. - */ - fun setLatestReceivedEvent(event: Event?): RoomSummary { - mLatestReceivedEvent = event - return this - } - - /** - * Set the latest RoomState - * - * @param roomState The room state of the latest event. - * @return This summary for chaining calls. - */ - fun setLatestRoomState(roomState: RoomState?): RoomSummary { - mLatestRoomState = roomState - - // Keep this code for compatibility? - var isInvited = false - - // check for the invitation status - if (null != mLatestRoomState) { - val member = mLatestRoomState!!.getMember(userId) - isInvited = null != member && RoomMember.MEMBERSHIP_INVITE == member.membership - } - // when invited, the only received message should be the invitation one - if (isInvited) { - mInviterName = null - - if (null != mLatestReceivedEvent) { - inviterUserId = mLatestReceivedEvent!!.sender - mInviterName = inviterUserId - - // try to retrieve a display name - if (null != mLatestRoomState) { - mInviterName = mLatestRoomState!!.getMemberName(mLatestReceivedEvent!!.sender) - } - } - } else { - mInviterName = null - inviterUserId = mInviterName - } - - return this - } - - fun setRoomSyncSummary(roomSyncSummary: RoomSyncSummary) { - if (roomSyncSummary.heroes != null) { - mHeroes.clear() - mHeroes.addAll(roomSyncSummary.heroes) - } - - if (roomSyncSummary.joinedMembersCount != null) { - // Update the value - numberOfJoinedMembers = roomSyncSummary.joinedMembersCount - } - - if (roomSyncSummary.invitedMembersCount != null) { - // Update the value - numberOfInvitedMembers = roomSyncSummary.invitedMembersCount - } - } - - companion object { - - private const val serialVersionUID = -3683013938626566489L - - // list of supported types - private val supportedType = Arrays.asList( - EventType.STATE_ROOM_TOPIC, - EventType.ENCRYPTED, - EventType.ENCRYPTION, - EventType.STATE_ROOM_NAME, - EventType.STATE_ROOM_MEMBER, - EventType.STATE_ROOM_CREATE, - EventType.STATE_HISTORY_VISIBILITY, - EventType.STATE_ROOM_THIRD_PARTY_INVITE, - EventType.STICKER) - - // List of known unsupported types - private val knownUnsupportedType = Arrays.asList( - EventType.TYPING, - EventType.STATE_ROOM_POWER_LEVELS, - EventType.STATE_ROOM_JOIN_RULES, - EventType.STATE_CANONICAL_ALIAS, - EventType.STATE_ROOM_ALIASES, - EventType.PREVIEW_URLS, - EventType.STATE_RELATED_GROUPS, - EventType.STATE_ROOM_GUEST_ACCESS, - EventType.REDACTION) - - /** - * Test if the event can be summarized. - * Some event types are not yet supported. - * - * @param event the event to test. - * @return true if the event can be summarized - */ - fun isSupportedEvent(event: Event): Boolean { - val type = event.type - var isSupported = false - - // check if the msgtype is supported - if (TextUtils.equals(EventType.MESSAGE, type)) { - try { - val eventContent = event.contentAsJsonObject - var msgType = "" - - val element = eventContent!!.get("msgtype") - - if (null != element) { - msgType = element.asString - } - - isSupported = (TextUtils.equals(msgType, Message.MSGTYPE_TEXT) - || TextUtils.equals(msgType, Message.MSGTYPE_EMOTE) - || TextUtils.equals(msgType, Message.MSGTYPE_NOTICE) - || TextUtils.equals(msgType, Message.MSGTYPE_IMAGE) - || TextUtils.equals(msgType, Message.MSGTYPE_AUDIO) - || TextUtils.equals(msgType, Message.MSGTYPE_VIDEO) - || TextUtils.equals(msgType, Message.MSGTYPE_FILE)) - - if (!isSupported && !TextUtils.isEmpty(msgType)) { - Timber.e("isSupportedEvent : Unsupported msg type $msgType") - } - } catch (e: Exception) { - Timber.e(e, "isSupportedEvent failed " + e.message) - } - - } else if (EventType.ENCRYPTED == type) { - isSupported = event.content?.isNotEmpty() ?: false - } else if (EventType.STATE_ROOM_MEMBER == type) { - val eventContentAsJsonObject = event.contentAsJsonObject - if (eventContentAsJsonObject != null) { - if (eventContentAsJsonObject.entrySet().isEmpty()) { - Timber.d("isSupportedEvent : room member with no content is not supported") - } else { - // do not display the avatar / display name update - val prevEventContent = event.prevContent() - val eventContent = event.content() - var membership: String? = null - var preMembership: String? = null - if (eventContent != null) { - membership = eventContent.membership - } - if (prevEventContent != null) { - preMembership = prevEventContent.membership - } - - isSupported = !TextUtils.equals(membership, preMembership) - - if (!isSupported) { - Timber.d("isSupportedEvent : do not support avatar display name update") - } - } - } - } else { - isSupported = supportedType.contains(type) || event.isCallEvent && !TextUtils.isEmpty(type) && EventType.CALL_CANDIDATES != type - } - - if (!isSupported) { - // some events are known to be never traced - // avoid warning when it is not required. - if (!knownUnsupportedType.contains(type)) { - Timber.e("isSupportedEvent : Unsupported event type $type") - } - } - - return isSupported - } - } -} 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 deleted file mode 100644 index a7ab1035a9..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/timeline/EventTimeline.java +++ /dev/null @@ -1,52 +0,0 @@ -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/api/session/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt index cacf786dd8..6b72884c0d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt @@ -1,20 +1,21 @@ package im.vector.matrix.android.api.session import android.support.annotation.MainThread +import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.internal.database.SessionRealmHolder -import im.vector.matrix.android.internal.events.sync.job.SyncThread +import im.vector.matrix.android.internal.session.sync.job.SyncThread -interface Session { +interface Session : RoomService { @MainThread fun open() + @MainThread + fun close() + fun syncThread(): SyncThread // Visible for testing request directly. Will be deleted fun realmHolder(): SessionRealmHolder - @MainThread - fun close() - } \ No newline at end of file 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/session/events/model/Event.kt similarity index 96% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/Event.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt index 7d46fed641..06cc008824 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/session/events/model/Event.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.events +package im.vector.matrix.android.api.session.events.model import com.google.gson.JsonObject import com.squareup.moshi.Json @@ -50,6 +50,4 @@ data class Event( || EventType.CALL_HANGUP == type } -} - - +} \ No newline at end of file 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/session/events/model/EventType.kt similarity index 96% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/EventType.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/EventType.kt index 809ba43f57..bfb0bdc89a 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/session/events/model/EventType.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.events +package im.vector.matrix.android.api.session.events.model object EventType { 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/session/events/model/UnsignedData.kt similarity index 84% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/events/UnsignedData.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/UnsignedData.kt index f22604c3cb..a66f6569f1 100644 --- 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/session/events/model/UnsignedData.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.events +package im.vector.matrix.android.api.session.events.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt new file mode 100644 index 0000000000..4c41bfb808 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/Room.kt @@ -0,0 +1,7 @@ +package im.vector.matrix.android.api.session.room + +interface Room { + + val roomId: String + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt new file mode 100644 index 0000000000..fa343f2882 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt @@ -0,0 +1,13 @@ +package im.vector.matrix.android.api.session.room + +import android.arch.lifecycle.LiveData + +interface RoomService { + + fun getRoom(roomId: String): Room? + + fun getAllRooms(): List + + fun observeAllRooms(): LiveData> + +} \ 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/session/room/model/Invite.kt similarity index 67% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Invite.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Invite.kt index 79b9fa8485..51be64c4bb 100644 --- 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/session/room/model/Invite.kt @@ -1,10 +1,12 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass +import im.vector.matrix.android.api.session.room.Signed @JsonClass(generateAdapter = true) 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/session/room/model/Membership.kt similarity index 67% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Membership.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Membership.kt index c7657acbf9..8bb57b15c5 100644 --- 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/session/room/model/Membership.kt @@ -1,11 +1,13 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model 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 + @Json(name = "ban") BAN; + +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/PowerLevels.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevels.kt similarity index 85% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/PowerLevels.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevels.kt index dc69642c1d..bb648186c0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/PowerLevels.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/PowerLevels.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import android.text.TextUtils import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.EventType +import im.vector.matrix.android.api.session.events.model.EventType import java.util.* @JsonClass(generateAdapter = true) @@ -19,13 +19,14 @@ data class PowerLevels( @Json(name = "state_default") val stateDefault: Int = 50, @Json(name = "notifications") val notifications: Map = HashMap() ) { + /** * Returns the user power level of a dedicated user Id * * @param userId the user id * @return the power level */ - fun getUserPowerLevel(userId: String): Int { + fun getUserPowerLevel(userId: String): Int { // sanity check if (!TextUtils.isEmpty(userId)) { val powerLevel = users[userId] @@ -41,7 +42,7 @@ data class PowerLevels( * @param userId the user * @param powerLevel the new power level */ - fun setUserPowerLevel(userId: String?, powerLevel: Int) { + fun setUserPowerLevel(userId: String?, powerLevel: Int) { if (null != userId) { users[userId] = Integer.valueOf(powerLevel) } @@ -54,7 +55,7 @@ data class PowerLevels( * @param userId the user id * @return true if the user can send the event */ - fun maySendEventOfType(eventTypeString: String, userId: String): Boolean { + fun maySendEventOfType(eventTypeString: String, userId: String): Boolean { return if (!TextUtils.isEmpty(eventTypeString) && !TextUtils.isEmpty(userId)) { getUserPowerLevel(userId) >= minimumPowerLevelForSendingEventAsMessage(eventTypeString) } else false @@ -67,7 +68,7 @@ data class PowerLevels( * @param userId the user id * @return true if the user can send a room message */ - fun maySendMessage(userId: String): Boolean { + fun maySendMessage(userId: String): Boolean { return maySendEventOfType(EventType.MESSAGE, userId) } @@ -78,7 +79,7 @@ data class PowerLevels( * @param eventTypeString the type of event (in Event.EVENT_TYPE_XXX values) * @return the required minimum power level. */ - fun minimumPowerLevelForSendingEventAsMessage(eventTypeString: String?): Int { + fun minimumPowerLevelForSendingEventAsMessage(eventTypeString: String?): Int { return events[eventTypeString] ?: eventsDefault } @@ -89,7 +90,7 @@ data class PowerLevels( * @param eventTypeString the type of event (in Event.EVENT_TYPE_STATE_ values). * @return the required minimum power level. */ - fun minimumPowerLevelForSendingEventAsStateEvent(eventTypeString: String?): Int { + fun minimumPowerLevelForSendingEventAsStateEvent(eventTypeString: String?): Int { return events[eventTypeString] ?: stateDefault } @@ -100,7 +101,7 @@ data class PowerLevels( * @param key the notification key * @return the level */ - fun notificationLevel(key: String?): Int { + fun notificationLevel(key: String?): Int { if (null != key && notifications.containsKey(key)) { val valAsVoid = notifications[key] 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/session/room/model/RoomDirectoryVisibility.kt similarity index 71% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomDirectoryVisibility.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomDirectoryVisibility.kt index c6faf2df34..6887533e4f 100644 --- 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/session/room/model/RoomDirectoryVisibility.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json 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/session/room/model/RoomHistoryVisibility.kt similarity index 80% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomHistoryVisibility.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomHistoryVisibility.kt index 23d69708d0..19bb7f8119 100644 --- 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/session/room/model/RoomHistoryVisibility.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json 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/session/room/model/RoomMember.kt similarity index 81% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomMember.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomMember.kt index 7cbfb4418c..d292206226 100644 --- 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/session/room/model/RoomMember.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.UnsignedData +import im.vector.matrix.android.api.session.events.model.UnsignedData @JsonClass(generateAdapter = true) data class RoomMember( diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomNameContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomNameContent.kt similarity index 76% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomNameContent.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomNameContent.kt index bafa4149fb..0559356141 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomNameContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomNameContent.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomTopicContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomTopicContent.kt similarity index 76% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomTopicContent.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomTopicContent.kt index 02ba7477b4..5967e93483 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/RoomTopicContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomTopicContent.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass 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/session/room/model/Signed.kt similarity index 80% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/rooms/Signed.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Signed.kt index 0f7aa5a95b..c533e33071 100644 --- 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/session/room/model/Signed.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.rooms +package im.vector.matrix.android.api.session.room import com.squareup.moshi.Json diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveData.kt new file mode 100644 index 0000000000..74237561da --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveData.kt @@ -0,0 +1,22 @@ +package im.vector.matrix.android.internal.database + +import android.arch.lifecycle.LiveData +import io.realm.RealmChangeListener +import io.realm.RealmModel +import io.realm.RealmResults + +class RealmLiveData(private val realmResults: RealmResults, + private val mapper: (T) -> U) : LiveData>() { + + private val listener = RealmChangeListener> { results -> + value = results.map { mapper.invoke(it) } + } + + override fun onActive() { + realmResults.addChangeListener(listener) + } + + override fun onInactive() { + realmResults.removeChangeListener(listener) + } +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/SessionRealmHolder.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/SessionRealmHolder.kt index 5d1195cb92..254ff8b642 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/SessionRealmHolder.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/SessionRealmHolder.kt @@ -3,21 +3,27 @@ package im.vector.matrix.android.internal.database import android.support.annotation.MainThread import io.realm.Realm import io.realm.RealmConfiguration +import java.util.concurrent.atomic.AtomicBoolean class SessionRealmHolder(private val realmConfiguration: RealmConfiguration ) { lateinit var instance: Realm + private val isOpen = AtomicBoolean(false) @MainThread fun open() { - instance = Realm.getInstance(realmConfiguration) + if (isOpen.compareAndSet(false, true)) { + instance = Realm.getInstance(realmConfiguration) + } } @MainThread fun close() { - instance.close() - Realm.compactRealm(realmConfiguration) + if (isOpen.compareAndSet(true, false)) { + instance.close() + Realm.compactRealm(realmConfiguration) + } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt index 05b25dbbf8..767cada7bf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt @@ -1,10 +1,10 @@ package im.vector.matrix.android.internal.database.mapper import com.squareup.moshi.Types -import im.vector.matrix.android.api.events.Event -import im.vector.matrix.android.api.events.UnsignedData +import im.vector.matrix.android.api.session.events.model.UnsignedData import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.di.MoshiProvider +import im.vector.matrix.android.api.session.events.model.Event object EventMapper { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt index 6d5bacd810..1901a6eea2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/RoomEntityQueries.kt @@ -2,7 +2,7 @@ package im.vector.matrix.android.internal.database.query import im.vector.matrix.android.internal.database.model.RoomEntity import io.realm.Realm -import io.realm.RealmResults +import io.realm.RealmQuery fun RoomEntity.Companion.getForId(realm: Realm, roomId: String): RoomEntity? { return realm.where(RoomEntity::class.java) @@ -10,10 +10,10 @@ fun RoomEntity.Companion.getForId(realm: Realm, roomId: String): RoomEntity? { .findFirst() } -fun RoomEntity.Companion.getAllAsync(realm: Realm, membership: RoomEntity.Membership? = null): RealmResults { +fun RoomEntity.Companion.getAll(realm: Realm, membership: RoomEntity.Membership? = null): RealmQuery { val query = realm.where(RoomEntity::class.java) if (membership != null) { query.equalTo("membership", membership.name) } - return query.findAllAsync() + return query } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/crypto/MXCrypto.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/crypto/MXCrypto.java index 91be02ee7b..4943f7cc87 100755 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/crypto/MXCrypto.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/crypto/MXCrypto.java @@ -54,7 +54,6 @@ import im.vector.matrix.android.internal.legacy.rest.model.crypto.KeysUploadResp import im.vector.matrix.android.internal.legacy.rest.model.crypto.RoomKeyContent; import im.vector.matrix.android.internal.legacy.rest.model.crypto.RoomKeyRequest; import im.vector.matrix.android.internal.legacy.rest.model.crypto.RoomKeyRequestBody; -import im.vector.matrix.android.internal.legacy.rest.model.sync.SyncResponse; import im.vector.matrix.android.internal.legacy.util.JsonUtils; import im.vector.matrix.android.internal.legacy.util.Log; @@ -600,7 +599,7 @@ public class MXCrypto { * @param fromToken the start sync token * @param isCatchingUp true if there is a catch-up in progress. */ - public void onSyncCompleted(final im.vector.matrix.android.internal.events.sync.data.SyncResponse syncResponse, final String fromToken, final boolean isCatchingUp) { + public void onSyncCompleted(final im.vector.matrix.android.internal.session.sync.model.SyncResponse syncResponse, final String fromToken, final boolean isCatchingUp) { getEncryptingThreadHandler().post(new Runnable() { @Override public void run() { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/IMXStore.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/IMXStore.java index ab390bc2ac..c8efaaff56 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/IMXStore.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/IMXStore.java @@ -430,7 +430,7 @@ public interface IMXStore { * @param roomId the room id * @param event the event */ - void storeRoomStateEvent(String roomId, im.vector.matrix.android.api.events.Event event); + void storeRoomStateEvent(String roomId, im.vector.matrix.android.api.session.events.model.Event event); /** * Retrieve the room state creation events @@ -438,7 +438,7 @@ public interface IMXStore { * @param roomId the room id * @param callback the asynchronous callback */ - void getRoomStateEvents(String roomId, ApiCallback> callback); + void getRoomStateEvents(String roomId, ApiCallback> callback); /** * Return the list of latest unsent events. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXFileStore.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXFileStore.java index 38c026d9e0..0a7a0a16e4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXFileStore.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXFileStore.java @@ -1369,7 +1369,7 @@ public class MXFileStore extends MXMemoryStore { private Map> mPendingRoomStateEvents = new HashMap<>(); @Override - public void storeRoomStateEvent(final String roomId, final im.vector.matrix.android.api.events.Event event) { + public void storeRoomStateEvent(final String roomId, final im.vector.matrix.android.api.session.events.model.Event event) { /*boolean isAlreadyLoaded = true; synchronized (mRoomStateEventsByRoomId) { @@ -1477,7 +1477,7 @@ public class MXFileStore extends MXMemoryStore { } @Override - public void getRoomStateEvents(final String roomId, final ApiCallback> callback) { + public void getRoomStateEvents(final String roomId, final ApiCallback> callback) { boolean isAlreadyLoaded = true; /*synchronized (mRoomStateEventsByRoomId) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXMemoryStore.java b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXMemoryStore.java index 1482abfdc2..159035494a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXMemoryStore.java +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/legacy/data/store/MXMemoryStore.java @@ -871,7 +871,7 @@ public class MXMemoryStore implements IMXStore { } @Override - public void storeRoomStateEvent(String roomId, im.vector.matrix.android.api.events.Event event) { + public void storeRoomStateEvent(String roomId, im.vector.matrix.android.api.session.events.model.Event event) { /*synchronized (mRoomStateEventsByRoomId) { Map events = mRoomStateEventsByRoomId.get(roomId); @@ -888,8 +888,8 @@ public class MXMemoryStore implements IMXStore { } @Override - public void getRoomStateEvents(final String roomId, final ApiCallback> callback) { - final List events = new ArrayList<>(); + public void getRoomStateEvents(final String roomId, final ApiCallback> callback) { + final List events = new ArrayList<>(); /*synchronized (mRoomStateEventsByRoomId) { if (mRoomStateEventsByRoomId.containsKey(roomId)) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 820ec2b092..5944f8a099 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -1,13 +1,16 @@ package im.vector.matrix.android.internal.session +import android.arch.lifecycle.LiveData import android.os.Looper import android.support.annotation.MainThread import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.internal.auth.data.SessionParams import im.vector.matrix.android.internal.database.SessionRealmHolder -import im.vector.matrix.android.internal.di.SessionModule -import im.vector.matrix.android.internal.events.sync.SyncModule -import im.vector.matrix.android.internal.events.sync.job.SyncThread +import im.vector.matrix.android.internal.session.room.RoomSummaryObserver +import im.vector.matrix.android.internal.session.sync.SyncModule +import im.vector.matrix.android.internal.session.sync.job.SyncThread import org.koin.core.scope.Scope import org.koin.standalone.KoinComponent import org.koin.standalone.StandAloneContext @@ -15,7 +18,8 @@ import org.koin.standalone.getKoin import org.koin.standalone.inject -class DefaultSession(private val sessionParams: SessionParams) : Session, KoinComponent { +class DefaultSession(private val sessionParams: SessionParams +) : Session, KoinComponent, RoomService { companion object { const val SCOPE: String = "session" @@ -25,6 +29,7 @@ class DefaultSession(private val sessionParams: SessionParams) : Session, KoinCo private val realmInstanceHolder by inject() private val roomSummaryObserver by inject() + private val roomService by inject() private val syncThread by inject() private var isOpen = false @@ -63,6 +68,20 @@ class DefaultSession(private val sessionParams: SessionParams) : Session, KoinCo isOpen = false } + // ROOM SERVICE + + override fun getRoom(roomId: String): Room? { + return roomService.getRoom(roomId) + } + + override fun getAllRooms(): List { + return roomService.getAllRooms() + } + + override fun observeAllRooms(): LiveData> { + return roomService.observeAllRooms() + } + // Private methods ***************************************************************************** private fun checkIsMainThread() { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt similarity index 81% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/SessionModule.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index 66e653c064..03af4f0e85 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -1,12 +1,13 @@ -package im.vector.matrix.android.internal.di +package im.vector.matrix.android.internal.session +import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.internal.auth.data.SessionParams import im.vector.matrix.android.internal.database.SessionRealmHolder import im.vector.matrix.android.internal.legacy.MXDataHandler import im.vector.matrix.android.internal.legacy.MXSession import im.vector.matrix.android.internal.legacy.data.store.MXFileStore -import im.vector.matrix.android.internal.session.DefaultSession -import im.vector.matrix.android.internal.session.RoomSummaryObserver +import im.vector.matrix.android.internal.session.room.DefaultRoomService +import im.vector.matrix.android.internal.session.room.RoomSummaryObserver import io.realm.RealmConfiguration import org.koin.dsl.context.ModuleDefinition import org.koin.dsl.module.Module @@ -36,6 +37,10 @@ class SessionModule(private val sessionParams: SessionParams) : Module { RoomSummaryObserver(get(), get(), get()) } + scope(DefaultSession.SCOPE) { + DefaultRoomService(get(), get()) as RoomService + } + scope(DefaultSession.SCOPE) { val store = MXFileStore(sessionParams.credentials, false, get()) val dataHandler = MXDataHandler(store, sessionParams.credentials) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt new file mode 100644 index 0000000000..9c903d3143 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt @@ -0,0 +1,7 @@ +package im.vector.matrix.android.internal.session.room + +import im.vector.matrix.android.api.session.room.Room + +data class DefaultRoom( + override val roomId: String +) : Room \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt new file mode 100644 index 0000000000..d533eae245 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt @@ -0,0 +1,38 @@ +package im.vector.matrix.android.internal.session.room + +import android.arch.lifecycle.LiveData +import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.RoomService +import im.vector.matrix.android.internal.database.RealmLiveData +import im.vector.matrix.android.internal.database.SessionRealmHolder +import im.vector.matrix.android.internal.database.model.RoomEntity +import im.vector.matrix.android.internal.database.query.getAll +import im.vector.matrix.android.internal.database.query.getForId +import io.realm.Realm +import io.realm.RealmConfiguration + +class DefaultRoomService(private val realmConfiguration: RealmConfiguration, + val mainThreadRealm: SessionRealmHolder) + : RoomService { + + override fun getAllRooms(): List { + val realm = Realm.getInstance(realmConfiguration) + val rooms = RoomEntity.getAll(realm).findAll().map { DefaultRoom(it.roomId) } + realm.close() + return rooms + } + + override fun getRoom(roomId: String): Room? { + val realm = Realm.getInstance(realmConfiguration) + val room = RoomEntity.getForId(realm, roomId)?.let { DefaultRoom(it.roomId) } + realm.close() + return room + } + + override fun observeAllRooms(): LiveData> { + val roomResults = RoomEntity.getAll(mainThreadRealm.instance).findAllAsync() + return RealmLiveData(roomResults) { DefaultRoom(it.roomId) } + } + + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/RoomSummaryObserver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryObserver.kt similarity index 86% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/RoomSummaryObserver.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryObserver.kt index 80777943dc..3bd9a87b9d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/RoomSummaryObserver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryObserver.kt @@ -1,14 +1,14 @@ -package im.vector.matrix.android.internal.session +package im.vector.matrix.android.internal.session.room -import im.vector.matrix.android.api.events.EventType -import im.vector.matrix.android.api.rooms.RoomNameContent -import im.vector.matrix.android.api.rooms.RoomTopicContent +import im.vector.matrix.android.api.session.events.model.EventType +import im.vector.matrix.android.api.session.room.model.RoomNameContent +import im.vector.matrix.android.api.session.room.model.RoomTopicContent import im.vector.matrix.android.internal.database.SessionRealmHolder import im.vector.matrix.android.internal.database.mapper.asDomain import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.model.RoomSummaryEntity -import im.vector.matrix.android.internal.database.query.getAllAsync +import im.vector.matrix.android.internal.database.query.getAll import im.vector.matrix.android.internal.database.query.getAllFromRoom import im.vector.matrix.android.internal.database.query.getLast import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers @@ -29,7 +29,7 @@ internal class RoomSummaryObserver(private val mainThreadRealm: SessionRealmHold fun start() { if (isStarted.compareAndSet(false, true)) { - roomResults = RoomEntity.getAllAsync(mainThreadRealm.instance) + roomResults = RoomEntity.getAll(mainThreadRealm.instance).findAllAsync() roomResults.addChangeListener { rooms, changeSet -> manageRoomResults(rooms, changeSet.changes) manageRoomResults(rooms, changeSet.insertions) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/RoomSyncHandler.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt index 070247fd80..6be5dea3b9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt @@ -1,14 +1,14 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.internal.database.mapper.asEntity import im.vector.matrix.android.internal.database.model.ChunkEntity import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.query.getChunkIncludingEvents import im.vector.matrix.android.internal.database.query.getForId import im.vector.matrix.android.internal.database.query.getLastChunkFromRoom -import im.vector.matrix.android.internal.events.sync.data.InvitedRoomSync -import im.vector.matrix.android.internal.events.sync.data.RoomSync +import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync +import im.vector.matrix.android.internal.session.sync.model.RoomSync import io.realm.Realm import io.realm.RealmConfiguration diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncAPI.kt similarity index 73% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncAPI.kt index 9ae00c562e..6652648942 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncAPI.kt @@ -1,6 +1,6 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync -import im.vector.matrix.android.internal.events.sync.data.SyncResponse +import im.vector.matrix.android.internal.session.sync.model.SyncResponse 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/events/sync/SyncModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt similarity index 88% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncModule.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt index 10d7602b9f..963f8dc45c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncModule.kt @@ -1,6 +1,6 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync -import im.vector.matrix.android.internal.events.sync.job.SyncThread +import im.vector.matrix.android.internal.session.sync.job.SyncThread import im.vector.matrix.android.internal.session.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/events/sync/SyncRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncRequest.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt index 0048ae1b46..1d216a177f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync import arrow.core.Either import arrow.core.flatMap @@ -6,7 +6,7 @@ import arrow.core.leftIfNull import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.internal.events.sync.data.SyncResponse +import im.vector.matrix.android.internal.session.sync.model.SyncResponse import im.vector.matrix.android.internal.legacy.rest.model.filter.FilterBody import im.vector.matrix.android.internal.legacy.util.FilterUtil import im.vector.matrix.android.internal.network.executeRequest 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/session/sync/SyncResponseHandler.kt similarity index 99% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncResponseHandler.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncResponseHandler.kt index aa2b90d7aa..2e7424869c 100644 --- 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/session/sync/SyncResponseHandler.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync import android.text.TextUtils -import im.vector.matrix.android.api.events.Event -import im.vector.matrix.android.internal.events.sync.data.SyncResponse +import im.vector.matrix.android.api.session.events.model.Event +import im.vector.matrix.android.internal.session.sync.model.SyncResponse import im.vector.matrix.android.internal.legacy.MXDataHandler import im.vector.matrix.android.internal.legacy.data.Room import im.vector.matrix.android.internal.legacy.data.store.IMXStore diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncTokenStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncTokenStore.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt index 46df72574a..9fceffbabf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/SyncTokenStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTokenStore.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync +package im.vector.matrix.android.internal.session.sync import im.vector.matrix.android.internal.database.model.SyncEntity import io.realm.Realm diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/job/SyncThread.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/job/SyncThread.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt index a35fcffa6b..f471ed7209 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/job/SyncThread.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/job/SyncThread.kt @@ -1,11 +1,11 @@ -package im.vector.matrix.android.internal.events.sync.job +package im.vector.matrix.android.internal.session.sync.job import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.util.Cancelable -import im.vector.matrix.android.internal.events.sync.SyncRequest -import im.vector.matrix.android.internal.events.sync.SyncTokenStore -import im.vector.matrix.android.internal.events.sync.data.SyncResponse +import im.vector.matrix.android.internal.session.sync.SyncRequest +import im.vector.matrix.android.internal.session.sync.SyncTokenStore +import im.vector.matrix.android.internal.session.sync.model.SyncResponse import im.vector.matrix.android.internal.network.NetworkConnectivityChecker import im.vector.matrix.android.internal.util.BackgroundDetectionObserver import timber.log.Timber diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceInfo.kt similarity index 95% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceInfo.kt index 331bce6b87..3189783bac 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceInfo.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceListResponse.kt similarity index 94% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceListResponse.kt index 598e67287b..aaedb78e13 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceListResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceOneTimeKeysCountSyncResponse.kt similarity index 78% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceOneTimeKeysCountSyncResponse.kt index de7d9497c6..85e1b53e64 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DeviceOneTimeKeysCountSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DeviceOneTimeKeysCountSyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DevicesListResponse.kt similarity index 92% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/DevicesListResponse.kt index 5b57c7ad3e..0dad8d8db0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/DevicesListResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupSyncProfile.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupSyncProfile.kt similarity index 87% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupSyncProfile.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupSyncProfile.kt index bf7360b769..3073a2e5de 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupSyncProfile.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupSyncProfile.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupsSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupsSyncResponse.kt similarity index 91% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupsSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupsSyncResponse.kt index 3934d58e3a..21ee8e1622 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/GroupsSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/GroupsSyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedGroupSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/InvitedGroupSync.kt similarity index 86% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedGroupSync.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/InvitedGroupSync.kt index 7de27e7112..787601c98e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedGroupSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/InvitedGroupSync.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/InvitedRoomSync.kt similarity index 96% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/InvitedRoomSync.kt index 335614654a..77b1d940b6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/InvitedRoomSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/PresenceSyncResponse.kt similarity index 74% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/PresenceSyncResponse.kt index 251b9b4508..8c5812543d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/PresenceSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/PresenceSyncResponse.kt @@ -1,7 +1,7 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // PresenceSyncResponse represents the updates to the presence status of other users during server sync v2. @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomInviteState.kt similarity index 88% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomInviteState.kt index fadf7139b0..52056f5304 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomInviteState.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomInviteState.kt @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // RoomInviteState represents the state of a room that the user has been invited to. @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomResponse.kt similarity index 91% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomResponse.kt index 05cd35594f..028ed717f5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomResponse.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event /** * Class representing a room from a JSON response from room or global initial sync. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSync.kt similarity index 96% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSync.kt index 3601876411..cd3a532c38 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncAccountData.kt similarity index 69% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncAccountData.kt index 98244c2656..f158f94f4d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncAccountData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncAccountData.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event @JsonClass(generateAdapter = true) data class RoomSyncAccountData( diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncEphemeral.kt similarity index 76% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncEphemeral.kt index 7c9bded676..1c1087d731 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncEphemeral.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncEphemeral.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // RoomSyncEphemeral represents the ephemeral events in the room that aren't recorded in the timeline or state of the room (e.g. typing). @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncState.kt similarity index 77% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncState.kt index 807e3f7523..e0a628d479 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncState.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncState.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // RoomSyncState represents the state updates for a room during server sync v2. @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncTimeline.kt similarity index 85% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncTimeline.kt index 5edc511075..512711247a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncTimeline.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncTimeline.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // RoomSyncTimeline represents the timeline of messages and state changes for a room during server sync v2. @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncUnreadNotifications.kt similarity index 85% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncUnreadNotifications.kt index ee06af0eb8..c8c1269cf2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomSyncUnreadNotifications.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomSyncUnreadNotifications.kt @@ -1,9 +1,9 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event /** * `MXRoomSyncUnreadNotifications` represents the unread counts for a room. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomsSyncResponse.kt similarity index 95% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/RoomsSyncResponse.kt index 5dce5332dc..fa1930fb3f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/RoomsSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/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.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/SyncResponse.kt similarity index 95% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/SyncResponse.kt index 7c66f4c1c8..60ac12e9f6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/SyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/SyncResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.Json import com.squareup.moshi.JsonClass diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/ToDeviceSyncResponse.kt similarity index 70% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/ToDeviceSyncResponse.kt index fa81b354fe..52db7b0f7e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/ToDeviceSyncResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/ToDeviceSyncResponse.kt @@ -1,8 +1,8 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.events.Event +import im.vector.matrix.android.api.session.events.model.Event // ToDeviceSyncResponse represents the data directly sent to one of user's devices. @JsonClass(generateAdapter = true) 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/session/sync/model/TokensChunkResponse.kt similarity index 77% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/events/sync/data/TokensChunkResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/TokensChunkResponse.kt index 55b8064315..396a69ebe7 100644 --- 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/session/sync/model/TokensChunkResponse.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.internal.events.sync.data +package im.vector.matrix.android.internal.session.sync.model import com.squareup.moshi.JsonClass