diff --git a/Schema/ClientEvent.json b/Schema/ClientEvent.json index 967e806..a8cb424 100644 --- a/Schema/ClientEvent.json +++ b/Schema/ClientEvent.json @@ -45,6 +45,9 @@ "state_key": { "type": "string" }, + "redacts": { + "type": "string" + }, "type": { "type": "string", "required": true diff --git a/Schema/SyncResponse.json b/Schema/SyncResponse.json index 74c5259..364e25c 100644 --- a/Schema/SyncResponse.json +++ b/Schema/SyncResponse.json @@ -67,6 +67,7 @@ "origin_server_ts": { "type": "integer", "required": true }, "sender": { "type": "string", "required": true }, "state_key": { "type": "string" }, + "redacts": { "type": "string" }, "type": { "type": "string", "required": true } }, "type": "struct" diff --git a/src/Room.c b/src/Room.c index 0160d32..9dd0fe8 100644 --- a/src/Room.c +++ b/src/Room.c @@ -618,12 +618,13 @@ RoomLeave(Room *room, User *user, char **errp) return ret; } char * -RoomRedact(Room *room, User *user, char *eventID, char **errp) +RoomRedact(Room *room, User *user, char *eventID, char *reason, char **errp) { CommonID *userId = NULL; char *userString = NULL; char *server = NULL; HashMap *event = NULL; + HashMap *content = NULL; HashMap *pdu = NULL; char *ret = NULL; @@ -657,9 +658,11 @@ RoomRedact(Room *room, User *user, char *eventID, char **errp) goto end; } + content = HashMapCreate(); + HashMapSet(content, "reason", JsonValueString(reason)); event = RoomEventCreate(userString, "m.room.redaction", NULL, - HashMapCreate() + content ); HashMapSet(event, "redacts", JsonValueString(eventID)); pdu = RoomEventSend(room, event, errp); diff --git a/src/Room/V1/Send.c b/src/Room/V1/Send.c index 42f7396..03d50b9 100644 --- a/src/Room/V1/Send.c +++ b/src/Room/V1/Send.c @@ -56,6 +56,8 @@ EventFitsV1(PduV1 pdu) JsonFree(hm); return ret; } + +/* TODO: Rejection */ static PduV1Status RoomGetEventStatusV1(Room *room, PduV1 *pdu, State *prev, bool client, char **errp) { @@ -79,17 +81,17 @@ RoomGetEventStatusV1(Room *room, PduV1 *pdu, State *prev, bool client, char **er } if (!RoomAuthoriseEventV1(room, *pdu, prev, errp)) { - /* Reject this event as the current state does not allow it. - * TODO: Make the auth check function return a string showing the - * errorr status to the user. */ + /* Reject this event as the PDU's own state does not allow it. */ return PDUV1_STATUS_DROPPED; } if (!client) { + /* Checking for soft-failure is not that useful in that case, + * we're only doing pointless computation. */ State *current = StateCurrent(room); - if (!RoomAuthoriseEventV1(room, *pdu, current, NULL)) + if (!RoomAuthoriseEventV1(room, *pdu, current, errp)) { StateFree(current); return PDUV1_STATUS_SOFTFAIL; diff --git a/src/Routes/RouteRedact.c b/src/Routes/RouteRedact.c index c83b5e3..c421570 100644 --- a/src/Routes/RouteRedact.c +++ b/src/Routes/RouteRedact.c @@ -57,6 +57,7 @@ ROUTE_IMPL(RouteRedact, path, argp) char *transId = ArrayGet(path, 2); char *redactId = NULL; char *sender = NULL; + char *reason = NULL; Room *room = NULL; @@ -97,6 +98,7 @@ ROUTE_IMPL(RouteRedact, path, argp) response = MatrixErrorCreate(M_NOT_JSON, NULL); goto finish; } + reason = JsonValueAsString(HashMapGet(request, "reason")); user = UserAuthenticate(db, token); if (!user) @@ -123,7 +125,7 @@ ROUTE_IMPL(RouteRedact, path, argp) goto finish; } - if (!(redactId = RoomRedact(room, user, eventId, &err))) + if (!(redactId = RoomRedact(room, user, eventId, reason, &err))) { HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); response = MatrixErrorCreate(M_FORBIDDEN, err); diff --git a/src/include/Room.h b/src/include/Room.h index ac4ccb5..69e3c4d 100644 --- a/src/include/Room.h +++ b/src/include/Room.h @@ -234,7 +234,7 @@ extern bool RoomCanJoin(Room *, char *); /** * Makes a local user redact an event(from it's ID). */ -extern char * RoomRedact(Room *, User *, char *, char **); +extern char * RoomRedact(Room *, User *, char *, char *, char **); /** * Makes a local user join a room, and returns true if