mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Create user room key if needed (#3108)
This commit is contained in:
parent
82b73a4906
commit
2c87972a3a
6 changed files with 67 additions and 2 deletions
|
@ -354,7 +354,30 @@ func (c *Creator) PerformCreateRoom(ctx context.Context, userID spec.UserID, roo
|
|||
SendAsServer: api.DoNotSendToOtherServers,
|
||||
})
|
||||
}
|
||||
if err = api.SendInputRoomEvents(ctx, c.RSAPI, userID.Domain(), inputs, false); err != nil {
|
||||
|
||||
// first send the `m.room.create` event, so we have a roomNID
|
||||
if err = api.SendInputRoomEvents(ctx, c.RSAPI, userID.Domain(), inputs[:1], false); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("roomserverAPI.SendInputRoomEvents failed")
|
||||
return "", &util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.InternalServerError{},
|
||||
}
|
||||
}
|
||||
|
||||
// create user room key if needed
|
||||
if createRequest.RoomVersion == gomatrixserverlib.RoomVersionPseudoIDs {
|
||||
_, err = c.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, userID, roomID)
|
||||
if err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("GetOrCreateUserRoomPrivateKey failed")
|
||||
return "", &util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.InternalServerError{},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send the remaining events
|
||||
if err = api.SendInputRoomEvents(ctx, c.RSAPI, userID.Domain(), inputs[1:], false); err != nil {
|
||||
util.GetLogger(ctx).WithError(err).Error("roomserverAPI.SendInputRoomEvents failed")
|
||||
return "", &util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
|
|
|
@ -183,6 +183,14 @@ func (r *Inviter) PerformInvite(
|
|||
inviteEvent = event
|
||||
}
|
||||
|
||||
// if we invited a local user, we can also create a user room key, if it doesn't exist yet.
|
||||
if isTargetLocal && event.Version() == gomatrixserverlib.RoomVersionPseudoIDs {
|
||||
_, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, *invitedUser, *validRoomID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get user room private key: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Send the invite event to the roomserver input stream. This will
|
||||
// notify existing users in the room about the invite, update the
|
||||
// membership table and ensure that the event is ready and available
|
||||
|
|
|
@ -293,6 +293,15 @@ func (r *Joiner) performJoinRoomByID(
|
|||
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
// create user room key if needed
|
||||
if buildRes.RoomVersion == gomatrixserverlib.RoomVersionPseudoIDs {
|
||||
_, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, *userID, *roomID)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("GetOrCreateUserRoomPrivateKey failed")
|
||||
return "", "", fmt.Errorf("failed to get user room private key: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// The room join is local. Send the new join event into the
|
||||
// roomserver. First of all check that the user isn't already
|
||||
// a member of the room. This is best-effort (as in we won't
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue