summaryrefslogtreecommitdiff
path: root/internal/processing/streaming/streamdelete.go
blob: cd541bc5733c937b35a1ebd6137d3246145b4bbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package streaming

import (
	"fmt"
	"strings"

	"github.com/superseriousbusiness/gotosocial/internal/stream"
)

func (p *processor) StreamDelete(statusID string) error {
	errs := []string{}

	// we want to range through ALL streams for ALL accounts here to make sure it's very clear to everyone that the status has been deleted
	p.streamMap.Range(func(k interface{}, v interface{}) bool {
		// the key of this map should be an accountID (string)
		accountID, ok := k.(string)
		if !ok {
			errs = append(errs, "key in streamMap was not a string!")
			return false
		}

		// the value of the map should be a buncha streams
		streamsForAccount, ok := v.(*stream.StreamsForAccount)
		if !ok {
			errs = append(errs, fmt.Sprintf("stream map error for account stream %s", accountID))
		}

		// lock the streams while we work on them
		streamsForAccount.Lock()
		defer streamsForAccount.Unlock()
		for _, s := range streamsForAccount.Streams {
			// lock each individual stream as we work on it
			s.Lock()
			defer s.Unlock()
			if s.Connected {
				s.Messages <- &stream.Message{
					Stream:  []string{s.Type},
					Event:   "delete",
					Payload: statusID,
				}
			}
		}
		return true
	})

	if len(errs) != 0 {
		return fmt.Errorf("one or more errors streaming status delete: %s", strings.Join(errs, ";"))
	}

	return nil
}