diff --git a/Realtime/Realtime/Conversation/LCIMConversationQuery.cs b/Realtime/Realtime/Conversation/LCIMConversationQuery.cs index 725aa8d..24d532b 100644 --- a/Realtime/Realtime/Conversation/LCIMConversationQuery.cs +++ b/Realtime/Realtime/Conversation/LCIMConversationQuery.cs @@ -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> Find() { return await client.ConversationController.Find(this); } + + /// + /// Retrieves the first conversation from the query. + /// + /// + public async Task First() { + Limit(1); + ReadOnlyCollection conversations = await Find(); + return conversations?.First(); + } } } diff --git a/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs b/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs index 97a2dcd..71e6216 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs @@ -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); + } } } diff --git a/Realtime/Realtime/LCIMClient.cs b/Realtime/Realtime/LCIMClient.cs index c56a74f..a7ef349 100644 --- a/Realtime/Realtime/LCIMClient.cs +++ b/Realtime/Realtime/LCIMClient.cs @@ -204,14 +204,14 @@ namespace LeanCloud.Realtime { /// /// Occurs when the last delivered message is updated. /// - public Action OnLastDeliveredAtUpdated { + public Action OnLastDeliveredAtUpdated { get; set; } /// - /// Occurs when the last delivered message is updated. + /// Occurs when the last read message is updated. /// - public Action OnLastReadAtUpdated { + public Action OnLastReadAtUpdated { get; set; }