Live video on the AT Protocol

discord: don't ping if you're hydrating an empty database (#251)

authored by Eli Mallon and committed by GitHub b10b97bd de558a73

+16 -14
+1 -1
pkg/atproto/atproto.go
··· 153 153 } 154 154 log.Debug(ctx, "record type", "key", k, "type", nsid.String()) 155 155 156 - err = atsync.handleCreateUpdate(ctx, signerDID.String(), rkey, bs, v.String(), nsid, false) 156 + err = atsync.handleCreateUpdate(ctx, signerDID.String(), rkey, bs, v.String(), nsid, false, true) 157 157 if err != nil { 158 158 log.Warn(ctx, "failed to handle create update", "err", err) 159 159 // invalid CBOR and stuff should get ignored, so
+1 -1
pkg/atproto/firehose.go
··· 215 215 break 216 216 } 217 217 218 - err = atsync.handleCreateUpdate(ctx, evt.Repo, rkey, recCBOR, op.Cid.String(), collection, ek == repomgr.EvtKindUpdateRecord) 218 + err = atsync.handleCreateUpdate(ctx, evt.Repo, rkey, recCBOR, op.Cid.String(), collection, ek == repomgr.EvtKindUpdateRecord, false) 219 219 if err != nil { 220 220 log.Error(ctx, "failed to handle create update", "err", err) 221 221 continue
+14 -12
pkg/atproto/sync.go
··· 20 20 lexutil "github.com/bluesky-social/indigo/lex/util" 21 21 ) 22 22 23 - func (atsync *ATProtoSynchronizer) handleCreateUpdate(ctx context.Context, userDID string, rkey syntax.RecordKey, recCBOR *[]byte, cid string, collection syntax.NSID, isUpdate bool) error { 23 + func (atsync *ATProtoSynchronizer) handleCreateUpdate(ctx context.Context, userDID string, rkey syntax.RecordKey, recCBOR *[]byte, cid string, collection syntax.NSID, isUpdate bool, isFirstSync bool) error { 24 24 ctx = log.WithLogValues(ctx, "func", "handleCreateUpdate", "userDID", userDID, "rkey", rkey.String(), "cid", cid, "collection", collection.String()) 25 25 now := time.Now() 26 26 r, err := atsync.Model.GetRepo(userDID) ··· 131 131 } 132 132 go atsync.Bus.Publish(streamerRepo.DID, scm) 133 133 134 - for _, webhook := range atsync.CLI.DiscordWebhooks { 135 - if webhook.DID == streamerRepo.DID && webhook.Type == "chat" { 136 - go func() { 137 - err := discord.SendChat(ctx, webhook, r, scm) 138 - if err != nil { 139 - log.Error(ctx, "failed to send livestream to discord", "err", err) 140 - } else { 141 - log.Log(ctx, "sent livestream to discord", "user", userDID, "webhook", webhook.URL) 142 - } 143 - }() 134 + if !isUpdate && !isFirstSync { 135 + for _, webhook := range atsync.CLI.DiscordWebhooks { 136 + if webhook.DID == streamerRepo.DID && webhook.Type == "chat" { 137 + go func() { 138 + err := discord.SendChat(ctx, webhook, r, scm) 139 + if err != nil { 140 + log.Error(ctx, "failed to send livestream to discord", "err", err) 141 + } else { 142 + log.Log(ctx, "sent livestream to discord", "user", userDID, "webhook", webhook.URL) 143 + } 144 + }() 145 + } 144 146 } 145 147 } 146 148 ··· 291 293 } 292 294 go atsync.Bus.Publish(userDID, lsv) 293 295 294 - if !isUpdate { 296 + if !isUpdate && !isFirstSync { 295 297 log.Warn(ctx, "Livestream detected! Blasting followers!", "title", rec.Title, "url", u, "createdAt", rec.CreatedAt, "repo", userDID) 296 298 notifications, err := atsync.Model.GetFollowersNotificationTokens(userDID) 297 299 if err != nil {