MCPcopy Create free account
hub / github.com/daodst/chat / SendTyping

Function SendTyping

clientapi/routing/sendtyping.go:33–67  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

31// SendTyping handles PUT /rooms/{roomID}/typing/{userID}
32// sends the typing events to client API typingProducer
33func 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}

Callers 1

SetupFunction · 0.85

Calls 4

checkMemberInRoomFunction · 0.85
ContextMethod · 0.80
SendTypingMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected