From 789a58bd7ab85736ae681f1104fa3abc5ad3a5cd Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Fri, 22 Feb 2019 22:43:25 -0500 Subject: [PATCH] api, frontend: add moderator tag to mods in comments --- api/comment_list.go | 42 +++++++++++++++++++------------- api/commenter.go | 1 + frontend/js/commento.js | 3 +++ frontend/sass/commento-card.scss | 11 +++++++++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/api/comment_list.go b/api/comment_list.go index 90bcd2a..dfc9047 100644 --- a/api/comment_list.go +++ b/api/comment_list.go @@ -119,25 +119,24 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) { } commenterHex := "anonymous" - isModerator := false - if *x.CommenterToken != "anonymous" { - c, err := commenterGetByCommenterToken(*x.CommenterToken) - if err != nil { - if err == errorNoSuchToken { - commenterHex = "anonymous" - } else { - bodyMarshal(w, response{"success": false, "message": err.Error()}) - return - } + c, err := commenterGetByCommenterToken(*x.CommenterToken) + if err != nil { + if err == errorNoSuchToken { + commenterHex = "anonymous" } else { - commenterHex = c.CommenterHex + bodyMarshal(w, response{"success": false, "message": err.Error()}) + return } + } else { + commenterHex = c.CommenterHex + } - for _, mod := range d.Moderators { - if mod.Email == c.Email { - isModerator = true - break - } + isModerator := false + modList := map[string]bool{} + for _, mod := range d.Moderators { + modList[mod.Email] = true + if mod.Email == c.Email { + isModerator = true } } @@ -149,11 +148,20 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) { return } + _commenters := map[string]commenter{} + for commenterHex, cr := range commenters { + if _, ok := modList[cr.Email]; ok { + cr.IsModerator = true + } + cr.Email = "" + _commenters[commenterHex] = cr + } + bodyMarshal(w, response{ "success": true, "domain": domain, "comments": comments, - "commenters": commenters, + "commenters": _commenters, "requireModeration": d.RequireModeration, "requireIdentification": d.RequireIdentification, "isFrozen": d.State == "frozen", diff --git a/api/commenter.go b/api/commenter.go index 59db6fc..c50c3fe 100644 --- a/api/commenter.go +++ b/api/commenter.go @@ -12,4 +12,5 @@ type commenter struct { Photo string `json:"photo"` Provider string `json:"provider,omitempty"` JoinDate time.Time `json:"joinDate,omitempty"` + IsModerator bool `json:"isModerator"` } diff --git a/frontend/js/commento.js b/frontend/js/commento.js index 3ddef80..35af7dd 100644 --- a/frontend/js/commento.js +++ b/frontend/js/commento.js @@ -743,6 +743,9 @@ if (isModerator && comment.state !== "approved") { classAdd(card, "dark-card"); } + if (commenter.isModerator) { + classAdd(name, "moderator"); + } if (comment.state === "flagged") { classAdd(name, "flagged"); } diff --git a/frontend/sass/commento-card.scss b/frontend/sass/commento-card.scss index 3583a7a..f22e647 100644 --- a/frontend/sass/commento-card.scss +++ b/frontend/sass/commento-card.scss @@ -42,6 +42,17 @@ border-radius: 100px; } + .commento-moderator::after { + content: "Moderator"; + text-transform: uppercase; + font-size: 10px; + background: $green-7; + color: white; + margin-left: 8px; + padding: 2px 6px 2px 6px; + border-radius: 100px; + } + .commento-subtitle { display: block; color: #999;