Improved activity page

This commit is contained in:
2021-11-23 15:47:25 +09:00
parent 1cf4e6a1ae
commit 0f5f18db0c
12 changed files with 113 additions and 32 deletions

View File

@ -47,8 +47,9 @@ func (activity *ActivityConsumeAnime) Self() Loggable {
// LastActivityConsumeAnime returns the last activity for the given anime.
func (user *User) LastActivityConsumeAnime(animeID AnimeID) *ActivityConsumeAnime {
activities := FilterActivitiesConsumeAnime(func(activity *ActivityConsumeAnime) bool {
return activity.AnimeID == animeID && activity.CreatedBy == user.ID
activities := FilterActivitiesConsumeAnime(func(activity Activity) bool {
consume := activity.(*ActivityConsumeAnime)
return consume.AnimeID == animeID && consume.CreatedBy == user.ID
})
if len(activities) == 0 {
@ -56,15 +57,15 @@ func (user *User) LastActivityConsumeAnime(animeID AnimeID) *ActivityConsumeAnim
}
sort.Slice(activities, func(i, j int) bool {
return activities[i].Created > activities[j].Created
return activities[i].GetCreated() > activities[j].GetCreated()
})
return activities[0]
return activities[0].(*ActivityConsumeAnime)
}
// FilterActivitiesConsumeAnime filters all anime consumption activities by a custom function.
func FilterActivitiesConsumeAnime(filter func(*ActivityConsumeAnime) bool) []*ActivityConsumeAnime {
var filtered []*ActivityConsumeAnime
func FilterActivitiesConsumeAnime(filter func(Activity) bool) []Activity {
var filtered []Activity
for obj := range DB.All("ActivityConsumeAnime") {
realObject := obj.(*ActivityConsumeAnime)

View File

@ -47,7 +47,7 @@ func (item *AnimeListItem) Edit(ctx aero.Context, key string, value reflect.Valu
// Broadcast event to all users so they can reload the activity page if needed.
for receiver := range StreamUsers() {
activityEvent := event.New("activity", receiver.IsFollowing(user.ID))
activityEvent := event.New("watch activity", receiver.IsFollowing(user.ID))
receiver.BroadcastEvent(activityEvent)
}
}

View File

@ -7,6 +7,7 @@ import (
"strings"
"github.com/aerogo/aero"
"github.com/aerogo/aero/event"
"github.com/aerogo/api"
"github.com/aerogo/markdown"
"github.com/animenotifier/notify.moe/arn/autocorrect"
@ -182,6 +183,12 @@ func (post *Post) Create(ctx aero.Context) error {
activity := NewActivityCreate("Post", post.ID, user.ID)
activity.Save()
// Broadcast event to all users so they can reload the activity page if needed
for receiver := range StreamUsers() {
activityEvent := event.New("post activity", receiver.IsFollowing(user.ID))
receiver.BroadcastEvent(activityEvent)
}
return nil
}

View File

@ -37,10 +37,16 @@ type Settings struct {
Notification NotificationSettings `json:"notification"`
Editor EditorSettings `json:"editor"`
Privacy PrivacySettings `json:"privacy"`
Activity ActivitySettings `json:"activity"`
Calendar CalendarSettings `json:"calendar" editable:"true"`
Theme string `json:"theme" editable:"true"`
}
// ActivitySettings ...
type ActivitySettings struct {
ShowFollowedOnly bool `json:"showFollowedOnly" editable:"true"`
}
// PrivacySettings ...
type PrivacySettings struct {
ShowAge bool `json:"showAge" editable:"true"`

View File

@ -6,6 +6,7 @@ import (
"reflect"
"github.com/aerogo/aero"
"github.com/aerogo/aero/event"
"github.com/aerogo/api"
"github.com/aerogo/markdown"
"github.com/animenotifier/notify.moe/arn/autocorrect"
@ -120,6 +121,12 @@ func (thread *Thread) Create(ctx aero.Context) error {
activity := NewActivityCreate("Thread", thread.ID, user.ID)
activity.Save()
// Broadcast event to all users so they can reload the activity page if needed
for receiver := range StreamUsers() {
activityEvent := event.New("post activity", receiver.IsFollowing(user.ID))
receiver.BroadcastEvent(activityEvent)
}
return nil
}

View File

@ -55,6 +55,10 @@ func (user *User) Unfollow(userID UserID) bool {
// IsFollowing checks if the object follows the user ID.
func (user *User) IsFollowing(userID UserID) bool {
if userID == user.ID {
return true
}
for _, item := range user.FollowIDs {
if item == userID {
return true