This commit is contained in:
12600k-rog-d4
2025-12-09 20:33:57 +08:00
parent 144ed3cbdf
commit 8f4d399cfd
1498 changed files with 3778 additions and 3654 deletions

View File

@@ -0,0 +1,53 @@
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,
})
}