bluesky appview implementation using microcosm and other services server.reddwarf.app
appview bluesky reddwarf microcosm
1package main 2 3import ( 4 "context" 5 "fmt" 6 "log" 7 "net/http" 8 "os" 9 "time" 10 11 "tangled.org/whey.party/rdcs/microcosm/constellation" 12 "tangled.org/whey.party/rdcs/microcosm/slingshot" 13 "tangled.org/whey.party/rdcs/sticket" 14 15 // "github.com/bluesky-social/indigo/atproto/atclient" 16 // comatproto "github.com/bluesky-social/indigo/api/atproto" 17 // appbsky "github.com/bluesky-social/indigo/api/bsky" 18 // "github.com/bluesky-social/indigo/atproto/atclient" 19 // "github.com/bluesky-social/indigo/atproto/identity" 20 // "github.com/bluesky-social/indigo/atproto/syntax" 21 "github.com/bluesky-social/indigo/api/agnostic" 22 // "github.com/bluesky-social/jetstream/pkg/models" 23) 24 25const ( 26 JETSTREAM_URL = "ws://localhost:6008/subscribe" 27 SPACEDUST_URL = "ws://localhost:9998/subscribe" 28 SLINGSHOT_URL = "http://localhost:7729" 29 CONSTELLATION_URL = "http://localhost:7728" 30) 31 32func main() { 33 fmt.Fprintf(os.Stdout, "RDCS started") 34 35 ctx := context.Background() 36 mailbox := sticket.New() 37 sl := slingshot.NewSlingshot(SLINGSHOT_URL) 38 cs := constellation.NewConstellation(CONSTELLATION_URL) 39 // spacedust is type definitions only 40 // jetstream types is probably available from jetstream/pkg/models 41 42 responsewow, _ := agnostic.RepoGetRecord(ctx, sl, "", "app.bsky.feed.profile", "did:plc:44ybard66vv44zksje25o7dz", "self") 43 44 fmt.Fprintf(os.Stdout, responsewow.Uri) 45 46 http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { 47 mailbox.HandleWS(&w, r) 48 }) 49 50 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 51 fmt.Fprintf(w, "hello worldio !") 52 clientUUID := sticket.GetUUIDFromRequest(r) 53 hasSticket := clientUUID != "" 54 if hasSticket { 55 go func(targetUUID string) { 56 // simulated heavy processing 57 time.Sleep(2 * time.Second) 58 59 lateData := map[string]any{ 60 "postId": 101, 61 "newComments": []string{ 62 "Wow great tutorial!", 63 "I am stuck on step 1.", 64 }, 65 } 66 67 success := mailbox.SendToClient(targetUUID, "post_thread_update", lateData) 68 if success { 69 log.Println("Successfully sent late data via Sticket") 70 } else { 71 log.Println("Failed to send late data (client disconnected?)") 72 } 73 }(clientUUID) 74 } 75 }) 76 http.ListenAndServe(":7152", nil) 77} 78 79func getPostThreadV2(w http.ResponseWriter, r *http.Request) { 80 fmt.Fprintf(w, "hello worldio !") 81}