|
2 | 2 | using libsignalservice; |
3 | 3 | using Microsoft.Extensions.Logging; |
4 | 4 | using Signal_Windows.Lib; |
| 5 | +using Signal_Windows.Lib.Models; |
5 | 6 | using Signal_Windows.Models; |
6 | 7 | using Signal_Windows.Storage; |
7 | 8 | using System; |
@@ -86,14 +87,7 @@ private SignalMessageContainer Get(int index) |
86 | 87 | if (!Cache.ContainsKey(pageIndex)) |
87 | 88 | { |
88 | 89 | Logger.LogTrace("Get() cache miss ({0})", pageIndex); |
89 | | - Cache[pageIndex] = App.Handle.GetMessages(Conversation, pageIndex * PAGE_SIZE, PAGE_SIZE); |
90 | | - foreach (var msg in Cache[pageIndex]) |
91 | | - { |
92 | | - if (msg.Message.Author == null) |
93 | | - { |
94 | | - ConversationView.AddToOutgoingMessagesCache(msg); |
95 | | - } |
96 | | - } |
| 90 | + LoadPage(pageIndex); |
97 | 91 | } |
98 | 92 | var page = Cache[pageIndex]; |
99 | 93 | var item = page[inpageIndex]; |
@@ -144,24 +138,40 @@ public int Add(object value, bool hideUnreadMarker) |
144 | 138 | Logger.LogTrace("Add() Id={0} Index={1} PageIndex={2} InpageIndex={3}", message.Message.Id, message.Index, pageIndex, inpageIndex); |
145 | 139 | if (!Cache.ContainsKey(pageIndex)) |
146 | 140 | { |
147 | | - Cache[pageIndex] = App.Handle.GetMessages(Conversation, pageIndex * PAGE_SIZE, PAGE_SIZE); |
148 | | - foreach (var msg in Cache[pageIndex]) |
149 | | - { |
150 | | - if (msg.Message.Author == null) |
151 | | - { |
152 | | - ConversationView.AddToOutgoingMessagesCache(msg); |
153 | | - } |
154 | | - } |
| 141 | + LoadPage(pageIndex); |
155 | 142 | } |
156 | 143 | Cache[pageIndex].Insert(inpageIndex, message); |
157 | 144 | int virtualIndex = GetVirtualIndex(message.Index); |
158 | 145 | Logger.LogTrace("Add() Index={0} VirtualIndex={1}", message.Index, virtualIndex); |
159 | 146 | CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, message, virtualIndex)); |
160 | | - if (message.Message.Author == null) |
| 147 | + FillUpdateCaches(message); |
| 148 | + return message.Index; |
| 149 | + } |
| 150 | + |
| 151 | + private void LoadPage(int pageIndex) |
| 152 | + { |
| 153 | + Cache[pageIndex] = App.Handle.GetMessages(Conversation, pageIndex * PAGE_SIZE, PAGE_SIZE); |
| 154 | + foreach (var msg in Cache[pageIndex]) |
161 | 155 | { |
162 | | - ConversationView.AddToOutgoingMessagesCache(message); |
| 156 | + FillUpdateCaches(msg); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + private void FillUpdateCaches(SignalMessageContainer msg) |
| 161 | + { |
| 162 | + if (msg.Message.Author == null) |
| 163 | + { |
| 164 | + ConversationView.AddToOutgoingMessagesCache(msg); |
| 165 | + } |
| 166 | + int attachmentIndex = 0; |
| 167 | + foreach (var attachment in msg.Message.Attachments) |
| 168 | + { |
| 169 | + if (attachment.Status != SignalAttachmentStatus.Finished && attachment.Status != SignalAttachmentStatus.Failed_Permanently) |
| 170 | + { |
| 171 | + ConversationView.AddToUnfinishedAttachmentsCache(new SignalAttachmentContainer(attachment, attachmentIndex, msg.Index)); |
| 172 | + } |
| 173 | + attachmentIndex++; |
163 | 174 | } |
164 | | - return message.Index; |
165 | 175 | } |
166 | 176 |
|
167 | 177 | public void Clear() |
|
0 commit comments