Set the real message.id in the response instead of the content hash Introduce the new field "content_id" and use it for the same purpose as the "id" field was used: to detect if a dismissed message should be displayed again. This behaviour is described in I2ccaaa55ac549cb37eed851f8ed40f4d5f345f72 Change-Id: Ifd67230ea09884e0f31b140e2e2ccf550f0534b5
diff --git a/gr-messageoftheday/gr-messageoftheday-banner.js b/gr-messageoftheday/gr-messageoftheday-banner.js index 9d7c839..dc9e393 100644 --- a/gr-messageoftheday/gr-messageoftheday-banner.js +++ b/gr-messageoftheday/gr-messageoftheday-banner.js
@@ -52,12 +52,12 @@ _handleDismissMessage() { document.cookie = - `msg-${this._message.id}=1; path=/; expires=${this._getExpires()}`; + `msg-${this._message.content_id}=1; path=/; expires=${this._getExpires()}`; this._hidden = true; } _isHidden() { - this._hidden = document.cookie.search(`msg-${this._message.id}=`) > -1; + this._hidden = document.cookie.search(`msg-${this._message.content_id}=`) > -1; } _getExpires() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java index 3369392..64fcdcb 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java +++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/GetMessage.java
@@ -28,6 +28,7 @@ public class GetMessage implements RestReadView<ConfigResource> { private static final String SECTION_MESSAGE = "message"; + private static final String KEY_ID = "id"; private static final String KEY_STARTS_AT = "startsAt"; private static final String KEY_EXPIRES_AT = "expiresAt"; @@ -78,7 +79,8 @@ } motd.html = message; - motd.id = Integer.toString(motd.html.hashCode()); + motd.id = cfg.getString(SECTION_MESSAGE, null, KEY_ID); + motd.contentId = Integer.toString(motd.html.hashCode()); return Response.ok(motd); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java index e17127c..09a2624 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java +++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/MessageOfTheDayInfo.java
@@ -20,6 +20,8 @@ public class MessageOfTheDayInfo { /** The ID of the message. */ public String id; + /** Content ID of the message */ + public String contentId; /** The time from which on the message will be displayed. */ public Date startsAt; /** The time from which on the message will not be displayed anymore. */
diff --git a/src/main/resources/Documentation/rest-api-config.md b/src/main/resources/Documentation/rest-api-config.md index 0bb32a8..417e20f 100644 --- a/src/main/resources/Documentation/rest-api-config.md +++ b/src/main/resources/Documentation/rest-api-config.md
@@ -32,6 +32,7 @@ )]}' { "id": "hello", + "content_id": "768630922", "starts_at": "Feb 4, 2020 5:53:00 PM", "expires_at": "Dec 30, 2020 6:00:00 PM", "html": "hello you!" @@ -68,7 +69,8 @@ The `MessageOfTheDayInfo` entity contains information about the message of the day. -* `id`: ID of the message generated based on the message content. +* `id`: ID of the message +* `content_id`: ID generated based on the message content * `starts_at`: Date, when the message will be first displayed * `expires_at`: Date, after which the message will not be displayed anymore * `html`: String, containing the HTML-formatted message