mirror of https://github.com/usbharu/Hideout.git
refactor: 不要になった関数を削除
This commit is contained in:
parent
ee88e29770
commit
7141c7bc6a
|
@ -8,17 +8,6 @@ interface MastodonNotificationRepository {
|
||||||
suspend fun deleteById(id: Long)
|
suspend fun deleteById(id: Long)
|
||||||
suspend fun findById(id: Long): MastodonNotification?
|
suspend fun findById(id: Long): MastodonNotification?
|
||||||
|
|
||||||
@Suppress("LongParameterList", "FunctionMaxLength")
|
|
||||||
suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
|
|
||||||
loginUser: Long,
|
|
||||||
maxId: Long?,
|
|
||||||
minId: Long?,
|
|
||||||
sinceId: Long?,
|
|
||||||
limit: Int,
|
|
||||||
typesTmp: MutableList<NotificationType>,
|
|
||||||
accountId: List<Long>
|
|
||||||
): List<MastodonNotification>
|
|
||||||
|
|
||||||
suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
||||||
loginUser: Long,
|
loginUser: Long,
|
||||||
types: List<NotificationType>,
|
types: List<NotificationType>,
|
||||||
|
|
|
@ -62,35 +62,6 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab
|
||||||
MastodonNotifications.select { MastodonNotifications.id eq id }.singleOrNull()?.toMastodonNotification()
|
MastodonNotifications.select { MastodonNotifications.id eq id }.singleOrNull()?.toMastodonNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
|
|
||||||
loginUser: Long,
|
|
||||||
maxId: Long?,
|
|
||||||
minId: Long?,
|
|
||||||
sinceId: Long?,
|
|
||||||
limit: Int,
|
|
||||||
typesTmp: MutableList<NotificationType>,
|
|
||||||
accountId: List<Long>
|
|
||||||
): List<MastodonNotification> = query {
|
|
||||||
val query = MastodonNotifications.select {
|
|
||||||
MastodonNotifications.userId eq loginUser
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxId != null) {
|
|
||||||
query.andWhere { MastodonNotifications.id lessEq maxId }
|
|
||||||
}
|
|
||||||
if (minId != null) {
|
|
||||||
query.andWhere { MastodonNotifications.id greaterEq minId }
|
|
||||||
}
|
|
||||||
if (sinceId != null) {
|
|
||||||
query.andWhere { MastodonNotifications.id greaterEq sinceId }
|
|
||||||
}
|
|
||||||
val result = query
|
|
||||||
.limit(limit)
|
|
||||||
.orderBy(Timelines.createdAt, SortOrder.DESC)
|
|
||||||
|
|
||||||
return@query result.map { it.toMastodonNotification() }
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
override suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
||||||
loginUser: Long,
|
loginUser: Long,
|
||||||
types: List<NotificationType>,
|
types: List<NotificationType>,
|
||||||
|
|
|
@ -28,37 +28,6 @@ class MongoMastodonNotificationRepositoryWrapper(
|
||||||
override suspend fun findById(id: Long): MastodonNotification? =
|
override suspend fun findById(id: Long): MastodonNotification? =
|
||||||
mongoMastodonNotificationRepository.findById(id).getOrNull()
|
mongoMastodonNotificationRepository.findById(id).getOrNull()
|
||||||
|
|
||||||
override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
|
|
||||||
loginUser: Long,
|
|
||||||
maxId: Long?,
|
|
||||||
minId: Long?,
|
|
||||||
sinceId: Long?,
|
|
||||||
limit: Int,
|
|
||||||
typesTmp: MutableList<NotificationType>,
|
|
||||||
accountId: List<Long>
|
|
||||||
): List<MastodonNotification> {
|
|
||||||
val query = Query()
|
|
||||||
|
|
||||||
if (maxId != null) {
|
|
||||||
val criteria = Criteria.where("id").lte(maxId)
|
|
||||||
query.addCriteria(criteria)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minId != null) {
|
|
||||||
val criteria = Criteria.where("id").gte(minId)
|
|
||||||
query.addCriteria(criteria)
|
|
||||||
}
|
|
||||||
if (sinceId != null) {
|
|
||||||
val criteria = Criteria.where("id").gte(sinceId)
|
|
||||||
query.addCriteria(criteria)
|
|
||||||
}
|
|
||||||
|
|
||||||
query.limit(limit)
|
|
||||||
query.with(Sort.by(Sort.Direction.DESC, "createdAt"))
|
|
||||||
|
|
||||||
return mongoTemplate.find(query, MastodonNotification::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
override suspend fun findByUserIdAndInTypesAndInSourceActorId(
|
||||||
loginUser: Long,
|
loginUser: Long,
|
||||||
types: List<NotificationType>,
|
types: List<NotificationType>,
|
||||||
|
|
|
@ -6,17 +6,6 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Notification
|
||||||
import dev.usbharu.hideout.mastodon.domain.model.NotificationType
|
import dev.usbharu.hideout.mastodon.domain.model.NotificationType
|
||||||
|
|
||||||
interface NotificationApiService {
|
interface NotificationApiService {
|
||||||
@Suppress("LongParameterList")
|
|
||||||
suspend fun notifications(
|
|
||||||
loginUser: Long,
|
|
||||||
maxId: Long?,
|
|
||||||
minId: Long?,
|
|
||||||
sinceId: Long?,
|
|
||||||
limit: Int,
|
|
||||||
types: List<NotificationType>,
|
|
||||||
excludeTypes: List<NotificationType>,
|
|
||||||
accountId: List<Long>
|
|
||||||
): List<Notification>
|
|
||||||
|
|
||||||
suspend fun notifications(
|
suspend fun notifications(
|
||||||
loginUser: Long,
|
loginUser: Long,
|
||||||
|
|
|
@ -19,53 +19,6 @@ class NotificationApiServiceImpl(
|
||||||
private val statusQueryService: StatusQueryService
|
private val statusQueryService: StatusQueryService
|
||||||
) :
|
) :
|
||||||
NotificationApiService {
|
NotificationApiService {
|
||||||
override suspend fun notifications(
|
|
||||||
loginUser: Long,
|
|
||||||
maxId: Long?,
|
|
||||||
minId: Long?,
|
|
||||||
sinceId: Long?,
|
|
||||||
limit: Int,
|
|
||||||
types: List<NotificationType>,
|
|
||||||
excludeTypes: List<NotificationType>,
|
|
||||||
accountId: List<Long>
|
|
||||||
): List<Notification> = transaction.transaction {
|
|
||||||
val typesTmp = mutableListOf<NotificationType>()
|
|
||||||
|
|
||||||
typesTmp.addAll(types)
|
|
||||||
typesTmp.removeAll(excludeTypes)
|
|
||||||
|
|
||||||
val mastodonNotifications =
|
|
||||||
mastodonNotificationRepository.findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId(
|
|
||||||
loginUser,
|
|
||||||
maxId,
|
|
||||||
minId,
|
|
||||||
sinceId,
|
|
||||||
limit,
|
|
||||||
typesTmp,
|
|
||||||
accountId
|
|
||||||
)
|
|
||||||
|
|
||||||
val accounts = accountService.findByIds(
|
|
||||||
mastodonNotifications.map {
|
|
||||||
it.accountId
|
|
||||||
}
|
|
||||||
).associateBy { it.id.toLong() }
|
|
||||||
|
|
||||||
val statuses = statusQueryService.findByPostIds(mastodonNotifications.mapNotNull { it.statusId })
|
|
||||||
.associateBy { it.id.toLong() }
|
|
||||||
|
|
||||||
mastodonNotifications.map {
|
|
||||||
Notification(
|
|
||||||
id = it.id.toString(),
|
|
||||||
type = convertNotificationType(it.type),
|
|
||||||
createdAt = it.createdAt.toString(),
|
|
||||||
account = accounts.getValue(it.accountId),
|
|
||||||
status = statuses[it.statusId],
|
|
||||||
report = null,
|
|
||||||
relationshipSeveranceEvent = null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun notifications(
|
override suspend fun notifications(
|
||||||
loginUser: Long,
|
loginUser: Long,
|
||||||
|
|
Loading…
Reference in New Issue