2 * Sone - NewElements.kt - Copyright © 2020 David ‘Bombe’ Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package net.pterodactylus.sone.web
19 import net.pterodactylus.sone.data.Post
20 import net.pterodactylus.sone.data.PostReply
21 import net.pterodactylus.sone.data.Sone
22 import net.pterodactylus.sone.notify.ListNotification
23 import net.pterodactylus.sone.notify.PostVisibilityFilter
24 import net.pterodactylus.sone.notify.ReplyVisibilityFilter
25 import javax.inject.Inject
26 import javax.inject.Named
29 * Container for new elements that should be shown in the web interface.
31 * This is just a wrapper around the notifications that store the new elements.
33 class NewElements @Inject constructor(
34 @Named("newRemotePost") private val newPostNotification: ListNotification<Post>,
35 @Named("newRemotePostReply") private val newReplyNotification: ListNotification<PostReply>,
36 @Named("localPost") private val localPostNotification: ListNotification<Post>,
37 @Named("localReply") private val localReplyNotification: ListNotification<PostReply>,
38 private val postVisibilityFilter: PostVisibilityFilter,
39 private val replyVisibilityFilter: ReplyVisibilityFilter
42 fun newPosts(currentSone: Sone? = null): Collection<Post> =
43 listOf(newPostNotification, localPostNotification)
44 .flatMap(ListNotification<Post>::elements)
45 .filter { postVisibilityFilter.isPostVisible(currentSone, it) }
47 fun newReplies(): Collection<PostReply> =
48 listOf(newReplyNotification, localReplyNotification)
49 .flatMap(ListNotification<PostReply>::elements)
50 .filter { replyVisibilityFilter.isReplyVisible(null, it) }