SendTyping handles PUT /rooms/{roomID}/typing/{userID} sends the typing events to client API typingProducer
( req *http.Request, device *userapi.Device, roomID string, userID string, rsAPI roomserverAPI.ClientRoomserverAPI, syncProducer *producers.SyncAPIProducer, )
| 31 | // SendTyping handles PUT /rooms/{roomID}/typing/{userID} |
| 32 | // sends the typing events to client API typingProducer |
| 33 | func SendTyping( |
| 34 | req *http.Request, device *userapi.Device, roomID string, |
| 35 | userID string, rsAPI roomserverAPI.ClientRoomserverAPI, |
| 36 | syncProducer *producers.SyncAPIProducer, |
| 37 | ) util.JSONResponse { |
| 38 | if device.UserID != userID { |
| 39 | return util.JSONResponse{ |
| 40 | Code: http.StatusForbidden, |
| 41 | JSON: jsonerror.Forbidden("Cannot set another user's typing state"), |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Verify that the user is a member of this room |
| 46 | resErr := checkMemberInRoom(req.Context(), rsAPI, userID, roomID) |
| 47 | if resErr != nil { |
| 48 | return *resErr |
| 49 | } |
| 50 | |
| 51 | // parse the incoming http request |
| 52 | var r typingContentJSON |
| 53 | resErr = httputil.UnmarshalJSONRequest(req, &r) |
| 54 | if resErr != nil { |
| 55 | return *resErr |
| 56 | } |
| 57 | |
| 58 | if err := syncProducer.SendTyping(req.Context(), userID, roomID, r.Typing, r.Timeout); err != nil { |
| 59 | util.GetLogger(req.Context()).WithError(err).Error("eduProducer.Send failed") |
| 60 | return jsonerror.InternalServerError() |
| 61 | } |
| 62 | |
| 63 | return util.JSONResponse{ |
| 64 | Code: http.StatusOK, |
| 65 | JSON: struct{}{}, |
| 66 | } |
| 67 | } |
no test coverage detected