From bd44d4247c8e0be6b8611431cf521fe88f8545a2 Mon Sep 17 00:00:00 2001 From: Tim DuBois Date: Fri, 21 Apr 2017 00:18:10 +0200 Subject: [PATCH] Highlighting for author comments, author can be set in isso.conf --- isso/__init__.py | 1 + isso/css/isso.css | 5 +++++ isso/js/app/api.js | 15 +++++++++++++++ isso/js/app/isso.js | 2 ++ isso/js/app/text/comment.jade | 2 +- isso/views/comments.py | 10 ++++++++++ share/isso.conf | 4 ++++ 7 files changed, 38 insertions(+), 1 deletion(-) diff --git a/isso/__init__.py b/isso/__init__.py index 7795c4ffc..db9fd50c2 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -90,6 +90,7 @@ def __init__(self, conf): self.signer = URLSafeTimedSerializer(self.db.preferences.get("session-key")) self.markup = html.Markup(conf.section('markup')) self.hasher = hash.new(conf.section("hash")) + self.author = self.hasher.uhash(conf.get('general', 'author')); super(Isso, self).__init__(conf) diff --git a/isso/css/isso.css b/isso/css/isso.css index 456740c96..2da77342b 100644 --- a/isso/css/isso.css +++ b/isso/css/isso.css @@ -23,6 +23,11 @@ color: #AAA; } +.isso-highlight { + padding: 0em 0em 0.5em 0.5em; + background-color: rgba(200, 200, 200, 0.4); +} + .isso-comment { max-width: 68em; padding-top: 0.95em; diff --git a/isso/js/app/api.js b/isso/js/app/api.js index d0fbf2f6f..d2ee59c9f 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -177,6 +177,20 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { return deferred.promise; }; + var author = function() { + var deferred = Q.defer(); + curl("GET", endpoint + "/author", null, function(rv) { + if (rv.status === 200) { + deferred.resolve(JSON.parse(rv.body)); + } else if (rv.status === 404) { + deferred.resolve({author: ""}); + } else { + deferred.reject(rv.body); + } + }); + return deferred.promise; + }; + var like = function(id) { var deferred = Q.defer(); curl("POST", endpoint + "/id/" + id + "/like", null, @@ -201,6 +215,7 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { view: view, fetch: fetch, count: count, + author: author, like: like, dislike: dislike }; diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 0523e9bd4..bd36acc45 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -5,6 +5,8 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n", "use strict"; + api.author().then(function(rv) { config["blogauthor"] = rv; }); + var Postbox = function(parent) { var localStorage = utils.localStorageImpl, diff --git a/isso/js/app/text/comment.jade b/isso/js/app/text/comment.jade index 4884bf7d0..d6d483fc1 100644 --- a/isso/js/app/text/comment.jade +++ b/isso/js/app/text/comment.jade @@ -1,4 +1,4 @@ -div(class='isso-comment' id='isso-#{comment.id}') +div(class=(comment.hash == conf.blogauthor) ? 'isso-comment isso-highlight' : 'isso-comment' id='isso-#{comment.id}') if conf.avatar div(class='avatar') svg(data-hash='#{comment.hash}') diff --git a/isso/views/comments.py b/isso/views/comments.py index d3283058f..4ee2dffa3 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -82,6 +82,7 @@ class API(object): ('new', ('POST', '/new')), ('count', ('GET', '/count')), ('counts', ('POST', '/count')), + ('author', ('GET', '/author')), ('view', ('GET', '/id/')), ('edit', ('PUT', '/id/')), ('delete', ('DELETE', '/id/')), @@ -480,6 +481,15 @@ def counts(self, environ, request): return JSON(self.comments.count(*data), 200) + def author(self, environ, request): + + rv = self.isso.author + + if rv == "": + raise NotFound + + return JSON(rv, 200) + def preview(self, environment, request): data = request.get_json() diff --git a/share/isso.conf b/share/isso.conf index 7c275ace0..fa66020b6 100644 --- a/share/isso.conf +++ b/share/isso.conf @@ -26,6 +26,10 @@ name = # host = +# The email address you use on this website. +# This will identify you as the author of the site via highlighted comments. +author = + # time range that allows users to edit/remove their own comments. # It supports years, weeks, days, hours, minutes, seconds. # 3h45m12s equals to 3 hours, 45 minutes and 12 seconds.