SaveReadMarker implements POST /rooms/{roomId}/read_markers
( req *http.Request, userAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI, syncProducer *producers.SyncAPIProducer, device *api.Device, roomID string, )
| 138 | |
| 139 | // SaveReadMarker implements POST /rooms/{roomId}/read_markers |
| 140 | func SaveReadMarker( |
| 141 | req *http.Request, |
| 142 | userAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI, |
| 143 | syncProducer *producers.SyncAPIProducer, device *api.Device, roomID string, |
| 144 | ) util.JSONResponse { |
| 145 | // Verify that the user is a member of this room |
| 146 | resErr := checkMemberInRoom(req.Context(), rsAPI, device.UserID, roomID) |
| 147 | if resErr != nil { |
| 148 | return *resErr |
| 149 | } |
| 150 | |
| 151 | var r eventutil.ReadMarkerJSON |
| 152 | resErr = httputil.UnmarshalJSONRequest(req, &r) |
| 153 | if resErr != nil { |
| 154 | return *resErr |
| 155 | } |
| 156 | |
| 157 | if r.FullyRead == "" { |
| 158 | return util.JSONResponse{ |
| 159 | Code: http.StatusBadRequest, |
| 160 | JSON: jsonerror.BadJSON("Missing m.fully_read mandatory field"), |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | data, err := json.Marshal(fullyReadEvent{EventID: r.FullyRead}) |
| 165 | if err != nil { |
| 166 | return jsonerror.InternalServerError() |
| 167 | } |
| 168 | |
| 169 | dataReq := api.InputAccountDataRequest{ |
| 170 | UserID: device.UserID, |
| 171 | DataType: "m.fully_read", |
| 172 | RoomID: roomID, |
| 173 | AccountData: data, |
| 174 | } |
| 175 | dataRes := api.InputAccountDataResponse{} |
| 176 | if err := userAPI.InputAccountData(req.Context(), &dataReq, &dataRes); err != nil { |
| 177 | util.GetLogger(req.Context()).WithError(err).Error("userAPI.InputAccountData failed") |
| 178 | return util.ErrorResponse(err) |
| 179 | } |
| 180 | |
| 181 | // Handle the read receipt that may be included in the read marker |
| 182 | if r.Read != "" { |
| 183 | return SetReceipt(req, syncProducer, device, roomID, "m.read", r.Read) |
| 184 | } |
| 185 | |
| 186 | return util.JSONResponse{ |
| 187 | Code: http.StatusOK, |
| 188 | JSON: struct{}{}, |
| 189 | } |
| 190 | } |
no test coverage detected