From 705a3f052bf5f31c9a86300c6bf429c088642bf9 Mon Sep 17 00:00:00 2001 From: Alexander Simmerl Date: Thu, 1 Dec 2016 11:30:33 +0100 Subject: [PATCH] Always reference the connected uesr in connection events As it would put additional burden on the client to distinct which user to get (target or normal) we just always use the connected user to avoid potentially breaking and spotty logic. --- core/feed.go | 23 ++++++++++++++++++----- core/feed_test.go | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/feed.go b/core/feed.go index 003e056..19b06bb 100644 --- a/core/feed.go +++ b/core/feed.go @@ -216,6 +216,7 @@ func FeedEvents( sources = []source{ sourceConnection( append(am.followers(origin), am.friends(origin)...), + origin, opts, ), sourceGlobal(events, currentApp, opts), @@ -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()...) } @@ -335,6 +336,7 @@ func FeedNews( sources = []source{ sourceConnection( append(am.followers(origin), am.friends(origin)...), + origin, eventOpts, ), sourceGlobal(events, currentApp, eventOpts), @@ -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()...) } @@ -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), } @@ -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 @@ -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, diff --git a/core/feed_test.go b/core/feed_test.go index 9949cc0..437e522 100644 --- a/core/feed_test.go +++ b/core/feed_test.go @@ -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) }