mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
Add register() call to event system
(imported from commit 0c9fbfec1866591b2169ce2da2bc2af6003f8f31)
This commit is contained in:
@@ -19,7 +19,7 @@ TEST_SUITE = False
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
INTERNAL_IPS = ('127.0.0.1',)
|
INTERNAL_IPS = ('127.0.0.1',)
|
||||||
if DEPLOYED:
|
if DEPLOYED:
|
||||||
ALLOWED_HOSTS = ['.humbughq.com']
|
ALLOWED_HOSTS = ['localhost', '.humbughq.com']
|
||||||
else:
|
else:
|
||||||
ALLOWED_HOSTS = ['localhost']
|
ALLOWED_HOSTS = ['localhost']
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ urlpatterns += patterns('zephyr.views',
|
|||||||
url(r'^json/get_profile$', 'json_get_profile'),
|
url(r'^json/get_profile$', 'json_get_profile'),
|
||||||
url(r'^json/report_error$', 'json_report_error'),
|
url(r'^json/report_error$', 'json_report_error'),
|
||||||
url(r'^json/update_message_flags$', 'json_update_flags'),
|
url(r'^json/update_message_flags$', 'json_update_flags'),
|
||||||
|
url(r'^json/register$', 'json_events_register'),
|
||||||
|
|
||||||
# These are json format views used by the API. They require an API key.
|
# These are json format views used by the API. They require an API key.
|
||||||
url(r'^api/v1/get_profile$', 'api_get_profile'),
|
url(r'^api/v1/get_profile$', 'api_get_profile'),
|
||||||
@@ -137,6 +138,8 @@ urlpatterns += patterns('zephyr.views',
|
|||||||
{'GET': 'list_subscriptions_backend',
|
{'GET': 'list_subscriptions_backend',
|
||||||
'POST': 'add_subscriptions_backend',
|
'POST': 'add_subscriptions_backend',
|
||||||
'PATCH': 'update_subscriptions_backend'}),
|
'PATCH': 'update_subscriptions_backend'}),
|
||||||
|
url(r'^api/v1/register$', 'rest_dispatch',
|
||||||
|
{'POST': 'events_register_backend'}),
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns += patterns('zephyr.tornadoviews',
|
urlpatterns += patterns('zephyr.tornadoviews',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import time
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import simplejson
|
import simplejson
|
||||||
|
import requests
|
||||||
|
|
||||||
IDLE_EVENT_QUEUE_TIMEOUT_SECS = 60 * 10
|
IDLE_EVENT_QUEUE_TIMEOUT_SECS = 60 * 10
|
||||||
|
|
||||||
@@ -118,3 +119,20 @@ def gc_event_queues():
|
|||||||
def setup_event_queue_gc(io_loop):
|
def setup_event_queue_gc(io_loop):
|
||||||
pc = PeriodicCallback(gc_event_queues, EVENT_QUEUE_GC_FREQ_MSECS, io_loop)
|
pc = PeriodicCallback(gc_event_queues, EVENT_QUEUE_GC_FREQ_MSECS, io_loop)
|
||||||
pc.start()
|
pc.start()
|
||||||
|
|
||||||
|
# Called from Django
|
||||||
|
def request_event_queue(user_profile, apply_markdown):
|
||||||
|
if settings.TORNADO_SERVER:
|
||||||
|
req = {'dont_block' : 'true',
|
||||||
|
'apply_markdown': simplejson.dumps(apply_markdown),
|
||||||
|
'client' : 'internal'}
|
||||||
|
resp = requests.get(settings.TORNADO_SERVER + '/api/v1/events',
|
||||||
|
auth=requests.auth.HTTPBasicAuth(user_profile.user.email,
|
||||||
|
user_profile.api_key),
|
||||||
|
params=req)
|
||||||
|
|
||||||
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
return resp.json['queue_id']
|
||||||
|
|
||||||
|
return None
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ var viewport = $(window);
|
|||||||
|
|
||||||
var get_updates_params = {
|
var get_updates_params = {
|
||||||
pointer: -1,
|
pointer: -1,
|
||||||
server_generation: -1 /* to be filled in on document.ready */
|
server_generation: -1, /* to be filled in on document.ready */
|
||||||
|
last_event_id: 0
|
||||||
};
|
};
|
||||||
var get_updates_failures = 0;
|
var get_updates_failures = 0;
|
||||||
|
|
||||||
@@ -604,6 +605,7 @@ function get_updates(options) {
|
|||||||
|
|
||||||
get_updates_params.pointer = furthest_read;
|
get_updates_params.pointer = furthest_read;
|
||||||
get_updates_params.dont_block = options.dont_block || get_updates_failures > 0;
|
get_updates_params.dont_block = options.dont_block || get_updates_failures > 0;
|
||||||
|
get_updates_params.queue_id = page_params.event_queue_id;
|
||||||
if (reload.is_pending()) {
|
if (reload.is_pending()) {
|
||||||
// We only send a server_generation to the server if we're
|
// We only send a server_generation to the server if we're
|
||||||
// interested in an immediate reply to tell us if we need to
|
// interested in an immediate reply to tell us if we need to
|
||||||
@@ -637,9 +639,6 @@ function get_updates(options) {
|
|||||||
reload.initiate();
|
reload.initiate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_updates_params.queue_id === undefined) {
|
|
||||||
get_updates_params.queue_id = data.queue_id;
|
|
||||||
}
|
|
||||||
var messages = [];
|
var messages = [];
|
||||||
var new_pointer;
|
var new_pointer;
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,8 @@ def rest_get_events(request, user_profile, handler,
|
|||||||
@has_request_variables
|
@has_request_variables
|
||||||
def get_events_backend(request, user_profile, handler,
|
def get_events_backend(request, user_profile, handler,
|
||||||
last_event_id = REQ(converter=to_non_negative_int, default=None),
|
last_event_id = REQ(converter=to_non_negative_int, default=None),
|
||||||
queue_id = REQ(default=None), apply_markdown=True):
|
queue_id = REQ(default=None), apply_markdown=True,
|
||||||
|
dont_block = REQ(default=False, converter=json_to_bool)):
|
||||||
if queue_id is None:
|
if queue_id is None:
|
||||||
client = allocate_client_descriptor(user_profile.id, apply_markdown)
|
client = allocate_client_descriptor(user_profile.id, apply_markdown)
|
||||||
queue_id = client.event_queue.id
|
queue_id = client.event_queue.id
|
||||||
@@ -225,7 +226,7 @@ def get_events_backend(request, user_profile, handler,
|
|||||||
client.event_queue.prune(last_event_id)
|
client.event_queue.prune(last_event_id)
|
||||||
client.disconnect_handler()
|
client.disconnect_handler()
|
||||||
|
|
||||||
if not client.event_queue.empty():
|
if not client.event_queue.empty() or dont_block:
|
||||||
return json_success({'events': client.event_queue.contents(),
|
return json_success({'events': client.event_queue.contents(),
|
||||||
'queue_id': queue_id})
|
'queue_id': queue_id})
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ from zephyr.lib.response import json_success, json_error, json_response, json_me
|
|||||||
from zephyr.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
|
from zephyr.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
|
||||||
from zephyr.lib.cache import cache_with_key
|
from zephyr.lib.cache import cache_with_key
|
||||||
from zephyr.lib.unminify import SourceMap
|
from zephyr.lib.unminify import SourceMap
|
||||||
|
from zephyr.lib.event_queue import request_event_queue
|
||||||
from zephyr import tornado_callbacks
|
from zephyr import tornado_callbacks
|
||||||
|
|
||||||
from confirmation.models import Confirmation
|
from confirmation.models import Confirmation
|
||||||
@@ -446,6 +446,7 @@ def home(request):
|
|||||||
needs_tutorial = needs_tutorial,
|
needs_tutorial = needs_tutorial,
|
||||||
desktop_notifications_enabled =
|
desktop_notifications_enabled =
|
||||||
user_profile.enable_desktop_notifications,
|
user_profile.enable_desktop_notifications,
|
||||||
|
event_queue_id = request_event_queue(user_profile, True)
|
||||||
))
|
))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1400,3 +1401,23 @@ def json_report_error(request, user_profile, message=POST, stacktrace=POST,
|
|||||||
"User saw error in UI: %s"
|
"User saw error in UI: %s"
|
||||||
% (message, stacktrace, user_agent, ui_message))
|
% (message, stacktrace, user_agent, ui_message))
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
|
@authenticated_json_post_view
|
||||||
|
def json_events_register(request, user_profile):
|
||||||
|
return events_register_backend(request, user_profile)
|
||||||
|
|
||||||
|
@authenticated_api_view
|
||||||
|
@has_request_variables
|
||||||
|
def api_events_register(request, user_profile,
|
||||||
|
apply_markdown=POST(default=False, converter=json_to_bool)):
|
||||||
|
return events_register_backend(request, user_profile,
|
||||||
|
apply_markdown=apply_markdown)
|
||||||
|
|
||||||
|
@has_request_variables
|
||||||
|
def events_register_backend(request, user_profile, apply_markdown=True,
|
||||||
|
event_types=POST(converter=json_to_list)):
|
||||||
|
queue_id = request_event_queue(user_profile, apply_markdown)
|
||||||
|
if queue_id is not None:
|
||||||
|
return json_success({'queue_id': queue_id, 'last_event_id': 0})
|
||||||
|
|
||||||
|
return json_error(msg="Tornado not available")
|
||||||
|
|||||||
Reference in New Issue
Block a user