@@ -96,6 +96,7 @@ protected override SubscribeCallback CreateUpdateListener()
96
96
/// </para>
97
97
/// </summary>
98
98
/// <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>
99
100
/// <seealso cref="OnMembershipUpdated"/>
100
101
public async Task < ChatOperationResult > Update ( ChatMembershipData membershipData )
101
102
{
@@ -151,11 +152,33 @@ internal static async Task<PNResult<PNMembershipsResult>> UpdateMembershipsData(
151
152
} ) . ExecuteAsync ( ) . ConfigureAwait ( false ) ;
152
153
}
153
154
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"/>
154
166
public async Task < ChatOperationResult > SetLastReadMessage ( Message message )
155
167
{
156
168
return await SetLastReadMessageTimeToken ( message . TimeToken ) . ConfigureAwait ( false ) ;
157
169
}
158
170
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"/>
159
182
public async Task < ChatOperationResult > SetLastReadMessageTimeToken ( string timeToken )
160
183
{
161
184
var result = new ChatOperationResult ( "Membership.SetLastReadMessageTimeToken()" , chat ) ;
@@ -171,24 +194,43 @@ public async Task<ChatOperationResult> SetLastReadMessageTimeToken(string timeTo
171
194
return result ;
172
195
}
173
196
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 ( )
175
207
{
208
+ var result = new ChatOperationResult < long > ( "Membership.GetUnreadMessagesCount()" , chat ) ;
176
209
if ( ! long . TryParse ( LastReadMessageTimeToken , out var lastRead ) )
177
210
{
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 ;
180
214
}
181
215
lastRead = lastRead == 0 ? EMPTY_TIMETOKEN : lastRead ;
182
216
var countsResponse = await chat . PubnubInstance . MessageCounts ( ) . Channels ( new [ ] { ChannelId } )
183
217
. ChannelsTimetoken ( new [ ] { lastRead } ) . ExecuteAsync ( ) . ConfigureAwait ( false ) ;
184
- if ( countsResponse . Status . Error )
218
+ if ( result . RegisterOperation ( countsResponse ) )
185
219
{
186
- chat . Logger . Error ( $ "Error when trying to get message counts on channel \" { ChannelId } \" : { countsResponse . Status . ErrorData } ") ;
187
- return - 1 ;
220
+ return result ;
188
221
}
189
- return countsResponse . Result . Channels [ ChannelId ] ;
222
+ result . Result = countsResponse . Result . Channels [ ChannelId ] ;
223
+ return result ;
190
224
}
191
225
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>
192
234
public override async Task < ChatOperationResult > Refresh ( )
193
235
{
194
236
return await chat . GetChannelMemberships ( ChannelId , filter : $ "uuid.id == \" { UserId } \" ") . ConfigureAwait ( false ) ;
0 commit comments