mirror of https://github.com/usbharu/Hideout.git
feat: 絵文字リアクションの受信ができるように
This commit is contained in:
parent
8af489c93c
commit
51837ea379
|
@ -9,7 +9,7 @@ import dev.usbharu.hideout.activitypub.service.common.ExtendedActivityVocabulary
|
||||||
|
|
||||||
class ObjectDeserializer : JsonDeserializer<Object>() {
|
class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
@Suppress("LongMethod", "CyclomaticComplexMethod")
|
||||||
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object {
|
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?): Object? {
|
||||||
requireNotNull(p)
|
requireNotNull(p)
|
||||||
val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p))
|
val treeNode: JsonNode = requireNotNull(p.codec?.readTree(p))
|
||||||
if (treeNode.isValueNode) {
|
if (treeNode.isValueNode) {
|
||||||
|
@ -24,7 +24,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
|
ExtendedActivityVocabulary.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
|
||||||
}
|
}
|
||||||
} else if (type.isValueNode) {
|
} else if (type.isValueNode) {
|
||||||
ExtendedActivityVocabulary.values().first { it.name.equals(type.asText(), true) }
|
ExtendedActivityVocabulary.values().firstOrNull() { it.name.equals(type.asText(), true) }
|
||||||
} else {
|
} else {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,7 @@ class ObjectDeserializer : JsonDeserializer<Object>() {
|
||||||
ExtendedActivityVocabulary.Video -> TODO()
|
ExtendedActivityVocabulary.Video -> TODO()
|
||||||
ExtendedActivityVocabulary.Mention -> TODO()
|
ExtendedActivityVocabulary.Mention -> TODO()
|
||||||
ExtendedActivityVocabulary.Emoji -> p.codec.treeToValue(treeNode, Emoji::class.java)
|
ExtendedActivityVocabulary.Emoji -> p.codec.treeToValue(treeNode, Emoji::class.java)
|
||||||
|
null -> null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TODO()
|
TODO()
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.activity.like
|
package dev.usbharu.hideout.activitypub.service.activity.like
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException
|
import dev.usbharu.hideout.activitypub.domain.exception.FailedToGetActivityPubResourceException
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Emoji
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.Like
|
import dev.usbharu.hideout.activitypub.domain.model.Like
|
||||||
import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor
|
import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||||
|
import dev.usbharu.hideout.activitypub.service.objects.emoji.EmojiService
|
||||||
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
|
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteService
|
||||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji
|
||||||
import dev.usbharu.hideout.core.service.reaction.ReactionService
|
import dev.usbharu.hideout.core.service.reaction.ReactionService
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@ -16,7 +19,8 @@ class APLikeProcessor(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
private val apUserService: APUserService,
|
private val apUserService: APUserService,
|
||||||
private val apNoteService: APNoteService,
|
private val apNoteService: APNoteService,
|
||||||
private val reactionService: ReactionService
|
private val reactionService: ReactionService,
|
||||||
|
private val emojiService: EmojiService
|
||||||
) :
|
) :
|
||||||
AbstractActivityPubProcessor<Like>(transaction) {
|
AbstractActivityPubProcessor<Like>(transaction) {
|
||||||
override suspend fun internalProcess(activity: ActivityPubProcessContext<Like>) {
|
override suspend fun internalProcess(activity: ActivityPubProcessContext<Like>) {
|
||||||
|
@ -29,9 +33,16 @@ class APLikeProcessor(
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val post = apNoteService.fetchNoteWithEntity(target).second
|
val post = apNoteService.fetchNoteWithEntity(target).second
|
||||||
|
|
||||||
|
val emoji = if (content.startsWith(":")) {
|
||||||
|
val tag = activity.activity.tag
|
||||||
|
(tag.firstOrNull { it is Emoji } as Emoji?)?.let { emojiService.fetchEmoji(it).second }
|
||||||
|
} else {
|
||||||
|
UnicodeEmoji(content)
|
||||||
|
}
|
||||||
|
|
||||||
reactionService.receiveReaction(
|
reactionService.receiveReaction(
|
||||||
content,
|
emoji ?: UnicodeEmoji("❤"),
|
||||||
actor.substringAfter("://").substringBefore("/"),
|
|
||||||
personWithEntity.second.id,
|
personWithEntity.second.id,
|
||||||
post.id
|
post.id
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package dev.usbharu.hideout.core.service.reaction
|
package dev.usbharu.hideout.core.service.reaction
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.core.domain.model.emoji.Emoji
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
interface ReactionService {
|
interface ReactionService {
|
||||||
suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long)
|
suspend fun receiveReaction(emoji: Emoji, actorId: Long, postId: Long)
|
||||||
suspend fun receiveRemoveReaction(actorId: Long, postId: Long)
|
suspend fun receiveRemoveReaction(actorId: Long, postId: Long)
|
||||||
suspend fun sendReaction(name: String, actorId: Long, postId: Long)
|
suspend fun sendReaction(emoji: Emoji, actorId: Long, postId: Long)
|
||||||
suspend fun removeReaction(actorId: Long, postId: Long)
|
suspend fun removeReaction(actorId: Long, postId: Long)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package dev.usbharu.hideout.core.service.reaction
|
package dev.usbharu.hideout.core.service.reaction
|
||||||
|
|
||||||
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
|
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
|
||||||
import dev.usbharu.hideout.core.domain.model.emoji.UnicodeEmoji
|
import dev.usbharu.hideout.core.domain.model.emoji.Emoji
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||||
|
@ -14,11 +14,15 @@ class ReactionServiceImpl(
|
||||||
private val reactionRepository: ReactionRepository,
|
private val reactionRepository: ReactionRepository,
|
||||||
private val apReactionService: APReactionService
|
private val apReactionService: APReactionService
|
||||||
) : ReactionService {
|
) : ReactionService {
|
||||||
override suspend fun receiveReaction(name: String, domain: String, actorId: Long, postId: Long) {
|
override suspend fun receiveReaction(
|
||||||
|
emoji: Emoji,
|
||||||
|
actorId: Long,
|
||||||
|
postId: Long
|
||||||
|
) {
|
||||||
if (reactionRepository.existByPostIdAndActorIdAndEmojiId(postId, actorId, 0).not()) {
|
if (reactionRepository.existByPostIdAndActorIdAndEmojiId(postId, actorId, 0).not()) {
|
||||||
try {
|
try {
|
||||||
reactionRepository.save(
|
reactionRepository.save(
|
||||||
Reaction(reactionRepository.generateId(), UnicodeEmoji("❤"), postId, actorId)
|
Reaction(reactionRepository.generateId(), emoji, postId, actorId)
|
||||||
)
|
)
|
||||||
} catch (_: ExposedSQLException) {
|
} catch (_: ExposedSQLException) {
|
||||||
}
|
}
|
||||||
|
@ -34,7 +38,7 @@ class ReactionServiceImpl(
|
||||||
reactionRepository.delete(reaction)
|
reactionRepository.delete(reaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun sendReaction(name: String, actorId: Long, postId: Long) {
|
override suspend fun sendReaction(emoji: Emoji, actorId: Long, postId: Long) {
|
||||||
val findByPostIdAndUserIdAndEmojiId =
|
val findByPostIdAndUserIdAndEmojiId =
|
||||||
reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
|
reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
|
||||||
|
|
||||||
|
@ -43,7 +47,7 @@ class ReactionServiceImpl(
|
||||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||||
}
|
}
|
||||||
|
|
||||||
val reaction = Reaction(reactionRepository.generateId(), UnicodeEmoji("❤"), postId, actorId)
|
val reaction = Reaction(reactionRepository.generateId(), emoji, postId, actorId)
|
||||||
reactionRepository.save(reaction)
|
reactionRepository.save(reaction)
|
||||||
apReactionService.reaction(reaction)
|
apReactionService.reaction(reaction)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue