usercache: rename methods

"Update" better expresses what is being done to the cache.
This commit is contained in:
Skip R
2026-02-06 17:44:37 -08:00
parent 1fcc910184
commit 2310d2c036
4 changed files with 12 additions and 12 deletions

View File

@@ -69,7 +69,7 @@ func (dc *DiscordClient) FetchMessages(ctx context.Context, fetchParams bridgev2
// Update our user cache with all of the users present in the response. This // Update our user cache with all of the users present in the response. This
// indirectly makes `GetUserInfo` on `DiscordClient` return the information // indirectly makes `GetUserInfo` on `DiscordClient` return the information
// we've fetched above. // we've fetched above.
cachedDiscordUserIDs := dc.userCache.HandleMessages(msgs) cachedDiscordUserIDs := dc.userCache.UpdateWithMessages(msgs)
{ {
log := zerolog.Ctx(ctx).With(). log := zerolog.Ctx(ctx).With().

View File

@@ -132,7 +132,7 @@ func (cl *DiscordClient) connect(ctx context.Context) error {
// Populate the user cache with the users from the READY payload. // Populate the user cache with the users from the READY payload.
log.Debug().Int("n_users", len(cl.Session.State.Ready.Users)).Msg("Inserting users from READY into cache") log.Debug().Int("n_users", len(cl.Session.State.Ready.Users)).Msg("Inserting users from READY into cache")
cl.userCache.HandleReady(&cl.Session.State.Ready) cl.userCache.UpdateWithReady(&cl.Session.State.Ready)
cl.BeginSyncing(ctx) cl.BeginSyncing(ctx)

View File

@@ -189,7 +189,7 @@ func (d *DiscordClient) handleDiscordEvent(rawEvt any) {
switch evt := rawEvt.(type) { switch evt := rawEvt.(type) {
case *discordgo.Ready: case *discordgo.Ready:
log.Info().Msg("Received READY dispatch from discordgo") log.Info().Msg("Received READY dispatch from discordgo")
d.userCache.HandleReady(evt) d.userCache.UpdateWithReady(evt)
d.UserLogin.BridgeState.Send(status.BridgeState{ d.UserLogin.BridgeState.Send(status.BridgeState{
StateEvent: status.StateConnected, StateEvent: status.StateConnected,
}) })
@@ -207,11 +207,11 @@ func (d *DiscordClient) handleDiscordEvent(rawEvt any) {
Msg("Dropping message that lacks an author") Msg("Dropping message that lacks an author")
return return
} }
d.userCache.HandleMessage(evt.Message) d.userCache.UpdateWithMessage(evt.Message)
wrappedEvt := d.wrapDiscordMessage(evt) wrappedEvt := d.wrapDiscordMessage(evt)
d.UserLogin.Bridge.QueueRemoteEvent(d.UserLogin, &wrappedEvt) d.UserLogin.Bridge.QueueRemoteEvent(d.UserLogin, &wrappedEvt)
case *discordgo.UserUpdate: case *discordgo.UserUpdate:
d.userCache.HandleUserUpdate(evt) d.userCache.UpdateWithUserUpdate(evt)
case *discordgo.MessageReactionAdd: case *discordgo.MessageReactionAdd:
wrappedEvt := d.wrapDiscordReaction(evt.MessageReaction, true) wrappedEvt := d.wrapDiscordReaction(evt.MessageReaction, true)
d.UserLogin.Bridge.QueueRemoteEvent(d.UserLogin, &wrappedEvt) d.UserLogin.Bridge.QueueRemoteEvent(d.UserLogin, &wrappedEvt)

View File

@@ -46,7 +46,7 @@ func NewUserCache(session *discordgo.Session) *UserCache {
} }
} }
func (uc *UserCache) HandleReady(ready *discordgo.Ready) { func (uc *UserCache) UpdateWithReady(ready *discordgo.Ready) {
if ready == nil { if ready == nil {
return return
} }
@@ -59,25 +59,25 @@ func (uc *UserCache) HandleReady(ready *discordgo.Ready) {
} }
} }
// HandleMessage updates the user cache with the users involved in a single // UpdateWithMessage updates the user cache with the users involved in a single
// message (author, mentioned, mentioned author, etc.) // message (author, mentioned, mentioned author, etc.)
// //
// The updated user IDs are returned. // The updated user IDs are returned.
func (uc *UserCache) HandleMessage(msg *discordgo.Message) []string { func (uc *UserCache) UpdateWithMessage(msg *discordgo.Message) []string {
if msg == nil { if msg == nil {
return []string{} return []string{}
} }
// For now just forward to HandleMessages until a need for a specialized // For now just forward to HandleMessages until a need for a specialized
// path makes itself known. // path makes itself known.
return uc.HandleMessages([]*discordgo.Message{msg}) return uc.UpdateWithMessages([]*discordgo.Message{msg})
} }
// HandleMessages updates the user cache with the total set of users involved // UpdateWithMessages updates the user cache with the total set of users involved
// with multiple messages (authors, mentioned users, mentioned authors, etc.) // with multiple messages (authors, mentioned users, mentioned authors, etc.)
// //
// The updated user IDs are returned. // The updated user IDs are returned.
func (uc *UserCache) HandleMessages(msgs []*discordgo.Message) []string { func (uc *UserCache) UpdateWithMessages(msgs []*discordgo.Message) []string {
if len(msgs) == 0 { if len(msgs) == 0 {
return []string{} return []string{}
} }
@@ -110,7 +110,7 @@ func (uc *UserCache) HandleMessages(msgs []*discordgo.Message) []string {
return slices.Collect(maps.Keys(collectedUsers)) return slices.Collect(maps.Keys(collectedUsers))
} }
func (uc *UserCache) HandleUserUpdate(update *discordgo.UserUpdate) { func (uc *UserCache) UpdateWithUserUpdate(update *discordgo.UserUpdate) {
if update == nil || update.User == nil { if update == nil || update.User == nil {
return return
} }