Matrix app service instead of client

This commit is contained in:
2021-03-27 11:59:23 +01:00
parent ade520749a
commit b4ce6600a4
22 changed files with 2918 additions and 9 deletions

View File

@@ -12,13 +12,14 @@ import java.util.stream.Collectors
class MatrixService(private val matrixClient: MatrixClient): MatrixApi {
private val logger = KotlinLogging.logger {}
override suspend fun createRoom(name: String, alias: String, usersToInvite: Set<User>): String {
override suspend fun createRoom(name: String, alias: String, usersToInvite: Set<User>, topic: String?): String {
logger.debug { "Creating room name=$name alias=$alias" }
val usersToInviteId = usersToInvite.stream().map { user -> MatrixId.UserId(user.matrixId) }
val roomId = matrixClient.roomsApi.createRoom(
name = name,
roomAliasId = MatrixId.RoomAliasId("#$alias:synapse"),
invite = usersToInviteId.collect(Collectors.toSet())
invite = usersToInviteId.collect(Collectors.toSet()),
topic = topic
)
return roomId.full
}

View File

@@ -9,7 +9,7 @@ class CreateRoomForTravel(private val matrixApi: MatrixApi) {
suspend fun createRoomForTravel(travel: Travel): String {
val name = createRoomName(travel)
val alias = createRoomAlias(travel)
return matrixApi.createRoom(name, alias, travel.users())
return matrixApi.createRoom(name, alias, travel.users(), travel.description)
}
private fun createRoomName(travel: Travel): String {

View File

@@ -7,7 +7,7 @@ interface MatrixApi {
* Create room and invite users.
* @return Room Id.
*/
suspend fun createRoom(name: String, alias: String, usersToInvite: Set<User>): String
suspend fun createRoom(name: String, alias: String, usersToInvite: Set<User>, topic: String?): String
suspend fun inviteUser(roomId: String, user: User)
}

View File

@@ -25,11 +25,11 @@ matrix:
serverName: synapse
# The localpart (username) of the user associated with the application service
# or just the username of your bot.
username: test
username: okupamicoche
# (optional) Display name for the bot user.
displayname: Okupa mi coche
# (optional) The mode you want to use to create a bot. Default is CLIENT. The other is APPSERVICE.
mode: CLIENT
mode: APPSERVICE
# (optional) Configure how users managed by your bot do automatically join rooms.
# ENABLED allows automatic joins to every invited room.
# DISABLED disables this feature.
@@ -57,4 +57,13 @@ matrix:
# (optional) Use http or https. Default is true (so uses https).
secure: false
# The token to authenticate against the Homeserver.
token: MDAxNWxvY2F0aW9uIHN5bmFwc2UKMDAxM2lkZW50aWZpZXIga2V5CjAwMTBjaWQgZ2VuID0gMQowMDIwY2lkIHVzZXJfaWQgPSBAdGVzdDpzeW5hcHNlCjAwMTZjaWQgdHlwZSA9IGFjY2VzcwowMDIxY2lkIG5vbmNlID0gMGNZN240LTBVVF43LDAqaQowMDJmc2lnbmF0dXJlII52qsn8HZL-aZJ_7xdWTK7-JHqdRklbn9MZ77ieh-hBCg
token: 30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46
appservice:
# A unique token for Homeservers to use to authenticate requests to application services.
hsToken: 312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e
# A list of users, aliases and rooms namespaces that the application service controls.
namespaces:
users: [ ]
aliases:
- localpartRegex: "#viaje_.*"
rooms: [ ]