···8989 }
90909191 // skip identity lookup if account is not active
9292- if acc.Status != models.AccountStatusActive || acc.UpstreamStatus != models.AccountStatusActive {
9292+ if !acc.IsActive() {
9393 return acc, nil, nil
9494 }
9595···110110 return err
111111 }
112112113113- if acc.Status != models.AccountStatusActive || acc.UpstreamStatus != models.AccountStatusActive {
113113+ if !acc.IsActive() {
114114 logger.Info("dropping commit message for non-active account", "status", acc.Status, "upstreamStatus", acc.UpstreamStatus)
115115 return nil
116116 }
···156156 return err
157157 }
158158159159- if acc.Status != models.AccountStatusActive || acc.UpstreamStatus != models.AccountStatusActive {
159159+ if !acc.IsActive() {
160160 logger.Info("dropping commit message for non-active account", "status", acc.Status, "upstreamStatus", acc.UpstreamStatus)
161161 return nil
162162 }
···229229 attribute.Int64("seq", evt.Seq),
230230 attribute.Bool("active", evt.Active),
231231 )
232232+ logger.Info("relay got account event")
232233233234 acc, _, err := r.preProcessEvent(ctx, evt.Did, hostname, hostID, logger)
234235 if err != nil {
235236 return err
236237 }
237238238238- if evt.Status != nil {
239239- span.SetAttributes(attribute.String("repo_status", *evt.Status))
240240- }
241241- logger.Info("relay got account event")
242242-243239 if !evt.Active && evt.Status == nil {
244244- // XXX: what should we do here?
245240 logger.Warn("invalid account event", "active", evt.Active, "status", evt.Status)
246241 }
247242248248- // Process the upstream account status change
249249- if err := r.db.Model(models.Account{}).Where("uid = ?", acc.UID).Update("upstream_status", evt.Status).Error; err != nil {
250250- return err
243243+ newStatus := models.AccountStatusInactive
244244+ if evt.Active {
245245+ newStatus = models.AccountStatusActive
246246+ } else if evt.Status != nil {
247247+ newStatus = models.AccountStatus(*evt.Status)
251248 }
252249253253- // wrangle various status codes in to what is expected in account event
254254- publicStatus := acc.Status
255255- if publicStatus == models.AccountStatusActive && evt.Status != nil {
256256- publicStatus = models.AccountStatus(*evt.Status)
257257- }
258258- publicActive := publicStatus == models.AccountStatusActive
259259- ptrStatus := (*string)(&publicStatus)
260260- if publicActive {
261261- ptrStatus = nil
250250+ if newStatus != acc.UpstreamStatus {
251251+ // updates upstream status in account database
252252+ if err := r.db.Model(models.Account{}).Where("uid = ?", acc.UID).Update("upstream_status", newStatus).Error; err != nil {
253253+ return err
254254+ }
255255+ acc.UpstreamStatus = newStatus
256256+257257+ // clear account cache
258258+ r.accountCache.Remove(acc.DID)
262259 }
263260264261 // emit the event
265262 err = r.Events.AddEvent(ctx, &stream.XRPCStreamEvent{
266263 RepoAccount: &comatproto.SyncSubscribeRepos_Account{
267267- Active: publicActive,
264264+ Active: acc.IsActive(),
268265 Did: acc.DID,
269269- Status: ptrStatus, // TODO: sometimes will be "active"
266266+ Status: acc.StatusField(),
270267 Time: evt.Time,
271268 },
272269 PrivUid: acc.UID,
+22
cmd/rerelay/relay/models/methods.go
···2121 }
2222 return fmt.Sprintf("%s://%s/xrpc/com.atproto.sync.subscribeRepos", scheme, h.Hostname)
2323}
2424+2525+func (a *Account) AccountStatus() AccountStatus {
2626+ if a.Status != AccountStatusActive {
2727+ return a.Status
2828+ }
2929+ return a.UpstreamStatus
3030+}
3131+3232+// Returns a pointer to a copy of status string; or nil if status is active.
3333+//
3434+// Helpful for account info responses which have a boolean 'active' and optional 'status' field (like the #account message)
3535+func (a *Account) StatusField() *string {
3636+ if a.IsActive() {
3737+ return nil
3838+ }
3939+ s := string(a.AccountStatus())
4040+ return &s
4141+}
4242+4343+func (a *Account) IsActive() bool {
4444+ return (a.Status == AccountStatusActive || a.Status == AccountStatusThrottled) && a.UpstreamStatus == AccountStatusActive
4545+}