Skip to content

Commit

Permalink
Merge pull request #27 from tapglue/connection-events-origin
Browse files Browse the repository at this point in the history
Always reference the connected uesr in connection events
  • Loading branch information
xla authored Dec 1, 2016
2 parents b942595 + 705a3f0 commit 5e38243
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit 5e38243

Please sign in to comment.