Commit Graph

2892 Commits

Author SHA1 Message Date
Leo Franchi 5b2f4462fb Only count messages in home view when determining home_unread_count
(imported from commit 22a0a00bd242a4a12efc5dca723c13f7c9b47f2c)
2013-03-28 11:44:58 -04:00
Luke Faraone 85b4ffbf2e Change matching for client strings in /activity to use __startswith.
This way we can match prefixes, like "API: Foo".

(imported from commit 2acde88e31b4f2f4a418f3930975a5f3a4e9ef2d)
2013-03-28 08:11:37 -07:00
Luke Faraone 0d51e59fd5 Implement URLs for API redesign.
(imported from commit 2020491a737ec4c1e99a63f84eb6cfc594a2dd56)
2013-03-28 07:57:38 -07:00
Luke Faraone 09c9d92149 Refactor get_messages into the _backend pattern and add rest_ method.
(imported from commit 9b1ae464a882a6fa6da2a4cfd5a6543f5d2b3e51)
2013-03-28 07:57:36 -07:00
Luke Faraone 8bb944729d Switch get_old_messages to REQ and make the function signature uniform.
Previously user_profile was a kwarg, which was inconsistent with all other
_backend functions.

(imported from commit 6b857bcb2c3c978079af2f6edd367c1804d51988)
2013-03-28 07:53:39 -07:00
Luke Faraone 7eee9d4905 Implement generic REQ class which pulls from request.REQUEST.
This is to allow flexibility in functions that we think should be callable
via either GET or POST.

As part of this, POSTRequestMock was extended to populate the REQUEST
dict.

(imported from commit b9d32d2b65ff8a25885452992cf7dd37b9664246)
2013-03-28 07:53:39 -07:00
Luke Faraone 5d22ee9a76 Create update_subscriptions_backend to allow mass mutation of user subs.
This includes a process_patch_as_post decorator which enables this view
to be invoked as a PATCH on an object.

Hopefully this decorator can go away once POST values are correctly parsed
in Django for PATCH verb invocations.

(imported from commit 6cf9d69cfb9dea5354ea37408566146757b5be54)
2013-03-28 07:53:39 -07:00
Luke Faraone 08e379d23f Add method for retrieving the pointer only.
(imported from commit 2324d3c6cddca73dddca8a24dfa8d61d41236a54)
2013-03-28 07:53:38 -07:00
Luke Faraone a49c37917a Implement generic rest_dispatch method for new API.
(imported from commit 912ee803db03098f195d18648ab98401915fead6)
2013-03-28 07:53:38 -07:00
Luke Faraone 0c0f99ccc6 Split off json_stream_exists to the _backend pattern, rename paramater for consistency.
(imported from commit 61378e9abe716552f69cf11fc0f1fce61de0639c)
2013-03-28 07:53:37 -07:00
Luke Faraone 60075e596f stream_exists_backend now returns a 404 if the stream is not found.
Update tests and compose.js to handle the 404.

(imported from commit d9ba4fe59c34bd14d9198e3365a845888fa04f03)
2013-03-28 07:53:37 -07:00
Luke Faraone 825f59799a Switch foo_list_subscriptions to the backend pattern.
This slightly reduces code duplication and in the future the {api,json}_ methods
will hopefully go away, leaving only the _backend methods.

(imported from commit 82a6e4a2ff2ba5d272068e9ff043ea47a1a8d278)
2013-03-28 07:53:37 -07:00
Luke Faraone bfb741c9bb Factor out client extraction and API key validation from authenticated_api_view
(imported from commit b8e3fc2f956b4de07ea0fe9b6f596dd353013935)
2013-03-28 07:53:36 -07:00
Luke Faraone b63e5e3235 Refactor runtorando AsyncDjangoHandler URLs into a list.
(imported from commit f5c65f69dd2ccb5a0ba6339b28b8c486cde2c7ff)
2013-03-28 07:53:36 -07:00
Luke Faraone 2be8f80f47 Make request._client a public member, dropping the '_'.
(imported from commit 5fc7ab57157ceb40c8bca9b0c97a47d8fac6745b)
2013-03-28 07:53:36 -07:00
Luke Faraone 9519484c8f Remove 'client' paramater from update_user_activity
(imported from commit 906bf35c1b6d056170bdf3472146e38dabce53bb)
2013-03-28 07:53:35 -07:00
Luke Faraone b6ed350c55 Remove explicit "client" parameter from send_message_backend.
Instead we now rely on the request._client value, which we were previously
passing along to s_m_b in all but one case.

For that one case, we just modify the Request object to include the value
beforehand.

(imported from commit 542f38f94bc447149cd4d2efaa5e8f48f756725b)
2013-03-28 07:53:34 -07:00
Luke Faraone fc2a071314 Scroll subscription settings into view on click.
Addresses a complaint brought up in our usability study.

We now hook into the "show" event on .subscription_settings elements and
do some obnoxious math to move the scrollbar the way we want.

Closes trac #1015.

(imported from commit 5d9cee1ffc242eb7b743fdccd2bd76bf0a7ba060)
2013-03-28 07:50:49 -07:00
Tim Abbott 78f5c2e877 Use the update_fields option to Django ORM .save().
This can result in a significant performance benefit because we only
need to update the columns that changed..

(imported from commit 42bef1fcc58ad79bd864f89263fe82e90743ee5b)
2013-03-28 07:36:11 -04:00
Tim Abbott 7b968cd088 Revert "Revert "to_dict: Update rendered_content in the database after rendered.""
This reverts commit 745b4a98d0e3f67acaa207ba53e9250060dcfe06.

(imported from commit ea59de391b93b82b08c35d92620d7d8ae263f34d)
2013-03-28 07:36:10 -04:00
Tim Abbott a4383f8264 Remove batch_bulk_create helper function.
The behavior we require is now standard in Django 1.5.

(imported from commit 509adb0bd371081a2dad7d4a04d24fcffbda7cdc)
2013-03-28 07:36:10 -04:00
Tim Abbott e8aa77c9b4 Set timeouts for our memcached caches.
The policy this implements is:
* 1 week for most persistent data (Clients, etc.)
* 1 day for messages

(imported from commit d57bb2c6b9626ffa2155c6d0ef9b60827d1f2381)
2013-03-28 07:36:10 -04:00
Tim Abbott e2d010ef2d Fix most unnecessary database queries in huddle creation.
This saves 2 database queries per user in the huddle when sending the
first message to a particular huddle.

(imported from commit f71aa32df846fb4b82651a93ff9608087ffcaa5a)
2013-03-28 07:36:10 -04:00
Zev Benjamin 304899cd8a blueslip: Indicate whether users saw an error in the error emails
(imported from commit dd31976a3279df5ea5de2a0433387c82c8f80d41)
2013-03-27 21:53:58 -04:00
Zev Benjamin 4d30089220 blueslip: Only try to report a given error once every 5 minutes
This is in addition to only successfully reporting a given error once
per session.  Previously, if an error was triggered many times before
the ajax call to report the error returned, we'd end up making many
ajax requests to report the error.

(imported from commit 559179e3c8c3fbf03bbb091a67361d447c80b7bb)
2013-03-27 21:52:55 -04:00
Zev Benjamin d1b9ab9fd8 Move SERVER_GENERATION definition to settings.py
(imported from commit 4be2b912a63f49f525c66f46db0bc5c466ad364f)
2013-03-27 14:15:03 -04:00
Zev Benjamin 5b4536172c Allow @has_request_variables on functions that don't actually use it
(imported from commit 3cf6db06c16d3d107a0fc4b11fc8c0f0258fc306)
2013-03-27 14:15:03 -04:00
Zev Benjamin 203b0fcc25 Use json_to_bool instead of simplejson.loads
(imported from commit 0d045c606925379450215349a17d6fe04d3f1be9)
2013-03-27 14:15:03 -04:00
Zev Benjamin 2da4c0a4bf Remove extraneous SERVER_GENERATION definition
It looks like this was supposed to be moved in e0d9182c but was
copied, instead.

(imported from commit 094f43e9cfd4dde380a3d1ef79b1c273b54ce1a3)
2013-03-27 14:15:03 -04:00
Tim Abbott 4502e563d1 Reduce code duplication for coding filling memcached caches.
(imported from commit e7e053c6fa27fd7a1143696196e9ee974ec91c8f)
2013-03-27 12:59:24 -04:00
Tim Abbott 8fbc98601b Populate cache of Huddle objects on server restart.
(imported from commit 3214cfa70d0de01c42028a9d025f7607f609081b)
2013-03-27 12:59:24 -04:00
Tim Abbott 8b2cb6472b Cache the lookup of Huddle objects by hash.
This is used in the send_message code path.

(imported from commit 4d9a4d079fe5b10b94c11016e9ec8c5601addc2c)
2013-03-27 12:59:24 -04:00
Tim Abbott b2e76f50b9 Populate cache of Client objects on server restart.
(imported from commit 6d0ef309dadcd6c24fc9e17b0859becb053adccf)
2013-03-27 12:59:23 -04:00
Tim Abbott 36f09729e6 Run the memcached cache filling jobs in separate processes.
This will significantly improve the speed with which the memcached
caches are filled.

(imported from commit 445fec710a00b3d19b7962beddf89d4a75322eab)
2013-03-27 12:59:23 -04:00
Tim Abbott a774598a10 Populate cache of Recipient objects on server restart.
(imported from commit 752851c7c3ee565201dd59fb0455c82a8885d42d)
2013-03-27 12:59:23 -04:00
Tim Abbott cc065a3c90 Populate cache of Stream objects on server restart.
(imported from commit 131eeddc5ebe5cc0db2554514a730d2750078012)
2013-03-27 12:59:23 -04:00
Leo Franchi 79102044f4 Don't create a pika-connecting queue client if we have no RabbitMQ
(imported from commit 680e867abb61644cbc62a4280b4e47b03eb5abe7)
2013-03-27 11:06:10 -04:00
Tim Abbott 6fd4bf38c0 logs: Don't display database time when there were no queries.
(imported from commit 71297c920b63578ebc2770954345bfb9d4d8937f)
2013-03-27 08:19:27 -04:00
Tim Abbott 144987e581 logs: Provide total time passed for longpolled requests.
Also improve display of times passed -- we now use display short times
in milliseconds for easier reading.

(imported from commit 08e1e7e6acbef48453080864946f7602a3395e7c)
2013-03-27 08:19:27 -04:00
Tim Abbott 887389d16c logs: Output timestamps in milliseconds when less than a second.
(imported from commit 150038059a1d7c677004edf27d4af2e48bf41285)
2013-03-27 08:19:27 -04:00
Tim Abbott f3ad2d7a6b Centralize dispatch logic for which queue processor to use.
Previous we had around 4 copies of the logic for deciding whether we
should publish data via a SimpleQueueClient queue, a
TornadoQueueClient queue, or to directly handle the operation, which
resulted in their getting out of sync and buggy (see e.g. the previous
commit).

We need to add a lock around adding things to the queue to work around
a bug with pika's BlockingConnection.

I should note that the previous logic in some places had a bunch of
tests of the form "elif settings.TEST_SUITE" for doing the work that
would have been done by the queue processor directly; these should
have just been "else" clauses -- since we generally want that code to
run on development environments whether or not the test suite is
currently running.

(imported from commit 16bdbed4fff04b1bda6fde3b16bee7359917720b)
2013-03-27 08:19:27 -04:00
Tim Abbott 16574806f5 Don't initialize SimpleQueueClient inside Tornado.
Previously we had several files which initialized SimpleQueueClient()
for sending items to the UserActivity queue, even though those code
paths aren't used outside Tornado.  This resulted in slower Tornado
startup times.

(imported from commit ad97021ec18d3927233744037c548c22db33c321)
2013-03-27 08:19:27 -04:00
Tim Abbott 1df99937a9 Tornado: Fill the Tornado UserMessage cache using manual query.
The actual database query that we use to fill the UserMessage cache
only takes a few hundred milliseconds to run; however the process of
iterating through the results would take 3-5 seconds because the
Django ORM is not very efficient for small tables where we're only
interested in the integer values in a couple columns.

So we can save most of that Tornado startup time by just doing this
one query manually; I left the original query next to it in a comment
so it is easy to keep it all up to date as we change our product.

(imported from commit ac4675bcdda5d812ebfbe211450c85ee2787ee66)
2013-03-27 08:19:27 -04:00
Tim Abbott 4076704476 [django 1.5] models: Always return a string from __repr__() methods.
See http://bugs.python.org/issue5876 for an explanation for why this
is needed -- basically __repr__() needs to return a string, not a
unicode object in Python 2.

This causes problems on Django 1.5 because the more expressive
exception code in model.objects.get() will crash with a __repr__()
containing non-ascii unicode characters.

(imported from commit f44085e67d9d14629b821a29bbf65738f1794d6c)
2013-03-27 08:19:26 -04:00
Tim Abbott fde2243dbc [django 1.5] Update read flags handling to use new Django 1.5 syntax.
(imported from commit af1e2608b6d6d3677bf6266980d8dc77739aa4ba)
2013-03-27 08:19:26 -04:00
Leo Franchi dbb2157457 Make home view unread count only count messages newer than the pointer
(imported from commit 0f699ed23f59380b04606bd30600373956f89ae4)
2013-03-26 18:34:16 -04:00
Leo Franchi 9de2442bd9 Add infomation in JIRA integration in our integrations page
(imported from commit 2aef274c630cc918a6fde8fa33a4598ba8ee7f3f)
2013-03-26 14:14:47 -04:00
Jessica McKellar 297bc7f09b Don't hide the floating recipient bar when scrolling.
We made this change for performance reasons that don't exist now that
we only render a small portion of your messages, and it causes a
distracting flicker when you scroll through messages slowly.

(imported from commit 33379320f6b90d93ec8beac17323b287f8bb2485)
2013-03-26 14:06:27 -04:00
Jessica McKellar 9451451672 tutorial: streamline some sections, and bold user actions.
This may help with compliance.

(imported from commit 8ef250b07a0a1a7023bc74f89a46875c88fadef7)
2013-03-26 14:06:25 -04:00
Jessica McKellar 76dade3b6e tutorial: remove code formatting examples and just link to documentation.
Those examples make the tutorial feel much longer, and they aren't
relevant to people who aren't using Humbug to talk about code.

(imported from commit c3213775d26cf533b3d9bde691de08a53d427939)
2013-03-26 14:05:45 -04:00
Jessica McKellar 2fd56b3745 tutorial: de-emphasize that we don't auto-scroll.
It's not so black and white in a world where we auto-scroll at the
bottom, and we've observed that people trying Humbug over-focus on it.

(imported from commit 2057643f179d5d1666cb33438c5a513977197b37)
2013-03-26 14:05:45 -04:00
Jessica McKellar eaa2cc702e Autoscroll when you are at the bottom of your message feed.
(imported from commit 7ca92b13c874346f846aea8200a638a7914fe7d6)
2013-03-26 14:05:45 -04:00
Keegan McAllister 7309d57067 Output page_params as a single JSON object
This is a lot cleaner, and also cuts about 50-70 ms off of page load time in
local testing (with lots of users), presumably because there's less work to be
done by the slow Django template engine.

(imported from commit 257b700238ee5d9a4ae00a53011ed5bce018124c)
2013-03-26 13:51:21 -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
Keegan McAllister 38ebefe68f Remove unused variables
(imported from commit c18d43165c1dbdee28107ef21e26e474b819c653)
2013-03-26 13:50:03 -04:00
Jessica McKellar cc8ee68514 tests: assert that text objects are instances of basestring, since they might be str or unicode.
This fixes tests that have been failing for me for, well, months, that
I've been ignoring:

======================================================================
FAIL: test_successful_subscriptions_list (zephyr.tests.SubscriptionAPITest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jesstess/dev/humbug/zephyr/tests.py", line 631, in test_successful_subscriptions_list
    self.assertIsInstance(stream['name'], str)
AssertionError: u'Denmark' is not an instance of <type 'str'>

======================================================================
FAIL: test_get_stream_colors (zephyr.tests.SubscriptionPropertiesTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jesstess/dev/humbug/zephyr/tests.py", line 515, in test_get_stream_colors
    self.assertIsInstance(color,  str)
AssertionError: u'#c2c2c2' is not an instance of <type 'str'>

----------------------------------------------------------------------

The more comprehensive fix to this is going through both our API and
JSON calls and ensuring that we always return unicode objects,
documenting that, and then testing that more specifically. For now, at
least have passing tests.

(imported from commit ed1875ea1f66c1f1e89f80502c0d6abb323dc489)
2013-03-23 00:19:38 -04:00
Jessica McKellar 53ec385d0b create_user: ask for realm as part of user creation.
With open realms, you can't infer the realm from the e-mail address.

(imported from commit c05afa586f121a38673f9e62281cf26c8590570b)
2013-03-23 00:19:37 -04:00
Jessica McKellar f87ffd0703 create_user: fix missing spaces in options error message.
(imported from commit 25ea284b17dfb3160aca336e31203991f70994d8)
2013-03-23 00:19:37 -04:00
Jessica McKellar e5f1dad409 create_user: remove unused imports.
(imported from commit b2dd10f73fb0285c2c92ab56b1111cf9e859cedf)
2013-03-23 00:19:37 -04:00
Jessica McKellar ea11ce4ae6 create_user: Add Terms of Service warning.
(imported from commit bdb31aebad397e98db77d3ea95ef17ac9dd4737f)
2013-03-23 00:19:37 -04:00
Jessica McKellar 0c3382fabb Always give hashlib.sha1 and friends bytes.
This fixes an experienced bug where you couldn't subscribe to a stream
with non-ASCII characters (failing with a UnicodeEncodeError), as well
as many other potential bugs.

(imported from commit f084a4b4b597b85935655097a7b5a163811c4d71)
2013-03-23 00:10:10 -04:00
Jessica McKellar 55240e3de2 tests: test inviting someone to a non-ASCII stream.
(imported from commit d1788cf4712800c1b3445ad47510ac488e7935b0)
2013-03-23 00:10:10 -04:00
Jessica McKellar c4ceb2c276 tests: test inviting a new user with non-ASCII streams.
(imported from commit 049ae5a77c87eaaf0313b4b83d1dd038b14dcc22)
2013-03-23 00:10:09 -04:00
Jessica McKellar 9b89d7dc19 tests: add tests for sending non-ASCII messages.
(imported from commit 16093b2a080e7b00149129a9b53f308d8688def2)
2013-03-23 00:10:09 -04:00
Jessica McKellar 531ad235df tests: exercise non-ASCII login information.
(imported from commit 51a79a637a2d624c78627c84cd93d10cd700dff5)
2013-03-23 00:10:09 -04:00
Leo Franchi 378a8939ec Use TornadoQueueClient for activity queue when in the tornado process
(imported from commit 93ca4295403786ae26a2f70be17410674e6d053c)
2013-03-22 15:55:49 -04:00
Leo Franchi f64bc59dfb Automatically register consumer once asynchronous connection is completed
(imported from commit 3d860a9b79a42beffbd3b73f49aa2c25986dd3c6)
2013-03-22 15:55:49 -04:00
Leo Franchi 452105e393 Reconnect to rabbitmq in our queue client if the connection is lost
(imported from commit 82ed67f0c0f93e9f79ff65ef55b397815d20aaeb)
2013-03-22 15:55:48 -04:00
Keegan McAllister 4baeaaa532 TornadoQueueClient: Don't stop the Tornado I/O loop on RabbitMQ disconnect
Requires Pika 0.9.6 or later.

(imported from commit 316ab9f2a6b5c2a25ae8584e2604222b33e0dec3)
2013-03-22 15:55:48 -04:00
Keegan McAllister 6ffc2bbe65 TornadoQueueClient: Provide a callback when declaring queues
This is required by Pika 0.9.8.  We need at least 0.9.6 for the next
commit; I had been testing with 0.9.5 previously.  Anyway this way
seems more correct as well.

(imported from commit bfb9e9e78938073001f70c4d28a5e07cc4ebac32)
2013-03-22 15:55:48 -04:00
Leo Franchi c346abe6e2 Send Tornado callback notifications via RabbitMQ
(imported from commit 83814d8c6b78fe725aedea9d98fb588ed31123e7)
2013-03-22 15:55:40 -04:00
Keegan McAllister 23b8833ec5 Handle Tornado callback notify in a more generic, less HTTP-centric way
(imported from commit 85a74d1b40461236c4c95ad688e9796ab50f0bbf)
2013-03-22 15:51:23 -04:00
Keegan McAllister 8db92fd995 Split out the actual Tornado views from the callback handling / notification
(imported from commit 26d40556bf7f545d3606a01d83b16c7265bafb0e)
2013-03-22 15:50:35 -04:00
Keegan McAllister 591816d80e Use TornadoQueueClient in runtornado
(imported from commit cc4d5505987dc2826d177ff93d037b17f78072b8)
2013-03-22 15:39:07 -04:00
Keegan McAllister 373d3ece1c queue: Implement TornadoQueueClient
(imported from commit 2803bc91e42aa20d6e6dec87bfadd2f890268d05)
2013-03-22 15:39:07 -04:00
Waseem Daher 6760e68f94 integrations: Document Capistrano integration.
(imported from commit e26774e3657a71e8f21bf8ef2b1b1a9c289707da)
2013-03-22 14:37:54 -04:00
Leo Franchi 7837e36d0c Clean up some code by consolidating
(imported from commit 3978da70286174ad3666d08bcc8db2eb28446399)
2013-03-22 09:49:54 -04:00
Jessica McKellar 4f1bf1b2f2 realm_stats: restrict some usage stats to only active users.
They are more meaningful this way -- the fact that your bots that
never log in or inactive users don't have colored streams shouldn't
impact that statistic.

(imported from commit b39debda338cbbad06957bc969b42862a888026a)
2013-03-21 17:38:20 -04:00
Jessica McKellar 85086b6662 realm_stats: Also print enter-sends stats.
(imported from commit 34f9d9916e11ac2e2748ecbb8eb4f9a34a110340)
2013-03-21 17:38:20 -04:00
Leo Franchi 0184f31af0 Reprocess unread counts when subscribing to a stream.
This is required if the stream has unread messages in it
(from a previous subscription period). Otherwise the
unread count will be 0 until reload.

Fixes Trac #1117

(imported from commit 8f3d78eb52fdecb52456b0037cc89665c9027fbc)
2013-03-21 17:13:17 -04:00
Tim Abbott a8febf8fce Revert "to_dict: Update rendered_content in the database after rendered."
This reverts commit 4e5a370bc43defb5083cac3df45c649cf2366abf.

(imported from commit 745b4a98d0e3f67acaa207ba53e9250060dcfe06)
2013-03-21 10:30:23 -04:00
Leo Franchi 4edf85e730 Mark messages taller than the screen as read once we have moved past them
(imported from commit c142c2447a8f2b5ed40337a75c1afbaf05f9fecf)
2013-03-21 09:37:10 -04:00
Jeff Arnold a95b1a1a23 Revert "Automatically condense long messages"
This reverts commit 27244550d5d94980d7e33d8cc7c69708427dbbec.

(imported from commit e468051b8052d244beb09ba795605d70124254dd)
2013-03-20 18:45:12 -04:00
Jeff Arnold 795d968b91 Revert "Center the message condenser messages with respect to the message body"
This reverts commit da64f33551b500857bb91cb3ece959aafc9b1eb0.

(imported from commit 004f9a95cf5dfd4c4b8565d6eec15ceac27f7bf2)
2013-03-20 18:45:09 -04:00
Zev Benjamin e5c62d164c Center the message condenser messages with respect to the message body
Previously it was centered with respect to its enclosing div, which
looked slightly off.

(imported from commit da64f33551b500857bb91cb3ece959aafc9b1eb0)
2013-03-20 18:08:39 -04:00
Jeff Arnold c92d664b44 Automatically condense long messages
Addresses Trac #747.

(imported from commit 27244550d5d94980d7e33d8cc7c69708427dbbec)
2013-03-20 17:39:15 -04:00
Keegan McAllister 118cf4edec Modify encoding for URL fragment so Firefox doesn't decode it automatically
Fixes #826.

(imported from commit a4c0ada9559684db7e597686d9354219de742819)
2013-03-20 12:07:53 -04:00
Keegan McAllister e97c6f52ce Don't save narrow operators to the URL fragment if that's where they came from
In Firefox, prevents e.g. a slash in a stream name, which we wanted to store as
%2F, from converting back to a literal slash.

There is some appeal to normalizing the URL fragment after parsing, but in
general this way seems better.  It may decrease page load time on narrowed
views.

Doesn't yet fix #826; the URL is correct but the narrow is still wrong.

(imported from commit 32e3fa9e968139863f34b9698f1c8b39d06f0c14)
2013-03-20 12:07:53 -04:00
Keegan McAllister ae27deb30f Encode search operands using a cleaner-looking variant of URI encoding
Fixes #1098.

(imported from commit 1ed05248f3c6b69a48b9c74c0ce344621fe637b5)
2013-03-20 12:07:52 -04:00
Jessica McKellar 37e58b613d Truncate the tutorial stream name to fit the DB max stream name length.
(imported from commit e267656337f97d3ea14e14e957a405cf4fd2d06c)
2013-03-20 10:15:08 -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
Tim Abbott 02554b28cb to_dict: Update rendered_content in the database after rendered.
This change could significantly load the database if pushed to prod at
the same time as:

    send_message: Save rendered message content to the database.

goes out.  So this should go out in a different prod push from that
commit.

(imported from commit 4e5a370bc43defb5083cac3df45c649cf2366abf)
2013-03-20 07:34:10 -04:00
Leo Franchi 2ce683421b Only show 'More Messages Below" if there are actually more messages below
This fixes Trac #1004

(imported from commit fa57936aaf5b5f4ec74569bee389d18b989d6b9f)
2013-03-19 16:21:36 -04:00
Jeff Arnold 8613f6052e In the actions popover, put the most basic/common actions first
(imported from commit b2de5c1accffc776abe651c2140643ad380bb1e8)
2013-03-19 14:35:11 -04:00
Waseem Daher e1e7978fae "Lead designer" job posting.
(imported from commit 1f9e00e45f69d47842524d715fe5e8a8a4a8b7df)
2013-03-19 13:28:53 -04:00
Tim Abbott 17e9e56899 Fix get_stream caching the DoesNotExist value of None.
(imported from commit bdef7438758517ba9083ecc8bf110e3caa1ec041)
2013-03-19 11:17:31 -04:00
Leo Franchi c6f9dbdd54 Only sleep if there is more work to be done
(imported from commit f8a1380e0045c9470909c088a9d262f8a714c86e)
2013-03-19 09:55:12 -04:00
Leo Franchi 6d6c3364dc Rewrite message flag handling to fork out to a subprocess for batch handling
(imported from commit 1ef846f542950cabf32f8b176f5591cf5794a0ff)
2013-03-19 09:55:12 -04:00
Tim Abbott 9977cdde54 send_message: Save rendered message content to the database.
(imported from commit e5bd224687d5420f556b341286f03d3829973a3c)
2013-03-19 08:09:26 -04:00
Tim Abbott b0dedfa310 [south] Add rendered_content columns.
See the next commit for the models changes.

(imported from commit 90e753661f8abfcfcdb78a5bbc15ebaf7f2eff9b)
2013-03-19 08:09:26 -04:00
Tim Abbott b38a538f8c Rename userprofile_by_foo cache keys to user_profile_by_foo.
(imported from commit ef398abc48c9b81a3d339ffdce00bae274246d28)
2013-03-18 16:15:11 -04:00
Tim Abbott 8034980cc4 create_mit_user_if_needed: Check memcached before querying database.
This will save at least one database query whenever MIT users send
messages.

(imported from commit 9fd644885a380463d841762b8fafe928431e1263)
2013-03-18 16:15:11 -04:00
Tim Abbott 97d7d31b68 Rewrite internal_send_message to use check_send_message.
This will automatically fix bugs such as one in which
internal_send_message didn't properly strip() the subject argument
before sending a message.

We change the recipient_type argument to internal_send_message to take
the recipient type name (e.g. 'stream') both to better fit the API and
also because the previous code incorrectly handled huddles.

(imported from commit 78c2596d328f6bb1ce2eaa3eed9a9e48146e3b6a)
2013-03-18 16:15:11 -04:00
Tim Abbott bb80d1c58c Move check_send_message and helpers to actions.py.
(imported from commit d74c90e25bd63931955d2ad9b3890be53d674a48)
2013-03-18 16:15:11 -04:00
Tim Abbott ab04d6f403 check_send_message: Don't use json_success/error directly.
This is preparation for using it from internal_send_message as well.

(imported from commit 000784be7b40e0c93b38a5a916a4a915335ea821)
2013-03-18 16:15:11 -04:00
Tim Abbott fb77af8f10 Refactor send_message_backend to do checking in new function.
This is preparatory for using this new arguments checking function in
internal_send_message as well.

(imported from commit 578e09c50b8a700c019c7dd235b2d9527af34e39)
2013-03-18 16:15:11 -04:00
Tim Abbott 14efaea0bb send_message_backend: Reorganize subject argument checking.
(imported from commit 80daa46f47e7e5279f746db89b3632eeadb27325)
2013-03-18 16:15:11 -04:00
Tim Abbott 9909c8dc19 send_message: Use a memcached for the UserProfile-by-id cache.
This cache should save 2 database queries whenever we send a private
message.  However, previously it was per-process (which meant it was
mostly useless) and also buggy (it never stored anything in the cache,
so that it was completely useless).  Switching this to our standard
memcached setup will address both problems.

(imported from commit 1d807f30704bccf28de33a80523488aedc58a9be)
2013-03-18 16:15:11 -04:00
Tim Abbott c1d3a5b5e5 Use more caching of UserProfile objects in views.
(imported from commit 3abcceeb4fac1cfa5a9944a6455c60f6512dce6e)
2013-03-18 16:15:10 -04:00
Tim Abbott a23f6be28d Cache the results of Recipient queries in our memcached cache.
(imported from commit a6ba25a9c62d2738e4738b076370e4b2bc0ffaba)
2013-03-18 16:15:10 -04:00
Tim Abbott 3c143db01a Add memcached caching for get_stream lookups.
(imported from commit a089c8a99eaa1fa28ce401859cac1bdf0eb92a69)
2013-03-18 16:15:10 -04:00
Tim Abbott 9c2a9eb288 send_message: Avoid querying the stream object twice.
(imported from commit c23aab232a40195d92ae4b0e68af390c3b6b20ad)
2013-03-18 16:15:10 -04:00
Tim Abbott c0fece1cbd get_stream: Fetch the realm object as well.
(imported from commit 065ae574cb933cfc48371efd4327e70d37184dd4)
2013-03-18 16:15:10 -04:00
Tim Abbott c6c3cda089 do_send_message: Save a database query on message sending.
(imported from commit c5dc3d9888f9b1867e8d20d84795dde32cf95583)
2013-03-18 16:15:10 -04:00
Jessica McKellar 1ca2f6fa7f Add a management command to reset your stream colors to the default.
(imported from commit f6891ad40088bf34686a7d8a2d910a9a0f3be7c2)
2013-03-18 15:49:39 -04:00
Keegan McAllister 45eb9bcf47 tests: Disable tutorial through the server side variable needs_tutorial
This fixes a nondeterministic test failure for me.

The first message sent in the test suite appears to get dropped.  I don't know
why this is, and I'm pretty sure it was an existing bug.  This message used to
be the one disabling the tutorial, which might explain why that didn't always
work.

Regardless, this commit at least makes the test suite usable, and we can work
on fixing that bug later.

(imported from commit 063e40871b9883e3a6dab93a4e0a51c5b2dae4b7)
2013-03-18 13:46:46 -04:00
Waseem Daher 797b5ee63f Add page describing our Humbug apps.
(imported from commit 2e071782a13a497e57225b2a84c41d58f5e120b5)
2013-03-15 19:16:44 -04:00
Tim Abbott 9ae583b910 Use the User/UserProfile caches for Django requests too.
Previously we only used these caches for Tornado requests, because we
were not updating memcached when e.g. the user's pointer changed, and
so functions like update_pointer would not work correctly.

Now that we are updated memcached when the User and UserProfile
objects change, we can use these for all requests.

This saves 2 database queries on every Django request to the server.

(imported from commit aa5bffd885d14bde38b95e80a226bd5ab66f253d)
2013-03-15 18:09:34 -04:00
Tim Abbott 1e6ed16c23 Flush the User cache when saving User objects too.
(imported from commit e595209fe1190e2f3e0d55ad3b9bae0997b91d1a)
2013-03-15 18:09:34 -04:00
Tim Abbott b6f42cb1e1 Update UserProfile objects in memcached when we save them.
(imported from commit 59426e19eeeba131f363a4bc5f74f59b6dbe1066)
2013-03-15 18:09:33 -04:00
Zev Benjamin b08dbdfe48 blueslip: Send the user agent string back with the error report
(imported from commit ed77877465b1497cd3d78753c3398329302075ff)
2013-03-15 17:30:07 -04:00
Zev Benjamin 53a68144e0 Don't do processing for a get_old_messages if the message list it was for goes away
This was biting us before when the user would leave a narrow before a
get_old_messages call associated with it finished.  Specifically,
search.maybe_highlight_message() would assume a message was in the
DOM when it wasn't any more.

We also have to hide the 'loading more messages' indicator when
reseting the 'load more' status because otherwise it wouldn't get
hidden like normal in the load_old_messages() continuation, causing a
load_more_messages() not to fire when re-entering a narrow.

(imported from commit 4a136dd01305b039c0970f897b07e603b87d5d8e)
2013-03-15 16:40:05 -04:00
Tim Abbott 7e456ddba7 Cache get_status_list output for up to a minute.
This should substantially decrease the amount of server load generated
by the userpresence system.

I tested that this indeed was indeed saving one query on
/json/update_active_status requests on my laptop with 2 users from the
humbughq.com realm logged in.

(imported from commit 03e9d4eb95b9f664d489862684ae162db2076e08)
2013-03-15 16:37:41 -04:00
Tim Abbott ec07184721 cache_helpers: Fill in memcached message cache in batches of 1000.
This cache filling code takes about 5 seconds to run, which means it
will finish before Tornado starts reading from this cache, but if that
were to change, it would be much better to have made at least some
progress.

(imported from commit 60a3420cdb9ddf331d83573a3fdb6be1a5ee5a4f)
2013-03-15 16:37:41 -04:00
Tim Abbott e78ef47487 message_cache: Query related models to avoid more queries later.
(imported from commit c1442165c68e9eef1cb5d310624c1021c1a57350)
2013-03-15 16:37:40 -04:00
Tim Abbott d88591c19c cache: Fix the select_related() query name for sending_client.
Previously we were calling select_related() on Message.client, which
doesn't exist.  It seems kinda poor that this doesn't raise an
exception.

I believe this issue was causing us to do very large numbers of
database queries during get_updates calls during server restarts.

(imported from commit b79bd698820fbd9dd82bd61fc175c32cd5ce6d05)
2013-03-15 16:37:40 -04:00
Tim Abbott e080be82fb Add the user's client string to our Django logs.
This should let us distinguish e.g. mobile from API bots.

(imported from commit 192114a0f79bfa7fb918e8c026da63ef772c2449)
2013-03-15 16:37:40 -04:00
Tim Abbott a46eb8a36c Clean up excessive positional arguments to load_old_messages.
(imported from commit 072c0fcbd59256d55364a0fc6be42d5df8ab99e2)
2013-03-15 16:30:03 -04:00
Tim Abbott 43e43a4248 Fix HumbugAdminEmailHandler for non-exception logged errors.
Previously, AdminEmailHandler would crash if the record did not
contain any exception information (e.g. because it came from
logging.error()).

(imported from commit 868ec68f3a57eddbb2c851ecf9894e5eddf21e4c)
2013-03-15 14:53:17 -04:00
Tim Abbott d42e8ecb11 Log handlers: Provide the actual error message on errors.
Previously when we logged errors using logging.error() but didn't
throw an exception, we would send these totally useless error
humbugs/emails that look like this:

Error generated by Anonymous user (not logged in)
No stack trace available

This change makes those messages include the actual text passed to
logging.error(), which is substantially more useful.

(imported from commit 76a8220ffe66d19cb0ca8ba9d1b42d5ecc4fd511)
2013-03-15 14:53:16 -04:00
Tim Abbott 722918aa61 Use humbug_finish() wrapper for finish() with required arguments.
I think this is a little cleaner than the previous approach.

(imported from commit fa6233721f43c94003de643d7801a88a156affd2)
2013-03-15 12:53:07 -04:00
Tim Abbott 419e153422 runtornado: Mark block of get_response modified from the original Django.
(imported from commit 383d6960f0043175c026956e1724ec1d1157767b)
2013-03-15 12:53:06 -04:00
Tim Abbott ade7146cd9 Disable tornado request logging in favor of our Django logging.
(imported from commit 2144b2ac1cdb6062bb32fca4cc69ea3f4570cf69)
2013-03-15 12:53:06 -04:00
Tim Abbott 4df6736225 Call the Django response middleware from Tornado views.
But discard any changes the Django response middleware may have made
to anything other than the content.

This allows us to, for example, output our nice database query logging
for get_updates requests.

(imported from commit e1d2fd38ceb4d73ff50bdfaad7c72ddb24d0fe16)
2013-03-15 12:53:06 -04:00
Tim Abbott 549577a928 Pass the original request object to Tornado's finish().
This is preparatory for running the Django response middleware on
our Tornado responses.

(imported from commit 05da8ea9cb663a928b2f98a928f3992aae4f067c)
2013-03-15 12:53:06 -04:00
Zev Benjamin a495b0dfa6 Re-educate rogue emoticon
He was wrecking havoc by confusing the Javascript mode syntax
highlighter.

(imported from commit 27900cf6b6dc7866f2b2f108e79d28d6785aa466)
2013-03-15 12:43:12 -04:00
Leo Franchi 96041be75c Use 'undefined' instead of -1 as sentinel
(imported from commit 30cc280d89cf0c290459f9d90960cd8eaf76a22f)
2013-03-15 10:51:25 -04:00
Leo Franchi 79dfe57840 Mark all messages between start of scroll and end of scroll as read
If the user scrolls super fast, our scroll handler might not catch
the user  passing by some messages.

(imported from commit 14cebffcd1321f02443971ac5e1c922db19648ab)
2013-03-15 10:43:17 -04:00
Zev Benjamin 22457277f4 Move send_with_safety_check functionality into AsyncDjangoHandler
This will mainly be useful in the event system branch, where we want
to actually send a response from a file other than tornadoviews.py.

(imported from commit b7ae9bb9b062215ab44eb5f0a3a72d6baeee1d07)
2013-03-14 18:48:15 -04:00
Waseem Daher 0f621f5f89 Show Twitter previews on production.
This reverts commit 4baed7ba22482eff6ed381d319f6e21da904d9ba.

(imported from commit dcab148b24e95f90edd5f2f3f581b4037deed787)
2013-03-14 18:00:04 -04:00
Leo Franchi 07433b80cc Don't mark your message as read if it comes from the API
(imported from commit 0570d4db590e21b0fadd544b10c9865fa7acd66b)
2013-03-14 15:51:21 -04:00
Leo Franchi 95c9c6817f Mark messages as read as you scroll by them
(imported from commit 7e4595dcbfe900bde7f062e3fe9e2d53c71b6884)
2013-03-14 15:51:21 -04:00
Leo Franchi d3364eef5d Try a different color for mentions
(imported from commit e1f7e4c03abb54b8e7efbdff84314a902ad32697)
2013-03-14 15:38:09 -04:00
Tim Abbott 76837ebe2c fill_memcached_caches: Also fill the caches of User/UserProfile objects.
Since we flush memcached when we do a server restart, the flurry of
get_updates requests that fly in afterwards are all cache misses for
getting the User/UserProfile objects, so Tornado ends up spending
around 70ms per get_updates request rather than the usual 1-2ms.

So this should substantially improve our Tornado performance around
server restarts.

(imported from commit 07b8126bdfd4ff14e4c3362f9eda1fe5fd571c5b)
2013-03-14 15:07:42 -04:00
Tim Abbott cf58ee833a Rename lib/message_cache.py to lib/cache_helpers.py
(imported from commit 591e427aee47aea58b50d6c3fbd6a05cfe9378ea)
2013-03-14 15:07:41 -04:00
Tim Abbott 60c3cf826d restart-server: Fill memcached caches after clearing the cache.
Our previous code could in theory end up clearing the caches it had
just filled, if Tornado's cache filling work happened to be faster
than the memcached flush.

(imported from commit 48174aadad398fb7a7c917a1df765c1261b12a55)
2013-03-14 15:07:41 -04:00
Tim Abbott adb9c88151 message_cache: Clean up populate_message_cache.
(imported from commit a73e4fc4908d840f4f02aef13a9afe2fb683fd83)
2013-03-14 15:07:41 -04:00
Tim Abbott 0a9a553b5f Fix use of invalid hash keys with memcached.
Email addresses can contain characters that are not valid for
memcached cache keys.

(imported from commit d7cfd6d5292e4fc8f4e2b19f2c01a4097d878f1b)
2013-03-14 15:07:41 -04:00
Tim Abbott c098520bbd Move the key functions for various caches to cache.py.
(imported from commit b04826533c32516cc2eef3b35263a40385ae7be4)
2013-03-14 15:07:41 -04:00
Tim Abbott cc4bcb97c4 Clean up naming for Tornado user_profile cache keys.
(imported from commit 8f401b563c9ef49c739c121c9dc5bffff09c986d)
2013-03-14 15:07:41 -04:00
Tim Abbott 1580386946 Replace db_cache_with_key with a parameter on cache_with_key.
(imported from commit f2c600292888ba384ee4acc97c94f1d6f8bc9657)
2013-03-14 15:07:41 -04:00
Zev Benjamin 719e24a25b blueslip: Use reference counting to try and break the circular references we create
We create a circular reference between handler functions and our
wrappers for them so that we can pass the wrapper to jQuery.off when
users pass the original handler to us.  This reference-counting
system can't break all the circular references we create because
users can unbind event handlers without explicitly naming the
handlers they want to remove (they can remove all bindings on an
element, for example).  For now, we hope that this memory leak isn't
too bad.

(imported from commit 9615b5761b4b09ca7ca52c0d847e9b83330373fa)
2013-03-14 15:07:28 -04:00
Zev Benjamin e8470b9481 blueslip: Also override jQuery.off so that we can pass the correct handlers to the original jQuery.off
Previously, we couldn't actually unbind some event handlers.  The
problem was that when a user called $.off(events, handler), the
passed handler wouldn't match any that were actually bound because
the handler that was actually bound was our wrapper.

This bug specifically caused the handlers for our idle timers to
never be unbound, effectively never cancelling them.

(imported from commit 48efac954994a05c356d326e64a78ab0ace9fe3e)
2013-03-14 15:07:28 -04:00
Zev Benjamin 8709e3f8b4 blueslip: Store the handler wrapper on the original function
We will need this for removing event handlers.  This will
unfortunately create a memory leak, but we'll partially deal with
that later.

(imported from commit e439cb44d245e16d2254d1be053b68015a1f4c79)
2013-03-14 15:07:28 -04:00
Zev Benjamin 122996b656 blueslip: don't double-wrap handlers when invoked with the $.on(types-Object, selector, data) syntax
(imported from commit 458ee9248fc82efc6c2307634b2be6d3ce32246d)
2013-03-14 15:07:28 -04:00
Zev Benjamin 22bb67150c blueslip: Do not catch exceptions from callbacks in debug_mode
(imported from commit 6ea79285dfd9f1f7b5d9f5d663a84247757d8af4)
2013-03-14 15:07:28 -04:00
Zev Benjamin dfe69eef0d Funnel exceptions from ajax handlers through blueslip
(imported from commit 5ad08482989d25a0fd0ee02251b74a23f950a0b9)
2013-03-14 15:07:28 -04:00
Leo Franchi 7510f87eac Select first unread when narrowing by clicking on stream in sidebar
(imported from commit 557751f44e3fee61b6a55f8f8328e2f97e6adc04)
2013-03-14 15:01:13 -04:00
Tim Abbott a0d0bdb5cf Fix copy/paste in compose box.
(imported from commit 075a461136e040b7d5d752e9386d9321d76c956e)
2013-03-14 14:55:14 -04:00
Leo Franchi 4a23959b11 Remove pointer_updater param as it is no longer used
(imported from commit 80cc4a6d4c24660087981b1132ca2ed44c86a424)
2013-03-14 13:35:28 -04:00
Leo Franchi 7c7822601f Use request._client to detect a mobile pointer update
(imported from commit d06606ded33bc598e1bdb4b33279ce92b098ed02)
2013-03-14 13:35:28 -04:00
Waseem Daher 9c45b96b21 Make Dropbox inline image preview more robust to sharing links.
Sometimes Dropbox shares with /s/ and sometimes with /sh/,
and I'm not sure which controls it, but we should deal with both.

(imported from commit 2222450f25c418b5fbd60ab2c30477467e34c0d1)
2013-03-13 17:46:43 -04:00
Tim Abbott cd4709c0f1 update_pointer: Only have one request in flight at a time.
Previously, if for some reason pointer updates were not returning from
the server, the client would resend its request every second, rather
than waiting for the previous request to fail before sending a new
one.

(imported from commit d134adc50aabd135c7631913fecab3519aca6640)
2013-03-13 17:41:33 -04:00
Tim Abbott 99d4bc114b Move Zephyr mirroring liveness check to the UserPresence queries.
It's closer to a presence query than an update, and more importantly
this moves this out of Tornado -- previously Tornado was spending at
least 3ms per recipient on messages sent to the MIT realm fetching all
this data to return back to users.  This should save around 100ms per
message sent to a popular stream the MIT realm -- but more
importantly, each such event is 100ms during which Tornado is not
processing other messages.

(imported from commit 134169f0fdcd9f6640fda957edc4a28b07783d8e)
2013-03-13 17:41:29 -04:00
Leo Franchi 0f68411859 Mark messages as read when creating them in populate_db
(imported from commit 6bf0d5bf889e94618c355e56f145b353f7574e60)
2013-03-13 14:14:46 -04:00
Leo Franchi 153983a933 Add a manage.py command to add read flags up to the current pointer
This is required because our migration is going to go in two phases.
When we do the database migration (on pushing to master), we update
all messages at that point. But prod doesn't know about the new
flags field, so any new messages sent on prod will not have the
read bit set.

When we push to prod, we want to re-run the bit of the migration script
that automatically sets read flags on messages older than the users's
pointer.

(imported from commit 961d33e972eac9ada80089bf1b1269c7fb42d56b)
2013-03-13 14:14:45 -04:00
Leo Franchi e82b408be9 Add a shim for mobile clients to update new read flag
(imported from commit e8e269156ea671e590589f48f8494c25380a2dde)
2013-03-13 14:14:45 -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
Leo Franchi 93a3f14c43 Add backend support for handling new 'read' message flag
(imported from commit 6194e9332caa2d279cbc304f0d6a69f969aa9a72)
2013-03-13 14:14:45 -04:00
Leo Franchi 6a53d1c35d Add flags to dict in load_old_messages
(imported from commit 7f68ea97a424aa0b01983258dbf6e9a2a07a732a)
2013-03-13 14:14:45 -04:00
Leo Franchi a678ef2af8 Add flags field on UserMessage, created by previous south migration
(imported from commit e839a3871d27cd7082ecbc84946216143d373da0)
2013-03-13 14:14:45 -04:00
Zev Benjamin b9dd227bb5 Move seemless reposition on render code into _maybe_rerender
We also needed this when rerendering on append, so moving it into
_maybe_rerender allows the two places to share the code.

(imported from commit 027d99cae7864747cf1ec94c95e8ece495b5c907)
2013-03-13 14:07:22 -04:00
Leo Franchi 5ce3a41e6d Fix typo in user-visible string
(imported from commit 39131763be700b91be3bbbbb2d16ba1c3c8d7a85)
2013-03-13 13:50:45 -04:00
Leo Franchi 60eeffc82d Fix 0012 migration to work with sqlite
(imported from commit 05ed67e199bdaa1485912748b304cdb890b6115b)
2013-03-13 11:52:06 -04:00
Leo Franchi 794c897bbc Lower thresholds for migration speed
(imported from commit da749dcdeb9396fa71c09e0b6f7275a67b1568f0)
2013-03-13 11:52:04 -04:00
Tim Abbott f7ecfea7c1 Fix query for stream_name in compose module.
(imported from commit 8b8069a9fbf32805a77299e8375256e7a27e7ba1)
2013-03-13 11:22:11 -04:00
Waseem Daher 52b3da6668 Make clicking gravatar or "Humbug" take you home.
Looks like this was broken in 546063f88d58fb988363e5c89a13507deeb20afd.

(imported from commit 077186e60bf7a48742e71bbcb4e705c02f1ddc0a)
2013-03-13 11:16:09 -04:00
Tim Abbott 275af189a3 Cache permanent errors from the Twitter API.
This avoids our repeatedly retrying to fetch a tweet that doesn't
exist from the Twitter API.

(imported from commit b4ca1060d03da21e7e59e5b99e682d2e8457df15)
2013-03-13 11:12:25 -04:00
Tim Abbott 61ee8b1921 Unfade messages after you manually edit the recipient.
It's pretty confusing if this doesn't change.  In some other world we
could update the fade, but since we're currently only fading on reply,
I think it would be weird to update the fade when you're picking a new
recipient.

(imported from commit 8f77419d443d578068b57f847354ac6da7632ee2)
2013-03-13 11:12:25 -04:00
Tim Abbott 1e62ced172 Fix fading when replying to sender.
Previously, we compared the recipients of messages to the message that
you triggered the reply off of -- even if you did a reply-to-sender.
This commit changes the code to instead track what you faded by,
rather than just the message you faded on.

Fixes #1037.

(imported from commit d9e2cb4122501b1bc45e231d4b52c2e7f9284fdd)
2013-03-13 11:12:25 -04:00
Tim Abbott 24a235a091 compose: Move unfade_messages() call inside fade_around.
This makes the API a little cleaner.

(imported from commit c5eb9a4998971cdbe1f8ac3a14fd9759584771bb)
2013-03-13 11:12:25 -04:00
Tim Abbott 6c6a005920 Update recipient on renarrow when compose box is open but empty.
(imported from commit ff50b3b38833e7467ca77714acb1d81c22aeed0c)
2013-03-13 11:12:25 -04:00
Tim Abbott ee8d646d74 compose: Don't clear the compose box when recipient didn't change.
(imported from commit 5188a0f510e499c80d4c188a1ce59af4f2fe3262)
2013-03-13 11:12:23 -04:00
Tim Abbott 10be8d2a12 compose: Fix loss of message fading on renarrow.
Previously, if you renarrowed, all message fading would be cleared
until you close and then reopen the compose box.

Fixes #1024.

(imported from commit 57981ba29ab597c4c84ca6e4e9d04a8284f49117)
2013-03-13 11:10:51 -04:00
Tim Abbott 012f0566a1 compose: Fade all relevant messages on the page, not just neighbors.
(imported from commit 69e11a980b9cbd69753754b9a42248ef0f3d5a21)
2013-03-13 11:10:51 -04:00
Zev Benjamin 05eec2ae19 blueslip: Add some clarifying comments
(imported from commit 8b8ed83593d4dfb8ac3deb2c3442c2614481701a)
2013-03-13 10:55:34 -04:00
Zev Benjamin 09cf339c2b blueslip: Handle exceptions from jQuery event handlers and $(document).ready functions
We treat these exceptions the same way we treat fatal errors: report
the error message to our server and then allow the exception to reach
the top level.

We could also override document.onerror, but don't.  There are a
couple of ramifications of this:
* Exceptions caused by event handlers directly attached to DOM
  elements aren't handled
* Exceptions caused by code at the top level that triggers an error
  (such as parse errors in our Javascript files) aren't handled

The reason we don't override document.onerror is because the
document.onerror handler has a limited interface and doesn't receive
the exception object.  It only gets the message, file, and line
number of the error.  Additionally, exceptions that we allow to
propogate out of blueslip trigger an onerror event when they're never
caught.  In order to avoid handling the error twice (once by blueslip
and once by the onerror handler), we'd have to encode the fact that
the error has already been handled in the error message, which is
pretty ugly.

(imported from commit 7f049ae519dc198a9f7cfd41fd5dd18e584bd061)
2013-03-13 10:55:34 -04:00
Zev Benjamin 5bd4f2ccd7 blueslip: Throw a custom exception type
(imported from commit 4a3612b63bb4481a56901cc3dd6cea9a3d1a1aea)
2013-03-13 10:55:34 -04:00
Zev Benjamin 6d25940299 blueslip: Pass the stacktrace into report_error
This is to let us pass in the stack trace of an existing exception,
which will be required in a upcoming commit.

(imported from commit 421366a7a01deb770b7620417fb4660769c5db53)
2013-03-13 10:55:34 -04:00
Zev Benjamin a5b7c86303 Show an error message to users on fatal errors
(imported from commit a1ee2329e6b9dfa6f575106f1e32574bef0598a2)
2013-03-13 10:55:34 -04:00
Zev Benjamin fb0dd60857 Simply compose.check_stream_existence now that one of its return values isn't used
(imported from commit 8c910032e8ffd12b9691138ce03ceb096156e3f2)
2013-03-13 10:55:33 -04:00
Zev Benjamin 054d377709 Make stream existance error actually go somewhere
The referenced element where the error was supposed to go was removed
in 66fd42914e4fc33719c4f21ad401748989f20b49.  Now the error message uses
the regular compose error message area.

(imported from commit c82a6d863fa327ba982157d0b0607545d7e65cb7)
2013-03-13 10:55:33 -04:00
Zev Benjamin b383ee1dd4 Only report a given error message once per page load
(imported from commit 058fe321a991bbc50eed63b0bdbf75bcfa8afe2b)
2013-03-13 10:55:33 -04:00
Zev Benjamin 1109d20149 Send browser errors back to the server
(imported from commit 8c676017e8b3fc4f17552db15d32266099dba8f2)
2013-03-13 10:55:33 -04:00
Leo Franchi 2c4c6ba43e [schema][manual] Add South migration for flags on UserMessage
(imported from commit bdf6cf2d5427709e52ef051e3c4a19c5fbb4851c)
2013-03-13 10:20:56 -04:00
Zev Benjamin 65d2f65bbb Check if we need to rerender after appending messages to the MessageList
Previously, if the pointer was high on the page such that there was a
lot of empty space below and the render window was full (a situation
we could get into if we're following new messages arriving), a newly
recieved message would not be rendered even though it would have been
visible on the screen if we had done a rerender.  Adding the
_maybe_rerender() call to the end of append() ensures that we don't
end up in this situation.

(imported from commit 925d3cc62e8221b42f1d5ff1788e99c7d07ccc24)
2013-03-13 00:48:26 -04:00
Waseem Daher a57afd9a63 Use separate Twitter API key for prod.
(imported from commit ab43b42f69eaa569cf7a1ccba9f15d528050c22b)
2013-03-12 18:28:59 -04:00
Tim Abbott c947fbd0e9 Revert "Disable backfilling 1,000 messages on idle"
Now that Zev's message list branch is merged, there's no longer a
performance penalty for loading these old messages, and it improves
our narrowing performance to have them loaded.

This code is slightly different from the original commit
93d47710891cfc4db9fa00beaa5ccd10113aa1c3 since the way to access the
first element in the message list and the API for get_old_messages
have changed since then.

(imported from commit f295f892bea9327eb8316225b7b98f0e3b3fdc9a)
2013-03-12 18:16:55 -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
Luke Faraone 3c95013a15 Iconify public/private streams on subs page and new stream modal
This will hopefully make stream privacy more noticeable. We still don't
allow people to modify privacy after stream creation, however.

Since we now use a radio box on the stream creation modal we had to change
the selector used by subs.js to determine if a new stream was to be invite-
only.

(imported from commit 641a4fab74301a9b3ecd4b3859f010dd4ece193e)
2013-03-12 15:14:29 -04:00
Zev Benjamin 26580f2399 Deduplicate messages from get_updates
This is a workaround for bug #1062.

(imported from commit 449b00e653829e263583376a88ae67b1fe4f5eb6)
2013-03-12 14:36:45 -04:00
Waseem Daher 9920dcd22a Properly disable the tutorial in the test suite.
I think my previous commit causes the tutorial to run more regularly
in the test suite, so we,  in turn, need to be more systematic
about disabling it.

(imported from commit c3805438b0564874a358526d3592b86d147547c0)
2013-03-12 11:05:46 -04:00
Waseem Daher 33dc3a2fb7 Properly start tutorial on first run, even if you have new messages.
We were previously having an issue where the tutorial could
be pre-empted if you got a few messages while you were first
logging in.

I have some reservations about this being slightly fragile, and a
better approach might be to just have a bit that we use to determine
whether or not you've already seen a tutorial. (Or potentially that
checks whether or not you've ever sent a message.)

(imported from commit f8858f64a36bcd25887b76314caff283929f340c)
2013-03-12 09:56:57 -04:00
Waseem Daher dffde7714c Don't have the presence list occlude the "More messages" popup.
The issue, prior to this fix, is that the presence list actually
gets drawn *on top of* our "more messages" popup, which is ugly.

(Toggling the z-index on either or both of them did not seem
 necessarily to matter, but that's probably because z-index
 is subtler than I understand.)

This fixes Trac #1078.

(imported from commit a255aadb1884cf6c659085b26a36d378f680e83e)
2013-03-11 23:28:37 -04:00
Jessica McKellar 039178b12e tutorial: remove step telling you to colorize the tutorial stream.
We don't need it now that we auto-color.

(imported from commit 80066849b8f2aeef5e839f4fca40c9659b60a4af)
2013-03-11 16:47:04 -04:00
Jessica McKellar a8d6bd3322 Remove some unused imports.
(imported from commit bb8311848ca24fbb1fb1b3df8f8b4403eb38ce1c)
2013-03-11 16:47:03 -04:00
Jessica McKellar 2314809d73 Auto-color streams.
(imported from commit b669f864b0574e9e9af282ccb8783ccfaa12adfd)
2013-03-11 16:47:03 -04:00
Waseem Daher 3c6d489064 Don't do Twitter previews on prod.
(imported from commit 4baed7ba22482eff6ed381d319f6e21da904d9ba)
2013-03-11 15:18:57 -04:00
Leo Franchi 9466addbe2 Allow negative anchor param to get_old_message
When narrowing, we use the selected id in the home view as the anchor,
and if the user is new and hasn't selected any messages yet (or moved
the pointer since first using humbug), their home view selected message
will be -1. Rather than failing to get_old_messages for any narrows starting
from that point, return all matching messages.

(imported from commit 72cfe392d9ac01ed41abc8eadf0f47240e374665)
2013-03-11 15:11:24 -04:00
Waseem Daher 436d3b2578 Don't open the composebox when you click on a Twitter avatar.
(imported from commit 9844d15a522d1b31a84aee15c9c0617951c53cc9)
2013-03-11 14:38:21 -04:00
Zev Benjamin 05d89139dc Use blueslip instead of throwing errors directly
(imported from commit 095ae006fd344943d7dc1c0bbc86f0ac0458e755)
2013-03-11 13:22:12 -04:00
Zev Benjamin dc0913077a Add a new frontend error-reporting system
The new system, called blueslip, makes errors fatal when in debug
mode and only output a message when running in production.  In the
future, it could also send user errors back to us automatically.

(imported from commit 1232607c0311e885c8b5a5e8a45ffb28822426e0)
2013-03-11 13:22:12 -04:00
Zev Benjamin 36f7e6ffd5 Remove verbose_stacktrace function. Use console.trace instead
console.trace is available in both Firefox and Chrome and is more
powerful.

(imported from commit fa6e2cd5c78e7b0588b8656270d078bfa6af41fa)
2013-03-11 13:22:12 -04:00
Tim Abbott d679a72952 [manual] Cache results of the Twitter API in the database.
This should substantially improve the repeat-rendering time for pages
with large numbers of tweets since we don't need to go all the way to
twitter.com, which can take like a second, to render tweets properly.

To deploy this commit properly, one needs to run

./manage.py createcachetable third_party_api_results

(imported from commit 01b528e61f9dde2ee718bdec0490088907b6017e)
2013-03-11 13:15:55 -04:00
Zev Benjamin 9c28e52f91 Fix sort error for streams with names that are numeric
The jQuery .data() documentation says: "Every attempt is made to
convert the string to a JavaScript value (this includes booleans,
numbers, objects, arrays, and null) otherwise it is left as a
string. To retrieve the value's attribute as a string without any
attempt to convert it, use the attr() method."

(imported from commit f47c1cbb94cb5a98ea9842b00f45c35cd21873f9)
2013-03-11 13:00:01 -04:00
Waseem Daher bf2ad720c8 Specify both the width and the height for our emoji.
This should hopefully cause the page not to scroll around when we load
a giant block of emoji, because now the size of the emoji is known
before it finishes loading.

(imported from commit f566437edd725f6084c6a10c6230fd36e8d12346)
2013-03-11 12:52:11 -04:00
Zev Benjamin c50abd1c76 Fix jQuery selector exception from single quotes in stream names
Fixes #1065

(imported from commit 67f74e41f16c01d0d307bd8edf48dd70dde4edf4)
2013-03-11 12:38:15 -04:00
Waseem Daher 0e1b019f0a Allow Esc to blur the searchbox input.
This is a fix in response to an issue reported by Nelson.

(imported from commit 3db9e3a91d4e848408f19645e20382414a87b115)
2013-03-11 11:49:47 -04:00
Luke Faraone 8f52f8e4a2 Sort the streams sidebar the same way as the subscriptions page.
Closes trac #1050.

(imported from commit 8a6d5e067b7f726071e5797d70132cab689bbb49)
2013-03-11 11:44:06 -04:00
Tim Abbott 413a989058 Enable use_closest when moving pointer due to other clients.
Our mobile apps (which don't support in_home_view filtering) will move
the pointer to a message that isn't actually in the home view, so we
need to accept that sort of input for now (and maybe in general --
even if we fix our mobile apps, third-party clients may screw this up
too).

(imported from commit ce837e972f0581abd1df44fdb2dd5270dfb9afde)
2013-03-11 10:56:44 -04:00
Waseem Daher 29d504149c twitter: Only render the first Twitter link we see, not all of them.
(imported from commit 68582224962da14795d91a68197db1001ae7b75c)
2013-03-08 17:45:58 -05:00
Tim Abbott f37c6e7a1a do_create_realm: Use internal_send_message.
(imported from commit 92edff133d16f72cf954671392e413066fb22955)
2013-03-08 17:24:33 -05:00
Tim Abbott a6c461e3e0 internal_send_message: Render content before sending.
(imported from commit 00b80c71ccf5b1388d64cf8b6a2cb21b818ece4a)
2013-03-08 17:24:33 -05:00
Tim Abbott 254bc9f361 Attempt to render messages before accepting them from the user.
This fixes trac #407.

(imported from commit e33647eec32266790f864d14ad377d51956d2a6f)
2013-03-08 17:24:33 -05:00
Tim Abbott 2f022ebb34 bugdown: Allow caller of convert to tell whether we succeeded.
(imported from commit 9e3cab73e0d9e9ad31ba770210e535584cca3bb2)
2013-03-08 17:24:33 -05:00
Tim Abbott a22c5e63a8 create_user: Remove unused import.
(imported from commit 7a2a7c171b87d8098c0a589c1e6228c0b131eba1)
2013-03-08 17:24:33 -05:00
Waseem Daher 0e2e754c3d [manual] Use Twitter API v1.1 for inline previews.
This commit adds a dependency on python-twitter,
whose upstream is at https://github.com/bear/python-twitter,
and which for now needs to manually be installed on our
servers from the Debian package in sid.

(imported from commit 80cd9f4f59a6f0de6b75ac95e412c69e2a2e2490)
2013-03-08 17:10:06 -05:00
Waseem Daher 244b239828 twitter: Specify a width for the Twitter avatars.
This should make their size totally known to the DOM,
which should prevent jumpiness when they load.

(imported from commit 564d920014f5bc52c217adf54c2f5bab6ba625e0)
2013-03-08 17:03:47 -05:00
Jessica McKellar 2f644f8439 Add a management command to clean up lingering tutorial streams.
We now clean up the stream subscription in more places, but some
historical tutorial streams are still around and if an error or page
reload happens during the tutorial it'll stick around.

(imported from commit 8cf0ebda26bf752c1a23296a4ba85d194bbb3004)
2013-03-08 17:01:11 -05:00
Waseem Daher 1df648baa9 Add inline preview of Twitter links.
This uses the unauthed v1 of the Twitter API, which is going to go
away soon, but it's fine as an interim measure.

(imported from commit 709a250271321f5479854a363875c9da43e6382d)
2013-03-08 14:31:18 -05:00
Tim Abbott 4ab5cabb80 bugdown: Split out iteration through a tree into helper function.
(imported from commit ba73832c61eccdefe45f8e0d935216e6cc431176)
2013-03-08 14:31:17 -05:00
Waseem Daher 68fc8e161f github: Suppress pull request notifications for CUSTOMER18.
(imported from commit adacd7ef23b1762276888c9bda5c69fd6c89ede4)
2013-03-07 22:15:54 -05:00
Luke Faraone 93b4fcfeac Exclude humbuggers from the new stream modal
For people who aren't on the @humbughq.com realm the tutorial bot showed
up in the create new stream modal but attempting to invite them failed.

This was most often noticed with the tutorial bot.

In the future we should figure out a really good cross-realm story, but
in the near-term we need to probably exclude other people outside your
realm rather than special-casing @humbughq.com.

This closes trac #1059.

(imported from commit df704df0c8ae84b23d9491ce6ab77300831cdd20)
2013-03-07 16:58:29 -05:00
Waseem Daher a7495a8470 tutorial: Send an error message if the tutorial times out.
(imported from commit ae8b11f9b3d6e0480207492c4a3f64ac52b51367)
2013-03-07 16:52:52 -05:00
Waseem Daher 47da3b5229 tutorial: Get rid of unnecessary sleep.
We should start listening for the message right away,
not five seconds later.

(imported from commit 19de74e4dc309e81db56074bdc625aa76197b6ef)
2013-03-07 16:52:51 -05:00
Luke Faraone f73929c952 Update own name in sidebar when updating name globally.
We now add the my_fullname class to the entry for you in the sidebar so
that we can automatically update this element when changing your name.

This closes trac #979.

(imported from commit f1473d6bb6f18810311d42c85d4b57aab9966498)
2013-03-07 16:01:41 -05:00
Luke Faraone 34ecfb339f Add an alert to indicate bankruptcy is processing.
We also grey out the box to prevent the user from clicking twice.

This closes trac #1030.

(imported from commit eec810e3fbc5b7c9350c2d91e448fb27d4c856f8)
2013-03-07 15:50:16 -05:00
Zev Benjamin 740e48d427 Switch the MessageList from using a closed interval for its render window to a half-open interval
(imported from commit 53cdbd603d8ab68fdbb338a852cb214a35a0403d)
2013-03-07 15:22:28 -05:00
Zev Benjamin 94a3e2c7a4 Use a delegated event handler on the presence list
This code also has the side effect of making it no longer possible to
click to the right of a name to start composing a message to them.

Fixes #931

(imported from commit 80e995ccc8ead18b80a39181c47cc94d6063f0f6)
2013-03-07 14:54:41 -05:00
Zev Benjamin ebb095d0ce tests: Basic compose box tests
(imported from commit e1e7fc1f9efec464f1a86c1a8b39c1a6db207adb)
2013-03-07 14:30:08 -05:00
Tim Abbott d49e9bdf95 Select the first message to arrive in a narrowed view.
Previously, if a narrowed view started out with no message selected,
one would never be selected unless you clicked on it.

(imported from commit 11c6a1a8d046ec33a3dbea4067c40896be137485)
2013-03-07 13:24:46 -05:00
Tim Abbott c88684d1f5 Fix first message in narrowed views never appearing.
The message list data structure never had the rendered_idx values
initiatized except via _maybe_rerender (called when a message is
selected).  For the narrowed message list for streams with no messages
yet, we didn't select a message (as there was none to select); the end
result is that msg_list.append() will never rerender because it tries
to subtract undefined from undefined and gets NaN in its test for
whether it needs to rerender.

So fix this by initializing _min_rendered_idx and _max_rendered_idx to
valid values for the empty message list (the closed interval from 0 to -1).

(imported from commit 6afecb1569185a842a3a9108cedba7e88f8befad)
2013-03-07 13:24:46 -05:00
Waseem Daher 68e7a052cb Remove the link to 'activity' from the gear menu.
I find that I never use it, and I don't totally like our
experience in the app to be different from our users'.
Admittedly, this is a small way in which that's the case :)

Finally, since we do usability studies in @humbughq.com,
the link appears there too, and I'd like it not to.

(imported from commit 1225c4ae79de52fa98b21ce00a6542df76b667ea)
2013-03-07 13:12:45 -05:00
Jessica McKellar 9d821b9541 Tweak tutorial text about subjects.
Use less technical subjects, and make them good examples of actual
topics you'd want to discuss (previous examples like 'jQuery' might
leave people wondering "jQuery is a technology, not a topic, why is
that a subject?")

(imported from commit 23b74fe145ed2d325daa94a46e63c42c005b1459)
2013-03-07 10:14:13 -05:00
Waseem Daher 4ea7ac102f Allow internal_send_message to send cross-realm stream messages.
Prior to this change, any stream message sent by internal_send_message
could only be in the realm of the sender.

This was a problem most notably for... the tutorial bot, with the
hilarious consequence that the tutorial worked fine in humbughq.com,
but failed to start anywhere else.

(imported from commit 33a904a28e3a57e1a2cf9172c2e2a75b50967a50)
2013-03-06 23:04:57 -05:00
Reid Barton 6bb9ad4e3c Avoid cross-site logout attacks
Require POST method for /accounts/logout. This has the side effect of
automatically enabling Django's CSRF protection.

(imported from commit 44b1b6ebaadc1c03006e21ae54ac768e31234801)
2013-03-06 19:10:04 -05:00
Reid Barton bc0dbbb566 Detect image-ness by end of path component, not end of entire URL
(imported from commit 9dd2e9c7273d3c7d071a8e5f82014e28b2a99ee4)
2013-03-06 19:02:29 -05:00
Jeff Arnold 025b79d98b Don't change focus away from the PM recipient box on keydown
The typeaheads take some time to open and changing focus on keydown
sometimes prevents them from doing so before the focus is changed.

(imported from commit a8153704e60f3d6c34af55a3de5bd43071a15baf)
2013-03-06 18:42:52 -05:00
Waseem Daher f941a58ec1 Suppress enter-replies if a button or link has focus.
This is in response to the following bug report by Evan Broder:

FYI, it looks like if I accidentally tab to the "Formatting" link and
hit enter, it erases the message (and replaces it with a reply to
whatever the selected message is, I think?)

This is subtle and here's why: Suppose you have the focus on a
stream name in your left sidebar. j and k will still move your
cursor up and down, but Enter won't reply -- it'll just trigger
the link on the sidebar! So you keep pressing enter over and
over again. Until you click somewhere or press r.

Net-net though, I think it's a change worth making, because
it's good for keyboard accessibility.

(imported from commit b65bcc0abbc751718bb03d418c03961b9ed9e42b)
2013-03-06 18:10:20 -05:00