+++ /dev/null
-/**
- * Sone - LocalSoneMentionedInPostEvent.kt - Copyright © 2019 David ‘Bombe’ Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core.event
-
-import net.pterodactylus.sone.data.*
-
-/**
- * Event that signals that a new post or reply was found that mentioned a local
- * Sone, which happens if the [SoneTextParser] locates a [SonePart] in a post
- * or reply.
- */
-data class LocalSoneMentionedInPostEvent(val post: Post)
--- /dev/null
+/**
+ * Sone - MentionOfLocalSoneFoundEvent.kt - Copyright © 2019 David ‘Bombe’ Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event
+
+import net.pterodactylus.sone.data.*
+
+/**
+ * Event that signals that a new post or reply was found that mentioned a local
+ * Sone, which happens if the [SoneTextParser] locates a [SonePart] in a post
+ * or reply.
+ */
+data class MentionOfLocalSoneFoundEvent(val post: Post)
/**
* 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))
}
}
}
event.postReply.let { postReply ->
postReply.sone.isLocal.onFalse {
if (soneTextParser.parse(postReply.text, null).filterIsInstance<SonePart>().any { it.sone.isLocal }) {
- postReply.post.let(::LocalSoneMentionedInPostEvent).also(eventBus::post)
+ postReply.post.let(::MentionOfLocalSoneFoundEvent).also(eventBus::post)
}
}
}
private val soneProvider = TestSoneProvider()
private val postProvider = TestPostProvider()
private val soneTextParser = SoneTextParser(soneProvider, postProvider)
- private val capturedEvents = mutableListOf<LocalSoneMentionedInPostEvent>()
+ private val capturedEvents = mutableListOf<MentionOfLocalSoneFoundEvent>()
init {
eventBus.register(SoneMentionDetector(eventBus, soneTextParser))
eventBus.register(object : Any() {
@Subscribe
- fun captureEvent(localSoneMentionedInPostEvent: LocalSoneMentionedInPostEvent) {
- capturedEvents += localSoneMentionedInPostEvent
+ fun captureEvent(mentionOfLocalSoneFoundEvent: MentionOfLocalSoneFoundEvent) {
+ capturedEvents += mentionOfLocalSoneFoundEvent
}
})
}
fun `detector emits event on post that contains links to a remote and a local sone`() {
val post = createPost("text mentions sone://${localSone1.id} and sone://${remoteSone2.id}.")
eventBus.post(NewPostFoundEvent(post))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test
fun `detector emits one event on post that contains two links to the same local sone`() {
val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone1.id}.")
eventBus.post(NewPostFoundEvent(post))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test
fun `detector emits one event on post that contains links to two local sones`() {
val post = createPost("text mentions sone://${localSone1.id} and sone://${localSone2.id}.")
eventBus.post(NewPostFoundEvent(post))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test
val post = createPost()
val reply = emptyPostReply("text mentions sone://${remoteSone1.id} and sone://${localSone1.id}.", post)
eventBus.post(NewPostReplyFoundEvent(reply))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test
val post = createPost()
val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone1.id}.", post)
eventBus.post(NewPostReplyFoundEvent(reply))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test
val post = createPost()
val reply = emptyPostReply("text mentions sone://${localSone1.id} and sone://${localSone2.id}.", post)
eventBus.post(NewPostReplyFoundEvent(reply))
- assertThat(capturedEvents, contains(LocalSoneMentionedInPostEvent(post)))
+ assertThat(capturedEvents, contains(MentionOfLocalSoneFoundEvent(post)))
}
@Test