js: Convert static/js/sent_messages.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-27 15:50:19 -08:00
committed by Tim Abbott
parent 32288d245c
commit f499c4a858
14 changed files with 47 additions and 47 deletions

View File

@@ -196,7 +196,6 @@
"search": false,
"search_pill_widget": false,
"search_suggestion": false,
"sent_messages": false,
"server_events": false,
"settings": false,
"settings_account": false,

View File

@@ -38,6 +38,7 @@ const _drafts = {
};
const sent_messages = {
__esModule: true,
start_tracking_message: noop,
};
const _notifications = {
@@ -53,7 +54,7 @@ rewiremock("../../static/js/drafts").with(_drafts);
set_global("navigator", _navigator);
set_global("notifications", _notifications);
set_global("reminder", reminder);
set_global("sent_messages", sent_messages);
rewiremock("../../static/js/sent_messages").with(sent_messages);
rewiremock("../../static/js/rendered_markdown").with({
update_elements: () => {},
});

View File

@@ -24,7 +24,7 @@ set_global("ui", {
show_failed_message_success: () => {},
});
set_global("sent_messages", {
rewiremock("../../static/js/sent_messages").with({
mark_disparity: (local_id) => {
disparities.push(local_id);
},

View File

@@ -55,7 +55,6 @@ rewiremock.enable();
zrequire("message_store");
const server_events = zrequire("server_events");
zrequire("sent_messages");
set_global("$", $);

View File

@@ -16,10 +16,13 @@ const reload = {__esModule: true};
rewiremock("../../static/js/reload").with(reload);
const reload_state = {__esModule: true};
rewiremock("../../static/js/reload_state").with(reload_state);
const sent_messages = set_global("sent_messages", {
const sent_messages = {
__esModule: true,
start_tracking_message: noop,
report_server_ack: noop,
});
};
rewiremock("../../static/js/sent_messages").with(sent_messages);
rewiremock.enable();

View File

@@ -128,7 +128,6 @@ zrequire("search_suggestion");
zrequire("search");
zrequire("notifications");
zrequire("stream_list");
zrequire("sent_messages");
zrequire("starred_messages");
zrequire("recent_topics");

View File

@@ -24,7 +24,6 @@ import "../widgetize";
import "../message_list";
import "../narrow";
import "../reload";
import "../sent_messages";
import "../compose_state";
import "../compose_actions";
import "../transmit";

View File

@@ -21,6 +21,7 @@ const peer_data = require("./peer_data");
const people = require("./people");
const rendered_markdown = require("./rendered_markdown");
const rtl = require("./rtl");
const sent_messages = require("./sent_messages");
const settings_config = require("./settings_config");
const util = require("./util");
const zcommand = require("./zcommand");

View File

@@ -5,6 +5,7 @@ import * as narrow_state from "./narrow_state";
import * as people from "./people";
import * as pm_list from "./pm_list";
import * as rows from "./rows";
import * as sent_messages from "./sent_messages";
import * as util from "./util";
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html

View File

@@ -69,7 +69,6 @@ declare let scroll_bar: any;
declare let search: any;
declare let search_pill_widget: any;
declare let search_suggestion: any;
declare let sent_messages: any;
declare let server_events: any;
declare let settings: any;
declare let settings_account: any;

View File

@@ -1,18 +1,17 @@
"use strict";
import * as channel from "./channel";
const channel = require("./channel");
export let next_local_id;
export const messages = new Map();
exports.messages = new Map();
export function reset_id_state() {
next_local_id = 0;
}
exports.reset_id_state = function () {
exports.next_local_id = 0;
};
exports.get_new_local_id = function () {
exports.next_local_id += 1;
const local_id = exports.next_local_id;
export function get_new_local_id() {
next_local_id += 1;
const local_id = next_local_id;
return "loc-" + local_id.toString();
};
}
function report_send_time(send_time, receive_time, locally_echoed, rendered_changed) {
const data = {
@@ -31,7 +30,7 @@ function report_send_time(send_time, receive_time, locally_echoed, rendered_chan
});
}
class MessageState {
export class MessageState {
start = new Date();
received = undefined;
@@ -102,9 +101,8 @@ class MessageState {
return this.send_finished !== undefined && this.received !== undefined;
}
}
exports.MessageState = MessageState;
exports.start_tracking_message = function (opts) {
export function start_tracking_message(opts) {
const local_id = opts.local_id;
if (!opts.local_id) {
@@ -112,63 +110,61 @@ exports.start_tracking_message = function (opts) {
return;
}
if (exports.messages.has(local_id)) {
if (messages.has(local_id)) {
blueslip.error("We are re-using a local_id");
return;
}
const state = new exports.MessageState(opts);
const state = new MessageState(opts);
exports.messages.set(local_id, state);
};
messages.set(local_id, state);
}
exports.get_message_state = function (local_id) {
const state = exports.messages.get(local_id);
export function get_message_state(local_id) {
const state = messages.get(local_id);
if (!state) {
blueslip.warn("Unknown local_id: " + local_id);
}
return state;
};
}
exports.mark_disparity = function (local_id) {
const state = exports.get_message_state(local_id);
export function mark_disparity(local_id) {
const state = get_message_state(local_id);
if (!state) {
return;
}
state.mark_disparity();
};
}
exports.report_event_received = function (local_id) {
const state = exports.get_message_state(local_id);
export function report_event_received(local_id) {
const state = get_message_state(local_id);
if (!state) {
return;
}
state.report_event_received();
};
}
exports.start_resend = function (local_id) {
const state = exports.get_message_state(local_id);
export function start_resend(local_id) {
const state = get_message_state(local_id);
if (!state) {
return;
}
state.start_resend();
};
}
exports.report_server_ack = function (local_id) {
const state = exports.get_message_state(local_id);
export function report_server_ack(local_id) {
const state = get_message_state(local_id);
if (!state) {
return;
}
state.report_server_ack();
};
}
exports.initialize = function () {
exports.reset_id_state();
};
window.sent_messages = exports;
export function initialize() {
reset_id_state();
}

View File

@@ -6,6 +6,7 @@ const channel = require("./channel");
const echo = require("./echo");
const reload = require("./reload");
const reload_state = require("./reload_state");
const sent_messages = require("./sent_messages");
const server_events_dispatch = require("./server_events_dispatch");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html

View File

@@ -4,6 +4,7 @@ const channel = require("./channel");
const people = require("./people");
const reload = require("./reload");
const reload_state = require("./reload_state");
const sent_messages = require("./sent_messages");
exports.send_message = function (request, on_success, error) {
channel.post({

View File

@@ -24,6 +24,7 @@ const pm_conversations = require("./pm_conversations");
const pm_list = require("./pm_list");
const reload = require("./reload");
const rows = require("./rows");
const sent_messages = require("./sent_messages");
const spoilers = require("./spoilers");
const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");