Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ECO-4698] Fix presence according to reference implementation #1891

Merged
merged 17 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 0 additions & 25 deletions Source/ARTPresenceMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ - (instancetype)init {
if (self) {
// Default
_action = ARTPresenceEnter;
_syncSessionId = 0;
}
return self;
}

- (id)copyWithZone:(NSZone *)zone {
ARTPresenceMessage *message = [super copyWithZone:zone];
message->_action = self.action;
message->_syncSessionId = self.syncSessionId;
return message;
}

Expand All @@ -27,7 +25,6 @@ - (NSString *)description {
[description deleteCharactersInRange:NSMakeRange(description.length - (description.length>2 ? 2:0), 2)];
[description appendFormat:@",\n"];
[description appendFormat:@" action: %lu,\n", (unsigned long)self.action];
[description appendFormat:@" syncSessionId: %lu\n", (unsigned long)self.syncSessionId];
[description appendFormat:@"}"];
return description;
}
Expand Down Expand Up @@ -73,28 +70,6 @@ - (NSInteger)indexFromId {
return index;
}

- (BOOL)isNewerThan:(ARTPresenceMessage *)latest {
if (latest == nil) {
return YES;
}

if ([self isSynthesized] || [latest isSynthesized]) {
return !self.timestamp || [latest.timestamp timeIntervalSince1970] <= [self.timestamp timeIntervalSince1970];
}

NSInteger currentMsgSerial = [self msgSerialFromId];
NSInteger currentIndex = [self indexFromId];
NSInteger latestMsgSerial = [latest msgSerialFromId];
NSInteger latestIndex = [latest indexFromId];

if (currentMsgSerial == latestMsgSerial) {
return currentIndex > latestIndex;
}
else {
return currentMsgSerial > latestMsgSerial;
}
}

#pragma mark - NSObject

- (BOOL)isEqual:(id)object {
Expand Down
10 changes: 5 additions & 5 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,14 @@ - (void)performTransitionToState:(ARTRealtimeChannelState)state withParams:(ARTC
break;
case ARTRealtimeChannelDetached:
self.channelSerial = nil; // RTP5a1
[self.presence failsSync:params.errorInfo];
[self.presence failsSync:params.errorInfo]; // RTP5a
break;
case ARTRealtimeChannelFailed:
self.channelSerial = nil; // RTP5a1
self.attachResume = false;
[_attachedEventEmitter emit:nil with:params.errorInfo];
[_detachedEventEmitter emit:nil with:params.errorInfo];
[self.presence failsSync:params.errorInfo];
[self.presence failsSync:params.errorInfo]; // RTP5a
break;
default:
break;
Expand Down Expand Up @@ -726,17 +726,17 @@ - (void)detachChannel:(ARTChannelStateChangeParams *)params {
if (self.state_nosync == ARTRealtimeChannelDetached) {
return;
}
[self failPendingPresenceWithState:params.state info:params.errorInfo];
[self failPendingPresenceWithState:params.state info:params.errorInfo]; // RTP5a
[self performTransitionToState:ARTRealtimeChannelDetached withParams:params];
}

- (void)setFailed:(ARTChannelStateChangeParams *)params {
[self failPendingPresenceWithState:params.state info:params.errorInfo];
[self failPendingPresenceWithState:params.state info:params.errorInfo]; // RTP5a
[self performTransitionToState:ARTRealtimeChannelFailed withParams:params];
}

- (void)setSuspended:(ARTChannelStateChangeParams *)params {
[self failPendingPresenceWithState:params.state info:params.errorInfo];
[self failPendingPresenceWithState:params.state info:params.errorInfo]; // RTP5f
[self performTransitionToState:ARTRealtimeChannelSuspended withParams:params];
}

Expand Down