(responseWriter http.ResponseWriter, request *http.Request, job *messageAnswerJob)
| 98 | } |
| 99 | |
| 100 | func streamMessageAnswerJob(responseWriter http.ResponseWriter, request *http.Request, job *messageAnswerJob) { |
| 101 | replay, ch, unsubscribe, done := job.subscribe() |
| 102 | defer unsubscribe() |
| 103 | |
| 104 | for _, chunk := range replay { |
| 105 | if _, err := responseWriter.Write(chunk); err != nil { |
| 106 | return |
| 107 | } |
| 108 | if flusher, ok := responseWriter.(http.Flusher); ok { |
| 109 | flusher.Flush() |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if done { |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | var notify <-chan struct{} |
| 118 | if request != nil { |
| 119 | notify = request.Context().Done() |
| 120 | } |
| 121 | |
| 122 | for { |
| 123 | select { |
| 124 | case chunk, ok := <-ch: |
| 125 | if !ok { |
| 126 | return |
| 127 | } |
| 128 | if _, err := responseWriter.Write(chunk); err != nil { |
| 129 | return |
| 130 | } |
| 131 | if flusher, ok := responseWriter.(http.Flusher); ok { |
| 132 | flusher.Flush() |
| 133 | } |
| 134 | case <-notify: |
| 135 | return |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func generateMessageAnswer(id string, responseWriter http.ResponseWriter, host string, lang string, signedIn bool, responseError func(string, ...interface{})) { |
| 141 | responseErrorStream := func(message *object.Message, errorText string) { |
no test coverage detected