@@ -15,25 +15,13 @@ export default class PresenceAdapter {
1515 this . presence = new Presence ( channel . getChannel ( ) , phoenixOptions )
1616
1717 this . presence . onJoin ( ( key , currentPresence , newPresence ) => {
18- const currentPresences = parseCurrentPresences ( currentPresence )
19- const newPresences = newPresence [ 'metas' ]
20- channel . getChannel ( ) . trigger ( 'presence' , {
21- event : 'join' ,
22- key,
23- currentPresences,
24- newPresences,
25- } )
18+ const onJoinPayload = PresenceAdapter . onJoinPayload ( key , currentPresence , newPresence )
19+ channel . getChannel ( ) . trigger ( 'presence' , onJoinPayload )
2620 } )
2721
2822 this . presence . onLeave ( ( key , currentPresence , leftPresence ) => {
29- const currentPresences = parseCurrentPresences ( currentPresence )
30- const leftPresences = leftPresence [ 'metas' ]
31- channel . getChannel ( ) . trigger ( 'presence' , {
32- event : 'leave' ,
33- key,
34- currentPresences,
35- leftPresences,
36- } )
23+ const onLeavePayload = PresenceAdapter . onLeavePayload ( key , currentPresence , leftPresence )
24+ channel . getChannel ( ) . trigger ( 'presence' , onLeavePayload )
3725 } )
3826
3927 this . presence . onSync ( ( ) => {
@@ -86,6 +74,30 @@ export default class PresenceAdapter {
8674 return newState
8775 } , { } as RealtimePresenceState )
8876 }
77+
78+ static onJoinPayload ( key : string , currentPresence : PresenceState , newPresence : PresenceState ) {
79+ const currentPresences = parseCurrentPresences ( currentPresence )
80+ const newPresences = newPresence [ 'metas' ]
81+
82+ return {
83+ event : 'join' ,
84+ key,
85+ currentPresences,
86+ newPresences,
87+ }
88+ }
89+
90+ static onLeavePayload ( key : string , currentPresence : PresenceState , leftPresence : PresenceState ) {
91+ const currentPresences = parseCurrentPresences ( currentPresence )
92+ const leftPresences = leftPresence [ 'metas' ]
93+
94+ return {
95+ event : 'leave' ,
96+ key,
97+ currentPresences,
98+ leftPresences,
99+ }
100+ }
89101}
90102
91103function cloneState ( state : PresenceStates ) : PresenceStates {
0 commit comments