mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 12:52:24 +03:00
Use *spec.SenderID
for QuerySenderIDForUser
(#3164)
There are cases where a dendrite instance is unaware of a pseudo ID for a user, the user is not a member of that room. To represent this case, we currently use the 'zero' value, which is often not checked and so causes errors later down the line. To make this case more explict, and to be consistent with `QueryUserIDForSender`, this PR changes this to use a pointer (and `nil` to mean no sender ID). Signed-off-by: `Sam Wedgwood <sam@wedgwood.dev>`
This commit is contained in:
parent
af13fa1c75
commit
c7193e24d0
23 changed files with 129 additions and 65 deletions
|
@ -74,6 +74,16 @@ func SendRedaction(
|
|||
return *resErr
|
||||
}
|
||||
|
||||
// if user is member of room, and sender ID is nil, then this user doesn't have a pseudo ID for some reason,
|
||||
// which is unexpected.
|
||||
if senderID == nil {
|
||||
util.GetLogger(req.Context()).WithField("userID", *deviceUserID).WithField("roomID", roomID).Error("missing sender ID for user, despite having membership")
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.Unknown("internal server error"),
|
||||
}
|
||||
}
|
||||
|
||||
if txnID != nil {
|
||||
// Try to fetch response from transactionsCache
|
||||
if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID, req.URL); ok {
|
||||
|
@ -98,7 +108,7 @@ func SendRedaction(
|
|||
// "Users may redact their own events, and any user with a power level greater than or equal
|
||||
// to the redact power level of the room may redact events there"
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
|
||||
allowedToRedact := ev.SenderID() == senderID
|
||||
allowedToRedact := ev.SenderID() == *senderID
|
||||
if !allowedToRedact {
|
||||
plEvent := roomserverAPI.GetStateEvent(req.Context(), rsAPI, roomID, gomatrixserverlib.StateKeyTuple{
|
||||
EventType: spec.MRoomPowerLevels,
|
||||
|
@ -119,7 +129,7 @@ func SendRedaction(
|
|||
),
|
||||
}
|
||||
}
|
||||
allowedToRedact = pl.UserLevel(senderID) >= pl.Redact
|
||||
allowedToRedact = pl.UserLevel(*senderID) >= pl.Redact
|
||||
}
|
||||
if !allowedToRedact {
|
||||
return util.JSONResponse{
|
||||
|
@ -136,7 +146,7 @@ func SendRedaction(
|
|||
|
||||
// create the new event and set all the fields we can
|
||||
proto := gomatrixserverlib.ProtoEvent{
|
||||
SenderID: string(senderID),
|
||||
SenderID: string(*senderID),
|
||||
RoomID: roomID,
|
||||
Type: spec.MRoomRedaction,
|
||||
Redacts: eventID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue