Skip to content

Commit

Permalink
Removed unnecessary initial sync completed event handlers from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 4, 2023
1 parent 901df5e commit e69a0c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
29 changes: 1 addition & 28 deletions src/IO.Ably.Shared/Realtime/Presence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public sealed partial class Presence : IDisposable
private readonly Handlers<PresenceMessage> _handlers = new Handlers<PresenceMessage>();
private readonly IConnectionManager _connection;
private string _currentSyncChannelSerial;
private bool _initialSyncCompleted;
private bool _disposedValue;

internal Presence(IConnectionManager connection, RealtimeChannel channel, string clientId, ILogger logger)
Expand All @@ -35,28 +34,14 @@ internal Presence(IConnectionManager connection, RealtimeChannel channel, string
_clientId = clientId;
}

private event EventHandler InitialSyncCompleted;

internal event EventHandler SyncCompleted;

internal ILogger Logger { get; private set; }

/// <summary>
/// Has the sync completed.
/// </summary>
public bool SyncComplete
{
get => Map.InitialSyncCompleted | _initialSyncCompleted;

private set
{
_initialSyncCompleted = value;
if (_initialSyncCompleted)
{
OnInitialSyncCompleted();
}
}
}
public bool SyncComplete => Map.SyncCompleted;

/// <summary>
/// Indicates whether there is currently a sync in progress.
Expand All @@ -74,21 +59,11 @@ private set

internal ConcurrentQueue<QueuedPresenceMessage> PendingPresenceQueue { get; }

/// <summary>
/// Called when a protocol message HasPresenceFlag == false. The presence map should be considered in sync immediately
/// with no members present on the channel. See [RTP1] for more detail.
/// </summary>
internal void SkipSync()
{
SyncComplete = true;
}

/// <summary>
/// Disposes the current Presence instance. Removes all listening handlers.
/// </summary>
internal void RemoveAllListeners()
{
InitialSyncCompleted = null;
SyncCompleted = null;
_handlers.RemoveAll();
}
Expand Down Expand Up @@ -196,7 +171,6 @@ void OnChannelStateChanged(object sender, ChannelStateChange args)
void OnSyncEvent(object sender, EventArgs args) => CheckAndSet();

_channel.StateChanged += OnChannelStateChanged;
InitialSyncCompleted += OnSyncEvent;
Map.SyncNoLongerInProgress += OnSyncEvent;

// Do a manual check in case we are already in the desired state
Expand All @@ -205,7 +179,6 @@ void OnChannelStateChanged(object sender, ChannelStateChange args)

// unsubscribe from events
_channel.StateChanged -= OnChannelStateChanged;
InitialSyncCompleted -= OnSyncEvent;
Map.SyncNoLongerInProgress -= OnSyncEvent;

if (!syncIsComplete)
Expand Down
6 changes: 3 additions & 3 deletions src/IO.Ably.Shared/Realtime/PresenceMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private set
}
}

public bool InitialSyncCompleted { get; private set; }
public bool SyncCompleted { get; private set; }

public PresenceMessage[] Values
{
Expand Down Expand Up @@ -191,7 +191,7 @@ public PresenceMessage[] EndSync()
{
lock (_lock)
{
InitialSyncCompleted = true;
SyncCompleted = true;
IsSyncInProgress = false;
}
}
Expand All @@ -216,7 +216,7 @@ internal JObject GetState()
{
["channelName"] = _channelName,
["syncInProgress"] = _isSyncInProgress,
["initialSyncComplete"] = InitialSyncCompleted,
["initialSyncComplete"] = SyncCompleted,
["members"] = new JArray(matchingMembers),
};

Expand Down

0 comments on commit e69a0c5

Please sign in to comment.