diff options
author | FChannel <> | 2021-07-15 14:47:22 -0700 |
---|---|---|
committer | FChannel <> | 2021-07-15 14:47:22 -0700 |
commit | e97c3e9d2d1bedf63a7d341eb199c9500bcd8cd9 (patch) | |
tree | 809ed7c01e51e3ef7beb746b3dc77f17fdca3936 | |
parent | 22ee823b6e9200317337941c2ad41ca9df9dd855 (diff) |
can follow other boards followers or following by passing in the url you want to follow eg https://fchan.xyz/b/following and your board will follow all the boards that board is following or https://fchan.xyz/b/followers to follow all that boards followers
-rw-r--r-- | follow.go | 17 | ||||
-rw-r--r-- | main.go | 50 | ||||
-rw-r--r-- | static/faq.html | 2 | ||||
-rw-r--r-- | static/manage.html | 6 |
4 files changed, 58 insertions, 17 deletions
@@ -152,17 +152,22 @@ func RejectActivity(activity Activity) Activity { return accept } -func SetActorFollowerDB(db *sql.DB, activity Activity) Activity { - var query string - alreadyFollow := false - followers := GetActorFollowDB(db, activity.Actor.Id) +func IsAlreadyFollowing(db *sql.DB, actor string, follow string) bool { + followers := GetActorFollowingDB(db, actor) for _, e := range followers { - if e.Id == activity.Object.Actor { - alreadyFollow = true + if e.Id == follow { + return true } } + return false; +} + +func SetActorFollowerDB(db *sql.DB, activity Activity) Activity { + var query string + alreadyFollow := IsAlreadyFollowing(db, activity.Actor.Id, activity.Object.Actor) + if alreadyFollow { query = `delete from follower where id=$1 and follower=$2` activity.Summary = activity.Object.Actor + " Unfollow " + activity.Actor.Id @@ -474,15 +474,51 @@ func main() { if follow || adminFollow { r.ParseForm() - followActivity := MakeFollowActivity(db, r.FormValue("actor"), r.FormValue("follow")) + following := regexp.MustCompile(`(.+)\/following`) + followers := regexp.MustCompile(`(.+)\/followers`) + + follow := r.FormValue("follow") + actorId := r.FormValue("actor") + + //follow all of boards following + if following.MatchString(follow) { + followingActor := FingerActor(follow) + col := GetActorCollection(followingActor.Following) + for _, e := range col.Items { + if !IsAlreadyFollowing(db, actorId, e.Id) && e.Id != Domain { + followActivity := MakeFollowActivity(db, actorId, e.Id) + + if FingerActor(e.Id).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } + } + } + + //follow all of boards followers + } else if followers.MatchString(follow){ + followersActor := FingerActor(follow) + col := GetActorCollection(followersActor.Followers) + for _, e := range col.Items { + if !IsAlreadyFollowing(db, actorId, e.Id) && e.Id != Domain { + followActivity := MakeFollowActivity(db, actorId, e.Id) + if FingerActor(e.Id).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } + } + } + + //do a normal follow to a single board + } else { + followActivity := MakeFollowActivity(db, actorId, follow) - if followActivity.Actor.Id == Domain && !IsActorLocal(db, followActivity.Object.Actor) { - w.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it.")) - return - } + if followActivity.Actor.Id == Domain && !IsActorLocal(db, followActivity.Object.Actor) { + w.Write([]byte("main board can only follow local boards. Create a new board and then follow outside boards from it.")) + return + } - if FingerActor(r.FormValue("follow")).Id != "" { - MakeActivityRequestOutbox(db, followActivity) + if FingerActor(follow).Id != "" { + MakeActivityRequestOutbox(db, followActivity) + } } var redirect string diff --git a/static/faq.html b/static/faq.html index 5d70e8e..08a38f4 100644 --- a/static/faq.html +++ b/static/faq.html @@ -56,7 +56,7 @@ <p>Soon™.</p> <h4 id="version">What version is this FChannel instance?</h4> - <p>v0.0.9-dev</p> + <p>v0.0.10-dev</p> </div> <div style="width: 500px; margin:0 auto; margin-top: 50px; text-align: center;"> <a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a> diff --git a/static/manage.html b/static/manage.html index 86b35d4..a9dc47e 100644 --- a/static/manage.html +++ b/static/manage.html @@ -21,11 +21,11 @@ {{ $key := .Key }} {{ if .IsLocal }} <div id="following" class="popup-box" style="margin-bottom: 25px; margin-top: 5px; padding: 12px;"> - <h4 style="margin: 0; margin-bottom: 5px;">Subscribed</h4> + <h4 style="margin: 0; margin-bottom: 5px;">Following</h4> <a href="/autosubscribe?board={{ .Board.Name }}">{{ if .AutoSubscribe }}[Auto Subscribe On]{{ else }}[Auto Subscribe Off]{{ end }}</a> <form id="follow-form" action="/{{ .Key }}/{{ .Board.Name }}/follow" method="post" enctype="application/x-www-form-urlencoded" style="margin-top: 5px;"> <input id="follow" name="follow" style="margin-bottom: 12px;" placeholder="https://fchan.xyz/g"></input> - <input type="submit" value="Subscribe"><br> + <input type="submit" value="Follow"><br> <input type="hidden" name="actor" value="{{ $board.Actor.Id }}"> </form> <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> @@ -36,7 +36,7 @@ </div> <div id="followers" class="popup-box" style="margin-bottom: 25px; padding: 12px;"> - <h4 style="margin: 0; margin-bottom: 5px;">Subscribers</h4> + <h4 style="margin: 0; margin-bottom: 5px;">Followers</h4> <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> {{ range .Followers }} <li><a href="{{ . }}">{{ . }}</a></li> |