- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.2k
Live removal of issue comments using htmx websocket #28958
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
          
     Draft
      
      
            anbraten
  wants to merge
  84
  commits into
  go-gitea:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
anbraten:issue-updates
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +524
        
        
          −9
        
        
          
        
      
    
  
  
     Draft
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            84 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      2b247dd
              
                Update issue comments
              
              
                anbraten 5005245
              
                move dep
              
              
                anbraten 7cf50ef
              
                fix htmx ws loading
              
              
                anbraten 4947abc
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 3b35637
              
                add listeners
              
              
                anbraten e85f85b
              
                Merge branch 'main' into issue-updates
              
              
                anbraten d77073b
              
                add websocket service
              
              
                anbraten 17f4faf
              
                improve websocket service
              
              
                anbraten 948f1bd
              
                cleanup
              
              
                anbraten 1d6a34d
              
                update templates
              
              
                anbraten 337456a
              
                Merge branch 'main' into issue-updates
              
              
                anbraten e4beba8
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 21bcb1b
              
                adust template
              
              
                anbraten c2ca7d8
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten fb49e6b
              
                undo some changes
              
              
                anbraten 4c03093
              
                sort imports
              
              
                anbraten 7173bea
              
                render comment template
              
              
                anbraten bc2a352
              
                improve session data and rendering
              
              
                anbraten 26ab35c
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten b2f4aae
              
                cleanup
              
              
                anbraten afcdd78
              
                Merge branch 'main' into issue-updates
              
              
                anbraten 21485f8
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 7cda3aa
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten d9c4554
              
                Merge branch 'main' into issue-updates
              
              
                anbraten ea06a25
              
                cleanup
              
              
                anbraten 9ace44c
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 78b94ff
              
                finish
              
              
                anbraten c595916
              
                fix permission
              
              
                anbraten b805631
              
                sort imports
              
              
                anbraten e9ded26
              
                Merge branch 'main' into issue-updates
              
              
                anbraten b5f61df
              
                Merge branch 'main' into issue-updates
              
              
                anbraten 7de741c
              
                use custom create-websocket
              
              
                anbraten bdde78a
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten 3d2ec73
              
                Merge branch 'main' into issue-updates
              
              
                anbraten 4f97ad2
              
                Merge branch 'main' into issue-updates
              
              
                anbraten 72bb32f
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten c1512d3
              
                rename event to e
              
              
                anbraten 201fd83
              
                rename event to e
              
              
                anbraten 39421d6
              
                undo prettier
              
              
                anbraten 634834b
              
                undo more prettier changes
              
              
                anbraten 671a8df
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 94bcdba
              
                fix imports
              
              
                anbraten 77f89b7
              
                Merge branch 'main' into issue-updates
              
              
                anbraten 1602afd
              
                remove websocket init for now, fix lint
              
              
                silverwind f2f97a2
              
                Tweak comment
              
              
                silverwind 4d75e28
              
                add return
              
              
                anbraten 7f3435f
              
                Merge branch 'main' into issue-updates
              
              
                anbraten cf23cd6
              
                go mod tidy
              
              
                anbraten bb4443d
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten 372faaa
              
                add melody pubsub
              
              
                anbraten d86c1dc
              
                Update services/pubsub/types.go
              
              
                techknowlogick 70f2fee
              
                Merge branch 'main' into pubsub
              
              
                silverwind 154f61c
              
                Merge remote-tracking branch 'upstream/main' into pubsub
              
              
                anbraten 8919106
              
                Merge branch 'pubsub' of github.com:anbraten/gitea into pubsub
              
              
                anbraten 1328b2b
              
                undo
              
              
                anbraten 0aa3d5e
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 40fc078
              
                tidy
              
              
                anbraten c6abd32
              
                fmt
              
              
                anbraten e9502e0
              
                Merge branch 'main' into issue-updates
              
              
                anbraten b8dab69
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 088454f
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten 43ad9f5
              
                add comma
              
              
                anbraten 7cb8e2f
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 602a42a
              
                adjust websocket
              
              
                anbraten 6af641f
              
                Merge remote-tracking branch 'upstream/main' into pubsub
              
              
                anbraten f83d6fe
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 0262846
              
                adjust
              
              
                anbraten aed4810
              
                Merge remote-tracking branch 'upstream/main' into pubsub
              
              
                anbraten a2e1c14
              
                Merge remote-tracking branch 'upstream/main' into pubsub
              
              
                anbraten 85cf27e
              
                adjsut
              
              
                anbraten abcc609
              
                fix
              
              
                anbraten 597fac4
              
                add pubsub
              
              
                anbraten 63f4e6c
              
                cleanup
              
              
                anbraten 7daafae
              
                Merge branch 'issue-updates' into pubsub
              
              
                anbraten edb0f9c
              
                merge
              
              
                anbraten f2001a2
              
                fix
              
              
                anbraten cbfb0bd
              
                Merge branch 'main' into pubsub
              
              
                anbraten 56d11fc
              
                update
              
              
                anbraten 877eb69
              
                Merge branch 'pubsub' of github.com:anbraten/gitea into pubsub
              
              
                anbraten d34e36b
              
                Merge branch 'main' into issue-updates
              
              
                anbraten e6da1b1
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten 5ceae12
              
                Merge branch 'issue-updates' of github.com:anbraten/gitea into issue-…
              
              
                anbraten 7efef85
              
                fix memory pubsub
              
              
                anbraten 97544d8
              
                Merge remote-tracking branch 'upstream/main' into issue-updates
              
              
                anbraten File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright 2023 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|  | ||
| package websocket | ||
|  | ||
| import ( | ||
| "time" | ||
|  | ||
| "code.gitea.io/gitea/modules/context" | ||
| "code.gitea.io/gitea/modules/web" | ||
|  | ||
| "github.com/olahol/melody" | ||
| ) | ||
|  | ||
| var m *melody.Melody | ||
|  | ||
| func Init(r *web.Route) { | ||
| m = melody.New() | ||
| r.Any("/ui-updates", WebSocket) | ||
| m.HandleMessage(HandleMessage) | ||
|  | ||
| go func() { | ||
| for { | ||
| // TODO: send proper updated html | ||
| err := m.Broadcast([]byte("<div hx-swap-oob=\"beforebegin:.timeline-item.comment.form\"><div class=\"hello\">hello world!</div></div>")) | ||
| if err != nil { | ||
| break | ||
| } | ||
| time.Sleep(5 * time.Second) | ||
| } | ||
| }() | ||
| } | ||
|  | ||
| func WebSocket(ctx *context.Context) { | ||
| err := m.HandleRequest(ctx.Resp, ctx.Req) | ||
| if err != nil { | ||
| ctx.ServerError("HandleRequest", err) | ||
| } | ||
| } | ||
|         
                  anbraten marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| func HandleMessage(s *melody.Session, msg []byte) { | ||
| // TODO: Handle incoming messages | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import * as htmx from "htmx.org"; | ||
| import { showErrorToast } from "./modules/toast.js"; | ||
| import { ws } from "./ws.js"; | ||
|  | ||
| window.htmx = htmx; | ||
|  | ||
| // TODO: https://github.com/bigskysoftware/htmx/issues/1690 | ||
| ws(); | ||
| // import("htmx.org/dist/ext/ws.js"); | ||
|  | ||
| console.log("htmx.js loaded", htmx.version, htmx); | ||
|  | ||
| // https://htmx.org/reference/#config | ||
| htmx.config.requestClass = "is-loading"; | ||
| htmx.config.scrollIntoViewOnBoost = false; | ||
|  | ||
| // https://htmx.org/events/#htmx:sendError | ||
| document.body.addEventListener("htmx:sendError", (event) => { | ||
| // TODO: add translations | ||
| showErrorToast( | ||
| `Network error when calling ${event.detail.requestConfig.path}` | ||
| ); | ||
| }); | ||
|  | ||
| // https://htmx.org/events/#htmx:responseError | ||
| document.body.addEventListener("htmx:responseError", (event) => { | ||
| // TODO: add translations | ||
| showErrorToast( | ||
| `Error ${event.detail.xhr.status} when calling ${event.detail.requestConfig.path}` | ||
| ); | ||
| }); | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.