Commit Graph

45 Commits

Author SHA1 Message Date
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
Luke Faraone a73e86cd9f Keep the desktop client updated as to the app's new message count.
(imported from commit c8deb2a773ee5c82f9d2decdced936f2f18dd4e0)
2013-06-03 13:10:25 -07:00
Luke Faraone c5d3ca0247 Send notifications over the JS→C++ bridge if it exists.
When determining if desktop notifications are enabled, we can check whether
there is a "window.bridge" element.

Now when it comes time to actually send out notifications, we can just test
again for the existence of "window.bridge" and if so, shunt the data over
it.

(imported from commit 8104c91ea9da7bc485c86a3c21edc88905d2f47b)
2013-06-03 13:10:18 -07: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
Leo Franchi 10501c08cc Remove client-side mention calculation as it's done server-side via message flags
(imported from commit 603aa8aef69d486a8acda953ec72cdeeb7476dd7)
2013-05-24 21:23:58 -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
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 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
Tim Abbott b1f75e8d3f Clean up notifications.received_messages.
This is trying to make the logic flow clear -- e.g. we check once, at
the beginning, for whether the message is notifiable, and the checks
for whether the various notification settings are enabled are more
parallel.

(imported from commit a68c71a53055191bc16682a85f739ed8e40ddeae)
2013-05-09 10:35:49 -04:00
Zev Benjamin 45ba7c41e7 Don't generate a new favicon if we don't have to
(imported from commit 30e88dfddbdcd2343ce53270fece767d924c48f0)
2013-05-09 10:35:47 -04:00
Luke Faraone 6bc2d21b87 Make audible notifications a tunable.
This decouples from Chrome notifications, which gives us cross-platform
support in at least modern browsers.

We log this action so its replayable in our message logs.

This implements the model change indicated by the previous schema commit.

(imported from commit b21213cdde54f43670bbb0bf1f607147fc732b38)
2013-05-03 15:08:49 -07:00
Luke Faraone 734b91c8d4 Play a sound when you recieve a desktop notification in the app.
We test if the user supports sound in their browser, then determine which
sort of sound their browser supports.

When, whenever we show a desktop notification we also play a sound.

(imported from commit dae41e70a6e4f6ed60ffedaac546d77baee52675)
2013-05-03 15:08:48 -07:00
Tim Abbott de5038f4d7 Store the recipient stream name in message.stream.
Previously we were using message.display_recipient everywhere, which
is actually pretty confusing.

(imported from commit a58471172e28c039af8e290362e54b6660543924)
2013-04-22 11:14:03 -04:00
Zev Benjamin f6a6a6b220 Add per-stream desktop notifications
(imported from commit b4a0576847b3aec1495f017ca9805febe80c9275)
2013-04-10 16:11:27 -04:00
Zev Benjamin 79d0e78130 Remove extraneous delete statement
The close handler will be called on cancel anyway, so we don't need
to delete in the click handler.

(imported from commit 0fcf4b0d1408312a0889f2b69e01207c9c3835fa)
2013-04-04 11:34:05 -04:00
Keegan McAllister 6d9aca5f1a Move "page parameters" (email, enter_sends, etc) into a single object
(imported from commit 842b2371bf6364982f1358f1cd2d91118c7fb2bf)
2013-03-26 13:50:03 -04:00
Leo Franchi 6263c9ba1e Unify calculation of unread-count for notifications and use it in the title bar
Fixes trac #1004

(imported from commit 6f04d1d3ded198b46cc2ff1733b94b5c17beb581)
2013-03-20 10:09:40 -04:00
Leo Franchi ff42774551 Refactor unread client handling to use 'read' flags per message
(imported from commit ca48745396e7fbac456e5eb2e7dbe4adc62b3492)
2013-03-13 14:14:45 -04:00
Luke Faraone 10b15640e9 Highlight messages which contain your name.
This was requested by CUSTOMER18 and CUSTOMER4.

Closes trac #705.

(imported from commit a25c6b7ca0ae3ba89c03779b19c4d6b0af93a014)
2013-03-12 18:01:16 -04:00
Jeff Arnold e9cbae67b3 Make clicking notifications give focus to browser
Resolves Trac #1081

(imported from commit d5546ecda53a57b6dbbfc65db923432f8e4cc7b2)
2013-03-12 16:03:42 -04:00
Leo Franchi 7374fe53f1 Only show the "More messages below" if unread messages are in the home view
(imported from commit 6b1ded10519305bca935b093a74b59d7ab814c55)
2013-03-01 14:35:39 -05:00
Waseem Daher d3ebe22a58 Allow Safari desktop notifications.
Apparently the Safari version of requestPermission wants to take
a callback function as an argument and gets unhappy when you
don't give it to them.

I learned this tip from http://www.inserthtml.com/2012/07/html5-app/

But more importantly, from the draft spec at
http://dev.chromium.org/developers/design-documents/desktop-notifications/api-specification
mentions that requestPermission takes a callback function that is
invoked once the user accepts.

(imported from commit c1d98239028ffce2e294568c5711315f985160a3)
2013-02-26 17:51:31 -05:00
Leo Franchi d08b8459ed Only show unread notifications in the title bar if a message is shown in the home view.
(imported from commit 795a6cb55d480c57e84ea5e17ef3afdc5d62d68b)
2013-02-22 17:05:36 -05:00
Keegan McAllister ddcf2cb86e Set favicon from our generated images rather than using Notificon
We've been noticing a long delay between switching to a window with unread
messages and the time that those messages actually appear.  This got much worse
around the time we added Notificon.

Our hypothesis (supported by some testing) is that the work done by Notificon
in creating a <canvas>, drawing into it, serializing it to PNG, etc. is using
up some quota of background operations that would be better spent rendering
messages.

Switching to precomputed images should mitigate this problem.

Resolves #896.

May resolve #882 to our satisfaction.

(imported from commit a2d98a163486bdd35fdfb5351f96c5529ba5c7e9)
2013-02-15 16:19:50 -05:00
Keegan McAllister c0054f6335 notifications: Remove duplicated code
(imported from commit 3b6fe986ed51a3698460b2e6f984df6f71cc5f6f)
2013-02-15 16:18:24 -05:00
Jessica McKellar b8ad7f235a Replace the pipe character between stream and subject with a '>'.
It helps to clarify the relationship between subjects and streams.

(imported from commit 53ed623f3875939c5b6f812de54ccbe616cdb1db)
2013-02-15 11:01:06 -05:00
Jeff Arnold 04d31a12eb Let's not call an expensive function on every mouse movement
(imported from commit 762e4f51210afcc3d394841ee0708dba09e4bc01)
2013-02-12 17:09:35 -05:00
Jeff Arnold d0f422979b Change the favicon on notification (great for pinned tabs)
(imported from commit 025ad165d15b2e6d979c246776148f13ebc555fb)
2013-02-12 16:27:07 -05:00
Jeff Arnold f93661e798 Make @**Jeff Arnold** only notify me, not every Jeff
(imported from commit 8e59eceebb4c5af298b0251c126b181cf5899d93)
2013-02-12 10:42:52 -05:00
Jeff Arnold 875e125fb9 Cause @all or @everyone to alert everyone
(imported from commit e2d1cd8b6ea4f2cbae82d052643a5b88e979931c)
2013-02-12 10:27:09 -05:00
Jeff Arnold e2f3a85dbd Clean up the notification code
(imported from commit 5bd811ba40b3f535d474ac53e22fd16816f9bac6)
2013-02-12 10:27:09 -05:00
Jeff Arnold bb19978397 Reset the new message count whenever the user mouses over the window
(imported from commit 5813398dbc59acc9f9e53c1e0631fc7d327de50d)
2013-01-21 15:54:02 -05:00
Jeff Arnold 621dbcaac0 Firefox on Ubuntu claims falsely to be able to do webkit notifications
(imported from commit d4778f38eaefc4fe95d93c6f3dcb5e43bbef5bb2)
2013-01-21 15:53:52 -05:00
Jeff Arnold 360737d928 Fix lowercasing issue with notifications for people with same name
(imported from commit 7f9c6f040c428af2c53929e4251861dea9361f2f)
2013-01-18 18:02:14 -05:00
Jeff Arnold 5b9cb1ebcd Fix notifications for users whose username is their first or last name
(imported from commit 66a58e81571f4eed3c840950bde63ef245ca4d48)
2013-01-18 17:02:17 -05:00
Jeff Arnold 279ded6072 Notify when we see our username or our name plus punctuation
(imported from commit 158c78de264ef31f61670694764d025a773ae840)
2013-01-11 13:00:34 -05:00
Jeff Arnold 97e8fb893b Fire a notification for an @name match anywhere in the msg content
(imported from commit 1b6932b1b1094af6f0de2346ca721805e264490d)
2013-01-10 13:44:06 -05:00
Jeff Arnold 5d5c490613 Disable speaking-at-me notifications for mit.edu
(imported from commit 194c5241311b46f26ecb0b2bb2201b1a7af7b520)
2013-01-09 23:05:02 -05:00
Jeff Arnold 7709e21a24 Notify the user when someone is speaking at them
(imported from commit 662ea67b2cf210bfd327ae2db6f924e4424d6d50)
2013-01-09 20:18:39 -05:00
Jeff Arnold dbb63cb524 Don't continuously bug user if they dismiss the notifications box
Fixes Trac #514

(imported from commit 445af7cf458118be0394491aebbd9996817b08a4)
2013-01-08 11:04:16 -05:00
Jeff Arnold d67e2cc4f3 Put the domain earlier in the titlebar, to help distinguish tabs
(imported from commit 225072a7cc044b011114a8630b02d74640b39d55)
2012-12-05 16:03:02 -05:00
Zev Benjamin 7e4776322d [manual] Unify huddles and personals into private messages on the receive path
feedback-bot and zephyr_mirror will need to be updated and restarted
when this is deployed to prod.

(imported from commit fe2b524424c174bcb1b717a851a5d3815fda3f69)
2012-12-04 18:01:51 -05:00
Jeff Arnold ed1eff9bfa Dismiss all notifications when the tab regains focus
(imported from commit 53c807d7a02aabe62a832a129505d690e98e39cc)
2012-11-27 13:39:46 -05:00
Jeff Arnold 2f882b505a Show "how many messages have arrived while away" in the document title
(imported from commit 6e2a18be9953694048d107a56a03a67f8bc2bd5a)
2012-11-27 13:39:46 -05:00
Jeff Arnold 4cb0c6225e Add webkit desktop notifications
Partially addresses Trac #31

(imported from commit f1f04b5c50bf9f33b69c90926fd67015cd2dc219)
2012-11-26 14:43:55 -05:00