Commit Graph

628 Commits

Author SHA1 Message Date
Steve Howell 1cd113db10 Move message_viewport_info() from ui.js to viewport.js
The message_viewport_info() function encapsulates our logic
around the compose box and other elements blocking the viewport,
so viewport.js seems like a more logical home for it.  It also
makes ui.js, one of our largest modules, a little bit smaller.

(imported from commit 7838668b28175e161b87a6d7a8124b73012f0ff3)
2013-06-06 11:59:45 -04:00
Steve Howell 5a826040d8 Clean up code for unread counts and notifications.
The core simplification here is that zephyr.js no longer has:

  * the global home_unread_messages
  * the function unread_in_current_view() [which used the global]

The logic that used to be in zephyr is now in its proper home
of unread.js, which has these changes:

  * the structure returned from unread.get_counts() includes
    a new member called unread_in_current_view
  * there's a helper function unread.num_unread_current_messages()

Deprecating zephyr.unread_in_current_view() affected two callers:

 * notifications.update_title_count()
 * notifications_bar.update()

The above functions used to call back to zephyr to get counts, but
there was no nice way to enforce that they were getting counts
at the right time in the code flow, because they depended on
functions like process_visible_unread_messages() to orchestrate
updating internal unread counts before pushing out counts to the DOM.

Now both of those function take a parameter with the unread count,
and we then had to change all of their callers appropriately. This
went hand in hand with another goal, which is that we want all the
unread-counts logic to funnel though basically one place, which
is zephyr.update_unread_counts().  So now that function always
calls notifications_bar.update() [NEW] as well as calling into
the modules unread.js, stream_list.js, and notifications.js [OLD].

Adding the call to notifications_bar.update() in update_unread_counts()
made it so that some other places in the code no longer needed to call
notifications_bar.update(), so you'll see some lines of code
removed.  There are also cases where notifications.update_title_count()
was called redundantly, since the callers were already reaching
update_unread_counts() via other calls.

Finally, in ui.resizehandler, you'll see a simple case where the call
to notifications_bar.update() is preceded by an explicit call
to unread.get_counts().

(imported from commit ce84b9c8076c1f9bb20a61209913f0cb0dae098c)
2013-06-05 17:47:34 -04:00
Steve Howell 8be0ea972a Cosmetic: move function up in file.
This just moves keep_pointer_in_view() to be adjacent to recenter_view()
in the file.

(imported from commit 27056e2a949ffef262ac21130436f7303fd2935f)
2013-06-05 13:50:02 -04:00
Steve Howell 042cd8f222 Handle large/gigantic messages when recentering.
(imported from commit d57e702f504a9a3e6b7049a19217671902df4ab7)
2013-06-05 13:50:01 -04:00
Steve Howell 4c8a293750 Scroll more like barnowl again. (but closer to the edges)
We are moving back to a barnowl-ish scrolling algorithm for
the arrow keys, where when you have a message selected toward
the bottom of the screen, hitting down arrow and up arrow
effectively puts the originally selected message at the center
of the screen.  In order to avoid unnecessary scrolls, we
are making it so that you can move the pointer closer to the
edges.

(imported from commit c08233d6d2034a04469b8f424b39d94a230cafe0)
2013-06-05 13:50:01 -04:00
Zev Benjamin d95ea89f54 Fix a "can't read property 'id' of undefined" user error
`current_msg_list.get(id)` and `rows.get(id,
current_msg_list.table_name)` are not interchangable in terms of
checking for whether we have a message.  The former checks whether
the message is in the current message list while the latter checks
whether the message is in the current message list and currently
rendered.  `message_edit.end` only operates on rendered messages.

(imported from commit 203ee612bfd0aa94571dde9b601e948b3c6f6cbb)
2013-06-04 15:39:51 -04:00
Zev Benjamin 6bd61f458d Don't throw an exception if someone edits a very old message
Previously, if you didn't have a message that someone else had edited
in your message list, you would get an exception because we weren't
checking whether we actually had the message or not.

(imported from commit 33a5c6e7fe95b5397a32df5c7b5f6714d71e1e5f)
2013-06-04 15:38:42 -04:00
Steve Howell 3ee4161ace Allow pointer in more places.
Before this fix, the code would restrict the pointer to be above
either the 1/2 mark or 2/3 mark of the page, depending on your
scrolling direction.  This fix makes it so that the system leaves
your scroll and pointer alone when between the 1/5 mark and 4/5
mark.  This means the user can read more messages on the screen
at a time before getting paginated.

(imported from commit 98f6319bf63181dd331e037ac20a0c15518725ea)
2013-06-03 11:04:01 -04:00
acrefoot 6ae117ea5f Re-focus on the compose box after a send, auto-move cursor
Re-focuses on the compose box after a send, under these conditions:
1) narrowed to stream+subject -or- responding to PM/huddle
2) compose was initiated by clicking on a message or hitting "r"/"enter"
3) cursor has not moved since you've started the composition

Additionally, if you are thus narrowed, we will move your cursor when you've sent
a message to that message, assuming that such a message initially appears visible.

(imported from commit 373c858081694e6fc9994639340a847d66edb566)
2013-05-31 13:43:05 -04:00
Steve Howell 66b93d5cfd Fix barnowl style scrolling w/r/t fixed elements.
This change fixes the barnowl scrolling so that the ratios of
1/5, 1/2, and 2/3 are all relative to the visible viewport.

The core part of the fix is that we need to call
ui.message_viewport_info() to get the correct offsets for
the top/height of the actually visible viewport  Because
this function is fairly expensive, I didn't want the
helper functions needlessly re-calling it.  I could
have passed the helper functions the structure, but at
that point it was simpler to inline their functionality.

(imported from commit fb10d99313d568e85acfa70703c4651466acbc21)
2013-05-31 12:51:50 -04:00
Leo Franchi 56af48cd50 Split wildcard mentions from personal mentions, only email on personals
(imported from commit 18971d9e40dd2c93ef9c30edc963da33e3c65309)
2013-05-31 12:24:31 -04:00
Steve Howell 3f1b3af002 Add "Mentioning messages" to the upper left sidebar.
Treat "mentioned" messages like "starred" messages for narrowing.

Lots of ugly copy/paste here.  There might be opportunity for
some cleanup in places.

(imported from commit e7629890d42643c0000e1cc85422b2a0690f2cc4)
2013-05-30 14:45:01 -04:00
Keegan McAllister 371d0dbaa0 Identify app.js source map using a special comment
If we're going to minify third party code, the size heuristic may not hold
anymore.

(imported from commit 78ada1fee1446e78b3b1ad299ee3e975d1cd9002)
2013-05-30 13:51:46 -04:00
acrefoot c58ac9cc0c Re-focus on the compose box after a send
Re-focuses on the compose box after a send, but only if
the compose-box was opened by responding to the message
at the cursor (by hitting "r", enter, or clicking on the message)

(imported from commit 8e7560c8ea31397b57b2bc3e2e7d9dd996226a6f)
2013-05-29 13:07:45 -04:00
Steve Howell b3cb196452 Stabilize pointer after reply-to clicks..
The reply-to autoscroll was using a flag that was redundant
to suppress_scroll_pointer_update and then updating it prematurely,
which caused the pointer to move when you clicked on a message to
reply to it.  Now the pointer goes to the message you replied to.

(imported from commit e2f49fd6bd0da9a3f4b58c0eb08192ef0ee9abf0)
2013-05-29 10:11:39 -04:00
Steve Howell 975b984aee Slow down pointer adjustments at the bottom of the messages.
The main point of this fix is to move some more scroll-related code
into viewport.js, but it also fixes a bug where the size of #main_div
was not accurately representing the full height of the message list.
Making the calculation more accurate narrows the window where we
do pointer adjustements on mousewheel moves.

(imported from commit 5d821f459284c4dbd5ff8056001e54caf4355f1d)
2013-05-28 17:23:22 -04:00
Leo Franchi b548538a98 [manual] Send UserMessage flags in get_events updates
This commit must be deployed in a separate step from the previous [manual]
commit

(imported from commit c6f00e217062790fce8380f61f82ea8824fb3722)
2013-05-24 21:23:58 -04:00
Tim Abbott 8479b4f0cd [schema] Record and display whether a message was edited.
We also record the historical edits to the message in this JSON format:

 [{"prev_content": "new test message 14", "timestamp": 1369157249},
  {"prev_content": "new test message 13", "timestamp": 1369157118}]

but we don't actually do anything with the information as of yet.

(imported from commit 2d5ca449b87b33ad035ab0e076a22e150c8e7267)
2013-05-24 21:23:55 -04:00
Leo Franchi de8f43fec1 Add all unknown people to people_dict, even if they have only been PMed with
(imported from commit 01ca442127d5289a2cdfa5e9630aa928bea0b6eb)
2013-05-23 10:39:47 -04:00
Leo Franchi 3be1acebaa Use canonicalized names when processing unread counts
(imported from commit 9a4a1d48221f10489a9dcf3ab2532b73b0c26e4e)
2013-05-23 09:56:43 -04:00
Leo Franchi c12fd08050 Use same canonicalization for stream names when calculating recent subjects
(imported from commit d934f67cb469728162b8ae48b5fc63805bf18d8f)
2013-05-23 09:56:43 -04:00
Tim Abbott a34d640eb3 Rename message_edit.cancel to message_edit.end.
(imported from commit 5c720100afbf1e86c09eb2567f465c42353f95ec)
2013-05-22 13:04:37 -04:00
Tim Abbott e68c6bb1da Fix race where message editing might be cancelled after rerendering.
(imported from commit 989f1eace526d351cdbd9e15de594964de09a770)
2013-05-22 13:04:32 -04:00
Zev Benjamin c60a500a8f Track what user action triggered a compose
(imported from commit 3e23dd1f7e9e3a742b0c3b9e1b0eeb85cfa4c736)
2013-05-21 17:56:49 -04:00
Jessica McKellar 8609c59781 Only show edit subject hint on messages you sent.
(imported from commit 613a023bf22b07f879864690142e9d5e0a56f0ef)
2013-05-21 14:19:56 -04:00
Jessica McKellar a6a3110bfb Encourage users to edit placeholder subjects with an edit icon.
(imported from commit 0bfe67876b237ea2fb4f523b23b9cdbbd9a4027a)
2013-05-21 11:04:56 -04:00
Steve Howell 62d6360a48 Extracted model code out to unread.js.
Most of the model logic pertaining to unread counts had been in
zephyr.js, along with a couple global variables.  Now the code
is encapsulated in unread.js.  It was a pretty straightforward
extraction with some minor method name changes.  Also, a small
bit of the logic had also been in stream_list.js.

Conflicts:
	tools/jslint/check-all.js

(imported from commit f0abdd48f26ab20c5beaef203479eb5a70dacfff)
2013-05-20 23:42:11 -04:00
Tim Abbott d467a93877 Add support for updating messages after they've been received.
Currently the interface for editing messages is limited to a
command-line API tool; it's great for testing with e.g.:

./api/examples/edit-message --message=348135 --content="test $(date +%s)" --site=http://localhost:9991 --subject="test"

The next commit will add a user interface for actually doing the editing.

(imported from commit bdd408cec2946f31c2292e44f724f96ed5938791)
2013-05-20 23:40:26 -04:00
Steve Howell c2104e36c9 Fix geometry calculation for visible unread messages.
(imported from commit 91e5a6b83919c4cd935ea5e7586d84cc7a559cf6)
2013-05-20 23:37:57 -04:00
Steve Howell 69977ce825 Fix unread count in favicon when focusing window.
This fixes a pretty subtle bug where the window-focus handler
wasn't updating the unread counts in the title, but it was
hard to notice, because as soon as you moved the mouse, the
problem fixed itself.

Apart from fixing the bug, this patch eliminates the expensive
mouseover handler, which is a big win.

The fix to the window-focus involved some unrelated cleanup.  I
decoupled update_title_count() from received_messages(), as the
former method will probably live somewhere else soon.

Also, in order to get window-focus to update the title count,
I went pretty deep in the stack and added a call to
update_title_count() inside of update_unread_counts().  This
fixes window-focus as well as restoring that behavior to
code paths that were calling received_messages().

You'll see that call to update_title_count() is now adjacent
to the call to update_dom_with_unread_counts(), which is
fairly sensible, but then are calls to similar methods like
notifications.received_messages() that happen higher up in
the call chain, which seems kind of inconsistent to me.  I
also don't like the fact that you have to go through a
mostly model-based function to get to view-based stuff, so
there are some refactorings coming.

(imported from commit 2261450f205f1aa81d30194b371a1c5ac6a7bdec)
2013-05-20 23:29:56 -04:00
Tim Abbott 1df794efdc Don't use all_msg_list to memoize add_message_metadata.
The problem is that if you load a browser window in a stream narrow,
add_message_metadata will be called for the messages in the narrowed
view before it is called for the messages going into the main view
(thus inserting them into all_msg_list), resulting in duplicate
copies of messages.

This would be mostly OK except that we call
process_message_for_recent_subjects inside add_message_metadata, and
that function assumes it is only called once on each message
(otherwise it'll double-count the message).

(imported from commit a3e7f85874100cd93a6d07684605da04d9cc80c7)
2013-05-20 23:29:53 -04:00
Steve Howell 64fffc5b23 Account for navbar/composebox/etc. in determining visible messages.
Created a function message_viewport_info() to return more accurate
effective viewport info and called it from process_visible_unread_messages().
Also killed off a tiny bit of dead code in process_visible_unread_messages().

(imported from commit 985fcf2fb447dbf1026e2de37574c255a9bd6196)
2013-05-20 23:29:53 -04:00
Steve Howell 763782a6f0 Isolate stream_list.js's DOM manipulation when updating unread counts.
This refactoring basically splits off two functions from update_unread_counts(),
which then becomes a simple three-liner.

The function get_unread_counts() is extracted, and it's purely functional
computation.  It paves the way for a more pull-based approach to getting "unread"
counts, where other parts of the program can just call it to get values as
needed without worrying about side effects.  It is staying in zephyr.js for
now.

The other function is stream_list.update_dom_with_unread_counts(), which
has a new home in stream_list.js.  It handles all the DOM manipulation
aspect of unread counts in the left pane, mostly by delegating to smaller
functions within stream_list.  Some of those smaller functions can now
be turned into private methods FWIW, but I'm not sure it's worth the
trouble.

(imported from commit 799f9ebbaed8d530829a4741ef14be04bd8abf5a)
2013-05-14 15:21:27 -04:00
Steve Howell f024a7ab14 Call process_loaded_for_unread() more directly.
This is a prefactoring to eventually eliminate the home_unread_messages
global variable.  More commits to follow.

In order to set up process_loaded_for_unread() not to modify
global variable to get its job done, we want to pull it out of
add_messages(), so that add_messages() doesn't have to pass back
state to the 9 different places in the codebase where it's called.
There are only 2 places where process_loaded_for_unread() get
called after this commit.

In order to facilitate pulling up process_loaded_for_unread(), I
made it so that the contract for add_messages() was to accept
already-hydrated messages.  This way I could hydrate the messages
before calling process_loaded_for_unread() without have to
worry about double-caching them in add_messages.  This will
slightly improve performance, but it was mostly done for code
clarity.

(imported from commit ad5aaad5b1f22c31647370f4c9dcb5f89d7d99a7)
2013-05-14 15:21:27 -04:00
Tim Abbott a4c5c24029 Use the event system to sync onboarding steps across browser tabs.
(imported from commit 29311390133aca8f3a3d79fbe06dbbcabc4fb6ea)
2013-05-14 10:27:40 -04:00
Tim Abbott f87e62a8f3 Show unread counts for the home view in the left sidebar.
(imported from commit e56da93c45dff30ae150b0da676bab2278d25718)
2013-05-13 11:58:58 -04:00
Tim Abbott 14feac48e7 All PMs are in the home view.
(imported from commit c5e1a06fe39322f6065f2e56ef00b5f2f0e8aaf0)
2013-05-13 11:58:58 -04:00
Tim Abbott 8f29a39991 Remove the newer_than_pointer_count hack in unread accounting.
This was a workaround for a number of other bugs we had, but at this
point just serves to make debugging more difficult.

(imported from commit 6662b7854c265bd8016f6c8ce75a095731211a45)
2013-05-13 11:58:58 -04:00
Tim Abbott b7e682b157 Fix home view unread counts being 1 lower than they should be.
(imported from commit c9f9a623e862eaf9cb38626318df855ef7bad993)
2013-05-13 11:58:58 -04:00
Tim Abbott 91f8768fb7 Fix private message unread counts never displaying.
(imported from commit fda193ceba36dba2cd7b0694e15d1b927365dc26)
2013-05-13 11:58:58 -04:00
Jessica McKellar c7555c6cf9 Add support for completely collapsing messages through the info popover.
(imported from commit 0a01c4cc8f99019233659c175d73826e16cc95ee)
2013-05-10 18:00:57 -04:00
Leo Franchi 1267ffe542 Show unread counts next to expanded subject names
(imported from commit 6de1145cdec8d7e68395c1f9a7a95cd59136d805)
2013-05-09 10:41:32 -04:00
Tim Abbott 8d6551e37d Send notifications when a message appears offscreen even if focused.
Previously we never sent desktop notifications when the browser was
focused, even if the message appeared offscreen.  After this commit
there are only a few cases when PM or other notifiable message doesn't
trigger a desktop notification:

(1) You sent it yourself
(2) It was onscreen when it arrived while your Humbug window had focus

(imported from commit e381c02c0e6794594d6934f57249a11ba2a88210)
2013-05-09 10:35:49 -04:00
Zev Benjamin 1b5fb31b2c Make viewport a module that caches height and width values
The .height() and .width() functions are actually pretty expensive for
the number of times we call them.  The viewport height and width
don't change often, though, so we can just cache them and recalculate
them on window resize.

(imported from commit 129fb8c058144125e2974f6b7967cd9f1a5c9ead)
2013-05-09 10:35:47 -04:00
Zev Benjamin 4de79cf723 Make within_viewport take the row offset and row height
The .height() and .width() functions are actually pretty expensive
for the number of times we call them.  The callers of within_viewport
already know the offset and height of the row, so we just pass them
in so the values don't have to be recalculated.

(imported from commit d1c077bd87463d695f0bbe337b6a8b04ac2d17ce)
2013-05-09 10:35:47 -04:00
Zev Benjamin 7becd3e504 Move stream sidebar functions to their own module
(imported from commit 50771c1590eb3a0dbb151bf6a798bd14a4418857)
2013-05-09 10:35:46 -04:00
Zev Benjamin 26ea7e0897 Build the recent subjects list on demand
We previously kept the lists in the DOM for all streams and updated
them all when new messages arrived.  This was very expensive for
large numbers of streams, so we now just build the subject lists on
demand.

(imported from commit 937ad4322ce2014200aeae8645f79875f6af576e)
2013-05-07 11:47:13 -04:00
Zev Benjamin beba14a86c Only call add_message_metadata once when receiving messages in a narrowed view
We memoize add_message_metadata by checking if the message is already
in the all_msg_list.  Therefore, we need to add messages to that
message list before we add it to the narrowed_msg_list.

(imported from commit 4346179376ef6f982162c02c6152a0d294bfb2c0)
2013-05-07 11:47:12 -04:00
Leo Franchi 57d5bcf1f8 Only update unread counts if you're subscribed to that stream
(imported from commit 100047ad6ca1818cdf1c19dfafd0b2e06d95e380)
2013-05-06 13:52:30 -04:00
Leo Franchi 0da2f51ddb Calculate presence information with delta between server timestamp
(imported from commit b4b367ed620878e6d01287cb1aaae0730c7475c8)
2013-05-06 13:52:23 -04:00