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.

drafts: Save stream_id along with stream names for drafts.

sahil839238ba1c36f0c
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js
index 850f9ded685..cfbbff5d963 100644
--- a/frontend_tests/node_tests/drafts.js
+++ b/frontend_tests/node_tests/drafts.js
@@ -32,7 +32,12 @@ mock_esm("../../static/js/stream_data", {
get_color() {
return "#FFFFFF";
},
+ get_sub(stream_name) {
+ assert.equal(stream_name, "stream");
+ return {stream_id: 30};
+ },
});
+const sub_store = mock_esm("../../static/js/sub_store");
user_settings.twenty_four_hour_time = false;
const {localstorage} = zrequire("localstorage");
@@ -55,6 +60,7 @@ const compose_args_for_legacy_draft = {
const draft_1 = {
stream: "stream",
+ stream_id: 30,
topic: "topic",
type: "stream",
content: "Test stream message",
@@ -214,6 +220,7 @@ test("format_drafts", ({override, mock_template}) => {
topic: "topic",
type: "stream",
content: "Test stream message",
+ stream_id: 30,
updatedAt: feb12().getTime(),
};
const draft_2 = {
@@ -300,6 +307,11 @@ test("format_drafts", ({override, mock_template}) => {
const stub_render_now = timerender.render_now;
override(timerender, "render_now", (time) => stub_render_now(time, new Date(1549958107000)));
+ sub_store.get = function (stream_id) {
+ assert.equal(stream_id, 30);
+ return {name: "stream"};
+ };
+
mock_template("draft_table_body.hbs", false, (data) => {
// Tests formatting and sorting of drafts
assert.deepEqual(data.drafts, expected);
@@ -310,6 +322,19 @@ test("format_drafts", ({override, mock_template}) => {
override(drafts, "set_initial_element", noop);
$.create("#drafts_table .draft-row", {children: []});
+ drafts.launch();
+
+ $.clear_all_elements();
+ $.create("#drafts_table .draft-row", {children: []});
+ $("#draft_overlay").css = () => {};
+
+ sub_store.get = function (stream_id) {
+ assert.equal(stream_id, 30);
+ return {name: "stream-rename"};
+ };
+
+ expected[0].stream = "stream-rename";
+
drafts.launch();
timerender.__Rewire__("render_now", stub_render_now);
});
diff --git a/static/js/drafts.js b/static/js/drafts.js
index 29dbe25870c..5c3d2ed861d 100644
--- a/static/js/drafts.js
+++ b/static/js/drafts.js
@@ -20,6 +20,7 @@ import * as narrow from "./narrow";
import * as overlays from "./overlays";
import * as people from "./people";
import * as stream_data from "./stream_data";
+import * as sub_store from "./sub_store";
import * as timerender from "./timerender";
import * as util from "./util";
@@ -107,6 +108,10 @@ export function snapshot_message() {
message.private_message_recipient = recipient;
} else {
message.stream = compose_state.stream_name();
+ const sub = stream_data.get_sub(message.stream);
+ if (sub) {
+ message.stream_id = sub.stream_id;
+ }
message.topic = compose_state.topic();
}
return message;
@@ -241,9 +246,17 @@ export function format_draft(draft) {
// In case there is no stream for the draft, we need a
// single space char for proper rendering of the stream label
const space_string = new Handlebars.SafeString(" ");
- const stream = draft.stream.length > 0 ? draft.stream : space_string;
+ let stream = draft.stream.length > 0 ? draft.stream : space_string;
+ if (draft.stream_id) {
+ const sub = sub_store.get(draft.stream_id);
+ if (sub && sub.name !== stream) {
+ stream = sub.name;
+ draft.stream = stream;
+ draft_model.editDraft(id, draft);
+ }
+ }
let draft_topic = util.get_draft_topic(draft);
- const draft_stream_color = stream_data.get_color(draft.stream);
+ const draft_stream_color = stream_data.get_color(stream);
if (draft_topic === "") {
draft_topic = compose.empty_topic_placeholder();