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

Always reference the connected user in connection events #27

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
23 changes: 18 additions & 5 deletions core/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func FeedEvents(
sources = []source{
sourceConnection(
append(am.followers(origin), am.friends(origin)...),
origin,
opts,
),
sourceGlobal(events, currentApp, opts),
Expand All @@ -239,7 +240,7 @@ func FeedEvents(

cs := append(a.followings(u.ID), a.friends(u.ID)...)

sources = append(sources, sourceConnection(cs, opts))
sources = append(sources, sourceConnection(cs, origin, opts))
us = append(us, am.users()...)
}

Expand Down Expand Up @@ -335,6 +336,7 @@ func FeedNews(
sources = []source{
sourceConnection(
append(am.followers(origin), am.friends(origin)...),
origin,
eventOpts,
),
sourceGlobal(events, currentApp, eventOpts),
Expand All @@ -358,7 +360,7 @@ func FeedNews(

cs := append(a.followings(u.ID), a.friends(u.ID)...)

sources = append(sources, sourceConnection(cs, eventOpts))
sources = append(sources, sourceConnection(cs, origin, eventOpts))
us = append(us, am.users()...)
}

Expand Down Expand Up @@ -490,7 +492,7 @@ func FeedNotificationsSelf(
fs = am.filterFollowings(origin)
sources = []source{
sourceComment(objects, currentApp, origin, ps.IDs()...),
sourceConnection(fs.connections(), opts),
sourceConnection(fs.connections(), origin, opts),
sourceLikes(events, currentApp, opts, origin, ps.IDs()...),
sourceTarget(events, currentApp, origin, opts),
}
Expand Down Expand Up @@ -1024,7 +1026,11 @@ func sourceComment(
}

// sourceConnection creates follow events for the given connections.
func sourceConnection(cs connection.List, opts event.QueryOptions) source {
func sourceConnection(
cs connection.List,
origin uint64,
opts event.QueryOptions,
) source {
if len(cs) == 0 {
return func() (event.List, error) {
return event.List{}, nil
Expand Down Expand Up @@ -1058,16 +1064,23 @@ func sourceConnection(cs connection.List, opts event.QueryOptions) source {
return nil, err
}

userID := con.FromID

if con.FromID == origin {
userID = con.ToID
}

es = append(es, &event.Event{
Enabled: true,
ID: id,
Owned: true,
// FIXME: Remove target.
Target: &event.Target{
ID: strconv.FormatUint(con.ToID, 10),
Type: event.TargetUser,
},
Type: t,
UserID: con.FromID,
UserID: userID,
Visibility: event.VisibilityPrivate,
CreatedAt: con.CreatedAt,
UpdatedAt: con.UpdatedAt,
Expand Down
2 changes: 1 addition & 1 deletion core/feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestSourceConnection(t *testing.T) {
}
)

es, err := sourceConnection(cs, event.QueryOptions{})()
es, err := sourceConnection(cs, from, event.QueryOptions{})()
if err != nil {
t.Fatal(err)
}
Expand Down