# HG changeset patch # User neko259 # Date 2016-12-29 18:26:58 # Node ID 641fa167026ce6c0a6c9fd8384949c438b957b89 # Parent eaa1de722d6aba59c09a93816d6c555c672cad78 Remove websocket support. JS internal auto-update works fine enough diff --git a/boards/config/default_settings.ini b/boards/config/default_settings.ini --- a/boards/config/default_settings.ini +++ b/boards/config/default_settings.ini @@ -38,9 +38,5 @@ MaxLandingThreads = 20 # Enable archiving threads instead of deletion when the thread limit is reached ArchiveThreads = true -[External] -# Thread update -WebsocketsEnabled = false - [RSS] MaxItems = 20 diff --git a/boards/context_processors.py b/boards/context_processors.py --- a/boards/context_processors.py +++ b/boards/context_processors.py @@ -1,11 +1,7 @@ from boards.abstracts.settingsmanager import get_settings_manager, \ SETTING_LAST_NOTIFICATION_ID, SETTING_IMAGE_VIEWER, SETTING_ONLY_FAVORITES +from boards.models import Banner from boards.models.user import Notification -from boards.models import Banner - -__author__ = 'neko259' - -import neboard from boards import settings from boards.models import Post, Tag, Thread diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -264,31 +264,6 @@ class Post(models.Model, Viewable): return get_exporter(format_type).export(self, request, include_last_update) - def notify_clients(self, recursive=True): - """ - Sends post HTML data to the thread web socket. - """ - - if not settings.get_bool('External', 'WebsocketsEnabled'): - return - - thread_ids = list() - self.get_thread().notify_clients() - - if recursive: - for reply_number in re.finditer(REGEX_REPLY, self.get_raw_text()): - post_id = reply_number.group(1) - - try: - ref_post = Post.objects.get(id=post_id) - - if ref_post.get_thread().id not in thread_ids: - # If post is in this thread, its thread was already notified. - # Otherwise, notify its thread separately. - ref_post.notify_clients(recursive=False) - except ObjectDoesNotExist: - pass - def _build_url(self): opening = self.is_opening() opening_id = self.id if opening else self.get_thread().get_opening_post_id() diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -1,20 +1,17 @@ import logging -from adjacent import Client from datetime import timedelta - +from django.db import models, transaction from django.db.models import Count, Sum, QuerySet, Q from django.utils import timezone -from django.db import models, transaction -from boards.models.attachment import FILE_TYPES_IMAGE +import boards +from boards import settings from boards.models import STATUS_BUMPLIMIT, STATUS_ACTIVE, STATUS_ARCHIVE - -from boards import settings -import boards -from boards.utils import cached_result, datetime_to_epoch +from boards.models.attachment import FILE_TYPES_IMAGE from boards.models.post import Post from boards.models.tag import Tag +from boards.utils import cached_result, datetime_to_epoch FAV_THREAD_NO_UPDATES = -1 @@ -244,18 +241,6 @@ class Thread(models.Model): post.last_edit_time = last_edit_time post.save(update_fields=['last_edit_time']) - def notify_clients(self): - if not settings.get_bool('External', 'WebsocketsEnabled'): - return - - client = Client() - - channel_name = WS_CHANNEL_THREAD + str(self.get_opening_post_id()) - client.publish(channel_name, { - WS_NOTIFICATION_TYPE: WS_NOTIFICATION_TYPE_NEW_POST, - }) - client.send() - def get_absolute_url(self): return self.get_opening_post().get_absolute_url() diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -42,8 +42,6 @@ var ALLOWED_FOR_PARTIAL_UPDATE = [ var ATTR_CLASS = 'class'; var ATTR_UID = 'data-uid'; -var wsUser = ''; - var unreadPosts = 0; var documentOriginalTitle = ''; @@ -52,56 +50,6 @@ var threadId = $('div.thread').children( var blinkColor = $('
').css('background-color'); /** - * Connect to websocket server and subscribe to thread updates. On any update we - * request a thread diff. - * - * @returns {boolean} true if connected, false otherwise - */ -function connectWebsocket() { - var metapanel = $('.metapanel')[0]; - - var wsHost = metapanel.getAttribute('data-ws-host'); - var wsPort = metapanel.getAttribute('data-ws-port'); - - if (wsHost.length > 0 && wsPort.length > 0) { - var centrifuge = new Centrifuge({ - "url": 'ws://' + wsHost + ':' + wsPort + "/connection/websocket", - "project": metapanel.getAttribute('data-ws-project'), - "user": wsUser, - "timestamp": metapanel.getAttribute('data-ws-token-time'), - "token": metapanel.getAttribute('data-ws-token'), - "debug": false - }); - - centrifuge.on('error', function(error_message) { - console.log("Error connecting to websocket server."); - console.log(error_message); - console.log("Using javascript update instead."); - - // If websockets don't work, enable JS update instead - enableJsUpdate() - }); - - centrifuge.on('connect', function() { - var channelName = 'thread:' + threadId; - centrifuge.subscribe(channelName, function(message) { - getThreadDiff(); - }); - - // For the case we closed the browser and missed some updates - getThreadDiff(); - $('#autoupdate').hide(); - }); - - centrifuge.connect(); - - return true; - } else { - return false; - } -} - -/** * Get diff of the posts from the current thread timestamp. * This is required if the browser was closed and some post updates were * missed. @@ -226,15 +174,7 @@ function enableJsUpdate() { } function initAutoupdate() { - if (location.protocol === 'https:') { - return enableJsUpdate(); - } else { - if (connectWebsocket()) { - return true; - } else { - return enableJsUpdate(); - } - } + return enableJsUpdate(); } function getReplyCount() { diff --git a/boards/templates/boards/thread.html b/boards/templates/boards/thread.html --- a/boards/templates/boards/thread.html +++ b/boards/templates/boards/thread.html @@ -24,11 +24,7 @@ + data-ws-token-time="{{ ws_token_time }}"> {% with replies_count=thread.get_reply_count%} ♥ {{ thread.get_reply_count }}{% if thread.has_post_limit %}/{{ thread.max_posts }}{% endif %} diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -155,11 +155,7 @@ class AllThreadsView(PostMixin, FileUplo ip=ip, tags=tags, tripcode=form.get_tripcode(), monochrome=monochrome, images=images, - file_urls = file_urls) - - # This is required to update the threads to which posts we have replied - # when creating this one - post.notify_clients() + file_urls=file_urls) if form.is_subscribe(): settings_manager = get_settings_manager(request) diff --git a/boards/views/thread/thread.py b/boards/views/thread/thread.py --- a/boards/views/thread/thread.py +++ b/boards/views/thread/thread.py @@ -24,11 +24,6 @@ REQ_POST_ID = 'post_id' CONTEXT_LASTUPDATE = "last_update" CONTEXT_THREAD = 'thread' -CONTEXT_WS_TOKEN = 'ws_token' -CONTEXT_WS_PROJECT = 'ws_project' -CONTEXT_WS_HOST = 'ws_host' -CONTEXT_WS_PORT = 'ws_port' -CONTEXT_WS_TIME = 'ws_token_time' CONTEXT_MODE = 'mode' CONTEXT_OP = 'opening_post' CONTEXT_FAVORITE = 'is_favorite' @@ -75,16 +70,6 @@ class ThreadView(BaseBoardView, PostMixi params[CONTEXT_FAVORITE] = favorite params[CONTEXT_RSS_URL] = self.get_rss_url(post_id) - if settings.get_bool('External', 'WebsocketsEnabled'): - token_time = format(timezone.now(), u'U') - - params[CONTEXT_WS_TIME] = token_time - params[CONTEXT_WS_TOKEN] = utils.get_websocket_token( - timestamp=token_time) - params[CONTEXT_WS_PROJECT] = neboard.settings.CENTRIFUGE_PROJECT_ID - params[CONTEXT_WS_HOST] = request.get_host().split(':')[0] - params[CONTEXT_WS_PORT] = neboard.settings.CENTRIFUGE_PORT - params.update(self.get_data(thread_to_show)) return render(request, self.get_template(), params) @@ -139,7 +124,6 @@ class ThreadView(BaseBoardView, PostMixi thread=post_thread, ip=ip, tripcode=form.get_tripcode(), images=images, file_urls=file_urls) - post.notify_clients() if form.is_subscribe(): settings_manager = get_settings_manager(request) diff --git a/neboard/settings.py b/neboard/settings.py --- a/neboard/settings.py +++ b/neboard/settings.py @@ -188,15 +188,6 @@ ALLOWED_HOSTS = ['*'] POSTING_DELAY = 20 # seconds -# Websocket settins -CENTRIFUGE_HOST = 'localhost' -CENTRIFUGE_PORT = '9090' - -CENTRIFUGE_ADDRESS = 'http://{}:{}'.format(CENTRIFUGE_HOST, CENTRIFUGE_PORT) -CENTRIFUGE_PROJECT_ID = '' -CENTRIFUGE_PROJECT_SECRET = '' -CENTRIFUGE_TIMEOUT = 5 - SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' # Debug middlewares diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ httplib2 simplejson pytube requests -adjacent pillow django>=1.8 bbcode