FIX: Your own likes were missing on posts

FIX: Your own likes were missing on posts

diff --git a/app/assets/javascripts/discourse/widgets/post-menu.js.es6 b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
index ebb94fc..b613806 100644
--- a/app/assets/javascripts/discourse/widgets/post-menu.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-menu.js.es6
@@ -52,9 +52,36 @@ export function buildButton(name, widget) {
   }
 }
 
+function likeCount(attrs) {
+  const count = attrs.likeCount;
+
+  if (count > 0) {
+    const title = attrs.liked
+      ? count === 1
+        ? "post.has_likes_title_only_you"
+        : "post.has_likes_title_you"
+      : "post.has_likes_title";
+    const icon = attrs.yours ? "d-liked" : "";
+    const additionalClass = attrs.yours ? "my-likes" : "regular-likes";
+
+    return {
+      action: "toggleWhoLiked",
+      title,
+      className: `button-count like-count highlight-action ${additionalClass}`,
+      contents: count,
+      icon,
+      iconRight: true,
+      addContainer: attrs.yours,
+      titleOptions: { count: attrs.liked ? count - 1 : count }
+    };
+  }
+}
+
+registerButton("like-count", likeCount);
+
 registerButton("like", attrs => {
   if (!attrs.showLike) {
-    return;
+    return likeCount(attrs);
   }
 
   const className = attrs.liked
@@ -85,30 +112,6 @@ registerButton("like", attrs => {
   return button;
 });
 
-registerButton("like-count", attrs => {
-  const count = attrs.likeCount;
-
-  if (count > 0) {
-    const title = attrs.liked
-      ? count === 1
-        ? "post.has_likes_title_only_you"
-        : "post.has_likes_title_you"
-      : "post.has_likes_title";
-    const icon = attrs.yours ? "d-liked" : "";
-    const additionalClass = attrs.yours ? "my-likes" : "regular-likes";
-
-    return {
-      action: "toggleWhoLiked",
-      title,
-      className: `button-count like-count highlight-action ${additionalClass}`,
-      contents: count,
-      icon,
-      iconRight: true,
-      titleOptions: { count: attrs.liked ? count - 1 : count }
-    };
-  }
-});
-
 registerButton("flag-count", attrs => {
   let className = "button-count";
   if (attrs.reviewableScorePendingCount > 0) {
@@ -344,7 +347,10 @@ export default createWidget("post-menu", {
       if (buttonAtts.before) {
         let before = this.attachButton(buttonAtts.before);
         return h("div.double-button", [before, button]);
+      } else if (buttonAtts.addContainer) {
+        return h("div.double-button", [button]);
       }
+
       return button;
     }
   },
diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6
index e8511f5..f3aeec4 100644
--- a/test/javascripts/widgets/post-test.js.es6
+++ b/test/javascripts/widgets/post-test.js.es6
@@ -144,7 +144,7 @@ widgetTest("like count button", {
       actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }]
     });
     this.set("post", post);
-    this.set("args", { likeCount: 1, showLike: true });
+    this.set("args", { likeCount: 1 });
   },
   async test(assert) {
     assert.ok(find("button.like-count").length === 1);

GitHub sha: 47995d2d

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: