@@ -9,7 +9,7 @@ type UserToFollow = {
9
9
} ;
10
10
type OnUserFollowedPayload = {
11
11
userToFollow : UserToFollow ;
12
- action : "follow " | "unfollow " ;
12
+ action : "FOLLOW " | "UNFOLLOW " ;
13
13
} ;
14
14
15
15
const serverDebug = debug ( "server" ) ;
@@ -87,35 +87,36 @@ try {
87
87
} ,
88
88
) ;
89
89
90
- socket . on ( "on- user-follow" , async ( payload : OnUserFollowedPayload ) => {
90
+ socket . on ( "user-follow" , async ( payload : OnUserFollowedPayload ) => {
91
91
const roomID = `follow_${ payload . userToFollow . socketId } ` ;
92
+
92
93
switch ( payload . action ) {
93
- case "follow" :
94
+ case "FOLLOW" : {
94
95
await socket . join ( roomID ) ;
95
96
96
97
const sockets = await io . in ( roomID ) . fetchSockets ( ) ;
97
98
const followedBy = sockets . map ( ( socket ) => socket . id ) ;
98
99
99
- // Notify the user to follow that someone has followed them
100
- // More precisely, send the list of users that are following them
101
- // so that they can make decisions based on that
102
100
io . to ( payload . userToFollow . socketId ) . emit (
103
- "follow-room-user -change" ,
101
+ "user- follow-room-change" ,
104
102
followedBy ,
105
103
) ;
106
104
107
105
break ;
108
- case "unfollow" :
106
+ }
107
+ case "UNFOLLOW" : {
109
108
await socket . leave ( roomID ) ;
110
- const _sockets = await io . in ( roomID ) . fetchSockets ( ) ;
111
- const _followedBy = _sockets . map ( ( socket ) => socket . id ) ;
109
+
110
+ const sockets = await io . in ( roomID ) . fetchSockets ( ) ;
111
+ const followedBy = sockets . map ( ( socket ) => socket . id ) ;
112
112
113
113
io . to ( payload . userToFollow . socketId ) . emit (
114
- "follow-room-user -change" ,
115
- _followedBy ,
114
+ "user- follow-room-change" ,
115
+ followedBy ,
116
116
) ;
117
117
118
118
break ;
119
+ }
119
120
}
120
121
} ) ;
121
122
0 commit comments