From 797d40f9c111efbee5f3093b2d0b99f2b1c51681 Mon Sep 17 00:00:00 2001 From: Ryan Stafford Date: Sat, 16 Dec 2023 21:24:26 -0500 Subject: [PATCH] add support for blocking instances --- public/utils.js | 16 ++++++++++++++++ routes.go | 22 ++++++++++++++++++++++ templates/block.html | 14 ++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/public/utils.js b/public/utils.js index 5355d2f..c05cb41 100644 --- a/public/utils.js +++ b/public/utils.js @@ -257,17 +257,33 @@ function formSubmit(e) { if (data.get("op") == "block_post") { var post = document.getElementById("p"+data.get("postid")) var user = post.getElementsByClassName("submitter")[0].href + var userinstance = user.split('@').pop() + if (userinstance == user) { + userinstance = '' + } var community = post.getElementsByClassName("community")[0].href + var postinstance = community.split('@').pop() + if (postinstance == community) { + postinstance = '' + } var posts = Array.prototype.slice.call(document.getElementsByClassName("post")) for (var i = 0; i < posts.length; i++) { var user2 = posts[i].getElementsByClassName("submitter")[0].href + var userinstance2 = user2.split('@').pop() var community2 = posts[i].getElementsByClassName("community")[0].href + var postinstance2 = community2.split('@').pop() if (data.get("blockcommunity") != null && community2 == community) { posts[i].remove() } if (data.get("blockuser") != null && user2 == user) { posts[i].remove() } + if (data.get("blockuserinstance") != null && (userinstance == userinstance2 || userinstance == postinstance2)) { + posts[i].remove() + } + if (data.get("blockpostinstance") != null && (postinstance == userinstance2 || postinstance == postinstance2)) { + posts[i].remove() + } } targ.remove() return diff --git a/routes.go b/routes.go index 4ffdf78..a828a72 100644 --- a/routes.go +++ b/routes.go @@ -75,6 +75,14 @@ var funcMap = template.FuncMap{ } return false }, + "instance": func(actorID string) string { + l, err := url.Parse(actorID) + if err != nil { + fmt.Println(err) + return "" + } + return l.Host + }, "domain": func(p Post) string { if p.Post.URL.IsValid() { l, err := url.Parse(p.Post.URL.String()) @@ -1231,6 +1239,20 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { Block: true, }) } + if r.FormValue("blockpostinstance") != "" && len(state.Posts) > 0 { + instanceID, _ := strconv.ParseInt(r.FormValue("postinstanceid"), 10, 64) + state.Client.BlockInstance(context.Background(), lemmy.BlockInstance{ + InstanceID: instanceID, + Block: true, + }) + } + if r.FormValue("blockuserinstance") != "" && len(state.Posts) > 0 { + instanceID, _ := strconv.ParseInt(r.FormValue("userinstanceid"), 10, 64) + state.Client.BlockInstance(context.Background(), lemmy.BlockInstance{ + InstanceID: instanceID, + Block: true, + }) + } case "read_post": postid, _ := strconv.ParseInt(r.FormValue("postid"), 10, 64) post := lemmy.MarkPostAsRead{ diff --git a/templates/block.html b/templates/block.html index 311634c..4beaa8c 100644 --- a/templates/block.html +++ b/templates/block.html @@ -7,13 +7,27 @@ + {{ if and (not (index .Posts 0).Creator.Local) (ne (index .Posts 0).Creator.InstanceID .Community.CommunityView.Community.InstanceID) }} +
+ + +
+ {{ end }}
+ {{ if not .Community.CommunityView.Community.Local }} +
+ + +
+ {{ end }}
+ +