forked from GitHub-Mirror/riotX-android
RoomDirectoryPicker WIP
This commit is contained in:
@ -19,6 +19,7 @@ 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
|
||||
|
||||
/**
|
||||
@ -39,4 +40,10 @@ interface RoomDirectoryService {
|
||||
fun joinRoom(roomId: String,
|
||||
callback: MatrixCallback<Unit>)
|
||||
|
||||
/**
|
||||
* 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<Map<String, ThirdPartyProtocol>>)
|
||||
|
||||
}
|
@ -46,12 +46,12 @@ data class PublicRoomsParams(
|
||||
/**
|
||||
* Whether or not to include all known networks/protocols from application services on the homeserver. Defaults to false.
|
||||
*/
|
||||
@Json(name = "includeAllNetworks")
|
||||
@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 = "thirdPartyInstanceId")
|
||||
@Json(name = "third_party_instance_id")
|
||||
var thirdPartyInstanceId: String? = null
|
||||
)
|
||||
|
@ -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
|
||||
)
|
@ -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"
|
||||
}
|
||||
|
||||
}
|
@ -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<String>? = 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<String>? = 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<String, FieldType>? = 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<ThirdPartyProtocolInstance>? = null
|
||||
)
|
@ -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<String, Any>? = 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
|
||||
)
|
@ -36,6 +36,7 @@ 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
|
||||
@ -188,6 +189,11 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
||||
return roomDirectoryService.joinRoom(roomId, callback)
|
||||
}
|
||||
|
||||
override fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>) {
|
||||
assert(isOpen)
|
||||
return roomDirectoryService.getThirdPartyProtocol(callback)
|
||||
}
|
||||
|
||||
// GROUP SERVICE
|
||||
|
||||
override fun getGroup(groupId: String): Group? {
|
||||
|
@ -36,7 +36,9 @@ 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.*
|
||||
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
|
||||
@ -116,7 +118,11 @@ internal class SessionModule(private val sessionParams: SessionParams) {
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultRoomDirectoryService(get(), get(), get()) as RoomDirectoryService
|
||||
DefaultGetThirdPartyProtocolsTask(get()) as GetThirdPartyProtocolsTask
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
DefaultRoomDirectoryService(get(), get(), get(), get()) as RoomDirectoryService
|
||||
}
|
||||
|
||||
scope(DefaultSession.SCOPE) {
|
||||
|
@ -20,14 +20,17 @@ 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?,
|
||||
@ -45,4 +48,11 @@ internal class DefaultRoomDirectoryService(private val getPublicRoomTask: GetPub
|
||||
.dispatchTo(callback)
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
|
||||
override fun getThirdPartyProtocol(callback: MatrixCallback<Map<String, ThirdPartyProtocol>>) {
|
||||
getThirdPartyProtocolsTask
|
||||
.configureWith(Unit)
|
||||
.dispatchTo(callback)
|
||||
.executeBy(taskExecutor)
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRooms
|
||||
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
|
||||
@ -33,6 +34,14 @@ 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<Map<String, ThirdPartyProtocol>>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -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<Unit, Map<String, ThirdPartyProtocol>>
|
||||
|
||||
internal class DefaultGetThirdPartyProtocolsTask(private val roomAPI: RoomAPI) : GetThirdPartyProtocolsTask {
|
||||
|
||||
override fun execute(params: Unit): Try<Map<String, ThirdPartyProtocol>> {
|
||||
return executeRequest {
|
||||
apiCall = roomAPI.thirdPartyProtocols()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user