2021-07-11 14:22:21 +00:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2023-01-05 11:43:00 +00:00
|
|
|
Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2021-06-13 16:42:28 +00:00
|
|
|
package timeline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
2021-08-25 13:34:33 +00:00
|
|
|
"context"
|
2021-06-13 16:42:28 +00:00
|
|
|
"errors"
|
2021-06-21 13:56:00 +00:00
|
|
|
|
2022-07-19 08:47:55 +00:00
|
|
|
"codeberg.org/gruf/go-kv"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
2021-06-13 16:42:28 +00:00
|
|
|
)
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (t *timeline) Remove(ctx context.Context, statusID string) (int, error) {
|
2023-02-17 11:02:29 +00:00
|
|
|
l := log.WithContext(ctx).
|
|
|
|
WithFields(kv.Fields{
|
|
|
|
{"accountTimeline", t.accountID},
|
|
|
|
{"statusID", statusID},
|
|
|
|
}...)
|
2022-07-19 08:47:55 +00:00
|
|
|
|
2021-06-13 16:42:28 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
var removed int
|
|
|
|
|
|
|
|
// remove entr(ies) from the post index
|
|
|
|
removeIndexes := []*list.Element{}
|
2022-11-22 18:38:10 +00:00
|
|
|
if t.indexedItems != nil && t.indexedItems.data != nil {
|
|
|
|
for e := t.indexedItems.data.Front(); e != nil; e = e.Next() {
|
|
|
|
entry, ok := e.Value.(*indexedItemsEntry)
|
2021-06-13 16:42:28 +00:00
|
|
|
if !ok {
|
|
|
|
return removed, errors.New("Remove: could not parse e as a postIndexEntry")
|
|
|
|
}
|
2022-02-05 11:47:38 +00:00
|
|
|
if entry.itemID == statusID {
|
2021-06-21 13:56:00 +00:00
|
|
|
l.Debug("found status in postIndex")
|
2021-06-13 16:42:28 +00:00
|
|
|
removeIndexes = append(removeIndexes, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, e := range removeIndexes {
|
2022-11-22 18:38:10 +00:00
|
|
|
t.indexedItems.data.Remove(e)
|
2021-11-22 07:46:19 +00:00
|
|
|
removed++
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove entr(ies) from prepared posts
|
|
|
|
removePrepared := []*list.Element{}
|
2022-02-05 11:47:38 +00:00
|
|
|
if t.preparedItems != nil && t.preparedItems.data != nil {
|
|
|
|
for e := t.preparedItems.data.Front(); e != nil; e = e.Next() {
|
|
|
|
entry, ok := e.Value.(*preparedItemsEntry)
|
2021-06-13 16:42:28 +00:00
|
|
|
if !ok {
|
|
|
|
return removed, errors.New("Remove: could not parse e as a preparedPostsEntry")
|
|
|
|
}
|
2022-02-05 11:47:38 +00:00
|
|
|
if entry.itemID == statusID {
|
2021-06-21 13:56:00 +00:00
|
|
|
l.Debug("found status in preparedPosts")
|
2021-06-13 16:42:28 +00:00
|
|
|
removePrepared = append(removePrepared, e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, e := range removePrepared {
|
2022-02-05 11:47:38 +00:00
|
|
|
t.preparedItems.data.Remove(e)
|
2021-11-22 07:46:19 +00:00
|
|
|
removed++
|
2021-06-13 16:42:28 +00:00
|
|
|
}
|
|
|
|
|
2021-06-21 13:56:00 +00:00
|
|
|
l.Debugf("removed %d entries", removed)
|
2021-06-13 16:42:28 +00:00
|
|
|
return removed, nil
|
|
|
|
}
|
2021-07-11 14:22:21 +00:00
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (t *timeline) RemoveAllBy(ctx context.Context, accountID string) (int, error) {
|
2023-02-17 11:02:29 +00:00
|
|
|
l := log.WithContext(ctx).
|
|
|
|
WithFields(kv.Fields{
|
|
|
|
{"accountTimeline", t.accountID},
|
|
|
|
{"accountID", accountID},
|
|
|
|
}...)
|
2022-11-22 18:38:10 +00:00
|
|
|
|
2021-07-11 14:22:21 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
var removed int
|
|
|
|
|
|
|
|
// remove entr(ies) from the post index
|
|
|
|
removeIndexes := []*list.Element{}
|
2022-11-22 18:38:10 +00:00
|
|
|
if t.indexedItems != nil && t.indexedItems.data != nil {
|
|
|
|
for e := t.indexedItems.data.Front(); e != nil; e = e.Next() {
|
|
|
|
entry, ok := e.Value.(*indexedItemsEntry)
|
2021-07-11 14:22:21 +00:00
|
|
|
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 {
|
2022-11-22 18:38:10 +00:00
|
|
|
t.indexedItems.data.Remove(e)
|
2021-11-22 07:46:19 +00:00
|
|
|
removed++
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove entr(ies) from prepared posts
|
|
|
|
removePrepared := []*list.Element{}
|
2022-02-05 11:47:38 +00:00
|
|
|
if t.preparedItems != nil && t.preparedItems.data != nil {
|
|
|
|
for e := t.preparedItems.data.Front(); e != nil; e = e.Next() {
|
|
|
|
entry, ok := e.Value.(*preparedItemsEntry)
|
2021-07-11 14:22:21 +00:00
|
|
|
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 {
|
2022-02-05 11:47:38 +00:00
|
|
|
t.preparedItems.data.Remove(e)
|
2021-11-22 07:46:19 +00:00
|
|
|
removed++
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
l.Debugf("removed %d entries", removed)
|
|
|
|
return removed, nil
|
|
|
|
}
|