Exemplo n.º 1
0
 private void OnCommentDelete(WorkshopComment comment)
 {
     _busyEdit.Task(async() => {
         try {
             await WorkshopHolder.Client.DeleteAsync($"{_url}/{comment.Id}");
             Comments.Remove(comment);
             ++CommentsDeleted;
         } catch (Exception e) {
             NonfatalError.Notify("Failed to edit a comment", e);
         }
     });
 }
Exemplo n.º 2
0
 private void OnCommentChange(WorkshopComment comment, string newMessage)
 {
     _busyEdit.Task(async() => {
         try {
             await WorkshopHolder.Client.PatchAsync($"{_url}/{comment.Id}", new { comment = newMessage });
         } catch (Exception e) {
             NonfatalError.Notify("Failed to edit a comment", e);
             return;
         }
         try {
             comment.Message = (await WorkshopHolder.Client.GetAsync <WorkshopComment>($"{_url}/{comment.Id}")).Message;
         } catch (Exception e) {
             Logging.Warning(e);
             comment.Message = newMessage;
         }
         comment.ChangeTo = null;
     });
 }
Exemplo n.º 3
0
 private void OnReport(WorkshopComment comment, string message)
 {
     _busyReport.Task(async() => {
         try {
             await WorkshopHolder.Client.PostAsync($"{_reportsUrl}{comment.Id}", new { message });
         } catch (Exception e) {
             NonfatalError.Notify("Failed to send a report", e);
             return;
         }
         try {
             await WorkshopHolder.Client.GetAsync <WorkshopComment>($"{_url}/{comment.Id}");
         } catch (WorkshopException e) when(e.Code == HttpStatusCode.NotFound)
         {
             Comments.Remove(comment);
         } catch (Exception e) {
             Logging.Warning(e);
         }
     });
 }
Exemplo n.º 4
0
 private void OnLikeSet(WorkshopComment comment, bool likeSet)
 {
     if (_innerChange)
     {
         return;
     }
     if (_busyLike.Is)
     {
         _innerChange  = true;
         comment.Liked = !likeSet;
         _innerChange  = false;
     }
     _busyLike.Task(async() => {
         try {
             if (likeSet)
             {
                 await WorkshopHolder.Client.PostAsync($"{_likesUrl}{comment.Id}");
             }
             else
             {
                 await WorkshopHolder.Client.DeleteAsync($"{_likesUrl}{comment.Id}");
             }
         } catch (WorkshopException e) when(e.Code == HttpStatusCode.Conflict || e.Code == HttpStatusCode.NotFound)
         {
             // ignore such cases, as they usually mean desired task is already completed
             _innerChange  = true;
             comment.Likes = likeSet ? comment.Likes - 1 : comment.Likes + 1;
             _innerChange  = false;
         } catch (Exception e) {
             _innerChange  = true;
             comment.Liked = !likeSet;
             _innerChange  = false;
             NonfatalError.Notify(likeSet ? "Failed to send a like" : "Failed to delete a like", e);
         }
     });
 }