fix(irc): view channel history (#987)

fix(irc): irc monitor channels

* base64 sse stream key
This commit is contained in:
ze0s 2023-06-15 23:17:26 +02:00 committed by GitHub
parent 2af0021ce6
commit ecc84f5f2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -5,6 +5,7 @@ package irc
import (
"context"
"encoding/base64"
"fmt"
"strings"
"sync"
@ -638,7 +639,7 @@ func (s *service) SendCmd(ctx context.Context, req *domain.SendIrcCmdRequest) er
}
func (s *service) createSSEStream(networkId int64, channel string) {
key := fmt.Sprintf("%d%s", networkId, strings.TrimPrefix(channel, "#"))
key := genSSEKey(networkId, channel)
s.sse.CreateStreamWithOpts(key, sse.StreamOpts{
MaxEntries: sseMaxEntries,
@ -647,7 +648,11 @@ func (s *service) createSSEStream(networkId int64, channel string) {
}
func (s *service) removeSSEStream(networkId int64, channel string) {
key := fmt.Sprintf("%d%s", networkId, strings.TrimPrefix(channel, "#"))
key := genSSEKey(networkId, channel)
s.sse.RemoveStream(key)
}
func genSSEKey(networkId int64, channel string) string {
return base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf("%d%s", networkId, strings.ToLower(channel))))
}