diff --git a/backend/platform-bridge/cmd/main.go b/backend/platform-bridge/cmd/main.go index 9805b02..b788a0e 100644 --- a/backend/platform-bridge/cmd/main.go +++ b/backend/platform-bridge/cmd/main.go @@ -71,7 +71,32 @@ func main() { // Set message handler with logging. router.SetMessageHandler(func(msg *bridge.UnifiedMessage) (*bridge.UnifiedResponse, error) { - // Log incoming. + // Routing decisions. + isAdmin := mapper.IsAdmin(msg.Platform, msg.OriginalSenderUID) + + // Blocklist check — MUST run first, before logging/enrichment, + // to avoid wasting resources on blocked users/groups. + if blocked := blocklistStore.IsBlocked(msg.ChannelType, msg.ChannelID, msg.OriginalSenderUID, isAdmin); blocked { + msgLogger.Log(logging.LogEntry{ + Timestamp: time.Now(), + Direction: "incoming", + Platform: msg.Platform, + ChannelID: msg.ChannelID, + SenderID: msg.OriginalSenderUID, + SenderName: msg.OriginalSenderName, + GroupName: msg.GroupName, + Content: "[blocked]", + Success: true, + }) + return &bridge.UnifiedResponse{ + Messages: []bridge.ResponseMessage{ + {DisplayType: "silent", Content: "", FormatMode: "plain"}, + }, + Platform: msg.Platform, + }, nil + } + + // Log incoming (only non-blocked messages). msgLogger.Log(logging.LogEntry{ Timestamp: time.Now(), Direction: "incoming", @@ -85,9 +110,6 @@ func main() { MessageID: msg.MessageID, Success: true, }) - - // Routing decisions. - isAdmin := mapper.IsAdmin(msg.Platform, msg.OriginalSenderUID) adminNick := cfg.AdminNickname if isAdmin { if id := mapper.ResolveOrNil(msg.Platform, msg.OriginalSenderUID); id != nil && id.Nickname != "" { @@ -138,25 +160,6 @@ func main() { msg.Content = fmt.Sprintf("【私聊 %s】%s/%s (%s):\n%s", msg.Platform, adminNick, msg.OriginalSenderName, msg.OriginalSenderUID, msg.Content) } - // Blocklist/whitelist check (admin always bypasses). - if blocked := blocklistStore.IsBlocked(msg.ChannelType, msg.ChannelID, msg.OriginalSenderUID, isAdmin); blocked { - msgLogger.Log(logging.LogEntry{ - Timestamp: time.Now(), - Direction: "outgoing", - Platform: msg.Platform, - ChannelID: msg.ChannelID, - SenderID: msg.OriginalSenderUID, - SenderName: "Cyrene", - Content: "[blocked]", - Success: true, - }) - return &bridge.UnifiedResponse{ - Messages: []bridge.ResponseMessage{ - {DisplayType: "silent", Content: "", FormatMode: "plain"}, - }, - Platform: msg.Platform, - }, nil - } var response *bridge.UnifiedResponse var routeErr error