public void Handle(MessagesRemovedEventArgs args) { if (With == args.Dialog.With && args.Messages != null) { Execute.BeginOnUIThread(() => { foreach (var message in args.Messages) { if (EditedMessage?.Id == message.Id) { ClearReplyCommand.Execute(); } else if (ReplyInfo?.ReplyToMsgId == message.Id) { ClearReplyCommand.Execute(); } var removed = Items.Remove(message); if (removed == false) { // Check if this is really needed var already = Items.FirstOrDefault(x => x.Id == message.Id); if (already != null) { Items.Remove(already); } } } }); } }
private void DeleteMessagesInternal(TLMessageBase lastMessage, IList <TLMessageBase> messages) { var cachedMessages = new TLVector <long>(); var remoteMessages = new TLVector <int>(); for (int i = 0; i < messages.Count; i++) { if (messages[i].RandomId.HasValue && messages[i].RandomId != 0L) { cachedMessages.Add(messages[i].RandomId.Value); } if (messages[i].Id > 0) { remoteMessages.Add(messages[i].Id); } } CacheService.DeleteMessages(Peer.ToPeer(), lastMessage, remoteMessages); CacheService.DeleteMessages(cachedMessages); Execute.BeginOnUIThread(() => { for (int j = 0; j < messages.Count; j++) { if (_editedMessage != null && _editedMessage.Id == messages[j].Id) { ClearReplyCommand.Execute(); } else if (ReplyInfo != null && ReplyInfo.ReplyToMsgId == messages[j].Id) { ClearReplyCommand.Execute(); } Messages.Remove(messages[j]); } RaisePropertyChanged(() => With); SelectionMode = ListViewSelectionMode.None; //this.IsEmptyDialog = (this.Items.get_Count() == 0 && this.LazyItems.get_Count() == 0); //this.NotifyOfPropertyChange<TLObject>(() => this.With); }); }
public void Handle(MessagesRemovedEventArgs args) { if (With == args.Dialog.With && args.Messages != null) { BeginOnUIThread(() => { var groups = new Dictionary <long, Tuple <TLMessage, GroupedMessages> >(); foreach (var message in args.Messages) { if (message is TLMessage grouped && grouped.HasGroupedId && grouped.GroupedId is long groupedId && _groupedMessages.TryGetValue(groupedId, out TLMessage group) && group.Media is TLMessageMediaGroup groupMedia) { groupMedia.Layout.Messages.Remove(grouped); groups[groupedId] = Tuple.Create(group, groupMedia.Layout); } } foreach (var group in groups.Values) { if (group.Item2.Messages.Count > 0) { group.Item2.Calculate(); group.Item1.RaisePropertyChanged(() => group.Item1.Self); } else { _groupedMessages.TryRemove(group.Item2.GroupedId, out TLMessage removed); Items.Remove(group.Item1); } } foreach (var message in args.Messages) { if (EditedMessage?.Id == message.Id) { ClearReplyCommand.Execute(); } else if (ReplyInfo?.ReplyToMsgId == message.Id) { ClearReplyCommand.Execute(); } if (PinnedMessage?.Id == message.Id) { PinnedMessage = null; } if (Full is TLChannelFull channelFull && channelFull.PinnedMsgId == message.Id) { channelFull.PinnedMsgId = null; channelFull.HasPinnedMsgId = false; } var removed = Items.Remove(message); if (removed == false) { // Check if this is really needed var already = Items.FirstOrDefault(x => x.Id == message.Id); if (already != null) { Items.Remove(already); } } } }); } }