Skip to content

Commit

Permalink
Follower profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Nov 7, 2023
1 parent 4b48840 commit 1e926b6
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 35 deletions.
63 changes: 63 additions & 0 deletions _embed/templates/user-inbox/follower.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{- $url := .QueryParam "url" -}}
{{- $profile := .ActivityStream $url -}}
{{- $following := .AmFollowing $url -}}
{{- $outbox := $profile.Outbox | collection 4 -}}

<div hx-get="/@me/inbox/follower?url={{$url}}" hx-trigger="refreshSection from:window" hx-swap="outerHTML" hx-push-url="false">

{{- if ne "" $profile.Image.URL -}}
<div style="position:absolute; top:0px; left:0px; right:0px; height:160px; background-image:url('{{$profile.Image.URL}}'); background-size:cover;"></div>
<div style="height:160px;"></div>
{{- end -}}

<div class="flex-row space-below">
{{- if ne "" $profile.Icon.URL -}}
<img src="{{$profile.Icon.URL}}" class="circle-64">
{{- else -}}
<div class="circle-64"></div>
{{- end -}}
<div>
<h1 style="margin:0px;">{{- $profile.Name -}}</h1>
<div class="text-gray"><a href="{{$profile}}" target="_blank">@{{- $profile.PreferredUsername -}}</a></div>
<div>
<a href="{{$profile}}" class="button text-xs" target="_blank">View Profile</a>

{{- if $following.NotZero -}}
<button hx-post="/@me/inbox/following-delete?followingId={{$following.FollowingID.Hex}}" hx-push-url="false" hx-confirm="Do You Want To Stop Following {{$profile.Name}}?" class="button text-xs">&check; Following</a>
{{- else -}}
<button hx-get="/@me/inbox/following-add?url={{$profile.ID}}" hx-push-url="false" class="button text-xs">&plus; Follow</a>
{{- end -}}
</div>
</div>

</div>

{{- $profile.Summary | html -}}

{{- if eq 0 (len $outbox ) -}}
<div>This Person Does Not Have Any Posts.</div>

{{- else -}}

{{- range $outbox -}}
<hr>
<div role="link" script="on click go to url '{{.ID}}' in new window">
{{- if ne "" .Name -}}
<div><span class="bold">{{.Name | textOnly}}</span> &middot; {{.Published.Format "Jan 2, 2006"}}</div>
<div>{{.Content | textOnly | summary}}</div>

{{- else if ne "" .Summary -}}
<div class="bold">{{.Published.Format "Jan 2, 2006"}}</div>
<div>{{.Summary | textOnly | summary}}</div>

{{- else -}}
<div class="bold">{{.Published.Format "Jan 2, 2006"}}</div>
<div>{{.Content | textOnly | summary}}</div>

{{- end -}}

</div>
{{- end -}}

{{- end -}}
</div>
6 changes: 3 additions & 3 deletions _embed/templates/user-inbox/followers-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

{{ range $followers }}
<tr role="button">
<td hx-get="/@me/inbox/activitypub-profile?uri={{.Actor.ProfileURL}}" style="width:32px;">
<td hx-get="/@me/inbox/follower?url={{.Actor.ProfileURL}}" style="width:32px;">
<img src="{{.Actor.ImageURL}}" class="circle" style="width:24px;">
</td>
<td hx-get="/@me/inbox/activitypub-profile?uri={{.Actor.ProfileURL}}">
{{ if ne "" .Actor.Name }}
<td hx-get="/@me/inbox/follower?url={{.Actor.ProfileURL}}">
{{ if ne "" .Actor.Name }}
{{- .Actor.Name -}}
{{- else if ne "" .Actor.ProfileURL -}}
{{- .Actor.ProfileURL -}}
Expand Down
19 changes: 5 additions & 14 deletions _embed/templates/user-inbox/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,11 @@
]}
]
},
"follower-edit": {
"roles":["self"],
"follower":{
"roles": ["self"],
"steps":[
{"step":"with-follower", "steps":[
{"step":"as-modal", "steps":[
{"step":"edit", "form":{
"type":"layout-vertical",
"label":"Edit Follower",
"children": [
{"type":"text", "path":"name", "label":"Name", "readOnly":true},
{"type":"text", "path":"url", "label":"URL"}
]
}}
]}
{"step":"as-modal", "steps":[
{"step":"view-html", "file":"follower"}
]}
]
},
Expand Down Expand Up @@ -293,7 +284,7 @@
"steps":[
{"step":"with-following", "steps":[
{"step":"delete", "title":"Stop Following {{.Label}}", "message":"Are you sure you want to delete this follow?"},
{"step":"reload-page"}
{"step":"trigger-event", "event":"refreshSection"}
]}
]
},
Expand Down
19 changes: 1 addition & 18 deletions _embed/templates/user-outbox/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,14 @@
]}
]
},
"follower-edit": {
"roles":["self"],
"steps":[
{"step":"with-follower", "steps":[
{"step":"as-modal", "steps":[
{"step":"edit", "form":{
"type":"layout-vertical",
"label":"Edit Follower",
"children": [
{"type":"text", "path":"name", "label":"Name", "readOnly":true},
{"type":"text", "path":"url", "label":"URL"}
]
}}
]}
]}
]
},

"follow": {
"steps": [
{"step":"as-modal", "background":"profile", "steps":[
{"step":"view-html", "file":"follow"}
]}
]
},

"following": {"step":"view-html", "file":"inbox-following"},
"following-list": {"step":"view-html", "file":"inbox-following-list"},
"following-add":{
Expand Down
19 changes: 19 additions & 0 deletions render/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"time"

"github.com/benpate/derp"
"github.com/benpate/hannibal/streams"
"github.com/benpate/rosetta/html"
"github.com/davecgh/go-spew/spew"

Expand Down Expand Up @@ -162,5 +164,22 @@ func FuncMap(icons icon.Provider) template.FuncMap {
}
return ""
},

"collection": func(max int, collection streams.Document) ([]streams.Document, error) {
it, err := streams.NewIterator(collection)

if err != nil {
return nil, derp.ReportAndReturn(err)
}

result := make([]streams.Document, 0, max)

for it.HasNext() && len(result) < max {
document := it.Next().UnwrapActivity()
result = append(result, document)
}

return result, nil
},
}
}
19 changes: 19 additions & 0 deletions render/renderer_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,25 @@ func (w Inbox) Responses(message model.Message) template.HTML {
return template.HTML(buffer.String())
}

func (w Inbox) AmFollowing(uri string) model.Following {

// Get following service and new following record
followingService := w._factory.Following()
following := model.NewFollowing()

// Null check
if w._user == nil {
return following
}

// Retrieve following record. Discard errors
// nolint:errcheck
_ = followingService.LoadByURL(w._user.UserID, uri, &following)

// Return the (possibly empty) Following record
return following
}

func (w Inbox) debug() {
log.Debug().Interface("object", w.object()).Msg("renderer_Inbox")
}

0 comments on commit 1e926b6

Please sign in to comment.