Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

echo: Update message controls dynamically for failed messages.

Sayam Samal5583ddd3bf27
diff --git a/web/src/echo.ts b/web/src/echo.ts
index aa013afa9e7..cf668f82a34 100644
--- a/web/src/echo.ts
+++ b/web/src/echo.ts
@@ -2,6 +2,9 @@ import $ from "jquery";
import assert from "minimalistic-assert";
import {z} from "zod";
+import render_message_controls from "../templates/message_controls.hbs";
+import render_message_controls_failed_msg from "../templates/message_controls_failed_msg.hbs";
+
import * as alert_words from "./alert_words";
import * as blueslip from "./blueslip";
import * as compose_notifications from "./compose_notifications";
@@ -118,20 +121,22 @@ function hide_retry_spinner($row: JQuery): boolean {
return true;
}
-function show_message_failed(message_id: number, failed_msg: string): void {
+function show_message_failed(message_id: number, _failed_msg: string): void {
// Failed to send message, so display inline retry/cancel
message_live_update.update_message_in_all_views(message_id, ($row) => {
$row.find(".slow-send-spinner").addClass("hidden");
- const $failed_div = $row.find(".message_failed");
- $failed_div.toggleClass("hide", false);
- $failed_div.find(".failed_text").attr("title", failed_msg);
+ const $message_controls = $row.find(".message_controls");
+ $message_controls.html(render_message_controls_failed_msg());
});
+ // TODO: Show the `_failed_msg` in the UI, describing the reason for the failure.
}
function show_failed_message_success(message_id: number): void {
// Previously failed message succeeded
+ const msg = message_store.get(message_id);
message_live_update.update_message_in_all_views(message_id, ($row) => {
- $row.find(".message_failed").toggleClass("hide", true);
+ const $message_controls = $row.find(".message_controls");
+ $message_controls.html(render_message_controls({msg}));
});
}
diff --git a/web/styles/message_row.css b/web/styles/message_row.css
index 868f3102c41..bf20469d6b6 100644
--- a/web/styles/message_row.css
+++ b/web/styles/message_row.css
@@ -77,8 +77,7 @@
padding on either side of the message box. */
padding: 0 5px 0 3px;
- &:hover .message_controls,
- &:hover .message_failed {
+ &:hover .message_controls {
.empty-star:hover {
cursor: pointer;
}
@@ -142,8 +141,8 @@
@media (width < $sm_min), ((width >= $md_min) and (width < $mc_min)) {
/* This is intended to target the first message_controls child
- when there are 3 displayed. 4 = 3 + hidden message_failed element. */
- .message_control_button:nth-last-child(4) {
+ when there are 3 displayed. */
+ .message_control_button:nth-last-child(3) {
display: none;
}
}
@@ -504,35 +503,16 @@
}
}
- .message_failed {
- display: inline-flex;
- justify-content: space-between;
- cursor: pointer;
- position: relative;
- vertical-align: middle;
- padding-left: 2px;
-
- &.hide {
- display: none;
- }
+ .failed_message_action {
+ color: var(--color-failed-message-send-icon);
+ font-weight: bold;
+ padding: 1px;
+ opacity: 1;
+ visibility: visible;
.rotating {
- display: inline-block;
- outline: none;
-
animation: rotate 1s infinite linear;
}
-
- .failed_message_action {
- opacity: 1 !important;
- color: var(--color-failed-message-send-icon);
- font-weight: bold;
- padding: 1px;
- }
-
- .message_control_button {
- visibility: inherit;
- }
}
.star_container {
diff --git a/web/templates/message_body.hbs b/web/templates/message_body.hbs
index 25cb7af46c2..1d888bac0ce 100644
--- a/web/templates/message_body.hbs
+++ b/web/templates/message_body.hbs
@@ -37,7 +37,15 @@
<span data-tooltip-template-id="slow-send-spinner-tooltip-template" class="fa fa-circle-o-notch slow-send-spinner{{#unless msg/show_slow_send_spinner }} hidden{{/unless}}"></span>
{{/if}}
-{{> message_controls}}
+<div class="message_controls no-select">
+ {{#if msg/locally_echoed}}
+ {{#if msg/failed_request}}
+ {{> message_controls_failed_msg}}
+ {{/if}}
+ {{else}}
+ {{> message_controls}}
+ {{/if}}
+</div>
{{#unless status_message}}
{{#unless is_hidden}}
diff --git a/web/templates/message_controls.hbs b/web/templates/message_controls.hbs
index 33865d94789..1efbfbaf385 100644
--- a/web/templates/message_controls.hbs
+++ b/web/templates/message_controls.hbs
@@ -1,36 +1,19 @@
-<div class="message_controls no-select">
- {{#if msg/sent_by_me}}
+{{#if msg/sent_by_me}}
<div class="edit_content message_control_button"></div>
- {{/if}}
+{{/if}}
- {{#unless msg/sent_by_me}}
+{{#unless msg/sent_by_me}}
<div class="reaction_button message_control_button" data-tooltip-template-id="add-emoji-tooltip-template">
<div class="emoji-message-control-button-container">
<i class="message-controls-icon zulip-icon zulip-icon-smile" aria-label="{{t 'Add emoji reaction' }} (:)" role="button" aria-haspopup="true" tabindex="0"></i>
</div>
</div>
- {{/unless}}
+{{/unless}}
- {{#unless msg/locally_echoed}}
- <div class="actions_hover message_control_button" data-tooltip-template-id="message-actions-tooltip-template" >
- <i class="message-controls-icon message-actions-menu-button zulip-icon zulip-icon-more-vertical-spread" role="button" aria-haspopup="true" tabindex="0" aria-label="{{t 'Message actions' }}"></i>
- </div>
- {{/unless}}
-
- <div class="message_failed {{#unless msg.failed_request}}hide{{/unless}}">
- <div class="message_control_button failed_message_action" data-tippy-content="{{t 'Retry' }}">
- <i class="message-controls-icon fa fa-refresh refresh-failed-message" aria-label="{{t 'Retry' }}" role="button" tabindex="0"></i>
- </div>
-
- <div class="message_control_button failed_message_action" data-tooltip-template-id="dismiss-failed-send-button-tooltip-template">
- <i class="message-controls-icon fa fa-times-circle remove-failed-message" aria-label="{{t 'Dismiss' }}" role="button" tabindex="0"></i>
- </div>
- </div>
-
- {{#unless msg/locally_echoed}}
- <div class="star_container message_control_button {{#if msg/starred}}{{else}}empty-star{{/if}}" data-tooltip-template-id="{{#if msg/starred}}unstar{{else}}star{{/if}}-message-tooltip-template">
- <i role="button" tabindex="0" class="message-controls-icon star zulip-icon {{#if msg/starred}}zulip-icon-star-filled{{else}}zulip-icon-star{{/if}}"></i>
- </div>
- {{/unless}}
+<div class="actions_hover message_control_button" data-tooltip-template-id="message-actions-tooltip-template" >
+ <i class="message-controls-icon message-actions-menu-button zulip-icon zulip-icon-more-vertical-spread" role="button" aria-haspopup="true" tabindex="0" aria-label="{{t 'Message actions' }}"></i>
+</div>
+<div class="star_container message_control_button {{#if msg/starred}}{{else}}empty-star{{/if}}" data-tooltip-template-id="{{#if msg/starred}}unstar{{else}}star{{/if}}-message-tooltip-template">
+ <i role="button" tabindex="0" class="message-controls-icon star zulip-icon {{#if msg/starred}}zulip-icon-star-filled{{else}}zulip-icon-star{{/if}}"></i>
</div>
diff --git a/web/templates/message_controls_failed_msg.hbs b/web/templates/message_controls_failed_msg.hbs
new file mode 100644
index 00000000000..8f4954ec93d
--- /dev/null
+++ b/web/templates/message_controls_failed_msg.hbs
@@ -0,0 +1,7 @@
+<div class="message_control_button failed_message_action" data-tippy-content="{{t 'Retry' }}">
+ <i class="message-controls-icon fa fa-refresh refresh-failed-message" aria-label="{{t 'Retry' }}" role="button" tabindex="0"></i>
+</div>
+
+<div class="message_control_button failed_message_action" data-tooltip-template-id="dismiss-failed-send-button-tooltip-template">
+ <i class="message-controls-icon fa fa-times-circle remove-failed-message" aria-label="{{t 'Dismiss' }}" role="button" tabindex="0"></i>
+</div>