mirror of https://github.com/usbharu/Hideout.git
Apply suggestions from code review
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
31240b8797
commit
4c15be67f7
|
@ -12,11 +12,15 @@ interface PostId {
|
||||||
}
|
}
|
||||||
|
|
||||||
data class MentionNotificationRequest(
|
data class MentionNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long, override val postId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long,
|
||||||
|
override val postId: Long
|
||||||
) : NotificationRequest(
|
) : NotificationRequest(
|
||||||
userId, sourceActorId,
|
userId,
|
||||||
|
sourceActorId,
|
||||||
"mention"
|
"mention"
|
||||||
), PostId {
|
),
|
||||||
|
PostId {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
|
@ -30,7 +34,9 @@ data class MentionNotificationRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
data class PostNotificationRequest(
|
data class PostNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long, override val postId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long,
|
||||||
|
override val postId: Long
|
||||||
|
|
||||||
) : NotificationRequest(userId, sourceActorId, "post"), PostId {
|
) : NotificationRequest(userId, sourceActorId, "post"), PostId {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
|
@ -46,7 +52,9 @@ data class PostNotificationRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
data class RepostNotificationRequest(
|
data class RepostNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long, override val postId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long,
|
||||||
|
override val postId: Long
|
||||||
) : NotificationRequest(userId, sourceActorId, "repost"), PostId {
|
) : NotificationRequest(userId, sourceActorId, "repost"), PostId {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
id,
|
id,
|
||||||
|
@ -61,7 +69,8 @@ data class RepostNotificationRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
data class FollowNotificationRequest(
|
data class FollowNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long
|
||||||
) : NotificationRequest(userId, sourceActorId, "follow") {
|
) : NotificationRequest(userId, sourceActorId, "follow") {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
id,
|
id,
|
||||||
|
@ -76,7 +85,8 @@ data class FollowNotificationRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
data class FollowRequestNotificationRequest(
|
data class FollowRequestNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long
|
||||||
) : NotificationRequest(userId, sourceActorId, "follow-request") {
|
) : NotificationRequest(userId, sourceActorId, "follow-request") {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
id,
|
id,
|
||||||
|
@ -91,7 +101,10 @@ data class FollowRequestNotificationRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ReactionNotificationRequest(
|
data class ReactionNotificationRequest(
|
||||||
override val userId: Long, override val sourceActorId: Long, override val postId: Long, val reactionId: Long
|
override val userId: Long,
|
||||||
|
override val sourceActorId: Long,
|
||||||
|
override val postId: Long,
|
||||||
|
val reactionId: Long
|
||||||
|
|
||||||
) : NotificationRequest(userId, sourceActorId, "reaction"), PostId {
|
) : NotificationRequest(userId, sourceActorId, "reaction"), PostId {
|
||||||
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
override fun buildNotification(id: Long, createdAt: Instant): Notification = Notification(
|
||||||
|
|
|
@ -15,7 +15,6 @@ enum class NotificationType {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun parse(string: String): NotificationType? = when (string) {
|
fun parse(string: String): NotificationType? = when (string) {
|
||||||
|
|
||||||
"mention" -> mention
|
"mention" -> mention
|
||||||
"status" -> status
|
"status" -> status
|
||||||
"reblog" -> reblog
|
"reblog" -> reblog
|
||||||
|
|
|
@ -72,7 +72,6 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab
|
||||||
MastodonNotifications.userId eq loginUser
|
MastodonNotifications.userId eq loginUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (maxId != null) {
|
if (maxId != null) {
|
||||||
query.andWhere { MastodonNotifications.id lessEq maxId }
|
query.andWhere { MastodonNotifications.id lessEq maxId }
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,7 @@ import org.springframework.data.mongodb.repository.MongoRepository
|
||||||
|
|
||||||
interface MongoMastodonNotificationRepository : MongoRepository<MastodonNotification, Long> {
|
interface MongoMastodonNotificationRepository : MongoRepository<MastodonNotification, Long> {
|
||||||
|
|
||||||
|
|
||||||
fun deleteByUserId(userId: Long): Long
|
fun deleteByUserId(userId: Long): Long
|
||||||
|
|
||||||
|
|
||||||
fun deleteByIdAndUserId(id: Long, userId: Long): Long
|
fun deleteByIdAndUserId(id: Long, userId: Long): Long
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ class NotificationApiServiceImpl(
|
||||||
excludeTypes: List<NotificationType>,
|
excludeTypes: List<NotificationType>,
|
||||||
accountId: List<Long>
|
accountId: List<Long>
|
||||||
): List<Notification> = transaction.transaction {
|
): List<Notification> = transaction.transaction {
|
||||||
|
|
||||||
val typesTmp = mutableListOf<NotificationType>()
|
val typesTmp = mutableListOf<NotificationType>()
|
||||||
|
|
||||||
typesTmp.addAll(types)
|
typesTmp.addAll(types)
|
||||||
|
@ -44,9 +43,11 @@ class NotificationApiServiceImpl(
|
||||||
accountId
|
accountId
|
||||||
)
|
)
|
||||||
|
|
||||||
val accounts = accountService.findByIds(mastodonNotifications.map {
|
val accounts = accountService.findByIds(
|
||||||
|
mastodonNotifications.map {
|
||||||
it.accountId
|
it.accountId
|
||||||
}).associateBy { it.id.toLong() }
|
}
|
||||||
|
).associateBy { it.id.toLong() }
|
||||||
|
|
||||||
val statuses = statusQueryService.findByPostIds(mastodonNotifications.mapNotNull { it.statusId })
|
val statuses = statusQueryService.findByPostIds(mastodonNotifications.mapNotNull { it.statusId })
|
||||||
.associateBy { it.id.toLong() }
|
.associateBy { it.id.toLong() }
|
||||||
|
@ -93,7 +94,6 @@ class NotificationApiServiceImpl(
|
||||||
mastodonNotificationRepository.deleteByUserIdAndId(loginUser, notificationId)
|
mastodonNotificationRepository.deleteByUserIdAndId(loginUser, notificationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun convertNotificationType(notificationType: NotificationType): Notification.Type =
|
private fun convertNotificationType(notificationType: NotificationType): Notification.Type =
|
||||||
when (notificationType) {
|
when (notificationType) {
|
||||||
mention -> Notification.Type.mention
|
mention -> Notification.Type.mention
|
||||||
|
|
Loading…
Reference in New Issue