Skip to content

Commit

Permalink
Merge pull request #26 from tapglue/enrich-relations
Browse files Browse the repository at this point in the history
Enrich all users with relation info
  • Loading branch information
xla authored Dec 1, 2016
2 parents 184df65 + eb3fc45 commit f93e2b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
9 changes: 9 additions & 0 deletions core/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions core/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ConnectionByState(
) ConnectionByStateFunc {
return func(
currentApp *app.App,
originID uint64,
origin uint64,
state connection.State,
opts connection.QueryOptions,
) (*ConnectionFeed, error) {
Expand All @@ -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},
})
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion core/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit f93e2b8

Please sign in to comment.