Add explicit message field for locally_echoed.

We now set locally_echoed to true for messages that are
locally echoed, and we change some of our code to look
for this flag.
This commit is contained in:
Steve Howell
2017-07-17 10:52:57 -04:00
committed by Tim Abbott
parent fca158e387
commit 0e25055c1d
10 changed files with 23 additions and 17 deletions

View File

@@ -189,7 +189,7 @@ exports.check_form = function (form_selector, expected, test_name) {
exports.wait_for_message_actually_sent = function () {
casper.waitFor(function () {
return casper.evaluate(function () {
return current_msg_list.last().local_id === undefined;
return !current_msg_list.last().locally_echoed;
});
});
};

View File

@@ -27,7 +27,7 @@ casper.then(function () {
// wait for message to be sent
casper.waitFor(function () {
return casper.evaluate(function () {
return current_msg_list.last().local_id === undefined;
return !current_msg_list.last().locally_echoed;
});
});

View File

@@ -380,9 +380,10 @@ people.add(bob);
private_message_recipient: 'alice@example.com',
to_user_ids: '31',
local_id: 1,
locally_echoed: true,
};
assert.equal(payload.url, '/json/messages');
assert.equal(_.keys(payload.data).length, 11);
assert.equal(_.keys(payload.data).length, 12);
assert.deepEqual(payload.data, single_msg);
payload.data.id = stub_state.local_id_counter;
payload.success(payload.data);

View File

@@ -332,6 +332,8 @@ exports.send_message = function send_message(request) {
var locally_echoed = local_id !== undefined;
request.locally_echoed = locally_echoed;
function success(data) {
exports.send_message_success(local_id, data.id, start_time, locally_echoed);
}
@@ -339,7 +341,7 @@ exports.send_message = function send_message(request) {
function error(response) {
// If we're not local echo'ing messages, or if this message was not
// locally echoed, show error in compose box
if (request.local_id === undefined) {
if (!request.locally_echoed) {
compose_error(response, $('#new_message_content'));
return;
}

View File

@@ -94,6 +94,7 @@ function insert_local_message(message_request, local_id) {
message.avatar_url = page_params.avatar_url;
message.timestamp = new XDate().getTime() / 1000;
message.local_id = local_id;
message.locally_echoed = true;
message.id = message.local_id;
markdown.add_message_flags(message);
markdown.add_subject_links(message);
@@ -125,7 +126,7 @@ function insert_local_message(message_request, local_id) {
// It is a little bit funny to go through the message_events
// codepath, but it's sort of the idea behind local echo that
// we are simulating server events before they actually arrive.
message_events.insert_new_messages([message], local_id);
message_events.insert_new_messages([message], true);
return message.local_id;
}
@@ -180,7 +181,7 @@ exports.reify_message_id = function reify_message_id(local_id, server_id) {
}
message.id = server_id;
delete message.local_id;
message.locally_echoed = false;
var opts = {old_id: local_id, new_id: server_id};

View File

@@ -36,7 +36,7 @@ function get_editability(message, edit_limit_seconds_buffer) {
// Locally echoed messages are not editable, since the message hasn't
// finished being sent yet.
if (message.local_id !== undefined) {
if (message.locally_echoed) {
return editability_types.NO;
}
@@ -87,7 +87,7 @@ exports.save = function (row, from_topic_edited_only) {
}
// Editing a not-yet-acked message (because the original send attempt failed)
// just results in the in-memory message being changed
if (message.local_id !== undefined) {
if (message.locally_echoed) {
if (new_content !== message.raw_content || topic_changed) {
echo.edit_locally(message, new_content, topic_changed ? new_topic : undefined);
row = current_msg_list.get_row(message_id);
@@ -307,7 +307,7 @@ function edit_message(row, raw_content) {
edit_obj.scrolled_by = scroll_by;
message_viewport.scrollTop(message_viewport.scrollTop() + scroll_by);
if (feature_flags.propagate_topic_edits && message.local_id === undefined) {
if (feature_flags.propagate_topic_edits && !message.locally_echoed) {
var original_topic = message.subject;
message_edit_topic.keyup( function () {
var new_topic = message_edit_topic.val();

View File

@@ -54,7 +54,7 @@ function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
}
exports.insert_new_messages = function insert_new_messages(messages, local_id) {
exports.insert_new_messages = function insert_new_messages(messages, locally_echoed) {
messages = _.map(messages, message_store.add_message_metadata);
// You must add add messages to home_msg_list BEFORE
@@ -72,7 +72,7 @@ exports.insert_new_messages = function insert_new_messages(messages, local_id) {
}
if (local_id) {
if (locally_echoed) {
notifications.notify_local_mixes(messages);
}

View File

@@ -11,7 +11,7 @@ function batched_updater(flag, op, immediate) {
function server_request() {
// Wait for server IDs before sending flags
var real_msgs = _.filter(queue, function (msg) {
return msg.local_id === undefined;
return !msg.locally_echoed;
});
var real_msg_ids = _.map(real_msgs, function (msg) {
return msg.id;

View File

@@ -96,9 +96,11 @@ exports.initialize = function initialize() {
// Additionally, don't advance the pointer server-side
// if the selected message is local-only
if (event.msg_list === home_msg_list && page_params.narrow_stream === undefined) {
if (event.id > pointer.furthest_read &&
home_msg_list.get(event.id).local_id === undefined) {
pointer.furthest_read = event.id;
if (event.id > pointer.furthest_read) {
var msg = home_msg_list.get(event.id);
if (!msg.locally_echoed) {
pointer.furthest_read = event.id;
}
}
}

View File

@@ -1,5 +1,5 @@
<div zid="{{msg/id}}" id="{{table_name}}{{msg/id}}"
class="message_row{{^msg/is_stream}} private-message{{/msg/is_stream}}{{#include_sender}} include-sender{{/include_sender}}{{#contains_mention}} mention{{/contains_mention}}{{#include_footer}} last_message{{/include_footer}}{{#msg.unread}} unread{{/msg.unread}} {{#if msg.local_id}}local{{/if}} selectable_row">
class="message_row{{^msg/is_stream}} private-message{{/msg/is_stream}}{{#include_sender}} include-sender{{/include_sender}}{{#contains_mention}} mention{{/contains_mention}}{{#include_footer}} last_message{{/include_footer}}{{#msg.unread}} unread{{/msg.unread}} {{#if msg.locally_echoed}}local{{/if}} selectable_row">
<div class="unread_marker"><div class="unread-marker-fill"></div></div>
<div class="messagebox{{^include_sender}} prev_is_same_sender{{/include_sender}}{{^msg/is_stream}} private-message{{/msg/is_stream}} {{#if next_is_same_sender}}next_is_same_sender{{/if}}"
style="box-shadow: inset 2px 0px 0px 0px {{#if msg/is_stream}}{{background_color}}{{else}}#444444{{/if}}, -1px 0px 0px 0px {{#if msg/is_stream}}{{background_color}}{{else}}#444444{{/if}};">
@@ -34,7 +34,7 @@
{{/include_sender}}
</span>
<span class="alert-copied pull-right">{{t 'Copied!' }}</span>
<span class="message_time{{#if msg.local_id}} notvisible{{/if}}{{#if status_message}} status-time{{/if}}">{{timestr}}</span>
<span class="message_time{{#if msg.locally_echoed}} notvisible{{/if}}{{#if status_message}} status-time{{/if}}">{{timestr}}</span>
{{#if_and last_edit_timestr include_sender}}
{{#unless status_message}}
<div class="message_edit_notice" title="{{#tr this}}Edited (__last_edit_timestr__){{/tr}}">{{t "EDITED" }}</div>