See friends who liked a character

This commit is contained in:
Eduard Urbach 2018-04-19 17:48:15 +02:00
parent e8062017b5
commit 290c18b8b9
5 changed files with 52 additions and 3 deletions

View File

@ -67,5 +67,18 @@ func Get(ctx *aero.Context) string {
},
}
return ctx.HTML(components.CharacterDetails(character, characterAnime, quotes, mainQuote, user))
// Friends
friendIDs := utils.Intersection(character.Likes, user.Follows().Items)
friendObjects := arn.DB.GetMany("User", friendIDs)
friends := []*arn.User{}
for _, obj := range friendObjects {
if obj == nil {
continue
}
friends = append(friends, obj.(*arn.User))
}
return ctx.HTML(components.CharacterDetails(character, characterAnime, quotes, friends, mainQuote, user))
}

View File

@ -4,7 +4,7 @@ component CharacterTabs(character *arn.Character, user *arn.User)
Tab("Edit", "pencil", character.Link() + "/edit")
Tab("History", "history", character.Link() + "/history")
component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, quotes []*arn.Quote, mainQuote *arn.Quote, user *arn.User)
component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, quotes []*arn.Quote, friends []*arn.User, mainQuote *arn.Quote, user *arn.User)
.character-page
.character-left-column
.character-header
@ -66,6 +66,19 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
else
td.character-attributes-value= attribute.Value
if len(friends) > 0
.character-friends
h3.mountable Friends
.user-avatars.mountable
each friend in friends
.mountable(data-mountable-type="friend")
if friend.IsActive()
Avatar(friend)
else
.inactive-user
Avatar(friend)
if character.GetMapping("myanimelist/character") != ""
h3.mountable Links
@ -77,4 +90,3 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
a.light-button(href="/api" + character.Link(), target="_blank")
Icon("code")
span API

View File

@ -56,6 +56,10 @@
.quote-footer
display none
.character-friends
.user-avatars
justify-content flex-start
> 1250px
.character-page
horizontal

16
utils/Intersection.go Normal file
View File

@ -0,0 +1,16 @@
package utils
import "github.com/animenotifier/arn"
// Intersection returns common elements of a and b.
func Intersection(a []string, b []string) []string {
var c []string
for _, obj := range a {
if arn.Contains(b, obj) {
c = append(c, obj)
}
}
return c
}

View File

@ -6,6 +6,10 @@ var routeTests = map[string][]string{
"/+Akyoto",
},
"/user/:nick/characters/liked": []string{
"/+Akyoto/characters/liked",
},
"/user/:nick/forum/threads": []string{
"/+Akyoto/forum/threads",
},