Skip to content

Commit dadee4b

Browse files
XML comments updates, some missing ChatOperationResult and ConfigureAwait(false)
1 parent 221dee0 commit dadee4b

File tree

10 files changed

+911
-211
lines changed

10 files changed

+911
-211
lines changed

c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/MembershipTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public async Task TestUnreadMessagesCount()
165165

166166
var membership = TestUtils.AssertOperation(await unreadChannel.GetMemberships())
167167
.Memberships.FirstOrDefault(x => x.UserId == user.Id);
168-
var unreadCount = membership == null ? -1 : await membership.GetUnreadMessagesCount();
168+
var unreadCount = membership == null ? -1 : TestUtils.AssertOperation(await membership.GetUnreadMessagesCount());
169169
Assert.True(unreadCount >= 3, $"Expected >=3 unread but got: {unreadCount}");
170170
}
171171

@@ -184,7 +184,7 @@ public async Task TestUnreadCountAfterFetchHistory()
184184
}
185185
await Task.Delay(5000);
186186
var history = await channel.GetMessageHistory("99999999999999999", "00000000000000000", 1);
187-
var unread = await membership.GetUnreadMessagesCount();
187+
var unread = TestUtils.AssertOperation(await membership.GetUnreadMessagesCount());
188188
Assert.True(unread >= 1);
189189
}
190190
}

c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/UserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public async Task TestUserIsPresentOn()
132132

133133
await Task.Delay(4000);
134134

135-
var isOn = await user.IsPresentOn(someChannel.Id);
135+
var isOn = TestUtils.AssertOperation(await user.IsPresentOn(someChannel.Id));
136136

137137
Assert.True(isOn, "user.IsPresentOn() doesn't return true for most recently joined channel!");
138138
}

c-sharp-chat/PubnubChatApi/PubnubChatApi/Entities/Channel.cs

Lines changed: 141 additions & 50 deletions
Large diffs are not rendered by default.

c-sharp-chat/PubnubChatApi/PubnubChatApi/Entities/Chat.cs

Lines changed: 255 additions & 114 deletions
Large diffs are not rendered by default.

c-sharp-chat/PubnubChatApi/PubnubChatApi/Entities/Membership.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ protected override SubscribeCallback CreateUpdateListener()
9696
/// </para>
9797
/// </summary>
9898
/// <param name="membershipData">The ChatMembershipData object to update the membership with.</param>
99+
/// <returns>A ChatOperationResult indicating the success or failure of the operation.</returns>
99100
/// <seealso cref="OnMembershipUpdated"/>
100101
public async Task<ChatOperationResult> Update(ChatMembershipData membershipData)
101102
{
@@ -151,11 +152,33 @@ internal static async Task<PNResult<PNMembershipsResult>> UpdateMembershipsData(
151152
}).ExecuteAsync().ConfigureAwait(false);
152153
}
153154

155+
/// <summary>
156+
/// Sets the last read message for this membership.
157+
/// <para>
158+
/// Updates the membership to mark the specified message as the last one read by the user.
159+
/// This is used for tracking read receipts and unread message counts.
160+
/// </para>
161+
/// </summary>
162+
/// <param name="message">The message to mark as last read.</param>
163+
/// <returns>A ChatOperationResult indicating the success or failure of the operation.</returns>
164+
/// <seealso cref="SetLastReadMessageTimeToken"/>
165+
/// <seealso cref="GetUnreadMessagesCount"/>
154166
public async Task<ChatOperationResult> SetLastReadMessage(Message message)
155167
{
156168
return await SetLastReadMessageTimeToken(message.TimeToken).ConfigureAwait(false);
157169
}
158170

171+
/// <summary>
172+
/// Sets the last read message time token for this membership.
173+
/// <para>
174+
/// Updates the membership to mark the message with the specified time token as the last one read by the user.
175+
/// This is used for tracking read receipts and unread message counts.
176+
/// </para>
177+
/// </summary>
178+
/// <param name="timeToken">The time token of the message to mark as last read.</param>
179+
/// <returns>A ChatOperationResult indicating the success or failure of the operation.</returns>
180+
/// <seealso cref="SetLastReadMessage"/>
181+
/// <seealso cref="GetUnreadMessagesCount"/>
159182
public async Task<ChatOperationResult> SetLastReadMessageTimeToken(string timeToken)
160183
{
161184
var result = new ChatOperationResult("Membership.SetLastReadMessageTimeToken()", chat);
@@ -171,24 +194,43 @@ public async Task<ChatOperationResult> SetLastReadMessageTimeToken(string timeTo
171194
return result;
172195
}
173196

174-
public async Task<long> GetUnreadMessagesCount()
197+
/// <summary>
198+
/// Gets the count of unread messages for this membership.
199+
/// <para>
200+
/// Calculates the number of messages that have been sent to the channel since the last read message time token.
201+
/// </para>
202+
/// </summary>
203+
/// <returns>A ChatOperationResult with the number of unread messages</returns>
204+
/// <seealso cref="SetLastReadMessage"/>
205+
/// <seealso cref="SetLastReadMessageTimeToken"/>
206+
public async Task<ChatOperationResult<long>> GetUnreadMessagesCount()
175207
{
208+
var result = new ChatOperationResult<long>("Membership.GetUnreadMessagesCount()", chat);
176209
if (!long.TryParse(LastReadMessageTimeToken, out var lastRead))
177210
{
178-
chat.Logger.Error("LastReadMessageTimeToken is not a valid time token!");
179-
return -1;
211+
result.Error = true;
212+
result.Exception = new PNException("LastReadMessageTimeToken is not a valid time token!");
213+
return result;
180214
}
181215
lastRead = lastRead == 0 ? EMPTY_TIMETOKEN : lastRead;
182216
var countsResponse = await chat.PubnubInstance.MessageCounts().Channels(new[] { ChannelId })
183217
.ChannelsTimetoken(new[] { lastRead }).ExecuteAsync().ConfigureAwait(false);
184-
if (countsResponse.Status.Error)
218+
if (result.RegisterOperation(countsResponse))
185219
{
186-
chat.Logger.Error($"Error when trying to get message counts on channel \"{ChannelId}\": {countsResponse.Status.ErrorData}");
187-
return -1;
220+
return result;
188221
}
189-
return countsResponse.Result.Channels[ChannelId];
222+
result.Result = countsResponse.Result.Channels[ChannelId];
223+
return result;
190224
}
191225

226+
/// <summary>
227+
/// Refreshes the membership data from the server.
228+
/// <para>
229+
/// Fetches the latest membership information from the server and updates the local data.
230+
/// This is useful when you want to ensure you have the most up-to-date membership information.
231+
/// </para>
232+
/// </summary>
233+
/// <returns>A ChatOperationResult indicating the success or failure of the refresh operation.</returns>
192234
public override async Task<ChatOperationResult> Refresh()
193235
{
194236
return await chat.GetChannelMemberships(ChannelId, filter:$"uuid.id == \"{UserId}\"").ConfigureAwait(false);

0 commit comments

Comments
 (0)