···
const ListenTypeFollows = "follows"
type SubscriberData struct {
28
-
SubscribedTo syntax.DID
29
-
Conn *websocket.Conn
31
-
ListenTo Set[syntax.DID]
29
+
Conn *websocket.Conn
31
+
ListenTo Set[syntax.DID]
34
-
type UserData struct {
34
+
type ActorData struct {
targets *hashmap.Map[string, *SubscriberData]
likes map[syntax.RecordKey]bsky.FeedLike
follows *hashmap.Map[syntax.RecordKey, bsky.GraphFollow]
···
// storing the subscriber data in both Should Be Fine
// we dont modify subscriber data at the same time in two places
subscribers = hashmap.New[string, *SubscriberData]()
61
-
userData = hashmap.New[syntax.DID, *UserData]()
61
+
actorData = hashmap.New[syntax.DID, *ActorData]()
likeStream *client.Client
followStream *client.Client
···
func getSubscriberDids() []string {
_dids := make(Set[string], subscribers.Len())
subscribers.Range(func(s string, sd *SubscriberData) bool {
78
-
_dids[string(sd.SubscribedTo)] = struct{}{}
78
+
_dids[string(sd.ForActor)] = struct{}{}
dids := make([]string, 0, len(_dids))
···
88
-
func getUserData(did syntax.DID) *UserData {
89
-
ud, _ := userData.GetOrInsert(did, &UserData{
88
+
func getActorData(did syntax.DID) *ActorData {
89
+
ud, _ := actorData.GetOrInsert(did, &ActorData{
targets: hashmap.New[string, *SubscriberData](),
likes: make(map[syntax.RecordKey]bsky.FeedLike),
follows: hashmap.New[syntax.RecordKey, bsky.GraphFollow](),
···
97
-
func startListeningTo(sid string, sd *SubscriberData, did syntax.DID) {
98
-
ud := getUserData(did)
97
+
func markActorForLikes(sid string, sd *SubscriberData, did syntax.DID) {
98
+
ud := getActorData(did)
ud.targets.Insert(sid, sd)
102
-
func stopListeningTo(sid string, did syntax.DID) {
103
-
if ud, exists := userData.Get(did); exists {
102
+
func unmarkActorForLikes(sid string, did syntax.DID) {
103
+
if ud, exists := actorData.Get(did); exists {
···
160
-
ud := getUserData(did)
160
+
ud := getActorData(did)
164
-
ListenType: listenType,
164
+
ListenType: listenType,
···
for listenDid := range sd.ListenTo {
198
-
startListeningTo(sid, sd, listenDid)
198
+
markActorForLikes(sid, sd, listenDid)
// delete subscriber after we are done
for listenDid := range sd.ListenTo {
204
-
stopListeningTo(sid, listenDid)
204
+
unmarkActorForLikes(sid, listenDid)
···
// remove all current listens and add the ones the user requested
for listenDid := range sd.ListenTo {
233
-
stopListeningTo(sid, listenDid)
233
+
unmarkActorForLikes(sid, listenDid)
delete(sd.ListenTo, listenDid)
for _, listenDid := range innerMsg.ListenTo {
sd.ListenTo[listenDid] = struct{}{}
238
-
startListeningTo(sid, sd, listenDid)
238
+
markActorForLikes(sid, sd, listenDid)
···
byDid := syntax.DID(event.Did)
// skip handling event if its not from a source we are listening to
274
-
ud, exists := userData.Get(byDid)
274
+
ud, exists := actorData.Get(byDid)
if !exists || ud.targets.Len() == 0 {
···
ud.targets.Range(func(sid string, sd *SubscriberData) bool {
318
-
if sd.SubscribedTo != reposterDID {
318
+
if sd.ForActor != reposterDID {
···
if err := sd.Conn.WriteJSON(notification); err != nil {
330
-
logger.Error("failed to send notification", "subscriber", sd.SubscribedTo, "error", err)
330
+
logger.Error("failed to send notification", "subscriber", sd.ForActor, "error", err)
···
byDid := syntax.DID(event.Did)
344
-
ud, exists := userData.Get(byDid)
344
+
ud, exists := actorData.Get(byDid)
···
subjectDid := syntax.DID(r.Subject)
377
-
stopListeningTo(sid, subjectDid)
377
+
unmarkActorForLikes(sid, subjectDid)
delete(sd.ListenTo, subjectDid)
sd.ListenTo[subjectDid] = struct{}{}
381
-
startListeningTo(sid, sd, subjectDid)
381
+
markActorForLikes(sid, sd, subjectDid)