Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live removal of issue comments using htmx websocket #28958

Open
wants to merge 84 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
2b247dd
Update issue comments
anbraten Jan 27, 2024
5005245
move dep
anbraten Jan 27, 2024
7cf50ef
fix htmx ws loading
anbraten Jan 28, 2024
4947abc
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Jan 30, 2024
3b35637
add listeners
anbraten Feb 3, 2024
e85f85b
Merge branch 'main' into issue-updates
anbraten Feb 3, 2024
d77073b
add websocket service
anbraten Feb 3, 2024
17f4faf
improve websocket service
anbraten Feb 3, 2024
948f1bd
cleanup
anbraten Feb 3, 2024
1d6a34d
update templates
anbraten Feb 3, 2024
337456a
Merge branch 'main' into issue-updates
anbraten Feb 3, 2024
e4beba8
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 3, 2024
21bcb1b
adust template
anbraten Feb 3, 2024
c2ca7d8
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Feb 3, 2024
fb49e6b
undo some changes
anbraten Feb 3, 2024
4c03093
sort imports
anbraten Feb 3, 2024
7173bea
render comment template
anbraten Feb 3, 2024
bc2a352
improve session data and rendering
anbraten Feb 11, 2024
26ab35c
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 11, 2024
b2f4aae
cleanup
anbraten Feb 11, 2024
afcdd78
Merge branch 'main' into issue-updates
anbraten Feb 11, 2024
21485f8
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 16, 2024
7cda3aa
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Feb 16, 2024
d9c4554
Merge branch 'main' into issue-updates
anbraten Feb 16, 2024
ea06a25
cleanup
anbraten Feb 16, 2024
9ace44c
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 16, 2024
78b94ff
finish
anbraten Feb 16, 2024
c595916
fix permission
anbraten Feb 16, 2024
b805631
sort imports
anbraten Feb 16, 2024
e9ded26
Merge branch 'main' into issue-updates
anbraten Feb 17, 2024
b5f61df
Merge branch 'main' into issue-updates
anbraten Feb 19, 2024
7de741c
use custom create-websocket
anbraten Feb 20, 2024
bdde78a
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Feb 20, 2024
3d2ec73
Merge branch 'main' into issue-updates
anbraten Feb 20, 2024
4f97ad2
Merge branch 'main' into issue-updates
anbraten Feb 22, 2024
72bb32f
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 24, 2024
c1512d3
rename event to e
anbraten Feb 24, 2024
201fd83
rename event to e
anbraten Feb 24, 2024
39421d6
undo prettier
anbraten Feb 24, 2024
634834b
undo more prettier changes
anbraten Feb 24, 2024
671a8df
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Feb 27, 2024
94bcdba
fix imports
anbraten Feb 27, 2024
77f89b7
Merge branch 'main' into issue-updates
anbraten Mar 4, 2024
1602afd
remove websocket init for now, fix lint
silverwind Mar 4, 2024
f2f97a2
Tweak comment
silverwind Mar 7, 2024
4d75e28
add return
anbraten Mar 9, 2024
7f3435f
Merge branch 'main' into issue-updates
anbraten Mar 9, 2024
cf23cd6
go mod tidy
anbraten Mar 9, 2024
bb4443d
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Mar 9, 2024
372faaa
add melody pubsub
anbraten Mar 11, 2024
d86c1dc
Update services/pubsub/types.go
techknowlogick Mar 11, 2024
70f2fee
Merge branch 'main' into pubsub
silverwind Mar 13, 2024
154f61c
Merge remote-tracking branch 'upstream/main' into pubsub
anbraten Mar 21, 2024
8919106
Merge branch 'pubsub' of github.com:anbraten/gitea into pubsub
anbraten Mar 21, 2024
1328b2b
undo
anbraten Mar 21, 2024
0aa3d5e
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Mar 21, 2024
40fc078
tidy
anbraten Mar 21, 2024
c6abd32
fmt
anbraten Mar 21, 2024
e9502e0
Merge branch 'main' into issue-updates
anbraten Apr 3, 2024
b8dab69
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Apr 3, 2024
088454f
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Apr 3, 2024
43ad9f5
add comma
anbraten Apr 3, 2024
7cb8e2f
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Apr 6, 2024
602a42a
adjust websocket
anbraten Apr 6, 2024
6af641f
Merge remote-tracking branch 'upstream/main' into pubsub
anbraten Jun 20, 2024
f83d6fe
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Jun 20, 2024
0262846
adjust
anbraten Jun 26, 2024
aed4810
Merge remote-tracking branch 'upstream/main' into pubsub
anbraten Jul 9, 2024
a2e1c14
Merge remote-tracking branch 'upstream/main' into pubsub
anbraten Sep 19, 2024
85cf27e
adjsut
anbraten Sep 19, 2024
abcc609
fix
anbraten Sep 19, 2024
597fac4
add pubsub
anbraten Sep 20, 2024
63f4e6c
cleanup
anbraten Sep 20, 2024
7daafae
Merge branch 'issue-updates' into pubsub
anbraten Sep 20, 2024
edb0f9c
merge
anbraten Sep 20, 2024
f2001a2
fix
anbraten Sep 20, 2024
cbfb0bd
Merge branch 'main' into pubsub
anbraten Sep 20, 2024
56d11fc
update
anbraten Sep 20, 2024
877eb69
Merge branch 'pubsub' of github.com:anbraten/gitea into pubsub
anbraten Sep 20, 2024
d34e36b
Merge branch 'main' into issue-updates
anbraten Sep 25, 2024
e6da1b1
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Oct 1, 2024
5ceae12
Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
anbraten Oct 1, 2024
7efef85
fix memory pubsub
anbraten Oct 7, 2024
97544d8
Merge remote-tracking branch 'upstream/main' into issue-updates
anbraten Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion assets/go-licenses.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ require (
github.com/microcosm-cc/bluemonday v1.0.26
github.com/microsoft/go-mssqldb v1.7.2
github.com/minio/minio-go/v7 v7.0.77
github.com/mitchellh/mapstructure v1.5.0
github.com/msteinert/pam v1.2.0
github.com/nektos/act v0.2.63
github.com/niklasfasching/go-org v1.7.0
github.com/olahol/melody v1.1.4
github.com/olivere/elastic/v7 v7.0.32
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
Expand Down Expand Up @@ -235,11 +237,12 @@ require (
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
Expand All @@ -259,7 +262,6 @@ require (
github.com/miekg/dns v1.1.61 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pw
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/sessions v1.3.0 h1:XYlkq7KcpOB2ZhHBPv5WpjMIxrQosiZanfoy1HLZFzg=
github.com/gorilla/sessions v1.3.0/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
Expand All @@ -481,12 +483,13 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -650,6 +653,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olahol/melody v1.1.4 h1:RQHfKZkQmDxI0+SLZRNBCn4LiXdqxLKRGSkT8Dyoe/E=
github.com/olahol/melody v1.1.4/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E=
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"esbuild-loader": "4.2.2",
"escape-goat": "4.0.0",
"fast-glob": "3.3.2",
"htmx-ext-ws": "2.0.1",
"htmx.org": "2.0.3",
"idiomorph": "0.3.0",
"jquery": "3.7.1",
Expand Down
3 changes: 3 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"code.gitea.io/gitea/routers/web/user"
user_setting "code.gitea.io/gitea/routers/web/user/setting"
"code.gitea.io/gitea/routers/web/user/setting/security"
"code.gitea.io/gitea/routers/web/websocket"
auth_service "code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms"
Expand Down Expand Up @@ -546,6 +547,8 @@ func registerRoutes(m *web.Router) {

m.Any("/user/events", routing.MarkLongPolling, events.Events)

websocket.Init(m)

m.Group("/login/oauth", func() {
m.Get("/authorize", web.Bind(forms.AuthorizationForm{}), auth.AuthorizeOAuth)
m.Post("/grant", web.Bind(forms.GrantApplicationForm{}), auth.GrantApplicationOAuth)
Expand Down
22 changes: 22 additions & 0 deletions routers/web/websocket/websocket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package websocket

import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/websocket"
)

func Init(r *web.Router) {
m := websocket.Init()

r.Any("/-/ws", func(ctx *context.Context) {
err := m.HandleRequest(ctx.Resp, ctx.Req)
if err != nil {
ctx.ServerError("HandleRequest", err)
return
}
})
anbraten marked this conversation as resolved.
Show resolved Hide resolved
}
13 changes: 13 additions & 0 deletions services/context/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package context

import (
"bufio"
"errors"
"net"
"net/http"

web_types "code.gitea.io/gitea/modules/web/types"
Expand All @@ -30,6 +33,14 @@ type Response struct {
status int
befores []func(ResponseWriter)
beforeExecuted bool
hijacker http.Hijacker
}

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if r.hijacker == nil {
return nil, nil, errors.New("http.Hijacker not implemented by underlying http.ResponseWriter")
}
return r.hijacker.Hijack()
}

// Write writes bytes to HTTP endpoint
Expand Down Expand Up @@ -95,9 +106,11 @@ func WrapResponseWriter(resp http.ResponseWriter) *Response {
if v, ok := resp.(*Response); ok {
return v
}
hijacker, _ := resp.(http.Hijacker)
return &Response{
ResponseWriter: resp,
status: 0,
befores: make([]func(ResponseWriter), 0),
hijacker: hijacker,
}
}
65 changes: 65 additions & 0 deletions services/pubsub/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package pubsub

import (
"context"
"errors"
"sync"
)

type Memory struct {
sync.Mutex

topics map[string]map[*Subscriber]struct{}
}

// New creates an in-memory publisher.
func NewMemory() Broker {
return &Memory{
topics: make(map[string]map[*Subscriber]struct{}),
}
}

func (p *Memory) Publish(_ context.Context, _topic string, data []byte) error {
p.Lock()

topic, ok := p.topics[_topic]
if !ok {
p.Unlock()
return errors.New("topic not found")
}

for s := range topic {
go (*s)(data)
}
p.Unlock()

return nil
}

func (p *Memory) Subscribe(c context.Context, topic string, subscriber Subscriber) {
// Subscribe
p.Lock()
_, ok := p.topics[topic]
if !ok {
p.topics[topic] = make(map[*Subscriber]struct{})
}
p.topics[topic][&subscriber] = struct{}{}
p.Unlock()

// Unsubscribe when context is done
go func() {
// Wait for context to be done
<-c.Done()

// Unsubscribe
p.Lock()
delete(p.topics[topic], &subscriber)
if len(p.topics[topic]) == 0 {
delete(p.topics, topic)
}
p.Unlock()
}()
}
34 changes: 34 additions & 0 deletions services/pubsub/memory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package pubsub

import (
"context"
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

func TestPubsub(t *testing.T) {
var (
wg sync.WaitGroup
testTopic = "hello-world"
testMessage = []byte("test")
)

ctx, cancel := context.WithCancelCause(
context.Background(),
)

broker := NewMemory()
broker.Subscribe(ctx, testTopic, func(message []byte) { assert.Equal(t, testMessage, message); wg.Done() })
broker.Subscribe(ctx, testTopic, func(_ []byte) { wg.Done() })

wg.Add(2)
broker.Publish(ctx, testTopic, testMessage)

wg.Wait()
cancel(nil)
}
56 changes: 56 additions & 0 deletions services/pubsub/notifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package pubsub

import (
"context"

issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
notify_service "code.gitea.io/gitea/services/notify"
)

func InitWithNotifier() Broker {
broker := NewMemory() // TODO: allow for other pubsub implementations
notify_service.RegisterNotifier(newNotifier(broker))
return broker
}

type pubsubNotifier struct {
notify_service.NullNotifier
broker Broker
}

// NewNotifier create a new pubsubNotifier notifier
func newNotifier(broker Broker) notify_service.Notifier {
return &pubsubNotifier{
broker: broker,
}
}

func (p *pubsubNotifier) DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
data := struct {
Function string
Comment *issues_model.Comment
Doer *user_model.User
}{
Function: "DeleteComment",
Comment: c,
Doer: doer,
}

msg, err := json.Marshal(data)
if err != nil {
log.Error("Failed to marshal message: %v", err)
return
}

err = p.broker.Publish(ctx, "notify", msg)
if err != nil {
log.Error("Failed to publish message: %v", err)
return
}
}
14 changes: 14 additions & 0 deletions services/pubsub/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package pubsub

import "context"

// Subscriber receives published messages.
type Subscriber func(data []byte)

type Broker interface {
Publish(c context.Context, topic string, data []byte) error
Subscribe(c context.Context, topic string, subscriber Subscriber)
}
49 changes: 49 additions & 0 deletions services/websocket/comment_notifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package websocket

import (
"context"
"fmt"

issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"

"github.com/olahol/melody"
)

func (n *websocketNotifier) filterIssueSessions(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue) []*melody.Session {
return n.filterSessions(func(s *melody.Session, data *sessionData) bool {
// if the user is watching the issue, they will get notifications
if !data.isOnURL(fmt.Sprintf("/%s/%s/issues/%d", repo.Owner.Name, repo.Name, issue.Index)) {
return false
}

// the user will get notifications if they have access to the repos issues
hasAccess, err := access.HasAccessUnit(ctx, data.user, repo, unit.TypeIssues, perm.AccessModeRead)
if err != nil {
log.Error("Failed to check access: %v", err)
return false
}

return hasAccess
})
}

func (n *websocketNotifier) DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
sessions := n.filterIssueSessions(ctx, c.Issue.Repo, c.Issue)

for _, s := range sessions {
msg := fmt.Sprintf(htmxRemoveElement, fmt.Sprintf("#%s", c.HashTag()))
err := s.Write([]byte(msg))
if err != nil {
log.Error("Failed to write to session: %v", err)
}
}
}
Loading
Loading