stateEqual compares the new and the existing state event content. If they are equal, returns a *util.JSONResponse with the existing event_id, making this an idempotent request.
(ctx context.Context, rsAPI api.ClientRoomserverAPI, eventType, stateKey, roomID string, newContent map[string]interface{})
| 240 | // stateEqual compares the new and the existing state event content. If they are equal, returns a *util.JSONResponse |
| 241 | // with the existing event_id, making this an idempotent request. |
| 242 | func stateEqual(ctx context.Context, rsAPI api.ClientRoomserverAPI, eventType, stateKey, roomID string, newContent map[string]interface{}) *util.JSONResponse { |
| 243 | stateRes := api.QueryCurrentStateResponse{} |
| 244 | tuple := gomatrixserverlib.StateKeyTuple{ |
| 245 | EventType: eventType, |
| 246 | StateKey: stateKey, |
| 247 | } |
| 248 | err := rsAPI.QueryCurrentState(ctx, &api.QueryCurrentStateRequest{ |
| 249 | RoomID: roomID, |
| 250 | StateTuples: []gomatrixserverlib.StateKeyTuple{tuple}, |
| 251 | }, &stateRes) |
| 252 | if err != nil { |
| 253 | return nil |
| 254 | } |
| 255 | if existingEvent, ok := stateRes.StateEvents[tuple]; ok { |
| 256 | var existingContent map[string]interface{} |
| 257 | if err = json.Unmarshal(existingEvent.Content(), &existingContent); err != nil { |
| 258 | return nil |
| 259 | } |
| 260 | if reflect.DeepEqual(existingContent, newContent) { |
| 261 | return &util.JSONResponse{ |
| 262 | Code: http.StatusOK, |
| 263 | JSON: sendEventResponse{existingEvent.EventID()}, |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | } |
| 268 | return nil |
| 269 | } |
| 270 | |
| 271 | func generateSendEvent( |
| 272 | ctx context.Context, |
no test coverage detected