FIX: Refresh first post after assign and unassign (#212)

FIX: Refresh first post after assign and unassign (#212)

The first post showed the assign status when it was loaded and did not update if it changed. The page had to be refreshed for the text to be updated.

diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
index 3183d33..ae00c4d 100644
--- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
+++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
@@ -91,16 +91,21 @@ function registerTopicFooterButtons(api) {
 
       const taskActions = getOwner(this).lookup("service:task-actions");
       const topic = this.topic;
-      const assignedUser = topic.get("assigned_to_user.username");
 
-      if (assignedUser) {
+      if (topic.assigned_to_user || topic.assigned_to_group) {
         this.set("topic.assigned_to_user", null);
-        taskActions.unassign(topic.id);
-      } else if (topic.assigned_to_group) {
         this.set("topic.assigned_to_group", null);
-        taskActions.unassign(topic.id);
+        taskActions.unassign(topic.id).then(() => {
+          this.appEvents.trigger("post-stream:refresh", {
+            id: topic.postStream.firstPostId,
+          });
+        });
       } else {
-        taskActions.assign(topic);
+        taskActions.assign(topic).set("model.onSuccess", () => {
+          this.appEvents.trigger("post-stream:refresh", {
+            id: topic.postStream.firstPostId,
+          });
+        });
       }
     },
     dropdown() {

GitHub sha: 85fa1f90aab576f399d8d346b233d2265e42f185

This commit appears in #212 which was approved by ZogStriP. It was merged by SamSaffron.