mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 13:11:37 +00:00
Direct messages (#1012)
* Initial DM support, include invite event in stripped state for regular invites * Update go.mod, go.sum, test list
This commit is contained in:
parent
a16db1c408
commit
c8e11dfe53
@ -833,3 +833,4 @@ gst Guest user can call /events on another world_readable room (SYN-606)
|
||||
gst Real user can call /events on another world_readable room (SYN-606)
|
||||
gst Events come down the correct room
|
||||
pub Asking for a remote rooms list, but supplying the local server's name, returns the local rooms list
|
||||
std Can send a to-device message to two users which both receive it using /sync
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
2
go.mod
2
go.mod
@ -17,7 +17,7 @@ require (
|
||||
github.com/matrix-org/go-http-js-libp2p v0.0.0-20200318135427-31631a9ef51f
|
||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20200325174927-327088cdef10
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200505092542-ef8abbde3f6b
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200507150553-025991c971ea
|
||||
github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f
|
||||
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7
|
||||
github.com/mattn/go-sqlite3 v2.0.2+incompatible
|
||||
|
4
go.sum
4
go.sum
@ -367,8 +367,8 @@ github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bh
|
||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5 h1:kmRjpmFOenVpOaV/DRlo9p6z/IbOKlUC+hhKsAAh8Qg=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200505092542-ef8abbde3f6b h1:gxLun/noFJ7DplX7rqT8E4v4NkeDJ45tqW7LXC6k4C4=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200505092542-ef8abbde3f6b/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200507150553-025991c971ea h1:1qfbSjg3PwULY68AVRdZ3QIJoccNMbre0mSR7m7mqI4=
|
||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20200507150553-025991c971ea/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU=
|
||||
github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 h1:osLoFdOy+ChQqVUn2PeTDETFftVkl4w9t/OW18g3lnk=
|
||||
github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1/go.mod h1:cXoYQIENbdWIQHt1SyCo6Bl3C3raHwJ0wgVrXHSqf+A=
|
||||
github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f h1:pRz4VTiRCO4zPlEMc3ESdUOcW4PXHH4Kj+YDz1XyE+Y=
|
||||
|
@ -308,6 +308,7 @@ func buildInviteStrippedState(
|
||||
inviteState := []gomatrixserverlib.InviteV2StrippedState{
|
||||
gomatrixserverlib.NewInviteV2StrippedState(&input.Event.Event),
|
||||
}
|
||||
stateEvents = append(stateEvents, types.Event{Event: input.Event.Unwrap()})
|
||||
for _, event := range stateEvents {
|
||||
inviteState = append(inviteState, gomatrixserverlib.NewInviteV2StrippedState(&event.Event))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user