Commit Graph

111 Commits

Author SHA1 Message Date
Anders Kaseorg 055ebe76aa pointer.js: Add setter for furthest_read.
After migration to an ES6 module, `furthest_read` would no longer be
mutable from outside the module.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-07-08 21:22:54 -07:00
Steve Howell bca38200a8 message_store: Add an `each` helper.
This new helper allows us to do the same operation
on every message in our message_store.  We will
use this in a future commit to clear the `is_tall`
flags on all messages, after a resize.

We should be somewhat cautious about using this,
but simple operations should be really fast, even
if you have lots of messages in the store.
2019-02-25 21:12:07 +00:00
Steve Howell 37c78abe14 frontend: Use topic on message.
This seems like a small change (apart from all the
test changes), but it fundamentally changes how
the app finds "topic" on message objects.  Now
all code that used to set "subject" now sets "topic"
on message-like objects.  We convert incoming messages
to have topic, and we write to "topic" all the way up
to hitting the server (which now accepts "topic" on
incoming endpoints).

We fall back to subject as needed, but the code will
emit a warning that should be heeded--the "subject"
field is prone to becoming stale for things like
topic changes.
2019-01-07 19:20:56 -08:00
Steve Howell 1ad30c6858 subject -> topic: Sweep "message.subject" in frontend.
These were the last remaining files.  After this, only
util.js has a non-email-related use of "subject".
2019-01-01 20:49:38 -08:00
Steve Howell 8121d19122 minor: Change "subject" to "topic" in comments. 2018-12-29 11:38:39 -08:00
Steve Howell 55362263dd Isolate/eliminate uses of "match_subject". 2018-11-16 11:05:43 -08:00
Steve Howell 520e85b866 Use topic_data.js for topic typeaheads.
This replaces some old code with calls to topic_data.js.

Now our topic typeahead uses the same data as our
sidebar, stream suggestions, and the "n" key, so any
future improvements to that data will benefit all
features the same.

This is an important piece of #9857.
2018-07-23 16:08:24 -07:00
Armaan Ahluwalia 6d255efe4c app: Prepare JS files for consumption by webpack.
This commit prepares the frontend code to be consumed by webpack.

It is a hack: In theory, modules should be declaring and importing the
modules they depend on and the globals they expose directly.

However, that requires significant per-module work, which we don't
really want to block moving our toolchain to webpack on.

So we expose the modules by setting window.varName = varName; as
needed in the js files.
2018-07-05 10:53:36 +02:00
Tim Abbott 063d11b139 js: Standardize indentation of switch/case statements.
This gets my current draft eslint indentation configuration passing
cleaning on static/js.
2018-05-06 19:35:18 -07:00
Steve Howell 4f52e095e8 refactor: Extract pm_conversations.recent.
This is a pretty pure code move, where we moved stuff from
message_store to pm_conversations:

    insert_recent_private_message() -> recent.insert()
    recent_private_messages -> recent.get()

The object message_store.recent_private_messages was not
encapsulated in a function before this change.  Now it is
hidden in the scope of pm_conversations.recent.

Both of the modules touched here maintain 100% line coverage.
2018-02-12 09:34:59 -08:00
Steve Howell 204949396c refactor: Delete deprecated message.flags attribute.
Once we convert message.flags to more specific boolean attributes
like message.mentioned and message.alerted, we should get rid of
the `flags` attribute, as it will only confuse debugging.
2017-12-26 09:01:21 -05:00
Steve Howell 0a3d769911 local echo: Bypass message.flags array.
We no longer set message.flags in the local echo path.

In the markdown parsing step, we just set message.mentioned
directly.

And then we change `insert_new_messages` to no longer
convert flags to booleans, and move that code to only
happen for incoming server message events.
2017-12-26 09:01:21 -05:00
Steve Howell 4d8d17d134 refactor: Upstream calls to `set_message_booleans`.
We want to call `set_message_booleans` as soon as we
get data from the server, to avoid confusion about whether
`flags` is the authoritative field.

This commit has callers to `add_message_metadata` call
`set_message_booleans`.

This also sets us up to **not** call `set_message_booleans`
in the local echo codepath, where we can just have the
markdown processor set booleans natively.
2017-12-26 09:01:21 -05:00
Steve Howell e96b3ffc5a refactor: Remove flags parm in set_message_booleans.
In all cases the value of `flags` we were passing in was
actually `message.flags` (although it was slightly obscured in
one place), so now we just pass in `message`.

(We also move a tiny bit of defensive code to set `flags`
into `set_message_booleans`.)
2017-12-26 09:01:21 -05:00
Steve Howell 294a1fb8f8 refactor: Extract people.maybe_incr_recipient_count().
This logic used to be in extract_people_from_message(), but
we are deprecating extract_people_from_message(), whereas
the maybe_incr_recipient_count() function has logic that we
want to keep.
2017-11-07 09:51:10 -08:00
Tim Abbott 133f005530 markdown: Remove is_me_message UserMessage flags.
This never made sense to be a flag on the UserMessage table, since
it's not per-user state.  And in fact it doesn't need to be in a
database at all, since it's easily computed from content anyway.

Fixes #1099.
2017-08-27 09:34:24 -07:00
Tim Abbott 74c628b105 editing: Fix live update of ability to edit messages.
Previously, we didn't check the organization-level settings when
rendering a message list; instead, we only checked it when putting
messages into the message_store.  That resulted in the state being
stale in the event that the setting controlling whether one can edit
messages was changed.

We remove some node tests, because revidving the node test for their
new home in message_list_view would be more work than we probably want
to do with an upcoming release.  We basically need to be better about
exporting functions like populate_group_from_message_container and
set_topic_edit_properties, so we can do fine grained testing.

When we get around to the node tests, rather than exporting these
functions, it might make sense to create a new module with a name
like message_container.js, which would have all of these
last-second type of data manipulations on message objects.  This
would be nice to split out of message_list_view.js.  MLV is our
biggest module, and it's mostly cohesive, but it's real job
should be about assembling messages into a DOM list, which is
probably 80% of the code now.  The 20% that I'd want to consider
splitting out is actually closer in spirit to message_store.js.

Thanks to Steve Howell for helping with the node tests.
2017-08-23 12:03:35 -07:00
Steve Howell 187ec3a922 Set message.unread in set_message_booleans().
The sooner we make message.unread consistent with message.flags,
the better.
2017-08-04 13:31:26 -07:00
Steve Howell abe7f4cc40 Extract message_store.set_message_booleans().
We'll want to reuse this for message updates, and we'll eventually
want to bypass this for local echo.
2017-08-04 13:31:26 -07:00
Steve Howell 8a7397fef6 people.js: Explicitly sort user_ids numerically.
It's not always clear whether user_ids are strings or integers, so
we explicitly convert them to integers for sorting when creating
keys for PMs.

To keep the tests passing, this commit removes some unneeded
defensive code in message_store.js that only applies to contrived
test input.
2017-08-02 09:40:47 -07:00
Steve Howell a9e296db74 Remove topic_data.process_message().
We now call topic_data.add_message() and
topic_data.remove_message() when we get info about
incoming messages.  The old way of passing in a boolean
made the calling code hard to read and added unncessary
conditional logic to the codepath.

We also have vague plans to change how we handle
removing topics, since increment/decrement logic is now
kind of fragile, so making the "remove" path more explicit
prepares us to something smarter in the future, like just
figure out when the last topic has been removed by calling
a filter function or something outside of topic_data.js.

Another thing to note here is that the code changed here
in echo.js is dead code, since we've disabled
message editing for locally edited messages.  I considered
removing this code in a preparatory commit, but there's
other PR activity related to local echo that I don't want
to conflict with.

One nice aspect of removing process_message() is that
the new topic_data.js module does not refer to the legacy
field "subject" any more, nor do its node tests.
2017-07-27 14:26:22 -07:00
Steve Howell bc0761b22b Extract topic_data.js.
This new module tracks the recent topic names for any given
stream.

The code was pulled over almost verbatim from stream_data.js,
with minor renames to the function names.

We introduced a minor one-line function called stream_has_topics.
2017-07-27 14:26:22 -07:00
Steve Howell c256b1663e local echo: Extract message_store.reify_message_id().
We no longer do the message_store piece of reifying ids
via a trigger.  We now make an explicit call to an
ordinary function.

This has several benefits:
    - no more initialize() function
    - no more scary comments about garbage collection
    - the function has a real name now
    - the function is less indented
    - we can easily see when the message_store step happens
    - simpler node tests
    - simpler tracebacks (no jQuery cruft)
2017-07-21 11:38:25 -07:00
Cory Lynch e33b178054 message_store: Move initialization to ui_init.js. 2017-07-04 13:54:33 -07:00
Cory Lynch 55917b6761 message_store.js: Remove obsolete clear() function. 2017-06-20 06:24:27 -04:00
Akhil 64f2b51496 typeahead: Add pm_conversations module.
In pm_conversations.js, added function to make a user a PM partner and
another function to check if a user is a PM partner. A PM partner is
someone with whom the user has been in a PM with.
2017-06-01 08:05:37 +00:00
Akhil f04da3d52e typeahead: Add recent_senders module.
In recent_senders module, added a data structure to hold timestamps of
users' latest message in a topic. Also added a function to compare 2
users based on above timestamp. Added a function to process messages for
the data structure and a call in add_message_metadata. Also added node
tests for insertion of data into recent_senders.senders.
2017-06-01 08:05:37 +00:00
Steve Howell eae91eab08 Fix internals of message_store.get_pm_emails().
We now make sure we get the email based off the user ids
in message.display_recipient.
2017-04-17 20:36:59 -07:00
Steve Howell 31e7472cdb Fix quirk with message_store.get_pm_full_names().
After Iago changed his email, you would see strings like
"You and Iago, Cordelia," which was a consequence of looking up
Iago's full name using his old email.  Now we use user ids
internally for the lookup.
2017-04-17 20:36:59 -07:00
Steve Howell e9e1441217 Fix warnings related to email changes.
We now call people.pm_reply_user_string to populate
message.to_user_ids.  The old way of computing this used emails
instead of user ids, so if an email wasn't known, you'd get a
warning.
2017-04-17 20:36:59 -07:00
Steve Howell f06bd41586 Fix PM list sort ordering during scrollback situations.
Before this fix, if you scrolled back in your PM history for a
person that you've had recent conversations with, then we would
backdate the record of their most recent conversation, and this
would make the sort ordering under the "Private messages"
section incorrect.

This commit fixes this error by re-writing the function
message_store.insert_recent_private_message() to check any
prior timestamps for that user.  It also optimizes the function
a bit to short-circuit in O(1) time for cases where a recipient
already has a more recent timestamp, by having a Dict keyed
on user_ids_string.
2017-04-13 12:13:20 -07:00
Steve Howell f5550301cf Extract message_store.insert_recent_private_message().
This function is slightly easier to unit test, and it isolates us
from changing message formats.  This removes some extraneous
code that would ensure that message timestamps were >= 0 that
probaby dates back to some really old migrations.
2017-04-13 12:13:20 -07:00
Steve Howell fd856d728c Extract message_util.js 2017-03-19 21:03:45 -07:00
Steve Howell 8d3d70984d Extract message_events.js. 2017-03-19 21:03:45 -07:00
Steve Howell 1114c8bf62 Extract message_fetch.js. 2017-03-19 21:03:45 -07:00
Steve Howell a51caceea5 refactor: Extract unread_ops.js
This module mostly contains the mark_* functions that
update the server with info about unread counts.
2017-03-18 10:35:52 -07:00
Steve Howell 4ae81d9063 Populate message.to_user_ids in message_store.js. 2017-02-26 16:18:02 -08:00
Kartik Maji 0cf6c292d8 Add edit_history of message in update_messages.
Modified by tabbott to not be confused by embed_links edits.
2017-02-19 17:20:48 -08:00
Elliott Jin 4092aab620 unread: Refactor to move DOM element updates into UI layer. 2017-02-11 08:36:39 -08:00
Steve Howell ffd45971de Use user ids when processing recent PMs. 2017-02-10 21:57:50 -08:00
Steve Howell 44f155e7b2 Generate message.pm_with_url more directly from ids.
We have added people.pm_with_url(message), which computes a
PM url from a private message using user ids rather than emails.

We call this in add_message_metadata(), since the slugs will
be valid even if emails change, so we don't need to compute
them on the fly during message rendering.
2017-02-07 17:37:05 -08:00
Steve Howell 0555970fae message_store: Populate sender_email based on people.js.
Messages that come to us from the server may have an out
of date sender email, so we use message.sender_id and
people.js to get the current email.
2017-02-06 22:38:22 -08:00
Steve Howell 373c8a0bb5 Live-update PM list for full-name changes.
We now trigger an event in user_events.js, and we dynamically
build the list of names in pm_list.js by calling out to
people.get_recipients().

We have a few variations of functions that build lists of names
for huddles, which should be cleaned up eventually.  They are
called at different times in the code path, so the different
functions, while doing mostly the same thing, start with different
data sources.
2017-01-30 11:49:19 -08:00
Steve Howell 2980a9e33d Use user's current full name in recipient bars.
This breaks the function
message_store.get_private_message_recipient into two functions:
get_pm_emails and get_pm_full_names.

The get_pm_emails function behaves the same way as the original
function, but get_pm_full_names now dynamically gets full names
from people.js using the user_id in the message.display_recipient
row.

This makes the recipient bar show the correct new name if you reload
your page.  It doesn't help with live updates.
2017-01-30 11:49:19 -08:00
Steve Howell a98cbff788 Use user's current full name when rendering messages.
The field message.sender_full_name can be out of date, so
we recompute is using data from people.js in
add_message_metadata().
2017-01-30 11:49:19 -08:00
Steve Howell 73125e2718 refactor: Move is_current_user() to people.js.
We no longer have it in util.js, because we will
want to encapsulate this better for upcoming commits
related to email changes.
2017-01-21 21:45:12 -08:00
Robert Hönig 89a64de986 De-dup "outside_viewport" notifications on different tabs.
Pass down 'local_id' through functions that handle notifications for messages
that are sent locally. If 'local_id' is undefined, the message was not sent in
the respective tab, so no "outside_viewport" notification should be displayed.
This fixes #1783.
2017-01-12 17:08:18 -08:00
Tim Abbott 998dff9e50 lint: Add dangling commas in JavaScript objects. 2017-01-11 15:23:42 -08:00
Arpith Siromoney 9c64a08cad Add frontend support for emoji reactions.
This commit replaces the placeholder "clipboard" button with a reaction button.
This is done on any message that can't be edited. Also, on messages sent by
the user the actions popover (toggled by the down chevron icon) contains
an option to add a reaction.

When clicked, a popover with a search bar and a list of emojis is displayed.
If the right sidebar is collapsed (the viewport is small), the popover is placed
to the left of the button.
Focus is set to the search bar. Typing in the search bar filters emojis.

Emojis with which the user has reacted to this message are highlighted.
Clicking them sends an API request to remove that reaction.
Clicking on non-highlighted emojis sends an API request to add a reaction.
When the popover loses focus it is closed.

The frontend listens for reaction events. When an add-reaction event is
received, the emoji is displayed at the bottom of the message with a
count initialized to 1. If there was an existing reaction to the message with
the same emoji, the count is incremented.

Old messages fetched from the server contain reactions.
They are displayed (along with title and count) at the bottom
of each message.

When clicking the emoji reaction at the bottom of the message, if the
user has already reacted with that emoji to this message, the reaction
is removed and the count is decremented. Otherwise, a reaction is added
and the count is incremented.

Hovering over the emoji reaction at the bottom of the message displays
a list of users who have reacted with this emoji along with the
emoji name.

Hovering over the emoji reactions at the bottom of the message displays
a button to add a reaction.

Fixes #541.
2016-12-30 21:42:54 -08:00
Bojidar Marinov 8876179ef7 message-edit: Always rerender home view after topic editing.
When editing a message changes the current narrow, we rerender the
narrowed view earlier in the function, so we don't need to do it here.
But we still need to rerender the home view, or the messages will be
displayed incorrectly once the user unnarrows!

Tweaked by tabbott for clarity and simplicity.

Fixes #2464.
2016-12-29 16:11:54 -08:00