mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-21 13:17:13 +00:00
add support for blocking instances
This commit is contained in:
parent
3d549f66e8
commit
797d40f9c1
|
@ -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
|
||||
|
|
22
routes.go
22
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{
|
||||
|
|
|
@ -7,13 +7,27 @@
|
|||
<input type="checkbox" id="blockuser" name="blockuser" checked>
|
||||
<label for="blockuser">u/{{ fullname (index .Posts 0).Creator }}</label>
|
||||
</div>
|
||||
{{ if and (not (index .Posts 0).Creator.Local) (ne (index .Posts 0).Creator.InstanceID .Community.CommunityView.Community.InstanceID) }}
|
||||
<div>
|
||||
<input type="checkbox" id="blockuserinstance" name="blockuserinstance">
|
||||
<label for="blockuserinstance">{{ instance (index .Posts 0).Creator.ActorID }}</label>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div>
|
||||
<input type="checkbox" id="blockcommunity" name="blockcommunity">
|
||||
<label for="blockcommunity">c/{{ fullcname .Community.CommunityView.Community }}</label>
|
||||
</div>
|
||||
{{ if not .Community.CommunityView.Community.Local }}
|
||||
<div>
|
||||
<input type="checkbox" id="blockpostinstance" name="blockpostinstance">
|
||||
<label for="blockpostinstance">{{ instance .Community.CommunityView.Community.ActorID }}</label>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div>
|
||||
<input type="hidden" name="op" value="block_post">
|
||||
<input type="hidden" name="postid" value="{{(index .Posts 0).Post.ID}}">
|
||||
<input type="hidden" name="userinstanceid" value="{{(index .Posts 0).Creator.InstanceID}}">
|
||||
<input type="hidden" name="postinstanceid" value="{{.Community.CommunityView.Community.InstanceID}}">
|
||||
<input type="submit" value="block" name="submit">
|
||||
<input type="submit" value="cancel" name="submit">
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue