New activity renderer

This commit is contained in:
Eduard Urbach 2018-11-12 10:41:46 +09:00
parent d86eb966c9
commit 0f0ad9047a
4 changed files with 92 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package activity
import ( import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
) )
@ -12,26 +13,29 @@ const maxActivitiesPerPage = 40
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
// entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { activities := arn.FilterActivities(func(activity arn.Activity) bool {
// if entry.Action != "create" { if activity.Type() == "ActivityCreate" {
// return false obj := activity.(*arn.ActivityCreate).Object()
// }
// obj := entry.Object() if obj == nil {
return false
}
// if obj == nil { draft, isDraftable := obj.(arn.HasDraft)
// return false
// }
// _, isPostable := obj.(arn.Postable) if isDraftable && draft.IsDraft {
// return isPostable return false
// }) }
}
// arn.SortEditLogEntriesLatestFirst(entries) return true
})
// if len(entries) > maxActivitiesPerPage { arn.SortActivitiesLatestFirst(activities)
// entries = entries[:maxActivitiesPerPage]
// }
return ctx.HTML(components.ActivityFeed(nil, user)) if len(activities) > maxActivitiesPerPage {
activities = activities[:maxActivitiesPerPage]
}
return ctx.HTML(components.ActivityFeed(activities, user))
} }

View File

@ -1,12 +1,34 @@
component ActivityFeed(entries []*arn.Activity, user *arn.User) component ActivityFeed(entries []arn.Activity, user *arn.User)
h1 Activity h1 Activity
.activities .activities
each entry in entries each entry in entries
Activity(entry, user) Activity(entry, user)
component Activity(activity *arn.Activity, user *arn.User) component Activity(activity arn.Activity, user *arn.User)
h1= activity.Text() .activity.post-parent(id=fmt.Sprintf("activity-%s", activity.GetID()))
.post-author
Avatar(activity.Creator())
.post-content
.activity-header
.activity-parent
if activity.Type() == "ActivityCreate"
ActivityCreateTitle(activity.(*arn.ActivityCreate), user)
.activity-date.utc-date(data-date=activity.GetCreated())
if activity.Type() == "ActivityCreate"
ActivityCreateText(activity.(*arn.ActivityCreate), user)
component ActivityCreateTitle(activity *arn.ActivityCreate, user *arn.User)
if activity.ObjectType == "Post"
a(href=activity.Postable().Parent().Link())= activity.Postable().Parent().TitleByUser(user)
else if activity.ObjectType == "Thread"
a(href=activity.Postable().Link())= activity.Postable().TitleByUser(user)
component ActivityCreateText(activity *arn.ActivityCreate, user *arn.User)
if activity.ObjectType == "Post" || activity.ObjectType == "Thread"
div!= activity.Postable().HTML()
//- component ActivityFeed(entries []*arn.EditLogEntry, user *arn.User) //- component ActivityFeed(entries []*arn.EditLogEntry, user *arn.User)
//- h1 Activity //- h1 Activity

View File

@ -3,3 +3,15 @@
width 100% width 100%
max-width forum-width max-width forum-width
margin 0 auto margin 0 auto
.activity-header
horizontal
.activity-user
display none
.activity-parent
flex 1
.activity-date
color hsla(text-color-h, text-color-s, text-color-l, 0.5)

View File

@ -0,0 +1,34 @@
package main
import "github.com/animenotifier/arn"
func main() {
defer arn.Node.Close()
for entry := range arn.StreamEditLogEntries() {
if entry.Action != "create" {
continue
}
obj := entry.Object()
if obj == nil {
continue
}
draft, isDraftable := obj.(arn.HasDraft)
if isDraftable && draft.IsDraft {
continue
}
activity := arn.NewActivityCreate(
entry.ObjectType,
entry.ObjectID,
entry.UserID,
)
activity.Created = entry.Created
activity.Save()
}
}