private void OnTopMessageUpdated(object sender, TopMessageUpdatedEventArgs e) { BeginOnUIThread(() => { e.Dialog.TypingString = null; var currentPosition = Items.IndexOf(e.Dialog); var newPosition = currentPosition; for (var i = 0; i < Items.Count; i++) { if (// мигает диалог, если просто обновляется последнее сообщение, то номер становится на 1 больше // и сначала удаляем, а потом вставляем на туже позицию i != currentPosition && Items[i].GetDateIndex() <= e.Dialog.GetDateIndex()) { newPosition = i; break; } } if (currentPosition != newPosition) { if (currentPosition >= 0 && currentPosition < newPosition) { // т.к. будем сначала удалять диалог а потом вставлять, то // curPos + 1 = newPos - это вставка на тоже место и не имеет смысла // Update: имеет, т.к. обновляется инфа о последнем сообщении if (currentPosition + 1 == newPosition) { Items[currentPosition].NotifyOfPropertyChange(() => Items[currentPosition].Self); Items[currentPosition].NotifyOfPropertyChange(() => Items[currentPosition].UnreadCount); return; } Items.Remove(e.Dialog); Items.Insert(newPosition - 1, e.Dialog); } else { Items.Remove(e.Dialog); Items.Insert(newPosition, e.Dialog); } } else { // удалили сообщение и диалог должен переместиться ниже загруженной части списка if (!IsLastSliceLoaded && Items.Count > 0 && Items[Items.Count - 1].GetDateIndex() > e.Dialog.GetDateIndex()) { Items.Remove(e.Dialog); } Items[currentPosition].NotifyOfPropertyChange(() => Items[currentPosition].Self); Items[currentPosition].NotifyOfPropertyChange(() => Items[currentPosition].UnreadCount); } }); }
public void Handle(TopMessageUpdatedEventArgs args) { #if WP8 if (!_isFirstSliceLoaded) { Execute.ShowDebugMessage("DialogDetailsViewModel.Handle(TLMessageCommon) _isFirstSliceLoaded=false"); return; } #endif var serviceMessage = args.Message as TLMessageService; if (serviceMessage == null) { return; } Handle(serviceMessage); }
private void OnTopMessageUpdated(object sender, TopMessageUpdatedEventArgs e) { BeginOnUIThread(() => { var currentPosition = Items.IndexOf(e.Dialog); var newPosition = currentPosition; for (var i = 0; i < Items.Count; i++) { if (// мигает диалог, если просто обновляется последнее сообщение, то номер становится на 1 больше // и сначала удаляем, а потом вставляем на туже позицию i != currentPosition && Items[i].GetDateIndex() <= e.Dialog.GetDateIndex()) { newPosition = i; break; } } if (currentPosition != newPosition) { if (currentPosition < newPosition) { // т.к. будем сначала удалять диалог а потом вставлять, то // curPos + 1 = newPos - это вставка на тоже место и не имеет смысла if (currentPosition + 1 == newPosition) { Items[currentPosition].NotifyOfPropertyChange(() => Items[currentPosition].Self); return; } Items.Remove(e.Dialog); Items.Insert(newPosition - 1, e.Dialog); } else { Items.Remove(e.Dialog); Items.Insert(newPosition, e.Dialog); } } }); }
public void Handle(TopMessageUpdatedEventArgs e) { e.Dialog.RaisePropertyChanged(() => e.Dialog.With); Execute.BeginOnUIThread(() => { try { var chat = e.Dialog.With as TLChat; if (chat != null) { var dialog = e.Dialog as TLDialog; if (dialog != null) { var serviceMessage = dialog.TopMessageItem as TLMessageService; if (serviceMessage != null) { var migrateAction = serviceMessage.Action as TLMessageActionChatMigrateTo; if (migrateAction != null) { Remove(e.Dialog); return; } } } } var channel = e.Dialog.With as TLChannel; if (channel != null) { var dialog = e.Dialog as TLDialog; if (dialog != null) { var messageService = dialog.TopMessageItem as TLMessageService; if (messageService != null) { var deleteUserAction = messageService.Action as TLMessageActionChatDeleteUser; if (deleteUserAction != null && deleteUserAction.UserId == SettingsHelper.UserId) { Remove(e.Dialog); return; } } } } // TODO: e.Dialog.TypingString = null; var currentPosition = IndexOf(e.Dialog); if (currentPosition < 0) { var already = this.FirstOrDefault(x => x.Id == e.Dialog.Id); if (already != null) { currentPosition = IndexOf(already); } } var index = currentPosition; for (int i = 0; i < Count; i++) { if (i != currentPosition && this[i].GetDateIndexWithDraft() <= e.Dialog.GetDateIndexWithDraft()) { index = i; break; } } if (currentPosition == -1 && currentPosition == index) { // TODO //Telegram.Api.Helpers.Execute.ShowDebugMessage(string.Concat(new object[] //{ // "TLDialog with=", // e.Dialog.With, // " curPos=newPos=-1 isLastSliceLoaded=", // this.IsLastSliceLoaded //})); //if (!this.IsLastSliceLoaded) //{ // return; //} //Add(e.Dialog); } if (currentPosition != index) { if (currentPosition >= 0 && currentPosition < index) { if (currentPosition + 1 == index) { this[currentPosition].RaisePropertyChanged(() => this[currentPosition].Self); this[currentPosition].RaisePropertyChanged(() => this[currentPosition].UnreadCount); } else { Remove(e.Dialog); Insert(index - 1, e.Dialog); } } else { Remove(e.Dialog); Insert(index, e.Dialog); } } else { if (/*!this.IsLastSliceLoaded &&*/ Count > 0 && this[Count - 1].GetDateIndexWithDraft() > e.Dialog.GetDateIndexWithDraft()) { Remove(e.Dialog); } this[currentPosition].RaisePropertyChanged(() => this[currentPosition].Self); this[currentPosition].RaisePropertyChanged(() => this[currentPosition].UnreadCount); } } catch (Exception ex) { Log.Write(string.Format("DialogsViewModel.Handle OnTopMessageUpdatedEventArgs ex " + ex, new object[0]), null); throw ex; } }); }
public void Handle(TopMessageUpdatedEventArgs eventArgs) { eventArgs.Dialog.NotifyOfPropertyChange(() => eventArgs.Dialog.With); OnTopMessageUpdated(this, eventArgs); }