Live video on the AT Protocol

model: just use sql for recent livestreams

+5 -31
+2 -9
js/app/features/bluesky/blueskySlice.tsx
··· 293 293 const { bluesky } = thunkAPI.getState() as { 294 294 bluesky: BlueskyState; 295 295 }; 296 - let bskyAgent: Agent; 297 - if (!bluesky.pdsAgent) { 298 - // unauthed request to Bluesky Appview 299 - bskyAgent = new Agent("https://public.api.bsky.app"); 300 - } else { 301 - bskyAgent = bluesky.pdsAgent; 302 - } 303 - 304 - if (!bskyAgent) throw new Error("No Agent!"); 296 + // unauthed request to Bluesky Appview 297 + const bskyAgent = new Agent("https://public.api.bsky.app"); 305 298 306 299 return await bskyAgent.getProfiles({ 307 300 actors: actors,
+3 -22
pkg/model/livestream.go
··· 76 76 return &livestream, nil 77 77 } 78 78 79 - // type for livestream with seg start time 80 - type LivestreamWithSegmentStartTime struct { 81 - Livestream 82 - // should be latest_segments.latest_segment_start_time in the query 83 - LatestSegmentStartTime string 84 - } 85 - 86 79 // GetLatestLivestreams returns the most recent livestreams, given a limit and a cursor 87 80 // Only gets livestreams with a valid segment no less than 30 seconds old 88 81 func (m *DBModel) GetLatestLivestreams(limit int, before *time.Time) ([]Livestream, error) { 89 - var recentLivestreams []LivestreamWithSegmentStartTime 82 + var recentLivestreams []Livestream 90 83 thirtySecondsAgo := time.Now().Add(-30 * time.Second) 91 84 92 85 // get latest segment for the repo DID ··· 96 89 m.DB.Table("segments"). 97 90 Select("repo_did, MAX(start_time)"). 98 91 Group("repo_did")). 99 - Where("start_time > ?", thirtySecondsAgo). 92 + Where("start_time > ?", thirtySecondsAgo.UTC()). 100 93 Group("repo_did") 101 94 102 95 rankedLivestreamsSubQuery := m.DB.Table("livestreams"). ··· 130 123 return nil, nil 131 124 } 132 125 133 - var finalStreams []Livestream 134 - 135 - // for each seg, put results in map if seg start time is after 30 seconds ago 136 - for _, seg := range recentLivestreams { 137 - layout := "2006-01-02 15:04:05.000+00:00" 138 - segStartTime, _ := time.Parse(layout, seg.LatestSegmentStartTime) 139 - if segStartTime.After(thirtySecondsAgo) { 140 - finalStreams = append(finalStreams, seg.Livestream) 141 - //fmt.Printf("seg start time: %s vs 30 seconds ago: %s\n", segStartTime, thirtySecondsAgo.UTC()) 142 - } 143 - } 144 - 145 - return finalStreams, nil 126 + return recentLivestreams, nil 146 127 }