Skip to content

Commit

Permalink
Refactored onAttach realtime presence method, removed extra param
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Jan 12, 2024
1 parent adb6354 commit 7913d25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ably/realtime_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ func (c *RealtimeChannel) notify(msg *protocolMessage) {

if c.State() == ChannelStateAttached {
if !msg.Flags.Has(flagResumed) { // RTL12
c.Presence.onAttach(msg, true)
c.Presence.onAttach(msg)
c.emitErrorUpdate(newErrorFromProto(msg.Error), false)
}
} else {
c.Presence.onAttach(msg, true)
c.Presence.onAttach(msg)
c.setState(ChannelStateAttached, newErrorFromProto(msg.Error), msg.Flags.Has(flagResumed))
}
c.queue.Flush()
Expand Down
21 changes: 10 additions & 11 deletions ably/realtime_presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (pres *RealtimePresence) enterMembers(internalMembers []*PresenceMessage) {
}
}

func (pres *RealtimePresence) onAttach(msg *protocolMessage, isAttachWithoutMessageLoss bool) {
func (pres *RealtimePresence) onAttach(msg *protocolMessage) {
pres.mtx.Lock()
defer pres.mtx.Unlock()
// RTP1
Expand All @@ -173,18 +173,17 @@ func (pres *RealtimePresence) onAttach(msg *protocolMessage, isAttachWithoutMess
close(pres.syncDone)
}
}
pres.queue.Flush() // RTP5b
// RTP5b
pres.queue.Flush()
// RTP17f
if isAttachWithoutMessageLoss {
if len(pres.internalMembers) > 0 {
internalMembers := make([]*PresenceMessage, len(pres.internalMembers))
indexCounter := 0
for _, member := range pres.internalMembers {
internalMembers[indexCounter] = member
indexCounter = indexCounter + 1
}
go pres.enterMembers(internalMembers)
if len(pres.internalMembers) > 0 {
internalMembers := make([]*PresenceMessage, len(pres.internalMembers))
indexCounter := 0
for _, member := range pres.internalMembers {
internalMembers[indexCounter] = member
indexCounter = indexCounter + 1
}
go pres.enterMembers(internalMembers)
}
}

Expand Down

0 comments on commit 7913d25

Please sign in to comment.