Files
Pete/internal/poster/tracker.go
prosolis afe2ef996b Fix !post in round-robin mode, reaction VS16, image label
- !post falls back to newest unposted story for the channel when the
  in-memory queue is empty (the steady state under round-robin).
- Accept ️/️ (U+FE0F variation selector) as question reactions —
  the bare codepoints alone missed clients that render the colored emoji.
- Rewrite Guardian i.guim.co.uk thumbnails to width=1200 so we stop
  rejecting real images as "tracking pixels"; relabel the size warning.
- Log decrypt failures and reactions on events not in post_log so future
  silent drops surface instead of vanishing.
2026-05-24 09:14:37 -07:00

55 lines
1.5 KiB
Go

package poster
import (
"log/slog"
"sync"
"time"
"pete/internal/storage"
"maunium.net/go/mautrix/id"
)
// ReactionCallback is an optional hook fired after a reaction is recorded.
// Used to wire reaction-driven features (e.g. ❓ → summary) without coupling
// poster to those packages.
type ReactionCallback func(roomID id.RoomID, targetEventID id.EventID, guid, channel, emoji string)
var (
reactionCallbackMu sync.RWMutex
reactionCallback ReactionCallback
)
// SetReactionCallback installs a hook called after every recorded reaction.
// Pass nil to clear. Safe to call before or after the matrix client starts.
func SetReactionCallback(fn ReactionCallback) {
reactionCallbackMu.Lock()
reactionCallback = fn
reactionCallbackMu.Unlock()
}
// HandleReaction processes a reaction event by mapping it back to the story GUID.
func HandleReaction(roomID id.RoomID, eventID id.EventID, targetEventID id.EventID, emoji string, userID id.UserID) {
guid, channel, found := storage.LookupPostGUID(string(targetEventID))
if !found {
slog.Info("reaction on event not in post_log, ignoring",
"target_event", targetEventID, "emoji", emoji, "user", userID)
return
}
storage.InsertReaction(guid, channel, string(eventID), emoji, string(userID), time.Now().Unix())
slog.Debug("reaction recorded",
"guid", guid,
"channel", channel,
"emoji", emoji,
"user", userID,
)
reactionCallbackMu.RLock()
cb := reactionCallback
reactionCallbackMu.RUnlock()
if cb != nil {
go cb(roomID, targetEventID, guid, channel, emoji)
}
}