adds labels to accounts that have created records outside of Bluesky
23
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: remove label if a delete comes in for a non-expiry application

+50 -1
+50 -1
cmd/recordcollector/main.go
··· 246 246 return nil 247 247 } 248 248 249 + func (h *handler) removeLabel(ctx context.Context, did, label string) error { 250 + key := fmt.Sprintf("recordcollector_%s_%s", did, label) 251 + 252 + eventLabel := toolsozone.ModerationDefs_ModEventLabel{ 253 + CreateLabelVals: []string{}, 254 + NegateLabelVals: []string{label}, 255 + } 256 + input := &toolsozone.ModerationEmitEvent_Input{ 257 + CreatedBy: RecordCollectorDid, 258 + Event: &toolsozone.ModerationEmitEvent_Input_Event{ 259 + ModerationDefs_ModEventLabel: &eventLabel, 260 + }, 261 + Subject: &toolsozone.ModerationEmitEvent_Input_Subject{ 262 + AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ 263 + Did: did, 264 + }, 265 + }, 266 + } 267 + 268 + _, err := toolsozone.ModerationEmitEvent(ctx, h.client, input) 269 + if err != nil { 270 + h.logger.Error("failed to remove label", "err", err) 271 + return fmt.Errorf("failed to remove label: %w", err) 272 + } 273 + h.logger.Info("removing label", "did", did, "label", label) 274 + 275 + if err := h.redis.Del(ctx, key).Err(); err != nil { 276 + h.logger.Error("failed to delete redis key", "err", err, "key", key) 277 + // Don't return error -- label was removed 278 + } 279 + 280 + return nil 281 + } 282 + 249 283 func (h *handler) HandleEvent(ctx context.Context, event *models.Event) error { 250 284 h.lk.Lock() 251 285 defer h.lk.Unlock() ··· 254 288 return nil 255 289 } 256 290 291 + collection := event.Commit.Collection 292 + 293 + // if a delete comes in for a non-expiry label, issue a negation 294 + if event.Commit.Operation == models.CommitOperationDelete { 295 + for prefix, label := range labelPrefixes { 296 + nonExpiry := nonExpiryPrefixes[label] 297 + if strings.HasPrefix(collection, prefix) && nonExpiry { 298 + if err := h.removeLabel(ctx, event.Did, label); err != nil { 299 + return err 300 + } 301 + } 302 + } 303 + 304 + return nil 305 + } 306 + 257 307 if event.Commit.Operation != models.CommitOperationCreate { 258 308 return nil 259 309 } ··· 270 320 } 271 321 } 272 322 273 - collection := event.Commit.Collection 274 323 for _, prefix := range ignorePrefixes { 275 324 if strings.HasPrefix(collection, prefix) { 276 325 return nil