Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrich all users with relation info #26

Merged
merged 1 commit into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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