From eb3fc4535f9556607449f249a8cc25da223099af Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Thu, 1 Dec 2016 09:32:17 +0100 Subject: [PATCH] Enrich all users with relation info This adds the relation info to the user representations in lists where it was missing until now. --- core/comment.go | 9 +++++++++ core/connection.go | 15 +++++++++++---- core/like.go | 16 +++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/core/comment.go b/core/comment.go index 947d826..713afe3 100644 --- a/core/comment.go +++ b/core/comment.go @@ -201,6 +201,13 @@ func CommentList( return nil, err } + for _, u := range um { + err = enrichRelation(connections, currentApp, origin, u) + if err != nil { + return nil, err + } + } + return &CommentFeed{Comments: cs, UserMap: um}, nil } } @@ -254,6 +261,7 @@ type CommentUpdateFunc func( new *object.Object, ) (*object.Object, error) +// CommentUpdate replaces the given comment with new values. func CommentUpdate( objects object.Service, ) CommentUpdateFunc { @@ -306,6 +314,7 @@ func CommentUpdate( } } +// IsComment indicates if Object is a comment. func IsComment(o *object.Object) bool { if o.Type != TypeComment { return false diff --git a/core/connection.go b/core/connection.go index 2336321..9ae68b1 100644 --- a/core/connection.go +++ b/core/connection.go @@ -31,7 +31,7 @@ func ConnectionByState( ) ConnectionByStateFunc { return func( currentApp *app.App, - originID uint64, + origin uint64, state connection.State, opts connection.QueryOptions, ) (*ConnectionFeed, error) { @@ -45,7 +45,7 @@ func ConnectionByState( ics, err := connections.Query(currentApp.Namespace(), connection.QueryOptions{ Before: opts.Before, Enabled: &defaultEnabled, - FromIDs: []uint64{originID}, + FromIDs: []uint64{origin}, Limit: opts.Limit, States: []connection.State{state}, }) @@ -58,7 +58,7 @@ func ConnectionByState( Enabled: &defaultEnabled, Limit: opts.Limit, States: []connection.State{state}, - ToIDs: []uint64{originID}, + ToIDs: []uint64{origin}, }) if err != nil { return nil, err @@ -82,7 +82,7 @@ func ConnectionByState( ids := []uint64{} for _, c := range cons { - if c.FromID == originID { + if c.FromID == origin { ids = append(ids, c.ToID) } else { ids = append(ids, c.FromID) @@ -98,6 +98,13 @@ func ConnectionByState( return nil, err } + for _, u := range um { + err = enrichRelation(connections, currentApp, origin, u) + if err != nil { + return nil, err + } + } + return &ConnectionFeed{ Connections: cons, UserMap: um, diff --git a/core/like.go b/core/like.go index bafb695..ec48b85 100644 --- a/core/like.go +++ b/core/like.go @@ -242,6 +242,13 @@ func LikeList( return nil, err } + for _, u := range um { + err = enrichRelation(connections, currentApp, origin, u) + if err != nil { + return nil, err + } + } + return &LikeFeed{ Likes: es, UserMap: um, @@ -256,7 +263,7 @@ type LikesUserFunc func( opts event.QueryOptions, ) (*LikeFeed, error) -// LikesUserFunc returns all Likes for the given user. +// LikesUser returns all Likes for the given user. func LikesUser( connections connection.Service, events event.Service, @@ -321,6 +328,13 @@ func LikesUser( return nil, err } + for _, u := range um { + err = enrichRelation(connections, currentApp, origin, u) + if err != nil { + return nil, err + } + } + return &LikeFeed{ Likes: ls, PostMap: ps.toMap(),