From b13b3379900cb2c00458a86176282da98537fb06 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 27 Aug 2019 15:03:29 +0900 Subject: [PATCH] Activity page shows create events only --- arn/ActivityCreate.go | 13 +++++++++++++ arn/Post.go | 5 +++++ arn/Postable.go | 1 + arn/Thread.go | 5 +++++ pages/activity/activity.go | 20 ++++++-------------- pages/activity/activity.pixy | 8 +++++--- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/arn/ActivityCreate.go b/arn/ActivityCreate.go index a4694e4c..ba3f771b 100644 --- a/arn/ActivityCreate.go +++ b/arn/ActivityCreate.go @@ -61,3 +61,16 @@ func StreamActivityCreates() <-chan *ActivityCreate { return channel } + +// FilterActivityCreates filters all ActivityCreates by a custom function. +func FilterActivityCreates(filter func(Activity) bool) []Activity { + var filtered []Activity + + for obj := range StreamActivityCreates() { + if filter(obj) { + filtered = append(filtered, obj) + } + } + + return filtered +} diff --git a/arn/Post.go b/arn/Post.go index e8da6e93..20a3511a 100644 --- a/arn/Post.go +++ b/arn/Post.go @@ -56,6 +56,11 @@ func (post *Post) GetParentID() string { return post.ParentID } +// GetParentType returns the object type of the parent. +func (post *Post) GetParentType() string { + return post.ParentType +} + // SetParent sets a new parent. func (post *Post) SetParent(newParent PostParent) { // Remove from old parent diff --git a/arn/Postable.go b/arn/Postable.go index 2225f875..5e8bab03 100644 --- a/arn/Postable.go +++ b/arn/Postable.go @@ -23,6 +23,7 @@ type Postable interface { GetText() string GetCreated() string GetParentID() string + GetParentType() string } // ToPostables converts a slice of specific types to a slice of generic postables. diff --git a/arn/Thread.go b/arn/Thread.go index b79a112c..05734f88 100644 --- a/arn/Thread.go +++ b/arn/Thread.go @@ -54,6 +54,11 @@ func (thread *Thread) GetParentID() string { return "" } +// GetParentType always returns an empty string for threads. +func (thread *Thread) GetParentType() string { + return "" +} + // TypeName returns the type name. func (thread *Thread) TypeName() string { return "Thread" diff --git a/pages/activity/activity.go b/pages/activity/activity.go index 414b9dd3..ec63de89 100644 --- a/pages/activity/activity.go +++ b/pages/activity/activity.go @@ -28,7 +28,7 @@ func fetchActivities(user *arn.User, followedOnly bool) []arn.Activity { followedUserIDs = user.Follows().Items } - activities := arn.FilterActivities(func(activity arn.Activity) bool { + activities := arn.FilterActivityCreates(func(activity arn.Activity) bool { if followedOnly && !arn.Contains(followedUserIDs, activity.GetCreatedBy()) { return false } @@ -37,22 +37,14 @@ func fetchActivities(user *arn.User, followedOnly bool) []arn.Activity { return false } - if activity.TypeName() == "ActivityCreate" { - obj := activity.(*arn.ActivityCreate).Object() + obj := activity.(*arn.ActivityCreate).Object() - if obj == nil { - return false - } - - draft, isDraftable := obj.(arn.Draftable) - return !isDraftable || !draft.GetIsDraft() + if obj == nil { + return false } - if activity.TypeName() == "ActivityConsumeAnime" { - return activity.(*arn.ActivityConsumeAnime).Anime() != nil - } - - return false + draft, isDraftable := obj.(arn.Draftable) + return !isDraftable || !draft.GetIsDraft() }) arn.SortActivitiesLatestFirst(activities) diff --git a/pages/activity/activity.pixy b/pages/activity/activity.pixy index 80c23d22..c529adff 100644 --- a/pages/activity/activity.pixy +++ b/pages/activity/activity.pixy @@ -66,13 +66,15 @@ component ActivityConsumeAnimeText(activity *arn.ActivityConsumeAnime, user *arn span= fmt.Sprintf(" episode %d.", activity.ToEpisode) component ActivityCreateMeta(activity *arn.ActivityCreate, user *arn.User) - span in - if activity.ObjectType == "Post" - a(href=activity.Postable().Parent().Link())= activity.Postable().Parent().TitleByUser(user) + if activity.Postable().GetParentType() != "User" || activity.Postable().GetParentID() != activity.CreatedBy + span in + a(href=activity.Postable().Parent().Link())= activity.Postable().Parent().TitleByUser(user) else if activity.ObjectType == "Thread" + span in a(href=activity.Postable().Link())= activity.Postable().TitleByUser(user) else if activity.ObjectType == "AMV" || activity.ObjectType == "SoundTrack" || activity.ObjectType == "Quote" + span in a(href=activity.Object().(arn.PostParent).Link())= activity.Object().(arn.PostParent).TitleByUser(user) component ActivityCreateText(activity *arn.ActivityCreate, user *arn.User)