its for when you want to get like notifications for your reposts
2
fork

Configure Feed

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

refactor: remove unused func, reorganize a bit

dusk bbcf2989 75bb7d9b

+13 -24
+13 -24
main.go
··· 18 18 19 19 type Set[T comparable] map[T]struct{} 20 20 21 - // Data structures 22 21 type SubscriberData struct { 23 22 DID string 24 23 Conn *websocket.Conn ··· 32 31 RepostURI string `json:"repost_uri"` 33 32 } 34 33 35 - // Global state 36 34 var ( 35 + // storing the subscriber data in both Should Be Fine 36 + // we dont modify subscriber data at the same time in two places 37 37 subscribers = hashmap.New[string, *SubscriberData]() 38 38 listeningTo = hashmap.New[string, *hashmap.Map[string, *SubscriberData]]() 39 39 ··· 49 49 logger *slog.Logger 50 50 ) 51 51 52 - func getFollowsDids() []string { 53 - var dids []string 54 - subscribers.Range(func(s string, sd *SubscriberData) bool { 55 - for follow, _ := range sd.ListenTo { 56 - dids = append(dids, follow) 57 - } 58 - return true 59 - }) 60 - return dids 61 - } 62 - 63 52 func getSubscriberDids() []string { 64 53 dids := make([]string, 0, subscribers.Len()) 65 54 subscribers.Range(func(s string, sd *SubscriberData) bool { ··· 67 56 return true 68 57 }) 69 58 return dids 59 + } 60 + 61 + func listenTo(sd *SubscriberData, did string) { 62 + targetDids, _ := listeningTo.GetOrInsert(did, hashmap.New[string, *SubscriberData]()) 63 + targetDids.Insert(sd.DID, sd) 64 + } 65 + 66 + func stopListeningTo(subscriberDid, did string) { 67 + if targetDids, exists := listeningTo.Get(did); exists { 68 + targetDids.Del(subscriberDid) 69 + } 70 70 } 71 71 72 72 func main() { ··· 157 157 logger.Info("WebSocket connection closed", "error", err) 158 158 break 159 159 } 160 - } 161 - } 162 - 163 - func listenTo(sd *SubscriberData, did string) { 164 - targetDids, _ := listeningTo.GetOrInsert(did, hashmap.New[string, *SubscriberData]()) 165 - targetDids.Insert(sd.DID, sd) 166 - } 167 - 168 - func stopListeningTo(subscriberDid, did string) { 169 - if targetDids, exists := listeningTo.Get(did); exists { 170 - targetDids.Del(subscriberDid) 171 160 } 172 161 } 173 162