X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ftext%2FSoneMentionDetector.kt;h=f3d8cb41067da44474e5f135a9e163d66ebb499a;hb=0a2f92314bc1f78a6dea24dc353dd8ad3b041cb9;hp=7dd82854b7dcfa597ceaf61f68e03adfc62953a2;hpb=339671a5532a02cfbc25269b8ac3f13fc6a09295;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt b/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt index 7dd8285..f3d8cb4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt +++ b/src/main/kotlin/net/pterodactylus/sone/text/SoneMentionDetector.kt @@ -24,7 +24,7 @@ import javax.inject.* /** * Listens to [NewPostFoundEvent]s and [NewPostReplyFoundEvent], parses the - * texts and emits a [LocalSoneMentionedInPostEvent] if a [SoneTextParser] + * texts and emits a [MentionOfLocalSoneFoundEvent] if a [SoneTextParser] * finds a [SonePart] that points to a local [Sone]. */ class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, private val soneTextParser: SoneTextParser) { @@ -35,7 +35,18 @@ class SoneMentionDetector @Inject constructor(private val eventBus: EventBus, pr post.sone.isLocal.onFalse { val parts = soneTextParser.parse(post.text, null) if (parts.filterIsInstance().any { it.sone.isLocal }) { - eventBus.post(LocalSoneMentionedInPostEvent(post)) + eventBus.post(MentionOfLocalSoneFoundEvent(post)) + } + } + } + } + + @Subscribe + fun onNewPostReply(event: NewPostReplyFoundEvent) { + event.postReply.let { postReply -> + postReply.sone.isLocal.onFalse { + if (soneTextParser.parse(postReply.text, null).filterIsInstance().any { it.sone.isLocal }) { + postReply.post.let(::MentionOfLocalSoneFoundEvent).also(eventBus::post) } } }