feat: 通知を送信するように

This commit is contained in:
usbharu 2024-01-27 12:47:50 +09:00
parent cd0a659cd6
commit e7a6f52ef1
2 changed files with 28 additions and 3 deletions

View File

@ -3,8 +3,11 @@ package dev.usbharu.hideout.core.service.reaction
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException
import dev.usbharu.hideout.core.domain.model.emoji.Emoji
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
import dev.usbharu.hideout.core.service.notification.NotificationService
import dev.usbharu.hideout.core.service.notification.ReactionNotificationRequest
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -12,7 +15,9 @@ import org.springframework.stereotype.Service
@Service
class ReactionServiceImpl(
private val reactionRepository: ReactionRepository,
private val apReactionService: APReactionService
private val apReactionService: APReactionService,
private val notificationService: NotificationService,
private val postRepository: PostRepository
) : ReactionService {
override suspend fun receiveReaction(
emoji: Emoji,
@ -23,7 +28,16 @@ class ReactionServiceImpl(
reactionRepository.deleteByPostIdAndActorId(postId, actorId)
}
try {
reactionRepository.save(Reaction(reactionRepository.generateId(), emoji, postId, actorId))
val reaction = reactionRepository.save(Reaction(reactionRepository.generateId(), emoji, postId, actorId))
notificationService.publishNotify(
ReactionNotificationRequest(
postRepository.findById(postId)!!.actorId,
actorId,
postId,
reaction.id
)
)
} catch (_: DuplicateException) {
}
}
@ -49,6 +63,10 @@ class ReactionServiceImpl(
val reaction = Reaction(reactionRepository.generateId(), emoji, postId, actorId)
reactionRepository.save(reaction)
apReactionService.reaction(reaction)
val id = postRepository.findById(postId)!!.actorId
notificationService.publishNotify(ReactionNotificationRequest(id, actorId, postId, reaction.id))
}
override suspend fun removeReaction(actorId: Long, postId: Long) {

View File

@ -12,6 +12,9 @@ import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
import dev.usbharu.hideout.core.service.follow.SendFollowDto
import dev.usbharu.hideout.core.service.notification.FollowNotificationRequest
import dev.usbharu.hideout.core.service.notification.FollowRequestNotificationRequest
import dev.usbharu.hideout.core.service.notification.NotificationService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -24,7 +27,8 @@ class RelationshipServiceImpl(
private val apSendAcceptService: ApSendAcceptService,
private val apSendRejectService: ApSendRejectService,
private val apSendUndoService: APSendUndoService,
private val actorRepository: ActorRepository
private val actorRepository: ActorRepository,
private val notificationService: NotificationService
) : RelationshipService {
override suspend fun followRequest(actorId: Long, targetId: Long) {
logger.info("START Follow Request userId: {} targetId: {}", actorId, targetId)
@ -82,6 +86,8 @@ class RelationshipServiceImpl(
val target = actorRepository.findById(targetId) ?: throw UserNotFoundException.withId(targetId)
if (target.locked.not()) {
acceptFollowRequest(targetId, actorId)
} else {
notificationService.publishNotify(FollowRequestNotificationRequest(targetId, actorId))
}
}
@ -185,6 +191,7 @@ class RelationshipServiceImpl(
if (isRemoteActor(remoteActor)) {
apSendAcceptService.sendAcceptFollow(user, remoteActor)
}
notificationService.publishNotify(FollowNotificationRequest(actorId, targetId))
}
override suspend fun rejectFollowRequest(actorId: Long, targetId: Long) {