Files
common-server-public/archive/bbs-go-active/server/internal/services/eventhandler/user_like_handler.go
12600k-rog-d4 8f4d399cfd 20251209
2025-12-09 20:33:57 +08:00

54 lines
1.2 KiB
Go

package eventhandler
import (
"bbs-go/internal/models/constants"
"bbs-go/internal/pkg/event"
"bbs-go/internal/pkg/msg"
"bbs-go/internal/services"
"reflect"
)
func init() {
event.RegHandler(reflect.TypeOf(event.UserLikeEvent{}), handleUserLike)
event.RegHandler(reflect.TypeOf(event.UserUnLikeEvent{}), handleUserUnLike)
}
func handleUserLike(i interface{}) {
e := i.(event.UserLikeEvent)
if e.EntityType == constants.EntityTopic {
sendTopicLikeMsg(e.EntityId, e.UserId)
} else if e.EntityType == constants.EntityComment {
// TODO
}
}
func handleUserUnLike(i interface{}) {
e := i.(event.UserUnLikeEvent)
if e.EntityType == constants.EntityTopic {
// TODO
}
}
// sendTopicLikeMsg 话题收到点赞
func sendTopicLikeMsg(topicId, likeUserId int64) {
topic := services.TopicService.Get(topicId)
if topic == nil || topic.Status != constants.StatusOk {
return
}
if topic.UserId == likeUserId {
return
}
var (
from = likeUserId
to = topic.UserId
title = "点赞了你的话题"
quoteContent = "《" + topic.GetTitle() + "》"
)
services.MessageService.SendMsg(from, to, msg.TypeTopicLike, title, "", quoteContent,
&msg.TopicLikeExtraData{
TopicId: topicId,
LikeUserId: likeUserId,
})
}