diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt index bca7d480..f231d3f1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt @@ -70,11 +70,11 @@ data class HomeServerConnectionConfig( if (hsUri.scheme != "http" && hsUri.scheme != "https") { throw RuntimeException("Invalid home server URI: " + hsUri) } - // remove trailing / - homeServerUri = if (hsUri.toString().endsWith("/")) { + // ensure trailing / + homeServerUri = if (!hsUri.toString().endsWith("/")) { try { val url = hsUri.toString() - Uri.parse(url.substring(0, url.length - 1)) + Uri.parse("$url/") } catch (e: Exception) { throw RuntimeException("Invalid home server URI: $hsUri") } @@ -96,11 +96,11 @@ data class HomeServerConnectionConfig( if (identityServerUri.scheme != "http" && identityServerUri.scheme != "https") { throw RuntimeException("Invalid identity server URI: $identityServerUri") } - // remove trailing / - if (identityServerUri.toString().endsWith("/")) { + // ensure trailing / + if (!identityServerUri.toString().endsWith("/")) { try { val url = identityServerUri.toString() - this.identityServerUri = Uri.parse(url.substring(0, url.length - 1)) + this.identityServerUri = Uri.parse("$url/") } catch (e: Exception) { throw RuntimeException("Invalid identity server URI: $identityServerUri") } 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 742adb90..82264306 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 @@ -23,6 +23,7 @@ import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.crypto.CryptoService import im.vector.matrix.android.api.session.group.GroupService +import im.vector.matrix.android.api.session.room.RoomDirectoryService import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.api.session.signout.SignOutService import im.vector.matrix.android.api.session.sync.FilterService @@ -34,6 +35,7 @@ import im.vector.matrix.android.api.session.user.UserService */ interface Session : RoomService, + RoomDirectoryService, GroupService, UserService, CryptoService, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomDirectoryService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomDirectoryService.kt new file mode 100644 index 00000000..5b66ddd8 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomDirectoryService.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.session.room + +import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse +import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol +import im.vector.matrix.android.api.util.Cancelable + +/** + * This interface defines methods to get and join public rooms. It's implemented at the session level. + */ +interface RoomDirectoryService { + + /** + * Get rooms from directory + */ + fun getPublicRooms(server: String?, + publicRoomsParams: PublicRoomsParams, + callback: MatrixCallback): Cancelable + + /** + * Join a room by id + */ + fun joinRoom(roomId: String, + callback: MatrixCallback) + + /** + * Fetches the overall metadata about protocols supported by the homeserver. + * Includes both the available protocols and all fields required for queries against each protocol. + */ + fun getThirdPartyProtocol(callback: MatrixCallback>) + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt new file mode 100644 index 00000000..3ed3ec0c --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoom.kt @@ -0,0 +1,87 @@ +/* + * Copyright 2014 OpenMarket Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package im.vector.matrix.android.api.session.room.model.roomdirectory + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * Class representing the objects returned by /publicRooms call. + */ +@JsonClass(generateAdapter = true) +data class PublicRoom( + + /** + * Aliases of the room. May be empty. + */ + @Json(name = "aliases") + var aliases: List? = null, + + /** + * The canonical alias of the room, if any. + */ + @Json(name = "canonical_alias") + var canonicalAlias: String? = null, + + /** + * The name of the room, if any. + */ + @Json(name = "name") + var name: String? = null, + + /** + * Required. The number of members joined to the room. + */ + @Json(name = "num_joined_members") + var numJoinedMembers: Int = 0, + + /** + * Required. The ID of the room. + */ + @Json(name = "room_id") + var roomId: String, + + /** + * The topic of the room, if any. + */ + @Json(name = "topic") + var topic: String? = null, + + /** + * Required. Whether the room may be viewed by guest users without joining. + */ + @Json(name = "world_readable") + var worldReadable: Boolean = false, + + /** + * Required. Whether guest users may join the room and participate in it. If they can, they will be subject to ordinary power level rules like any other user. + */ + @Json(name = "guest_can_join") + var guestCanJoin: Boolean = false, + + /** + * The URL for the room's avatar, if one is set. + */ + @Json(name = "avatar_url") + var avatarUrl: String? = null, + + /** + * Undocumented item + */ + @Json(name = "m.federate") + var isFederated: Boolean = false + +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsFilter.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsFilter.kt new file mode 100644 index 00000000..b4de72e4 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsFilter.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2014 OpenMarket Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package im.vector.matrix.android.api.session.room.model.roomdirectory + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * Class to define a filter to retrieve public rooms + */ +@JsonClass(generateAdapter = true) +data class PublicRoomsFilter( + /** + * A string to search for in the room metadata, e.g. name, topic, canonical alias etc. (Optional). + */ + @Json(name = "generic_search_term") + var searchTerm: String? = null +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsParams.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsParams.kt new file mode 100644 index 00000000..e2af1c3c --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsParams.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2016 OpenMarket Ltd + * Copyright 2017 Vector Creations Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package im.vector.matrix.android.api.session.room.model.roomdirectory + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * Class to pass parameters to get the public rooms list + */ +@JsonClass(generateAdapter = true) +data class PublicRoomsParams( + /** + * Limit the number of results returned. + */ + @Json(name = "limit") + var limit: Int? = null, + + /** + * A pagination token from a previous request, allowing clients to get the next (or previous) batch of rooms. + * The direction of pagination is specified solely by which token is supplied, rather than via an explicit flag. + */ + @Json(name = "since") + var since: String? = null, + + /** + * Filter to apply to the results. + */ + @Json(name = "filter") + var filter: PublicRoomsFilter? = null, + + /** + * Whether or not to include all known networks/protocols from application services on the homeserver. Defaults to false. + */ + @Json(name = "include_all_networks") + var includeAllNetworks: Boolean = false, + + /** + * The specific third party network/protocol to request from the homeserver. Can only be used if include_all_networks is false. + */ + @Json(name = "third_party_instance_id") + var thirdPartyInstanceId: String? = null +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsResponse.kt new file mode 100644 index 00000000..3799d097 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/roomdirectory/PublicRoomsResponse.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2014 OpenMarket Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package im.vector.matrix.android.api.session.room.model.roomdirectory + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +/** + * Class representing the public rooms request response + */ +@JsonClass(generateAdapter = true) +data class PublicRoomsResponse( + /** + * A pagination token for the response. The absence of this token means there are no more results to fetch and the client should stop paginating. + */ + @Json(name = "next_batch") + var nextBatch: String? = null, + + /** + * A pagination token that allows fetching previous results. The absence of this token means there are no results before this batch, + * i.e. this is the first batch. + */ + @Json(name = "prev_batch") + var prevBatch: String? = null, + + /** + * A paginated chunk of public rooms. + */ + @Json(name = "chunk") + var chunk: List? = null, + + /** + * An estimate on the total number of public rooms, if the server has an estimate. + */ + @Json(name = "total_room_count_estimate") + var totalRoomCountEstimate: Int? = null +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/FieldType.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/FieldType.kt new file mode 100644 index 00000000..2e9f6956 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/FieldType.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.session.room.model.thirdparty + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class FieldType( + /** + * Required. A regular expression for validation of a field's value. This may be relatively coarse to verify the value as the application + * service providing this protocol may apply additional + */ + @Json(name = "regexp") + val regexp: String? = null, + + /** + * Required. An placeholder serving as a valid example of the field value. + */ + @Json(name = "placeholder") + val placeholder: String? = null +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/RoomDirectoryData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/RoomDirectoryData.kt new file mode 100644 index 00000000..11a347c0 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/RoomDirectoryData.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.session.room.model.thirdparty + +/** + * This class describes a rooms directory server. + */ +data class RoomDirectoryData( + + /** + * The server name (might be null) + * Set null when the server is the current user's home server. + */ + val homeServer: String? = null, + + /** + * The display name (the server description) + */ + val displayName: String = DEFAULT_HOME_SERVER_NAME, + + /** + * The third party server identifier + */ + val thirdPartyInstanceId: String? = null, + + /** + * Tell if all the federated servers must be included + */ + val includeAllNetworks: Boolean = false, + + /** + * the avatar url + */ + val avatarUrl: String? = null +) { + + companion object { + const val DEFAULT_HOME_SERVER_NAME = "Matrix" + } + +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocol.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocol.kt new file mode 100644 index 00000000..a31df794 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocol.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.session.room.model.thirdparty + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ThirdPartyProtocol( + /** + * Required. Fields which may be used to identify a third party user. These should be ordered to suggest the way that entities may be grouped, + * where higher groupings are ordered first. For example, the name of a network should be searched before the nickname of a user. + */ + @Json(name = "user_fields") + var userFields: List? = null, + + /** + * Required. Fields which may be used to identify a third party location. These should be ordered to suggest the way that + * entities may be grouped, where higher groupings are ordered first. For example, the name of a network should be + * searched before the name of a channel. + */ + @Json(name = "location_fields") + var locationFields: List? = null, + + /** + * Required. A content URI representing an icon for the third party protocol. + * + * FIXDOC: This field was not present in legacy Riot, and it is sometimes sent by the server (no not Required?) + */ + @Json(name = "icon") + var icon: String? = null, + + /** + * Required. The type definitions for the fields defined in the user_fields and location_fields. Each entry in those arrays MUST have an entry here. + * The string key for this object is field name itself. + * + * May be an empty object if no fields are defined. + */ + @Json(name = "field_types") + var fieldTypes: Map? = null, + + /** + * Required. A list of objects representing independent instances of configuration. For example, multiple networks on IRC + * if multiple are provided by the same application service. + */ + @Json(name = "instances") + var instances: List? = null +) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocolInstance.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocolInstance.kt new file mode 100644 index 00000000..d2bea700 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/thirdparty/ThirdPartyProtocolInstance.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.api.session.room.model.thirdparty + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class ThirdPartyProtocolInstance( + /** + * Required. A human-readable description for the protocol, such as the name. + */ + @Json(name = "desc") + var desc: String? = null, + + /** + * An optional content URI representing the protocol. Overrides the one provided at the higher level Protocol object. + */ + @Json(name = "icon") + var icon: String? = null, + + /** + * Required. Preset values for fields the client may use to search by. + */ + @Json(name = "fields") + var fields: Map? = null, + + /** + * Required. A unique identifier across all instances. + */ + @Json(name = "network_id") + var networkId: String? = null, + + /** + * FIXDOC Not documented on matrix.org doc + */ + @Json(name = "instance_id") + var instanceId: String? = null, + + + /** + * FIXDOC Not documented on matrix.org doc + */ + @Json(name = "bot_user_id") + var botUserId: String? = null +) \ No newline at end of file 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 42e5d8ed..420d675c 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 @@ -30,13 +30,18 @@ import im.vector.matrix.android.api.session.group.Group import im.vector.matrix.android.api.session.group.GroupService import im.vector.matrix.android.api.session.group.model.GroupSummary import im.vector.matrix.android.api.session.room.Room +import im.vector.matrix.android.api.session.room.RoomDirectoryService import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse +import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol import im.vector.matrix.android.api.session.signout.SignOutService import im.vector.matrix.android.api.session.sync.FilterService import im.vector.matrix.android.api.session.user.UserService import im.vector.matrix.android.api.session.user.model.User +import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.MatrixCallbackDelegate import im.vector.matrix.android.internal.database.LiveEntityObserver import im.vector.matrix.android.internal.di.MatrixKoinComponent @@ -64,6 +69,7 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi private val liveEntityUpdaters by inject>() private val sessionListeners by inject() private val roomService by inject() + private val roomDirectoryService by inject() private val groupService by inject() private val userService by inject() private val filterService by inject() @@ -171,6 +177,23 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi return roomService.liveRoomSummaries() } + // ROOM DIRECTORY SERVICE + + override fun getPublicRooms(server: String?, publicRoomsParams: PublicRoomsParams, callback: MatrixCallback): Cancelable { + assert(isOpen) + return roomDirectoryService.getPublicRooms(server, publicRoomsParams, callback) + } + + override fun joinRoom(roomId: String, callback: MatrixCallback) { + assert(isOpen) + return roomDirectoryService.joinRoom(roomId, callback) + } + + override fun getThirdPartyProtocol(callback: MatrixCallback>) { + assert(isOpen) + return roomDirectoryService.getThirdPartyProtocol(callback) + } + // GROUP SERVICE override fun getGroup(groupId: String): Group? { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index 6640cb2a..6d8084c0 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -21,6 +21,7 @@ import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.session.cache.CacheService import im.vector.matrix.android.api.session.group.GroupService +import im.vector.matrix.android.api.session.room.RoomDirectoryService import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.api.session.signout.SignOutService import im.vector.matrix.android.api.session.sync.FilterService @@ -33,10 +34,11 @@ import im.vector.matrix.android.internal.session.cache.RealmClearCacheTask import im.vector.matrix.android.internal.session.filter.* import im.vector.matrix.android.internal.session.group.DefaultGroupService import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater -import im.vector.matrix.android.internal.session.room.DefaultRoomService -import im.vector.matrix.android.internal.session.room.EventRelationsAggregationUpdater -import im.vector.matrix.android.internal.session.room.RoomAvatarResolver -import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater +import im.vector.matrix.android.internal.session.room.* +import im.vector.matrix.android.internal.session.room.directory.DefaultGetPublicRoomTask +import im.vector.matrix.android.internal.session.room.directory.DefaultGetThirdPartyProtocolsTask +import im.vector.matrix.android.internal.session.room.directory.GetPublicRoomTask +import im.vector.matrix.android.internal.session.room.directory.GetThirdPartyProtocolsTask import im.vector.matrix.android.internal.session.room.membership.RoomDisplayNameResolver import im.vector.matrix.android.internal.session.room.membership.RoomMemberDisplayNameResolver import im.vector.matrix.android.internal.session.room.prune.EventsPruner @@ -111,6 +113,18 @@ internal class SessionModule(private val sessionParams: SessionParams) { DefaultRoomService(get(), get(), get(), get()) as RoomService } + scope(DefaultSession.SCOPE) { + DefaultGetPublicRoomTask(get()) as GetPublicRoomTask + } + + scope(DefaultSession.SCOPE) { + DefaultGetThirdPartyProtocolsTask(get()) as GetThirdPartyProtocolsTask + } + + scope(DefaultSession.SCOPE) { + DefaultRoomDirectoryService(get(), get(), get(), get()) as RoomDirectoryService + } + scope(DefaultSession.SCOPE) { DefaultGroupService(get()) as GroupService } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt index cb8896e7..8845c372 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUrlResolver.kt @@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver private const val MATRIX_CONTENT_URI_SCHEME = "mxc://" -internal const val URI_PREFIX_CONTENT_API = "/_matrix/media/v1/" +internal const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/" internal class DefaultContentUrlResolver(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomDirectoryService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomDirectoryService.kt new file mode 100644 index 00000000..1a434dd6 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomDirectoryService.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.session.room + +import im.vector.matrix.android.api.MatrixCallback +import im.vector.matrix.android.api.session.room.RoomDirectoryService +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse +import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol +import im.vector.matrix.android.api.util.Cancelable +import im.vector.matrix.android.internal.session.room.directory.GetPublicRoomTask +import im.vector.matrix.android.internal.session.room.directory.GetThirdPartyProtocolsTask +import im.vector.matrix.android.internal.session.room.membership.joining.JoinRoomTask +import im.vector.matrix.android.internal.task.TaskExecutor +import im.vector.matrix.android.internal.task.configureWith + +internal class DefaultRoomDirectoryService(private val getPublicRoomTask: GetPublicRoomTask, + private val joinRoomTask: JoinRoomTask, + private val getThirdPartyProtocolsTask: GetThirdPartyProtocolsTask, + private val taskExecutor: TaskExecutor) : RoomDirectoryService { + + override fun getPublicRooms(server: String?, + publicRoomsParams: PublicRoomsParams, + callback: MatrixCallback): Cancelable { + return getPublicRoomTask + .configureWith(GetPublicRoomTask.Params(server, publicRoomsParams)) + .dispatchTo(callback) + .executeBy(taskExecutor) + } + + override fun joinRoom(roomId: String, callback: MatrixCallback) { + joinRoomTask + .configureWith(JoinRoomTask.Params(roomId)) + .dispatchTo(callback) + .executeBy(taskExecutor) + } + + override fun getThirdPartyProtocol(callback: MatrixCallback>) { + getThirdPartyProtocolsTask + .configureWith(Unit) + .dispatchTo(callback) + .executeBy(taskExecutor) + } +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAPI.kt index 39d9c4d3..af263970 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomAPI.kt @@ -20,22 +20,39 @@ import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomResponse +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse import im.vector.matrix.android.internal.network.NetworkConstants import im.vector.matrix.android.internal.session.room.membership.RoomMembersResponse import im.vector.matrix.android.internal.session.room.membership.joining.InviteBody +import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol import im.vector.matrix.android.internal.session.room.send.SendResponse import im.vector.matrix.android.internal.session.room.timeline.EventContextResponse import im.vector.matrix.android.internal.session.room.timeline.PaginationResponse import retrofit2.Call -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import retrofit2.http.Query +import retrofit2.http.* internal interface RoomAPI { + /** + * Get the third party server protocols. + * + * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-thirdparty-protocols + */ + @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "thirdparty/protocols") + fun thirdPartyProtocols(): Call> + + /** + * Lists the public rooms on the server, with optional filter. + * This API returns paginated responses. The rooms are ordered by the number of joined members, with the largest rooms first. + * + * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-publicrooms + */ + @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "publicRooms") + fun publicRooms(@Query("server") server: String?, + @Body publicRoomsParams: PublicRoomsParams + ): Call + /** * Create a room. * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-createroom @@ -213,6 +230,6 @@ internal interface RoomAPI { @Path("txnId") txId: String, @Path("roomId") roomId: String, @Path("eventId") parent_id: String, - @Body reason: Map + @Body reason: Map ): Call } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt new file mode 100644 index 00000000..4cf72285 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetPublicRoomTask.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.session.room.directory + +import arrow.core.Try +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsParams +import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoomsResponse +import im.vector.matrix.android.internal.network.executeRequest +import im.vector.matrix.android.internal.session.room.RoomAPI +import im.vector.matrix.android.internal.task.Task + +internal interface GetPublicRoomTask : Task { + data class Params( + val server: String?, + val publicRoomsParams: PublicRoomsParams + ) +} + +internal class DefaultGetPublicRoomTask(private val roomAPI: RoomAPI) : GetPublicRoomTask { + + override fun execute(params: GetPublicRoomTask.Params): Try { + return executeRequest { + apiCall = roomAPI.publicRooms(params.server, params.publicRoomsParams) + } + } +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt new file mode 100644 index 00000000..58987717 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/directory/GetThirdPartyProtocolsTask.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.session.room.directory + +import arrow.core.Try +import im.vector.matrix.android.api.session.room.model.thirdparty.ThirdPartyProtocol +import im.vector.matrix.android.internal.network.executeRequest +import im.vector.matrix.android.internal.session.room.RoomAPI +import im.vector.matrix.android.internal.task.Task + +internal interface GetThirdPartyProtocolsTask : Task> + +internal class DefaultGetThirdPartyProtocolsTask(private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask { + + override fun execute(params: Unit): Try> { + return executeRequest { + apiCall = roomAPI.thirdPartyProtocols() + } + } +} diff --git a/vector/build.gradle b/vector/build.gradle index e75bbd32..b9e01ed0 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -156,7 +156,7 @@ dependencies { implementation("com.airbnb.android:epoxy:$epoxy_version") kapt "com.airbnb.android:epoxy-processor:$epoxy_version" - implementation 'com.airbnb.android:mvrx:0.7.0' + implementation 'com.airbnb.android:mvrx:1.0.1' // Work implementation "android.arch.work:work-runtime-ktx:1.0.0" diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index 2860cf9a..591b1885 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -43,6 +43,8 @@ android:name="im.vector.riotredesign.features.reactions.EmojiReactionPickerActivity" android:label="@string/title_activity_emoji_reaction_picker" /> + + diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index 766a19f7..d2ae5d4a 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -30,6 +30,7 @@ import im.vector.riotredesign.core.di.AppModule import im.vector.riotredesign.features.home.HomeModule import im.vector.riotredesign.features.rageshake.VectorFileLogger import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler +import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule import org.koin.log.EmptyLogger import org.koin.standalone.StandAloneContext.startKoin import timber.log.Timber @@ -56,7 +57,8 @@ class VectorApplication : Application() { EpoxyController.defaultModelBuildingHandler = EpoxyAsyncUtil.getAsyncBackgroundHandler() val appModule = AppModule(applicationContext).definition val homeModule = HomeModule().definition - startKoin(listOf(appModule, homeModule), logger = EmptyLogger()) + val roomDirectoryModule = RoomDirectoryModule().definition + startKoin(listOf(appModule, homeModule, roomDirectoryModule), logger = EmptyLogger()) Matrix.getInstance().setApplicationFlavor(BuildConfig.FLAVOR_DESCRIPTION) } diff --git a/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt b/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt index 9505f80e..6aff3e5a 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/di/AppModule.kt @@ -19,7 +19,9 @@ package im.vector.riotredesign.core.di import android.content.Context import android.content.Context.MODE_PRIVATE import im.vector.matrix.android.api.Matrix +import im.vector.riotredesign.core.error.ErrorFormatter import im.vector.riotredesign.core.resources.LocaleProvider +import im.vector.riotredesign.core.resources.StringArrayProvider import im.vector.riotredesign.core.resources.StringProvider import im.vector.riotredesign.features.home.group.SelectedGroupStore import im.vector.riotredesign.features.home.room.VisibleRoomStore @@ -40,6 +42,10 @@ class AppModule(private val context: Context) { StringProvider(context.resources) } + single { + StringArrayProvider(context.resources) + } + single { context.getSharedPreferences("im.vector.riot", MODE_PRIVATE) } @@ -60,6 +66,10 @@ class AppModule(private val context: Context) { RoomSummaryComparator() } + single { + ErrorFormatter(get()) + } + single { NotificationDrawerManager(context) } diff --git a/vector/src/main/java/im/vector/riotredesign/core/epoxy/ErrorWithRetryItem.kt b/vector/src/main/java/im/vector/riotredesign/core/epoxy/ErrorWithRetryItem.kt new file mode 100644 index 00000000..c6bfb13a --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/core/epoxy/ErrorWithRetryItem.kt @@ -0,0 +1,46 @@ +/* + * + * * Copyright 2019 New Vector Ltd + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package im.vector.riotredesign.core.epoxy + +import android.widget.Button +import android.widget.TextView +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass +import im.vector.riotredesign.R + +@EpoxyModelClass(layout = R.layout.item_error_retry) +abstract class ErrorWithRetryItem : VectorEpoxyModel() { + + @EpoxyAttribute + var text: String? = null + + @EpoxyAttribute + var listener: (() -> Unit)? = null + + override fun bind(holder: Holder) { + holder.textView.text = text + holder.buttonView.setOnClickListener { listener?.invoke() } + } + + + class Holder : VectorEpoxyHolder() { + val textView by bind(R.id.itemErrorRetryText) + val buttonView by bind