|
4 | 4 | using libsignal.util;
|
5 | 5 | using libsignalservice;
|
6 | 6 | using libsignalservice.messages;
|
| 7 | +using libsignalservice.messages.multidevice; |
7 | 8 | using libsignalservice.push;
|
8 | 9 | using libsignalservice.util;
|
9 | 10 | using Microsoft.EntityFrameworkCore;
|
@@ -985,6 +986,59 @@ public static void UpdateExpiresInLocked(SignalConversation thread, uint exp)
|
985 | 986 | }
|
986 | 987 | }
|
987 | 988 |
|
| 989 | + internal static void UpdateMessageRead(ReadMessage readMessage) |
| 990 | + { |
| 991 | + SignalConversation conversation; |
| 992 | + lock (DBLock) |
| 993 | + { |
| 994 | + using (var ctx = new SignalDBContext()) |
| 995 | + { |
| 996 | + var message = ctx.Messages |
| 997 | + .Where(m => m.ComposedTimestamp == readMessage.getTimestamp()) |
| 998 | + .Single(); //TODO care about early reads sometime |
| 999 | + conversation = GetSignalConversation(ctx, message.ThreadId); |
| 1000 | + var currentLastSeenMessage = ctx.Messages |
| 1001 | + .Where(m => m.ThreadId == conversation.ThreadId) |
| 1002 | + .Skip((int) conversation.LastSeenMessageIndex-1) |
| 1003 | + .Take(1) |
| 1004 | + .Single(); |
| 1005 | + if (message.Id > currentLastSeenMessage.Id) |
| 1006 | + { |
| 1007 | + var diff = ctx.Messages |
| 1008 | + .Where(m => m.ThreadId == conversation.ThreadId && m.Id <= message.Id && m.Id > currentLastSeenMessage.Id) |
| 1009 | + .Count(); |
| 1010 | + conversation.LastSeenMessageIndex += diff; |
| 1011 | + conversation.UnreadCount -= (uint) diff; |
| 1012 | + ctx.SaveChanges(); |
| 1013 | + } |
| 1014 | + } |
| 1015 | + } |
| 1016 | + SignalLibHandle.Instance.DispatchAddOrUpdateConversation(conversation, null); |
| 1017 | + } |
| 1018 | + |
| 1019 | + private static SignalConversation GetSignalConversation(SignalDBContext ctx, string threadid) |
| 1020 | + { |
| 1021 | + SignalConversation conversation; |
| 1022 | + if (!threadid.EndsWith("=")) |
| 1023 | + { |
| 1024 | + conversation = ctx.Contacts |
| 1025 | + .Where(contact => threadid == contact.ThreadId) |
| 1026 | + .Include(c => c.LastMessage) |
| 1027 | + .ThenInclude(m => m.Content) |
| 1028 | + .SingleOrDefault(); |
| 1029 | + } |
| 1030 | + else |
| 1031 | + { |
| 1032 | + conversation = ctx.Groups |
| 1033 | + .Where(g => threadid == g.ThreadId) |
| 1034 | + .Include(g => g.GroupMemberships) |
| 1035 | + .ThenInclude(gm => gm.Contact) |
| 1036 | + .Include(g => g.LastMessage) |
| 1037 | + .ThenInclude(m => m.Content) |
| 1038 | + .SingleOrDefault(); |
| 1039 | + } |
| 1040 | + return conversation; |
| 1041 | + } |
988 | 1042 |
|
989 | 1043 | internal static SignalConversation UpdateMessageRead(long index, SignalConversation conversation)
|
990 | 1044 | {
|
|
0 commit comments