Skip to content

Commit 19d8cdc

Browse files
authored
Pbe 4109 implement state sync after disconnecting (#152)
* Move CreatedAt to EventBase * Implement retrieving missed WS events during disconnection period * Create test implementation for the state recovery after disconnected period * cleanup + improve test scenarios * cleanup * Fix potential null ref * rename var + add todo * Fix null reference * Fix cache null ref * Add 1 more test case to sync tests * Sort channel messages. This can be needed when client reconnects and sends a message before /sync result is returned and processed * Fix null ref on Channel.Type
1 parent 4c61f80 commit 19d8cdc

File tree

62 files changed

+467
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+467
-97
lines changed

Assets/Plugins/StreamChat/Core/InternalDTO/Responses/SyncResponseInternalDTO.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal partial class SyncResponseInternalDTO
2323
/// List of events
2424
/// </summary>
2525
[Newtonsoft.Json.JsonProperty("events", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
26-
public System.Collections.Generic.List<EventInternalDTO> Events { get; set; } = new System.Collections.Generic.List<EventInternalDTO>();
26+
public System.Collections.Generic.List<object> Events { get; set; } = new System.Collections.Generic.List<object>();
2727

2828
/// <summary>
2929
/// List of CIDs that user can't access

Assets/Plugins/StreamChat/Core/LowLevelClient/API/ChannelApi.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33
using StreamChat.Core.Helpers;
4+
using StreamChat.Core.InternalDTO.Requests;
45
using StreamChat.Core.InternalDTO.Responses;
56
using StreamChat.Core.LowLevelClient.API.Internal;
67
using StreamChat.Core.LowLevelClient.Models;
@@ -141,6 +142,12 @@ public Task SendTypingStartEventAsync(string channelType, string channelId)
141142
public Task SendTypingStopEventAsync(string channelType, string channelId)
142143
=> _internalChannelApi.SendTypingStopEventAsync(channelType, channelId);
143144

145+
public async Task<SyncResponse> SyncAsync(SyncRequest syncRequest)
146+
{
147+
var dto = await _internalChannelApi.SyncAsync(syncRequest.TrySaveToDto());
148+
return dto.ToDomain<SyncResponseInternalDTO, SyncResponse>();
149+
}
150+
144151
private readonly IInternalChannelApi _internalChannelApi;
145152
}
146153
}

Assets/Plugins/StreamChat/Core/LowLevelClient/API/IChannelApi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,8 @@ Task<MarkReadResponse> MarkReadAsync(string channelType, string channelId,
150150
Task SendTypingStartEventAsync(string channelType, string channelId);
151151

152152
Task SendTypingStopEventAsync(string channelType, string channelId);
153+
154+
//StreamTodo: perhaps we can skip this declaration and use the Internal one directly
155+
Task<SyncResponse> SyncAsync(SyncRequest syncRequest);
153156
}
154157
}

Assets/Plugins/StreamChat/Core/LowLevelClient/API/Internal/IInternalChannelApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ Task<MarkReadResponseInternalDTO> MarkReadAsync(string channelType, string chann
5252
Task SendTypingStartEventAsync(string channelType, string channelId);
5353

5454
Task SendTypingStopEventAsync(string channelType, string channelId);
55+
56+
Task<SyncResponseInternalDTO> SyncAsync(SyncRequestInternalDTO syncRequest);
5557
}
5658
}

Assets/Plugins/StreamChat/Core/LowLevelClient/API/Internal/InternalChannelApi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,8 @@ public Task SendTypingStopEventAsync(string channelType, string channelId)
133133
{
134134
Type = WSEventType.TypingStop
135135
});
136+
137+
public Task<SyncResponseInternalDTO> SyncAsync(SyncRequestInternalDTO syncRequest)
138+
=> Post<SyncRequestInternalDTO, SyncResponseInternalDTO>($"/sync", syncRequest);
136139
}
137140
}

Assets/Plugins/StreamChat/Core/LowLevelClient/API/Internal/InternalMessageApi.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Net.Http;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32
using StreamChat.Core.InternalDTO.Requests;
43
using StreamChat.Core.InternalDTO.Responses;
54
using StreamChat.Core.Web;

Assets/Plugins/StreamChat/Core/LowLevelClient/Events/EventBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace StreamChat.Core.LowLevelClient.Events
22
{
33
public abstract class EventBase
44
{
5+
public System.DateTimeOffset CreatedAt { get; set; }
6+
57
private System.Collections.Generic.Dictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();
68

79
[Newtonsoft.Json.JsonExtensionData]

Assets/Plugins/StreamChat/Core/LowLevelClient/Events/EventChannelDeleted.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public sealed class EventChannelDeleted : EventBase,
1515

1616
public string Cid { get; set; }
1717

18-
public System.DateTimeOffset? CreatedAt { get; set; }
19-
2018
public string Team { get; set; }
2119

2220
public string Type { get; set; }

Assets/Plugins/StreamChat/Core/LowLevelClient/Events/EventChannelHidden.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public sealed class EventChannelHidden : EventBase,
1818

1919
public bool? ClearHistory { get; set; }
2020

21-
public System.DateTimeOffset? CreatedAt { get; set; }
22-
2321
public string Type { get; set; }
2422

2523
public User User { get; set; }

Assets/Plugins/StreamChat/Core/LowLevelClient/Events/EventChannelTruncated.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public sealed class EventChannelTruncated : EventBase,
1717

1818
public string Cid { get; set; }
1919

20-
public System.DateTimeOffset? CreatedAt { get; set; }
21-
2220
public string Type { get; set; }
2321

2422
EventChannelTruncated ILoadableFrom<ChannelTruncatedEventInternalDTO, EventChannelTruncated>.LoadFromDto(

0 commit comments

Comments
 (0)