summaryrefslogtreecommitdiff
path: root/internal/timeline
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-07-11 16:22:21 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-11 16:22:21 +0200
commit846057f0d696fded87d105dec1245e9ba32763ce (patch)
tree9a4914c07bcf189a3eea0a2c091567c56cdf4963 /internal/timeline
parentfavourites GET implementation (#95) (diff)
downloadgotosocial-846057f0d696fded87d105dec1245e9ba32763ce.tar.xz
Block/unblock (#96)
* remote + local block logic, incl. federation * improve blocking stuff * fiddle with display of blocked profiles * go fmt
Diffstat (limited to 'internal/timeline')
-rw-r--r--internal/timeline/get.go18
-rw-r--r--internal/timeline/index.go37
-rw-r--r--internal/timeline/manager.go16
-rw-r--r--internal/timeline/postindex.go24
-rw-r--r--internal/timeline/prepare.go25
-rw-r--r--internal/timeline/preparedposts.go25
-rw-r--r--internal/timeline/remove.go70
-rw-r--r--internal/timeline/timeline.go8
8 files changed, 206 insertions, 17 deletions
diff --git a/internal/timeline/get.go b/internal/timeline/get.go
index f07d81d55..d7ebb7766 100644
--- a/internal/timeline/get.go
+++ b/internal/timeline/get.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
diff --git a/internal/timeline/index.go b/internal/timeline/index.go
index 8c6b0d578..8dd7fee97 100644
--- a/internal/timeline/index.go
+++ b/internal/timeline/index.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
@@ -44,7 +62,7 @@ grabloop:
}
for _, s := range filtered {
- if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID); err != nil {
+ if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID, s.AccountID, s.BoostOfAccountID); err != nil {
return fmt.Errorf("IndexBefore: error indexing status with id %s: %s", s.ID, err)
}
}
@@ -79,7 +97,7 @@ grabloop:
}
for _, s := range filtered {
- if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID); err != nil {
+ if _, err := t.IndexOne(s.CreatedAt, s.ID, s.BoostOfID, s.AccountID, s.BoostOfAccountID); err != nil {
return fmt.Errorf("IndexBehind: error indexing status with id %s: %s", s.ID, err)
}
}
@@ -91,24 +109,29 @@ func (t *timeline) IndexOneByID(statusID string) error {
return nil
}
-func (t *timeline) IndexOne(statusCreatedAt time.Time, statusID string, boostOfID string) (bool, error) {
+func (t *timeline) IndexOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) {
t.Lock()
defer t.Unlock()
postIndexEntry := &postIndexEntry{
- statusID: statusID,
- boostOfID: boostOfID,
+ statusID: statusID,
+ boostOfID: boostOfID,
+ accountID: accountID,
+ boostOfAccountID: boostOfAccountID,
}
return t.postIndex.insertIndexed(postIndexEntry)
}
-func (t *timeline) IndexAndPrepareOne(statusCreatedAt time.Time, statusID string) (bool, error) {
+func (t *timeline) IndexAndPrepareOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error) {
t.Lock()
defer t.Unlock()
postIndexEntry := &postIndexEntry{
- statusID: statusID,
+ statusID: statusID,
+ boostOfID: boostOfID,
+ accountID: accountID,
+ boostOfAccountID: boostOfAccountID,
}
inserted, err := t.postIndex.insertIndexed(postIndexEntry)
diff --git a/internal/timeline/manager.go b/internal/timeline/manager.go
index d50c9f783..00d87bb26 100644
--- a/internal/timeline/manager.go
+++ b/internal/timeline/manager.go
@@ -78,6 +78,8 @@ type Manager interface {
Remove(statusID string, timelineAccountID string) (int, error)
// WipeStatusFromAllTimelines removes one status from the index and prepared posts of all timelines
WipeStatusFromAllTimelines(statusID string) error
+ // WipeStatusesFromAccountID removes all statuses by the given accountID from the timelineAccountID's timelines.
+ WipeStatusesFromAccountID(accountID string, timelineAccountID string) error
}
// NewManager returns a new timeline manager with the given database, typeconverter, config, and log.
@@ -112,7 +114,7 @@ func (m *manager) Ingest(status *gtsmodel.Status, timelineAccountID string) (boo
}
l.Trace("ingesting status")
- return t.IndexOne(status.CreatedAt, status.ID, status.BoostOfID)
+ return t.IndexOne(status.CreatedAt, status.ID, status.BoostOfID, status.AccountID, status.BoostOfAccountID)
}
func (m *manager) IngestAndPrepare(status *gtsmodel.Status, timelineAccountID string) (bool, error) {
@@ -128,7 +130,7 @@ func (m *manager) IngestAndPrepare(status *gtsmodel.Status, timelineAccountID st
}
l.Trace("ingesting status")
- return t.IndexAndPrepareOne(status.CreatedAt, status.ID)
+ return t.IndexAndPrepareOne(status.CreatedAt, status.ID, status.BoostOfID, status.AccountID, status.BoostOfAccountID)
}
func (m *manager) Remove(statusID string, timelineAccountID string) (int, error) {
@@ -219,6 +221,16 @@ func (m *manager) WipeStatusFromAllTimelines(statusID string) error {
return err
}
+func (m *manager) WipeStatusesFromAccountID(accountID string, timelineAccountID string) error {
+ t, err := m.getOrCreateTimeline(timelineAccountID)
+ if err != nil {
+ return err
+ }
+
+ _, err = t.RemoveAllBy(accountID)
+ return err
+}
+
func (m *manager) getOrCreateTimeline(timelineAccountID string) (Timeline, error) {
var t Timeline
i, ok := m.accountTimelines.Load(timelineAccountID)
diff --git a/internal/timeline/postindex.go b/internal/timeline/postindex.go
index 44765bf50..db155d0fe 100644
--- a/internal/timeline/postindex.go
+++ b/internal/timeline/postindex.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
@@ -10,8 +28,10 @@ type postIndex struct {
}
type postIndexEntry struct {
- statusID string
- boostOfID string
+ statusID string
+ boostOfID string
+ accountID string
+ boostOfAccountID string
}
func (p *postIndex) insertIndexed(i *postIndexEntry) (bool, error) {
diff --git a/internal/timeline/prepare.go b/internal/timeline/prepare.go
index ac85d92e9..0fbd8ebba 100644
--- a/internal/timeline/prepare.go
+++ b/internal/timeline/prepare.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
@@ -207,8 +225,11 @@ func (t *timeline) prepare(statusID string) error {
// shove it in prepared posts as a prepared posts entry
preparedPostsEntry := &preparedPostsEntry{
- statusID: statusID,
- prepared: apiModelStatus,
+ statusID: gtsStatus.ID,
+ boostOfID: gtsStatus.BoostOfID,
+ accountID: gtsStatus.AccountID,
+ boostOfAccountID: gtsStatus.BoostOfAccountID,
+ prepared: apiModelStatus,
}
return t.preparedPosts.insertPrepared(preparedPostsEntry)
diff --git a/internal/timeline/preparedposts.go b/internal/timeline/preparedposts.go
index 1976189c8..7f8d84357 100644
--- a/internal/timeline/preparedposts.go
+++ b/internal/timeline/preparedposts.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
@@ -12,8 +30,11 @@ type preparedPosts struct {
}
type preparedPostsEntry struct {
- statusID string
- prepared *apimodel.Status
+ statusID string
+ boostOfID string
+ accountID string
+ boostOfAccountID string
+ prepared *apimodel.Status
}
func (p *preparedPosts) insertPrepared(i *preparedPostsEntry) error {
diff --git a/internal/timeline/remove.go b/internal/timeline/remove.go
index 8842c60cb..cf0b0b617 100644
--- a/internal/timeline/remove.go
+++ b/internal/timeline/remove.go
@@ -1,3 +1,21 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package timeline
import (
@@ -58,3 +76,55 @@ func (t *timeline) Remove(statusID string) (int, error) {
l.Debugf("removed %d entries", removed)
return removed, nil
}
+
+func (t *timeline) RemoveAllBy(accountID string) (int, error) {
+ l := t.log.WithFields(logrus.Fields{
+ "func": "RemoveAllBy",
+ "accountTimeline": t.accountID,
+ "accountID": accountID,
+ })
+ t.Lock()
+ defer t.Unlock()
+ var removed int
+
+ // remove entr(ies) from the post index
+ removeIndexes := []*list.Element{}
+ if t.postIndex != nil && t.postIndex.data != nil {
+ for e := t.postIndex.data.Front(); e != nil; e = e.Next() {
+ entry, ok := e.Value.(*postIndexEntry)
+ if !ok {
+ return removed, errors.New("Remove: could not parse e as a postIndexEntry")
+ }
+ if entry.accountID == accountID || entry.boostOfAccountID == accountID {
+ l.Debug("found status in postIndex")
+ removeIndexes = append(removeIndexes, e)
+ }
+ }
+ }
+ for _, e := range removeIndexes {
+ t.postIndex.data.Remove(e)
+ removed = removed + 1
+ }
+
+ // remove entr(ies) from prepared posts
+ removePrepared := []*list.Element{}
+ if t.preparedPosts != nil && t.preparedPosts.data != nil {
+ for e := t.preparedPosts.data.Front(); e != nil; e = e.Next() {
+ entry, ok := e.Value.(*preparedPostsEntry)
+ if !ok {
+ return removed, errors.New("Remove: could not parse e as a preparedPostsEntry")
+ }
+ if entry.accountID == accountID || entry.boostOfAccountID == accountID {
+ l.Debug("found status in preparedPosts")
+ removePrepared = append(removePrepared, e)
+ }
+ }
+ }
+ for _, e := range removePrepared {
+ t.preparedPosts.data.Remove(e)
+ removed = removed + 1
+ }
+
+ l.Debugf("removed %d entries", removed)
+ return removed, nil
+}
diff --git a/internal/timeline/timeline.go b/internal/timeline/timeline.go
index d0fadb19e..fe811a303 100644
--- a/internal/timeline/timeline.go
+++ b/internal/timeline/timeline.go
@@ -65,7 +65,7 @@ type Timeline interface {
//
// The returned bool indicates whether or not the status was actually inserted into the timeline. This will be false
// if the status is a boost and the original post or another boost of it already exists < boostReinsertionDepth back in the timeline.
- IndexOne(statusCreatedAt time.Time, statusID string, boostOfID string) (bool, error)
+ IndexOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error)
// OldestIndexedPostID returns the id of the rearmost (ie., the oldest) indexed post, or an error if something goes wrong.
// If nothing goes wrong but there's no oldest post, an empty string will be returned so make sure to check for this.
@@ -85,7 +85,7 @@ type Timeline interface {
//
// The returned bool indicates whether or not the status was actually inserted into the timeline. This will be false
// if the status is a boost and the original post or another boost of it already exists < boostReinsertionDepth back in the timeline.
- IndexAndPrepareOne(statusCreatedAt time.Time, statusID string) (bool, error)
+ IndexAndPrepareOne(statusCreatedAt time.Time, statusID string, boostOfID string, accountID string, boostOfAccountID string) (bool, error)
// OldestPreparedPostID returns the id of the rearmost (ie., the oldest) prepared post, or an error if something goes wrong.
// If nothing goes wrong but there's no oldest post, an empty string will be returned so make sure to check for this.
OldestPreparedPostID() (string, error)
@@ -109,6 +109,10 @@ type Timeline interface {
//
// The returned int indicates the amount of entries that were removed.
Remove(statusID string) (int, error)
+ // RemoveAllBy removes all statuses by the given accountID, from both the index and prepared posts.
+ //
+ // The returned int indicates the amount of entries that were removed.
+ RemoveAllBy(accountID string) (int, error)
}
// timeline fulfils the Timeline interface