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