feat: support OnLastDeliveredAt, OnLastReadAt

oneRain 2020-12-17 15:29:44 +08:00
parent 9a555a386c
commit 778cb622b6
3 changed files with 24 additions and 3 deletions

View File

@ -2,6 +2,9 @@
using System.Collections;
using System.Collections.ObjectModel;
using LeanCloud.Storage.Internal.Query;
using System.Linq;
using System.Collections.Generic;
using System;
namespace LeanCloud.Realtime {
public class LCIMConversationQuery {
@ -274,5 +277,15 @@ namespace LeanCloud.Realtime {
public async Task<ReadOnlyCollection<LCIMConversation>> Find() {
return await client.ConversationController.Find(this);
}
/// <summary>
/// Retrieves the first conversation from the query.
/// </summary>
/// <returns></returns>
public async Task<LCIMConversation> First() {
Limit(1);
ReadOnlyCollection<LCIMConversation> conversations = await Find();
return conversations?.First();
}
}
}

View File

@ -285,8 +285,16 @@ namespace LeanCloud.Realtime.Internal.Controller {
LCIMConversation conversation = await Client.GetOrQueryConversation(convId);
if (isRead) {
Client.OnMessageRead?.Invoke(conversation, msgId);
if (timestamp > conversation.LastReadTimestamp) {
conversation.LastReadTimestamp = timestamp;
Client.OnLastReadAtUpdated?.Invoke(conversation);
}
} else {
Client.OnMessageDelivered?.Invoke(conversation, msgId);
if (timestamp > conversation.LastDeliveredTimestamp) {
conversation.LastDeliveredTimestamp = timestamp;
Client.OnLastDeliveredAtUpdated?.Invoke(conversation);
}
}
}

View File

@ -204,14 +204,14 @@ namespace LeanCloud.Realtime {
/// <summary>
/// Occurs when the last delivered message is updated.
/// </summary>
public Action OnLastDeliveredAtUpdated {
public Action<LCIMConversation> OnLastDeliveredAtUpdated {
get; set;
}
/// <summary>
/// Occurs when the last delivered message is updated.
/// Occurs when the last read message is updated.
/// </summary>
public Action OnLastReadAtUpdated {
public Action<LCIMConversation> OnLastReadAtUpdated {
get; set;
}