From 0f0ad9047aa46596f23d197f0f6bbd772c9fc70e Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 12 Nov 2018 10:41:46 +0900 Subject: [PATCH] New activity renderer --- pages/activity/activity.go | 36 ++++++++++--------- pages/activity/activity.pixy | 28 +++++++++++++-- pages/activity/activity.scarlet | 14 +++++++- .../activity-recreate-from-log.go | 34 ++++++++++++++++++ 4 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 patches/activity-recreate-from-log/activity-recreate-from-log.go diff --git a/pages/activity/activity.go b/pages/activity/activity.go index 26617880..acafb9b6 100644 --- a/pages/activity/activity.go +++ b/pages/activity/activity.go @@ -2,6 +2,7 @@ package activity import ( "github.com/aerogo/aero" + "github.com/animenotifier/arn" "github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/utils" ) @@ -12,26 +13,29 @@ const maxActivitiesPerPage = 40 func Get(ctx *aero.Context) string { user := utils.GetUser(ctx) - // entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { - // if entry.Action != "create" { - // return false - // } + activities := arn.FilterActivities(func(activity arn.Activity) bool { + if activity.Type() == "ActivityCreate" { + obj := activity.(*arn.ActivityCreate).Object() - // obj := entry.Object() + if obj == nil { + return false + } - // if obj == nil { - // return false - // } + draft, isDraftable := obj.(arn.HasDraft) - // _, isPostable := obj.(arn.Postable) - // return isPostable - // }) + if isDraftable && draft.IsDraft { + return false + } + } - // arn.SortEditLogEntriesLatestFirst(entries) + return true + }) - // if len(entries) > maxActivitiesPerPage { - // entries = entries[:maxActivitiesPerPage] - // } + arn.SortActivitiesLatestFirst(activities) - return ctx.HTML(components.ActivityFeed(nil, user)) + if len(activities) > maxActivitiesPerPage { + activities = activities[:maxActivitiesPerPage] + } + + return ctx.HTML(components.ActivityFeed(activities, user)) } diff --git a/pages/activity/activity.pixy b/pages/activity/activity.pixy index 01f4b616..cf4fc4ec 100644 --- a/pages/activity/activity.pixy +++ b/pages/activity/activity.pixy @@ -1,12 +1,34 @@ -component ActivityFeed(entries []*arn.Activity, user *arn.User) +component ActivityFeed(entries []arn.Activity, user *arn.User) h1 Activity .activities each entry in entries Activity(entry, user) -component Activity(activity *arn.Activity, user *arn.User) - h1= activity.Text() +component Activity(activity arn.Activity, user *arn.User) + .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) //- h1 Activity diff --git a/pages/activity/activity.scarlet b/pages/activity/activity.scarlet index 1f3ed4f1..b19f5fb8 100644 --- a/pages/activity/activity.scarlet +++ b/pages/activity/activity.scarlet @@ -2,4 +2,16 @@ vertical width 100% max-width forum-width - margin 0 auto \ No newline at end of file + 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) \ No newline at end of file diff --git a/patches/activity-recreate-from-log/activity-recreate-from-log.go b/patches/activity-recreate-from-log/activity-recreate-from-log.go new file mode 100644 index 00000000..9508d5cc --- /dev/null +++ b/patches/activity-recreate-from-log/activity-recreate-from-log.go @@ -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() + } +}