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