mirror of https://github.com/zulip/zulip.git
ui: Move update_message_lists related functions to other related modules.
This commit moves mainly two functions from `ui.js` to `message_live_update`, `update_message_in_all_views` and `update_starred_view`. This is done in favor of eliminating `ui.js` and also these functions are more closely related to `message_live_update` module than to `ui` module. We also move `show_message_failed` and `show_failed_message_success` to `echo.js` for cleaner seperation of responsibilities.
This commit is contained in:
parent
aad2f7c7c5
commit
7e52509ee7
|
@ -10,6 +10,7 @@ import * as local_message from "./local_message";
|
||||||
import * as markdown from "./markdown";
|
import * as markdown from "./markdown";
|
||||||
import * as message_events from "./message_events";
|
import * as message_events from "./message_events";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
|
import * as message_live_update from "./message_live_update";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as notifications from "./notifications";
|
import * as notifications from "./notifications";
|
||||||
|
@ -23,7 +24,6 @@ import * as sent_messages from "./sent_messages";
|
||||||
import * as stream_list from "./stream_list";
|
import * as stream_list from "./stream_list";
|
||||||
import * as stream_topic_history from "./stream_topic_history";
|
import * as stream_topic_history from "./stream_topic_history";
|
||||||
import * as transmit from "./transmit";
|
import * as transmit from "./transmit";
|
||||||
import * as ui from "./ui";
|
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
||||||
|
@ -61,9 +61,25 @@ function insert_message(message) {
|
||||||
message_events.insert_new_messages([message], true);
|
message_events.insert_new_messages([message], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function show_message_failed(message_id, failed_msg) {
|
||||||
|
// Failed to send message, so display inline retry/cancel
|
||||||
|
message_live_update.update_message_in_all_views(message_id, ($row) => {
|
||||||
|
const $failed_div = $row.find(".message_failed");
|
||||||
|
$failed_div.toggleClass("hide", false);
|
||||||
|
$failed_div.find(".failed_text").attr("title", failed_msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_failed_message_success(message_id) {
|
||||||
|
// Previously failed message succeeded
|
||||||
|
message_live_update.update_message_in_all_views(message_id, ($row) => {
|
||||||
|
$row.find(".message_failed").toggleClass("hide", true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function failed_message_success(message_id) {
|
function failed_message_success(message_id) {
|
||||||
message_store.get(message_id).failed_request = false;
|
message_store.get(message_id).failed_request = false;
|
||||||
ui.show_failed_message_success(message_id);
|
show_failed_message_success(message_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resend_message(message, $row) {
|
function resend_message(message, $row) {
|
||||||
|
@ -442,7 +458,7 @@ export function _patch_waiting_for_ack(data) {
|
||||||
export function message_send_error(message_id, error_response) {
|
export function message_send_error(message_id, error_response) {
|
||||||
// Error sending message, show inline
|
// Error sending message, show inline
|
||||||
message_store.get(message_id).failed_request = true;
|
message_store.get(message_id).failed_request = true;
|
||||||
ui.show_message_failed(message_id, error_response);
|
show_message_failed(message_id, error_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
function abort_message(message) {
|
function abort_message(message) {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
|
import * as message_live_update from "./message_live_update";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
import * as starred_messages from "./starred_messages";
|
import * as starred_messages from "./starred_messages";
|
||||||
import * as ui from "./ui";
|
|
||||||
import * as unread_ops from "./unread_ops";
|
import * as unread_ops from "./unread_ops";
|
||||||
|
|
||||||
function send_flag_update_for_messages(msg_ids, flag, op) {
|
function send_flag_update_for_messages(msg_ids, flag, op) {
|
||||||
|
@ -86,7 +86,7 @@ export function update_starred_flag(message_id, new_value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
message.starred = new_value;
|
message.starred = new_value;
|
||||||
ui.update_starred_view(message_id, new_value);
|
message_live_update.update_starred_view(message_id, new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggle_starred_and_update_server(message) {
|
export function toggle_starred_and_update_server(message) {
|
||||||
|
@ -105,7 +105,7 @@ export function toggle_starred_and_update_server(message) {
|
||||||
// explicit interaction and we'd like to preserve the user
|
// explicit interaction and we'd like to preserve the user
|
||||||
// expectation invariant that all starred messages are read.
|
// expectation invariant that all starred messages are read.
|
||||||
unread_ops.notify_server_message_read(message);
|
unread_ops.notify_server_message_read(message);
|
||||||
ui.update_starred_view(message.id, message.starred);
|
message_live_update.update_starred_view(message.id, message.starred);
|
||||||
|
|
||||||
if (message.starred) {
|
if (message.starred) {
|
||||||
send_flag_update_for_messages([message.id], "starred", "add");
|
send_flag_update_for_messages([message.id], "starred", "add");
|
||||||
|
|
|
@ -31,6 +31,40 @@ function rerender_messages_view_for_user(user_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function update_message_in_all_views(message_id, callback) {
|
||||||
|
for (const msg_list of message_lists.all_rendered_message_lists()) {
|
||||||
|
const $row = msg_list.get_row(message_id);
|
||||||
|
if ($row === undefined) {
|
||||||
|
// The row may not exist, e.g. if you do an action on a message in
|
||||||
|
// a narrowed view
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
callback($row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function update_starred_view(message_id, new_value) {
|
||||||
|
const starred = new_value;
|
||||||
|
|
||||||
|
// Avoid a full re-render, but update the star in each message
|
||||||
|
// table in which it is visible.
|
||||||
|
update_message_in_all_views(message_id, ($row) => {
|
||||||
|
const $elt = $row.find(".star");
|
||||||
|
const $star_container = $row.find(".star_container");
|
||||||
|
if (starred) {
|
||||||
|
$elt.addClass("fa-star").removeClass("fa-star-o");
|
||||||
|
$star_container.removeClass("empty-star");
|
||||||
|
} else {
|
||||||
|
$elt.removeClass("fa-star").addClass("fa-star-o");
|
||||||
|
$star_container.addClass("empty-star");
|
||||||
|
}
|
||||||
|
const data_template_id = starred
|
||||||
|
? "unstar-message-tooltip-template"
|
||||||
|
: "star-message-tooltip-template";
|
||||||
|
$star_container.attr("data-tooltip-template-id", data_template_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function update_stream_name(stream_id, new_name) {
|
export function update_stream_name(stream_id, new_name) {
|
||||||
message_store.update_property("stream_name", new_name, {stream_id});
|
message_store.update_property("stream_name", new_name, {stream_id});
|
||||||
rerender_messages_view();
|
rerender_messages_view();
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import SimpleBar from "simplebar";
|
import SimpleBar from "simplebar";
|
||||||
|
|
||||||
import * as message_lists from "./message_lists";
|
|
||||||
|
|
||||||
// What, if anything, obscures the home tab?
|
// What, if anything, obscures the home tab?
|
||||||
|
|
||||||
export function replace_emoji_with_text($element) {
|
export function replace_emoji_with_text($element) {
|
||||||
|
@ -46,56 +44,6 @@ export function reset_scrollbar($element) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_message_in_all_views(message_id, callback) {
|
|
||||||
for (const msg_list of message_lists.all_rendered_message_lists()) {
|
|
||||||
const $row = msg_list.get_row(message_id);
|
|
||||||
if ($row === undefined) {
|
|
||||||
// The row may not exist, e.g. if you do an action on a message in
|
|
||||||
// a narrowed view
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
callback($row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function update_starred_view(message_id, new_value) {
|
|
||||||
const starred = new_value;
|
|
||||||
|
|
||||||
// Avoid a full re-render, but update the star in each message
|
|
||||||
// table in which it is visible.
|
|
||||||
update_message_in_all_views(message_id, ($row) => {
|
|
||||||
const $elt = $row.find(".star");
|
|
||||||
const $star_container = $row.find(".star_container");
|
|
||||||
if (starred) {
|
|
||||||
$elt.addClass("fa-star").removeClass("fa-star-o");
|
|
||||||
$star_container.removeClass("empty-star");
|
|
||||||
} else {
|
|
||||||
$elt.removeClass("fa-star").addClass("fa-star-o");
|
|
||||||
$star_container.addClass("empty-star");
|
|
||||||
}
|
|
||||||
const data_template_id = starred
|
|
||||||
? "unstar-message-tooltip-template"
|
|
||||||
: "star-message-tooltip-template";
|
|
||||||
$star_container.attr("data-tooltip-template-id", data_template_id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function show_message_failed(message_id, failed_msg) {
|
|
||||||
// Failed to send message, so display inline retry/cancel
|
|
||||||
update_message_in_all_views(message_id, ($row) => {
|
|
||||||
const $failed_div = $row.find(".message_failed");
|
|
||||||
$failed_div.toggleClass("hide", false);
|
|
||||||
$failed_div.find(".failed_text").attr("title", failed_msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function show_failed_message_success(message_id) {
|
|
||||||
// Previously failed message succeeded
|
|
||||||
update_message_in_all_views(message_id, ($row) => {
|
|
||||||
$row.find(".message_failed").toggleClass("hide", true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the compose content cursor position and restore when we
|
// Save the compose content cursor position and restore when we
|
||||||
// shift-tab back in (see hotkey.js).
|
// shift-tab back in (see hotkey.js).
|
||||||
let saved_compose_cursor = 0;
|
let saved_compose_cursor = 0;
|
||||||
|
|
|
@ -70,7 +70,6 @@ mock_esm("../src/top_left_corner", {
|
||||||
update_starred_count() {},
|
update_starred_count() {},
|
||||||
});
|
});
|
||||||
const typing_events = mock_esm("../src/typing_events");
|
const typing_events = mock_esm("../src/typing_events");
|
||||||
const ui = mock_esm("../src/ui");
|
|
||||||
const unread_ops = mock_esm("../src/unread_ops");
|
const unread_ops = mock_esm("../src/unread_ops");
|
||||||
const unread_ui = mock_esm("../src/unread_ui");
|
const unread_ui = mock_esm("../src/unread_ui");
|
||||||
const user_events = mock_esm("../src/user_events");
|
const user_events = mock_esm("../src/user_events");
|
||||||
|
@ -84,12 +83,14 @@ const electron_bridge = set_global("electron_bridge", {});
|
||||||
|
|
||||||
message_lists.update_recipient_bar_background_color = noop;
|
message_lists.update_recipient_bar_background_color = noop;
|
||||||
message_lists.current = {
|
message_lists.current = {
|
||||||
|
get_row: noop,
|
||||||
rerender_view: noop,
|
rerender_view: noop,
|
||||||
data: {
|
data: {
|
||||||
get_messages_sent_by_user: () => [],
|
get_messages_sent_by_user: () => [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
message_lists.home = {
|
message_lists.home = {
|
||||||
|
get_row: noop,
|
||||||
rerender_view: noop,
|
rerender_view: noop,
|
||||||
data: {
|
data: {
|
||||||
get_messages_sent_by_user: () => [],
|
get_messages_sent_by_user: () => [],
|
||||||
|
@ -996,28 +997,16 @@ run_test("update_message (unread)", ({override}) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("update_message (add star)", ({override}) => {
|
run_test("update_message (add star)", () => {
|
||||||
const event = event_fixtures.update_message_flags__starred_add;
|
const event = event_fixtures.update_message_flags__starred_add;
|
||||||
const stub = make_stub();
|
|
||||||
override(ui, "update_starred_view", stub.f);
|
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
assert.equal(stub.num_calls, 1);
|
|
||||||
const args = stub.get_args("message_id", "new_value");
|
|
||||||
assert_same(args.message_id, test_message.id);
|
|
||||||
assert_same(args.new_value, true); // for 'add'
|
|
||||||
const msg = message_store.get(test_message.id);
|
const msg = message_store.get(test_message.id);
|
||||||
assert.equal(msg.starred, true);
|
assert.equal(msg.starred, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("update_message (remove star)", ({override}) => {
|
run_test("update_message (remove star)", () => {
|
||||||
const event = event_fixtures.update_message_flags__starred_remove;
|
const event = event_fixtures.update_message_flags__starred_remove;
|
||||||
const stub = make_stub();
|
|
||||||
override(ui, "update_starred_view", stub.f);
|
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
assert.equal(stub.num_calls, 1);
|
|
||||||
const args = stub.get_args("message_id", "new_value");
|
|
||||||
assert_same(args.message_id, test_message.id);
|
|
||||||
assert_same(args.new_value, false);
|
|
||||||
const msg = message_store.get(test_message.id);
|
const msg = message_store.get(test_message.id);
|
||||||
assert.equal(msg.starred, false);
|
assert.equal(msg.starred, false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,8 +15,8 @@ const notifications = mock_esm("../src/notifications");
|
||||||
|
|
||||||
let disparities = [];
|
let disparities = [];
|
||||||
|
|
||||||
mock_esm("../src/ui", {
|
mock_esm("../src/message_live_update", {
|
||||||
show_failed_message_success() {},
|
update_message_in_all_views() {},
|
||||||
});
|
});
|
||||||
|
|
||||||
mock_esm("../src/sent_messages", {
|
mock_esm("../src/sent_messages", {
|
||||||
|
|
|
@ -6,7 +6,7 @@ const {mock_esm, set_global, with_overrides, zrequire} = require("./lib/namespac
|
||||||
const {run_test} = require("./lib/test");
|
const {run_test} = require("./lib/test");
|
||||||
|
|
||||||
const channel = mock_esm("../src/channel");
|
const channel = mock_esm("../src/channel");
|
||||||
const ui = mock_esm("../src/ui");
|
const message_live_update = mock_esm("../src/message_live_update");
|
||||||
|
|
||||||
mock_esm("../src/starred_messages", {
|
mock_esm("../src/starred_messages", {
|
||||||
add() {},
|
add() {},
|
||||||
|
@ -22,7 +22,7 @@ run_test("starred", ({override}) => {
|
||||||
};
|
};
|
||||||
let ui_updated;
|
let ui_updated;
|
||||||
|
|
||||||
override(ui, "update_starred_view", () => {
|
override(message_live_update, "update_starred_view", () => {
|
||||||
ui_updated = true;
|
ui_updated = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ run_test("starring local echo", () => {
|
||||||
|
|
||||||
message_flags.toggle_starred_and_update_server(locally_echoed_message);
|
message_flags.toggle_starred_and_update_server(locally_echoed_message);
|
||||||
|
|
||||||
// ui.update_starred_view not called
|
// message_live_update.update_starred_view not called
|
||||||
|
|
||||||
// channel post request not made
|
// channel post request not made
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue