Seperated global and followed activity feed
This commit is contained in:
parent
76990417e4
commit
f711cdb011
@ -9,11 +9,33 @@ import (
|
|||||||
|
|
||||||
const maxActivitiesPerPage = 40
|
const maxActivitiesPerPage = 40
|
||||||
|
|
||||||
// Get activity page.
|
// Global activity page.
|
||||||
func Get(ctx *aero.Context) string {
|
func Global(ctx *aero.Context) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
activities := fetchActivities(user, false)
|
||||||
|
return ctx.HTML(components.ActivityFeed(activities, user))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Followed activity page.
|
||||||
|
func Followed(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
activities := fetchActivities(user, true)
|
||||||
|
return ctx.HTML(components.ActivityFeed(activities, user))
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchActivities filters the activities by the given filters.
|
||||||
|
func fetchActivities(user *arn.User, followedOnly bool) []arn.Activity {
|
||||||
|
var followedUserIDs []string
|
||||||
|
|
||||||
|
if followedOnly && user != nil {
|
||||||
|
followedUserIDs = user.Follows().Items
|
||||||
|
}
|
||||||
|
|
||||||
activities := arn.FilterActivities(func(activity arn.Activity) bool {
|
activities := arn.FilterActivities(func(activity arn.Activity) bool {
|
||||||
|
if followedOnly && !arn.Contains(followedUserIDs, activity.GetCreatedBy()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if activity.Type() == "ActivityCreate" {
|
if activity.Type() == "ActivityCreate" {
|
||||||
obj := activity.(*arn.ActivityCreate).Object()
|
obj := activity.(*arn.ActivityCreate).Object()
|
||||||
|
|
||||||
@ -21,8 +43,8 @@ func Get(ctx *aero.Context) string {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
draft, isDraftable := obj.(arn.HasDraft)
|
draft, isDraftable := obj.(arn.Draftable)
|
||||||
return !isDraftable || !draft.IsDraft
|
return !isDraftable || !draft.GetIsDraft()
|
||||||
}
|
}
|
||||||
|
|
||||||
if activity.Type() == "ActivityConsumeAnime" {
|
if activity.Type() == "ActivityConsumeAnime" {
|
||||||
@ -38,5 +60,5 @@ func Get(ctx *aero.Context) string {
|
|||||||
activities = activities[:maxActivitiesPerPage]
|
activities = activities[:maxActivitiesPerPage]
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.ActivityFeed(activities, user))
|
return activities
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,25 @@
|
|||||||
component ActivityFeed(entries []arn.Activity, user *arn.User)
|
component ActivityFeed(entries []arn.Activity, user *arn.User)
|
||||||
h1 Activity
|
h1.page-title Activity
|
||||||
|
|
||||||
|
.tabs
|
||||||
|
Tab("Global", "globe", "/activity")
|
||||||
|
Tab("Followed", "user-plus", "/activity/followed")
|
||||||
|
|
||||||
.activities
|
.activities
|
||||||
each entry in entries
|
if len(entries) == 0
|
||||||
Activity(entry, user)
|
p.no-data.mountable No activity here.
|
||||||
|
else
|
||||||
|
each entry in entries
|
||||||
|
Activity(entry, user)
|
||||||
|
|
||||||
|
#load-new-activities(data-count="0")
|
||||||
|
.buttons
|
||||||
|
button.page-main-action.action(data-action="reloadContent", data-trigger="click")
|
||||||
|
Icon("refresh")
|
||||||
|
span#load-new-activities-text 0 new activities
|
||||||
|
|
||||||
component Activity(activity arn.Activity, user *arn.User)
|
component Activity(activity arn.Activity, user *arn.User)
|
||||||
.activity.post-parent(id=fmt.Sprintf("activity-%s", activity.GetID()))
|
.activity.post-parent.mountable(id=fmt.Sprintf("activity-%s", activity.GetID()))
|
||||||
.post-author
|
.post-author
|
||||||
Avatar(activity.Creator())
|
Avatar(activity.Creator())
|
||||||
.post-content
|
.post-content
|
||||||
@ -29,19 +42,23 @@ component ActivityConsumeAnimeTitle(activity *arn.ActivityConsumeAnime, user *ar
|
|||||||
|
|
||||||
component ActivityConsumeAnimeText(activity *arn.ActivityConsumeAnime, user *arn.User)
|
component ActivityConsumeAnimeText(activity *arn.ActivityConsumeAnime, user *arn.User)
|
||||||
if activity.ToEpisode > activity.FromEpisode
|
if activity.ToEpisode > activity.FromEpisode
|
||||||
em= fmt.Sprintf("watched episodes %d - %d", activity.FromEpisode, activity.ToEpisode)
|
em.actvity-text-consume-anime= fmt.Sprintf("watched episodes %d - %d", activity.FromEpisode, activity.ToEpisode)
|
||||||
else
|
else
|
||||||
em= fmt.Sprintf("watched episode %d", activity.ToEpisode)
|
em.actvity-text-consume-anime= fmt.Sprintf("watched episode %d", activity.ToEpisode)
|
||||||
|
|
||||||
component ActivityCreateTitle(activity *arn.ActivityCreate, user *arn.User)
|
component ActivityCreateTitle(activity *arn.ActivityCreate, user *arn.User)
|
||||||
if activity.ObjectType == "Post"
|
if activity.ObjectType == "Post"
|
||||||
a(href=activity.Postable().Parent().Link())= activity.Postable().Parent().TitleByUser(user)
|
a(href=activity.Postable().Parent().Link())= activity.Postable().Parent().TitleByUser(user)
|
||||||
else if activity.ObjectType == "Thread"
|
else if activity.ObjectType == "Thread"
|
||||||
a(href=activity.Postable().Link())= activity.Postable().TitleByUser(user)
|
a(href=activity.Postable().Link())= activity.Postable().TitleByUser(user)
|
||||||
|
else if activity.ObjectType == "AMV" || activity.ObjectType == "SoundTrack" || activity.ObjectType == "Quote"
|
||||||
|
a(href=activity.Object().(arn.PostParent).Link())= activity.Object().(arn.PostParent).TitleByUser(user)
|
||||||
|
|
||||||
component ActivityCreateText(activity *arn.ActivityCreate, user *arn.User)
|
component ActivityCreateText(activity *arn.ActivityCreate, user *arn.User)
|
||||||
if activity.ObjectType == "Post" || activity.ObjectType == "Thread"
|
if activity.ObjectType == "Post" || activity.ObjectType == "Thread"
|
||||||
div!= activity.Postable().HTML()
|
div!= activity.Postable().HTML()
|
||||||
|
else
|
||||||
|
em.actvity-text-create= "new " + strings.ToLower(activity.ObjectType)
|
||||||
|
|
||||||
//- component ActivityFeed(entries []*arn.EditLogEntry, user *arn.User)
|
//- component ActivityFeed(entries []*arn.EditLogEntry, user *arn.User)
|
||||||
//- h1 Activity
|
//- h1 Activity
|
||||||
|
@ -14,4 +14,11 @@
|
|||||||
flex 1
|
flex 1
|
||||||
|
|
||||||
.activity-date
|
.activity-date
|
||||||
color hsla(text-color-h, text-color-s, text-color-l, 0.5)
|
color hsla(text-color-h, text-color-s, text-color-l, 0.5)
|
||||||
|
|
||||||
|
.actvity-text-create
|
||||||
|
opacity 0.8
|
||||||
|
|
||||||
|
#load-new-activities
|
||||||
|
[data-count="0"]
|
||||||
|
display none
|
@ -7,7 +7,7 @@ component Forum(tag string, threads []*arn.Thread, threadsPerPage int)
|
|||||||
ThreadList(threads)
|
ThreadList(threads)
|
||||||
|
|
||||||
.buttons
|
.buttons
|
||||||
button#new-thread.action(data-action="load", data-trigger="click", data-url="/new/thread")
|
button#new-thread.page-main-action.action(data-action="load", data-trigger="click", data-url="/new/thread")
|
||||||
Icon("plus")
|
Icon("plus")
|
||||||
span New thread
|
span New thread
|
||||||
//- if len(threads) == threadsPerPage
|
//- if len(threads) == threadsPerPage
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
.forum
|
.forum
|
||||||
vertical
|
vertical
|
||||||
align-items center
|
align-items center
|
||||||
|
|
||||||
.thread-link
|
.thread-link
|
||||||
width 100%
|
width 100%
|
||||||
max-width forum-width
|
max-width forum-width
|
||||||
|
|
||||||
> 1250px
|
> 1250px
|
||||||
#new-thread
|
.page-main-action
|
||||||
position fixed
|
position fixed
|
||||||
right content-padding
|
right content-padding
|
||||||
bottom content-padding
|
bottom content-padding
|
||||||
|
@ -20,7 +20,8 @@ func Register(l *layout.Layout) {
|
|||||||
l.Page("/login", login.Get)
|
l.Page("/login", login.Get)
|
||||||
|
|
||||||
// Activity
|
// Activity
|
||||||
l.Page("/activity", activity.Get)
|
l.Page("/activity", activity.Global)
|
||||||
|
l.Page("/activity/followed", activity.Followed)
|
||||||
|
|
||||||
// Calendar
|
// Calendar
|
||||||
l.Page("/calendar", calendar.Get)
|
l.Page("/calendar", calendar.Get)
|
||||||
|
@ -16,9 +16,15 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
draft, isDraftable := obj.(arn.HasDraft)
|
draft, isDraftable := obj.(arn.Draftable)
|
||||||
|
|
||||||
if isDraftable && draft.IsDraft {
|
if isDraftable && draft.GetIsDraft() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't create activity entries for anything
|
||||||
|
// other than posts and threads.
|
||||||
|
if entry.ObjectType != "Post" && entry.ObjectType != "Thread" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
scripts/Actions/Activity.ts
Normal file
6
scripts/Actions/Activity.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import AnimeNotifier from "scripts/AnimeNotifier"
|
||||||
|
|
||||||
|
// Reload content of current page
|
||||||
|
export function reloadContent(arn: AnimeNotifier) {
|
||||||
|
return arn.reloadContent()
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
export * from "./Activity"
|
||||||
export * from "./Audio"
|
export * from "./Audio"
|
||||||
export * from "./AnimeList"
|
export * from "./AnimeList"
|
||||||
export * from "./Diff"
|
export * from "./Diff"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import AnimeNotifier from "./AnimeNotifier"
|
import AnimeNotifier from "./AnimeNotifier"
|
||||||
|
import { plural } from "./Utils"
|
||||||
|
|
||||||
const reconnectDelay = 3000
|
const reconnectDelay = 3000
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ export default class ServerEvents {
|
|||||||
|
|
||||||
this.eventSource.addEventListener("ping", (e: any) => this.ping(e))
|
this.eventSource.addEventListener("ping", (e: any) => this.ping(e))
|
||||||
this.eventSource.addEventListener("etag", (e: any) => this.etag(e))
|
this.eventSource.addEventListener("etag", (e: any) => this.etag(e))
|
||||||
|
this.eventSource.addEventListener("activity", (e: any) => this.activity(e))
|
||||||
this.eventSource.addEventListener("notificationCount", (e: any) => this.notificationCount(e))
|
this.eventSource.addEventListener("notificationCount", (e: any) => this.notificationCount(e))
|
||||||
|
|
||||||
this.eventSource.onerror = () => {
|
this.eventSource.onerror = () => {
|
||||||
@ -58,6 +60,26 @@ export default class ServerEvents {
|
|||||||
this.etags.set(data.url, newETag)
|
this.etags.set(data.url, newETag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
activity(e: ServerEvent) {
|
||||||
|
if(!location.pathname.startsWith("/activity")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isFollowingUser = JSON.parse(e.data)
|
||||||
|
|
||||||
|
// If we're on the followed only feed and we receive an activity
|
||||||
|
// about a user we don't follow, ignore the message.
|
||||||
|
if(location.pathname.startsWith("/activity/followed") && !isFollowingUser) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let button = document.getElementById("load-new-activities")
|
||||||
|
let buttonText = document.getElementById("load-new-activities-text")
|
||||||
|
let newCount = parseInt(button.dataset.count) + 1
|
||||||
|
button.dataset.count = newCount.toString()
|
||||||
|
buttonText.textContent = plural(newCount, "new activity")
|
||||||
|
}
|
||||||
|
|
||||||
notificationCount(e: ServerEvent) {
|
notificationCount(e: ServerEvent) {
|
||||||
this.arn.notificationManager.setCounter(parseInt(e.data))
|
this.arn.notificationManager.setCounter(parseInt(e.data))
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
const specialized = {
|
||||||
|
"new activity": "new activities"
|
||||||
|
}
|
||||||
|
|
||||||
export function plural(count: number, singular: string): string {
|
export function plural(count: number, singular: string): string {
|
||||||
return (count === 1 || count === -1) ? (count + " " + singular) : (count + " " + singular + "s")
|
if(count === 1 || count === -1) {
|
||||||
|
return count + " " + singular
|
||||||
|
}
|
||||||
|
|
||||||
|
if(specialized[singular]) {
|
||||||
|
return count + " " + specialized[singular]
|
||||||
|
}
|
||||||
|
|
||||||
|
return count + " " + singular + "s"
|
||||||
}
|
}
|
@ -67,7 +67,7 @@ var routeTests = map[string][]string{
|
|||||||
},
|
},
|
||||||
|
|
||||||
"/user/:nick/animelist/watching/from/:index": []string{
|
"/user/:nick/animelist/watching/from/:index": []string{
|
||||||
"/+Akyoto/animelist/watching/from/3",
|
"/+Akyoto/animelist/watching/from/1",
|
||||||
},
|
},
|
||||||
|
|
||||||
"/user/:nick/animelist/completed": []string{
|
"/user/:nick/animelist/completed": []string{
|
||||||
|
Loading…
Reference in New Issue
Block a user