/**
* 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) {
post.sone.isLocal.onFalse {
val parts = soneTextParser.parse(post.text, null)
if (parts.filterIsInstance<SonePart>().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<SonePart>().any { it.sone.isLocal }) {
+ postReply.post.let(::MentionOfLocalSoneFoundEvent).also(eventBus::post)
}
}
}