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

Function stateEqual

clientapi/routing/sendevent.go:242–269  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

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.
242func 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
271func generateSendEvent(
272 ctx context.Context,

Callers 1

SendEventFunction · 0.85

Calls 1

QueryCurrentStateMethod · 0.65

Tested by

no test coverage detected