public async Task StartEdit() { Loading = true; BBcodeContent = await ForumTopicQueries.GetMessageBbcode(Data.Id); EditMode = true; Loading = false; }
public async void Init(ForumsTopicNavigationArgs args) { ViewModelLocator.ForumsMain.CurrentBackNavRegistrar = this; if (LoadingTopic) { return; } LoadingTopic = true; _prevArgs = args; Messages?.Clear(); AvailablePages?.Clear(); ToggleWatchingButtonText = "Toggle watching"; CurrentTopicData = await ForumTopicQueries.GetTopicData(_prevArgs.TopicId, _prevArgs.TopicPage, _prevArgs.LastPost, _prevArgs.MessageId); CurrentPage = _prevArgs.LastPost ? CurrentTopicData.AllPages : CurrentTopicData.CurrentPage; ViewModelLocator.GeneralMain.CurrentStatus = $"Forums - {(CurrentTopicData.IsLocked ? "Locked: " : "")}{CurrentTopicData?.Title}"; Messages = new ObservableCollection <ForumTopicMessageEntryViewModel>( CurrentTopicData.Messages.Select( entry => new ForumTopicMessageEntryViewModel(entry))); if (_prevArgs.FirstVisibleItemIndex != null) { RequestScroll?.Invoke(this, _prevArgs.FirstVisibleItemIndex.Value); } else if (_prevArgs.LastPost) { RequestScroll?.Invoke(this, Messages.Count - 1); } else if (CurrentTopicData.TargetMessageId != null /*|| (_prevArgs.MessageId != null && _prevArgs.MessageId != -1)*/) { //var index = _prevArgs.MessageId != null && _prevArgs.MessageId != -1 ? _prevArgs.MessageId.ToString() : CurrentTopicData.T RequestScroll?.Invoke(this, Messages.IndexOf(Messages.First(model => model.Data.Id == CurrentTopicData.TargetMessageId))); } var watched = _handyDataStorage.WatchedTopics.StoredItems.FirstOrDefault(model => model.Id == CurrentTopicData.Id); if (watched != null) { _isWatched = true; watched.OnCooldown = false; _handyDataStorage.WatchedTopics.SaveData(); } else { _isWatched = false; } RaisePropertyChanged(() => IsWatched); IsPinned = ViewModelLocator.ForumsMain.PinnedTopics.Any(entry => entry.Id == CurrentTopicData.Id); ViewModelLocator.ForumsMain.PinnedTopics.CollectionChanged += PinnedTopicsOnCollectionChanged; LoadingTopic = false; }
private async void Delete() { if (await ForumTopicQueries.DeleteComment(Data.Id)) { ViewModelLocator.ForumsTopic.RemoveMessage(this); } else { ResourceLocator.MessageDialogProvider.ShowMessageDialog("Unable to remove this comment", "Something went wrong"); } }
private async void CreateTopic() { Tuple <bool, string> result; if (_prevArgs.TopicType != null) { result = await ForumTopicQueries.CreateNewTopic(Title, Message, _prevArgs.TopicType.Value, _prevArgs.Id, Question, Answers.Any(model => !string.IsNullOrEmpty(model.Answer)) ?Answers.Select(model => model.Answer).ToList() : null); } else { result = await ForumTopicQueries.CreateNewTopic(Title, Message, _prevArgs.ForumType, _prevArgs.Id, Question, Answers.Any(model => !string.IsNullOrEmpty(model.Answer)) ?Answers.Select(model => model.Answer).ToList() : null); } if (result.Item1) { ResourceLocator.TelemetryProvider.TelemetryTrackEvent(TelemetryTrackedEvents.CreatedTopic); if (result.Item2 != null) { ViewModelLocator.GeneralMain.Navigate(PageIndex.PageForumIndex, new ForumsTopicNavigationArgs(result.Item2, null)); } else { ViewModelLocator.NavMgr.CurrentMainViewOnBackRequested(); } Message = Title = string.Empty; } else { ResourceLocator.MessageDialogProvider.ShowMessageDialog("Something went wrong while creating your topic. Remember that you can post new topics every 5 minutes.", "Something went wrong!"); } }
private async Task LoadCurrentTopicPageAsync(bool force = false, bool lastpost = false) { LoadingTopic = true; var data = await ForumTopicQueries.GetTopicData(CurrentTopicData.Id, CurrentPage, lastpost, null, force); if (!data.Messages.Any()) { CurrentPage = CurrentTopicData.CurrentPage; LoadingTopic = false; return; } CurrentTopicData = data; Messages = new ObservableCollection <ForumTopicMessageEntryViewModel>( CurrentTopicData.Messages.Select( entry => new ForumTopicMessageEntryViewModel(entry))); if (lastpost) { CurrentPage = CurrentTopicData.AllPages; RequestScroll?.Invoke(this, Messages.Count - 1); } LoadingTopic = false; }
public async void QuouteMessage(string dataId, string poster) { ReplyMessage += $"[quote={poster} message={dataId}]" + await ForumTopicQueries.GetQuote(dataId) + "[/quote]"; }
public void RemoveMessage(ForumTopicMessageEntryViewModel forumTopicMessageEntryViewModel) { Messages.Remove(forumTopicMessageEntryViewModel); ForumTopicQueries.NotifyMessageRemoved(forumTopicMessageEntryViewModel.Data); }