diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-05-07 16:46:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-07 16:46:11 +0100 |
commit | c8e11dfe53a97ac2e207c893f3f21f1216d86343 (patch) | |
tree | e74281a59222893e22250521eea15c234556cbdd /clientapi | |
parent | a16db1c4085c0079f72615f0c077fa5016c4fe0f (diff) |
Direct messages (#1012)
* Initial DM support, include invite event in stripped state for regular invites
* Update go.mod, go.sum, test list
Diffstat (limited to 'clientapi')
-rw-r--r-- | clientapi/routing/createroom.go | 45 | ||||
-rw-r--r-- | clientapi/routing/membership.go | 6 |
2 files changed, 49 insertions, 2 deletions
diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index 28e2b151..43a16945 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -30,6 +30,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" + "github.com/matrix-org/dendrite/clientapi/threepid" "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/gomatrixserverlib" @@ -351,6 +352,50 @@ func createRoom( } } + // If this is a direct message then we should invite the participants. + for _, invitee := range r.Invite { + // Build the membership request. + body := threepid.MembershipRequest{ + UserID: invitee, + } + // Build the invite event. + inviteEvent, err := buildMembershipEvent( + req.Context(), body, accountDB, device, gomatrixserverlib.Invite, + roomID, true, cfg, evTime, rsAPI, asAPI, + ) + if err != nil { + util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvent failed") + continue + } + // Build some stripped state for the invite. + candidates := append(gomatrixserverlib.UnwrapEventHeaders(builtEvents), *inviteEvent) + var strippedState []gomatrixserverlib.InviteV2StrippedState + for _, event := range candidates { + switch event.Type() { + // TODO: case gomatrixserverlib.MRoomEncryption: + // fallthrough + case gomatrixserverlib.MRoomMember: + fallthrough + case gomatrixserverlib.MRoomJoinRules: + strippedState = append( + strippedState, + gomatrixserverlib.NewInviteV2StrippedState(&event), + ) + } + } + // Send the invite event to the roomserver. + if err = producer.SendInvite( + req.Context(), + inviteEvent.Headered(roomVersion), + strippedState, // invite room state + cfg.Matrix.ServerName, // send as server + nil, // transaction ID + ); err != nil { + util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed") + return jsonerror.InternalServerError() + } + } + response := createRoomResponse{ RoomID: roomID, RoomAlias: roomAlias, diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index 9030f9f7..0a56eec5 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -89,7 +89,8 @@ func SendMembership( } event, err := buildMembershipEvent( - req.Context(), body, accountDB, device, membership, roomID, cfg, evTime, rsAPI, asAPI, + req.Context(), body, accountDB, device, membership, + roomID, false, cfg, evTime, rsAPI, asAPI, ) if err == errMissingUserID { return util.JSONResponse{ @@ -151,7 +152,7 @@ func buildMembershipEvent( ctx context.Context, body threepid.MembershipRequest, accountDB accounts.Database, device *authtypes.Device, - membership, roomID string, + membership, roomID string, isDirect bool, cfg *config.Dendrite, evTime time.Time, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) (*gomatrixserverlib.Event, error) { @@ -182,6 +183,7 @@ func buildMembershipEvent( DisplayName: profile.DisplayName, AvatarURL: profile.AvatarURL, Reason: reason, + IsDirect: isDirect, } if err = builder.SetContent(content); err != nil { |