add target and telegram target

This commit is contained in:
2022-01-07 21:35:11 +06:00
parent 6171eb3c40
commit 3661c1ca73
20 changed files with 232 additions and 3 deletions

View File

@@ -0,0 +1,18 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api project(":postssystem.features.publication.common")
api project(":postssystem.features.common.client")
}
}
}
}

View File

@@ -0,0 +1 @@
<manifest package="dev.inmo.postssystem.features.publication.client"/>

View File

@@ -0,0 +1,19 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api project(":postssystem.features.common.common")
api project(":postssystem.features.content.common")
api project(":postssystem.features.posts.common")
}
}
}
}

View File

@@ -0,0 +1 @@
<manifest package="dev.inmo.postssystem.features.publication.common"/>

View File

@@ -0,0 +1,19 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppJavaProjectPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api project(":postssystem.features.publication.common")
api project(":postssystem.features.common.server")
api project(":postssystem.features.content.server")
api project(":postssystem.features.posts.server")
}
}
}
}

View File

@@ -0,0 +1,33 @@
package dev.inmo.postssystem.features.publication.server
import dev.inmo.micro_utils.coroutines.asyncSafelyWithoutExceptions
import dev.inmo.postssystem.features.content.server.ServerReadContentStorage
import dev.inmo.postssystem.features.posts.common.PostId
import dev.inmo.postssystem.features.posts.server.ServerReadPostsStorage
import kotlinx.coroutines.*
class PublicationManager (
private val targets: List<PublicationTarget>,
private val postsRepo: ServerReadPostsStorage,
private val contentRepo: ServerReadContentStorage,
private val scope: CoroutineScope
) {
suspend fun publish(
postId: PostId
) {
val post = postsRepo.getById(postId) ?: return
val content = post.content.map {
scope.async {
contentRepo.getById(it)
}
}.awaitAll().filterNotNull()
val publicationPost = PublicationPost(post, content)
targets.map {
scope.asyncSafelyWithoutExceptions {
it.publish(publicationPost)
}
}.awaitAll()
}
}

View File

@@ -0,0 +1,11 @@
package dev.inmo.postssystem.features.publication.server
import dev.inmo.postssystem.features.content.common.RegisteredContent
import dev.inmo.postssystem.features.posts.common.RegisteredPost
import kotlinx.serialization.Serializable
@Serializable
data class PublicationPost(
val post: RegisteredPost,
val content: List<RegisteredContent>
)

View File

@@ -0,0 +1,5 @@
package dev.inmo.postssystem.features.publication.server
fun interface PublicationTarget {
suspend fun publish(post: PublicationPost)
}