2023-03-12 16:00:57 +01:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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-07-11 16:22:21 +02:00
|
|
|
|
2021-06-13 18:42:28 +02:00
|
|
|
package timeline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"container/list"
|
2021-08-25 15:34:33 +02:00
|
|
|
"context"
|
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) {
|
2023-02-17 12:02:29 +01:00
|
|
|
l := log.WithContext(ctx).
|
|
|
|
WithFields(kv.Fields{
|
2023-05-25 10:37:38 +02:00
|
|
|
{"accountTimeline", t.timelineID},
|
2023-02-17 12:02:29 +01:00
|
|
|
{"statusID", statusID},
|
|
|
|
}...)
|
2022-07-19 10:47:55 +02:00
|
|
|
|
2021-06-13 18:42:28 +02:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
if t.items == nil || t.items.data == nil {
|
|
|
|
// Nothing to do.
|
|
|
|
return 0, nil
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
|
|
|
|
2023-04-06 13:43:13 +02:00
|
|
|
var toRemove []*list.Element
|
|
|
|
for e := t.items.data.Front(); e != nil; e = e.Next() {
|
2023-10-04 14:09:42 +02:00
|
|
|
entry := e.Value.(*indexedItemsEntry)
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
if entry.itemID != statusID {
|
|
|
|
// Not relevant.
|
|
|
|
continue
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
l.Debug("removing item")
|
|
|
|
toRemove = append(toRemove, e)
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
for _, e := range toRemove {
|
|
|
|
t.items.data.Remove(e)
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
|
|
|
|
2023-04-06 13:43:13 +02:00
|
|
|
return len(toRemove), nil
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
2021-07-11 16:22:21 +02:00
|
|
|
|
2023-04-06 13:43:13 +02:00
|
|
|
func (t *timeline) RemoveAllByOrBoosting(ctx context.Context, accountID string) (int, error) {
|
|
|
|
l := log.
|
|
|
|
WithContext(ctx).
|
2023-02-17 12:02:29 +01:00
|
|
|
WithFields(kv.Fields{
|
2023-05-25 10:37:38 +02:00
|
|
|
{"accountTimeline", t.timelineID},
|
2023-02-17 12:02:29 +01:00
|
|
|
{"accountID", accountID},
|
|
|
|
}...)
|
2022-11-22 19:38:10 +01:00
|
|
|
|
2021-07-11 16:22:21 +02:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
if t.items == nil || t.items.data == nil {
|
|
|
|
// Nothing to do.
|
|
|
|
return 0, nil
|
2021-07-11 16:22:21 +02:00
|
|
|
}
|
|
|
|
|
2023-04-06 13:43:13 +02:00
|
|
|
var toRemove []*list.Element
|
|
|
|
for e := t.items.data.Front(); e != nil; e = e.Next() {
|
2023-10-04 14:09:42 +02:00
|
|
|
entry := e.Value.(*indexedItemsEntry)
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
if entry.accountID != accountID && entry.boostOfAccountID != accountID {
|
|
|
|
// Not relevant.
|
|
|
|
continue
|
2021-07-11 16:22:21 +02:00
|
|
|
}
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
l.Debug("removing item")
|
|
|
|
toRemove = append(toRemove, e)
|
2021-07-11 16:22:21 +02:00
|
|
|
}
|
2023-04-06 13:43:13 +02:00
|
|
|
|
|
|
|
for _, e := range toRemove {
|
|
|
|
t.items.data.Remove(e)
|
2021-07-11 16:22:21 +02:00
|
|
|
}
|
|
|
|
|
2023-04-06 13:43:13 +02:00
|
|
|
return len(toRemove), nil
|
2021-07-11 16:22:21 +02:00
|
|
|
}
|