Moved services each to own class
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
val ktor_version: String by project
|
||||
val kotlin_version: String by project
|
||||
val trixnity_version: String by project
|
||||
val logback_version: String by project
|
||||
val ktorVersion = "1.6.7"
|
||||
val kotlinVersion = "1.6.10"
|
||||
|
||||
|
||||
plugins {
|
||||
@@ -12,7 +10,7 @@ plugins {
|
||||
group = "eu.fosil"
|
||||
version = "0.0.1"
|
||||
application {
|
||||
mainClass.set("eu.fosil.ApplicationKt")
|
||||
mainClass.set("eu.fosil.okupamicoche.ApplicationKt")
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -22,21 +20,21 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// Ktor
|
||||
implementation("io.ktor:ktor-server-netty:$ktor_version")
|
||||
implementation("io.ktor:ktor-client-cio:$ktor_version")
|
||||
implementation("io.ktor:ktor-server-netty:$ktorVersion")
|
||||
implementation("io.ktor:ktor-client-cio:$ktorVersion")
|
||||
|
||||
// Trixnity
|
||||
implementation("net.folivo:trixnity-appservice:$trixnity_version")
|
||||
implementation("net.folivo:trixnity-appservice:1.1.6")
|
||||
|
||||
// Logger
|
||||
implementation("ch.qos.logback:logback-classic:$logback_version")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.10")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions {
|
||||
// freeCompilerArgs = listOf("-Xjsr305=strict")
|
||||
freeCompilerArgs = listOf("-Xjsr305=strict")
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,23 +7,7 @@ Guide for setting up a local development environment for the backend.
|
||||
```
|
||||
127.0.0.1 okupamicoche-synapse
|
||||
```
|
||||
|
||||
5. Generate data folder for Synapse
|
||||
```
|
||||
cd docker/synape
|
||||
docker run -it --rm \
|
||||
--mount type=volume,src=synapse-data,dst=/data \
|
||||
-e SYNAPSE_SERVER_NAME=okupamicoche-synapse \
|
||||
-e SYNAPSE_REPORT_STATS=no \
|
||||
matrixdotorg/synapse:latest generate
|
||||
```
|
||||
6. Run dockerized Synapse
|
||||
```
|
||||
docker run --name okupamicoche-synapse -p 8008:8008 --mount type=volume,src=synapse-data,dst=/data \
|
||||
-e SYNAPSE_CONFIG_PATH=/homeserver.yaml \
|
||||
-v $(pwd)/homeserver.yaml:/homeserver.yaml -v $(pwd)/okupamicoche-appservice.yaml:/okupamicoche-appservice.yaml \
|
||||
matrixdotorg/synapse:latest
|
||||
```
|
||||
3. First run: `docker-compose up`
|
||||
|
||||
## Run
|
||||
`docker start okupamicoche-synapse`
|
||||
|
||||
@@ -1,5 +1,2 @@
|
||||
ktor_version=1.6.7
|
||||
kotlin_version=1.6.10
|
||||
trixnity_version=1.1.6
|
||||
logback_version=1.2.10
|
||||
kotlin.code.style=official
|
||||
org.gradle.daemon=true
|
||||
@@ -1,102 +0,0 @@
|
||||
package eu.fosil
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import net.folivo.trixnity.appservice.rest.DefaultAppserviceService
|
||||
import net.folivo.trixnity.appservice.rest.MatrixAppserviceProperties
|
||||
import net.folivo.trixnity.appservice.rest.event.AppserviceEventTnxService
|
||||
import net.folivo.trixnity.appservice.rest.matrixAppserviceModule
|
||||
import net.folivo.trixnity.appservice.rest.room.AppserviceRoomService
|
||||
import net.folivo.trixnity.appservice.rest.room.CreateRoomParameter
|
||||
import net.folivo.trixnity.appservice.rest.user.AppserviceUserService
|
||||
import net.folivo.trixnity.appservice.rest.user.RegisterUserParameter
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.RoomAliasId
|
||||
import net.folivo.trixnity.core.model.RoomId
|
||||
import net.folivo.trixnity.core.model.UserId
|
||||
|
||||
val matrixClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
|
||||
suspend fun main() {
|
||||
|
||||
|
||||
coroutineScope {
|
||||
val appserviceService = DefaultAppserviceService(
|
||||
EventTnxService(),
|
||||
UserService(),
|
||||
RoomService()
|
||||
)
|
||||
|
||||
appserviceService.subscribeAllEvents {
|
||||
event -> println(event)
|
||||
}
|
||||
|
||||
launch {
|
||||
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
|
||||
matrixAppserviceModule(
|
||||
properties = MatrixAppserviceProperties("312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e"),
|
||||
appserviceService = appserviceService
|
||||
)
|
||||
}.start(wait = true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class EventTnxService : AppserviceEventTnxService {
|
||||
override suspend fun eventTnxProcessingState(tnxId: String): AppserviceEventTnxService.EventTnxProcessingState {
|
||||
println("eventTnxProcessingState")
|
||||
return AppserviceEventTnxService.EventTnxProcessingState.NOT_PROCESSED
|
||||
// return AppserviceEventTnxService.EventTnxProcessingState.PROCESSED
|
||||
}
|
||||
|
||||
override suspend fun onEventTnxProcessed(tnxId: String) {
|
||||
println("onEventTnxProcessed")
|
||||
}
|
||||
}
|
||||
|
||||
class UserService : AppserviceUserService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getRegisterUserParameter(userId: UserId): RegisterUserParameter {
|
||||
println("getRegisterUserParameter")
|
||||
return RegisterUserParameter("user parameter")
|
||||
}
|
||||
|
||||
override suspend fun onRegisteredUser(userId: UserId) {
|
||||
println("onRegisteredUser")
|
||||
}
|
||||
|
||||
override suspend fun userExistingState(userId: UserId): AppserviceUserService.UserExistingState {
|
||||
println("userExistingState")
|
||||
return AppserviceUserService.UserExistingState.CAN_BE_CREATED
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RoomService : AppserviceRoomService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
|
||||
println("getCreateRoomParameter")
|
||||
return CreateRoomParameter()
|
||||
}
|
||||
|
||||
override suspend fun onCreatedRoom(roomAlias: RoomAliasId, roomId: RoomId) {
|
||||
println("onCreatedRoom")
|
||||
}
|
||||
|
||||
override suspend fun roomExistingState(roomAlias: RoomAliasId): AppserviceRoomService.RoomExistingState {
|
||||
println("roomExistingState")
|
||||
return AppserviceRoomService.RoomExistingState.DOES_NOT_EXISTS
|
||||
}
|
||||
|
||||
}
|
||||
54
src/main/kotlin/eu/fosil/okupamicoche/Application.kt
Normal file
54
src/main/kotlin/eu/fosil/okupamicoche/Application.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
package eu.fosil.okupamicoche
|
||||
|
||||
import eu.fosil.okupamicoche.services.EventTnxService
|
||||
import eu.fosil.okupamicoche.services.RoomService
|
||||
import eu.fosil.okupamicoche.services.UserService
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import net.folivo.trixnity.appservice.rest.DefaultAppserviceService
|
||||
import net.folivo.trixnity.appservice.rest.MatrixAppserviceProperties
|
||||
import net.folivo.trixnity.appservice.rest.matrixAppserviceModule
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.events.Event
|
||||
import net.folivo.trixnity.core.model.events.m.room.CreateEventContent
|
||||
import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
|
||||
|
||||
val matrixClient = MatrixApiClient(
|
||||
baseUrl = Url("http://okupamicoche-synapse:8008/"),
|
||||
).apply { accessToken.value = "30c05ae90a248a4188e620216fa72e349803310ec83e2a77b34fe90be6081f46" }
|
||||
|
||||
suspend fun main() {
|
||||
coroutineScope {
|
||||
val appserviceService = DefaultAppserviceService(
|
||||
EventTnxService(), UserService(), RoomService()
|
||||
)
|
||||
|
||||
appserviceService.subscribeAllEvents {
|
||||
println(it)
|
||||
}
|
||||
|
||||
appserviceService.subscribe<CreateEventContent> {
|
||||
if (it is Event.RoomEvent) {
|
||||
println("${it.content.creator} created ${it.roomId}")
|
||||
}
|
||||
}
|
||||
|
||||
appserviceService.subscribe<RoomMessageEventContent.TextMessageEventContent> {
|
||||
println("TextMessageEventContent body=${it.content.body}")
|
||||
}
|
||||
|
||||
|
||||
launch {
|
||||
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
|
||||
matrixAppserviceModule(
|
||||
properties = MatrixAppserviceProperties("312df522183efd404ec1cd22d2ffa4bbc76a8c1ccf541dd692eef281356bb74e"),
|
||||
appserviceService = appserviceService
|
||||
)
|
||||
}.start(wait = true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import net.folivo.trixnity.appservice.rest.event.AppserviceEventTnxService
|
||||
|
||||
class EventTnxService : AppserviceEventTnxService {
|
||||
override suspend fun eventTnxProcessingState(tnxId: String): AppserviceEventTnxService.EventTnxProcessingState {
|
||||
println("eventTnxProcessingState tnxId=$tnxId")
|
||||
return AppserviceEventTnxService.EventTnxProcessingState.NOT_PROCESSED
|
||||
// return AppserviceEventTnxService.EventTnxProcessingState.PROCESSED
|
||||
}
|
||||
|
||||
override suspend fun onEventTnxProcessed(tnxId: String) {
|
||||
println("onEventTnxProcessed tnxId=$tnxId")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import eu.fosil.okupamicoche.matrixClient
|
||||
import net.folivo.trixnity.appservice.rest.room.AppserviceRoomService
|
||||
import net.folivo.trixnity.appservice.rest.room.CreateRoomParameter
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.RoomAliasId
|
||||
import net.folivo.trixnity.core.model.RoomId
|
||||
|
||||
class RoomService : AppserviceRoomService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getCreateRoomParameter(roomAlias: RoomAliasId): CreateRoomParameter {
|
||||
println("getCreateRoomParameter")
|
||||
return CreateRoomParameter()
|
||||
}
|
||||
|
||||
override suspend fun onCreatedRoom(roomAlias: RoomAliasId, roomId: RoomId) {
|
||||
println("onCreatedRoom")
|
||||
}
|
||||
|
||||
override suspend fun roomExistingState(roomAlias: RoomAliasId): AppserviceRoomService.RoomExistingState {
|
||||
println("roomExistingState")
|
||||
return AppserviceRoomService.RoomExistingState.DOES_NOT_EXISTS
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.fosil.okupamicoche.services
|
||||
|
||||
import eu.fosil.okupamicoche.matrixClient
|
||||
import net.folivo.trixnity.appservice.rest.user.AppserviceUserService
|
||||
import net.folivo.trixnity.appservice.rest.user.RegisterUserParameter
|
||||
import net.folivo.trixnity.client.api.MatrixApiClient
|
||||
import net.folivo.trixnity.core.model.UserId
|
||||
|
||||
class UserService : AppserviceUserService {
|
||||
override val matrixApiClient: MatrixApiClient
|
||||
get() = matrixClient
|
||||
|
||||
override suspend fun getRegisterUserParameter(userId: UserId): RegisterUserParameter {
|
||||
println("getRegisterUserParameter")
|
||||
return RegisterUserParameter("user parameter")
|
||||
}
|
||||
|
||||
override suspend fun onRegisteredUser(userId: UserId) {
|
||||
println("onRegisteredUser")
|
||||
}
|
||||
|
||||
override suspend fun userExistingState(userId: UserId): AppserviceUserService.UserExistingState {
|
||||
println("userExistingState")
|
||||
return AppserviceUserService.UserExistingState.CAN_BE_CREATED
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package eu.fosil
|
||||
|
||||
class ApplicationTest {
|
||||
}
|
||||
4
src/test/kotlin/eu/fosil/okupamicoche/ApplicationTest.kt
Normal file
4
src/test/kotlin/eu/fosil/okupamicoche/ApplicationTest.kt
Normal file
@@ -0,0 +1,4 @@
|
||||
package eu.fosil.okupamicoche
|
||||
|
||||
class ApplicationTest {
|
||||
}
|
||||
Reference in New Issue
Block a user