Append target profile to invite events created from a 3PID invite

This commit is contained in:
Brendan Abolivier 2017-09-13 12:52:55 +01:00
parent 532cc082a9
commit 45b1b549cb
No known key found for this signature in database
GPG key ID: 8EF1500759F70623
4 changed files with 28 additions and 5 deletions

View file

@ -20,6 +20,7 @@ import (
"os" "os"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
@ -58,6 +59,11 @@ func main() {
log.Panicf("Failed to setup key database(%q): %s", cfg.Database.ServerKey, err.Error()) log.Panicf("Failed to setup key database(%q): %s", cfg.Database.ServerKey, err.Error())
} }
accountDB, err := accounts.NewDatabase(string(cfg.Database.Account), cfg.Matrix.ServerName)
if err != nil {
log.Panicf("Failed to setup account database(%q): %s", cfg.Database.Account, err.Error())
}
keyRing := gomatrixserverlib.KeyRing{ keyRing := gomatrixserverlib.KeyRing{
KeyFetchers: []gomatrixserverlib.KeyFetcher{ KeyFetchers: []gomatrixserverlib.KeyFetcher{
// TODO: Use perspective key fetchers for production. // TODO: Use perspective key fetchers for production.
@ -78,7 +84,7 @@ func main() {
log.Info("Starting federation API server on ", cfg.Listen.FederationAPI) log.Info("Starting federation API server on ", cfg.Listen.FederationAPI)
api := mux.NewRouter() api := mux.NewRouter()
routing.Setup(api, *cfg, queryAPI, roomserverProducer, keyRing, federation) routing.Setup(api, *cfg, queryAPI, roomserverProducer, keyRing, federation, accountDB)
common.SetupHTTPAPI(http.DefaultServeMux, api) common.SetupHTTPAPI(http.DefaultServeMux, api)
log.Fatal(http.ListenAndServe(string(cfg.Listen.FederationAPI), nil)) log.Fatal(http.ListenAndServe(string(cfg.Listen.FederationAPI), nil))

View file

@ -333,6 +333,7 @@ func (m *monolith) setupAPIs() {
federationapi_routing.Setup( federationapi_routing.Setup(
m.api, *m.cfg, m.queryAPI, m.roomServerProducer, m.keyRing, m.federation, m.api, *m.cfg, m.queryAPI, m.roomServerProducer, m.keyRing, m.federation,
m.accountDB,
) )
publicroomsapi_routing.Setup(m.api, m.deviceDB, m.publicRoomsAPIDB) publicroomsapi_routing.Setup(m.api, m.deviceDB, m.publicRoomsAPIDB)

View file

@ -19,6 +19,7 @@ import (
"time" "time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/common/config"
@ -42,6 +43,7 @@ func Setup(
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
keys gomatrixserverlib.KeyRing, keys gomatrixserverlib.KeyRing,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
accountDB *accounts.Database,
) { ) {
v2keysmux := apiMux.PathPrefix(pathPrefixV2Keys).Subrouter() v2keysmux := apiMux.PathPrefix(pathPrefixV2Keys).Subrouter()
v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter() v1fedmux := apiMux.PathPrefix(pathPrefixV1Federation).Subrouter()
@ -81,7 +83,7 @@ func Setup(
v1fedmux.Handle("/3pid/onbind", common.MakeAPI("3pid_onbind", v1fedmux.Handle("/3pid/onbind", common.MakeAPI("3pid_onbind",
func(req *http.Request) util.JSONResponse { func(req *http.Request) util.JSONResponse {
return writers.CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation) return writers.CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB)
}, },
)).Methods("POST", "OPTIONS") )).Methods("POST", "OPTIONS")

View file

@ -22,6 +22,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
"github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/clientapi/producers"
@ -56,6 +57,7 @@ var errNotInRoom = errors.New("the server isn't currently in the room")
func CreateInvitesFrom3PIDInvites( func CreateInvitesFrom3PIDInvites(
req *http.Request, queryAPI api.RoomserverQueryAPI, cfg config.Dendrite, req *http.Request, queryAPI api.RoomserverQueryAPI, cfg config.Dendrite,
producer *producers.RoomserverProducer, federation *gomatrixserverlib.FederationClient, producer *producers.RoomserverProducer, federation *gomatrixserverlib.FederationClient,
accountDB *accounts.Database,
) util.JSONResponse { ) util.JSONResponse {
var body invites var body invites
if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil { if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil {
@ -65,7 +67,7 @@ func CreateInvitesFrom3PIDInvites(
evs := []gomatrixserverlib.Event{} evs := []gomatrixserverlib.Event{}
for _, inv := range body.Invites { for _, inv := range body.Invites {
event, err := createInviteFrom3PIDInvite( event, err := createInviteFrom3PIDInvite(
req.Context(), queryAPI, cfg, inv, federation, req.Context(), queryAPI, cfg, inv, federation, accountDB,
) )
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
@ -165,6 +167,7 @@ func ExchangeThirdPartyInvite(
func createInviteFrom3PIDInvite( func createInviteFrom3PIDInvite(
ctx context.Context, queryAPI api.RoomserverQueryAPI, cfg config.Dendrite, ctx context.Context, queryAPI api.RoomserverQueryAPI, cfg config.Dendrite,
inv invite, federation *gomatrixserverlib.FederationClient, inv invite, federation *gomatrixserverlib.FederationClient,
accountDB *accounts.Database,
) (*gomatrixserverlib.Event, error) { ) (*gomatrixserverlib.Event, error) {
// Build the event // Build the event
builder := &gomatrixserverlib.EventBuilder{ builder := &gomatrixserverlib.EventBuilder{
@ -174,8 +177,19 @@ func createInviteFrom3PIDInvite(
StateKey: &inv.MXID, StateKey: &inv.MXID,
} }
localpart, _, err := gomatrixserverlib.SplitID('@', *builder.StateKey)
if err != nil {
return nil, err
}
profile, err := accountDB.GetProfileByLocalpart(localpart)
if err != nil {
return nil, err
}
content := common.MemberContent{ content := common.MemberContent{
// TODO: Load the profile AvatarURL: profile.AvatarURL,
DisplayName: profile.DisplayName,
Membership: "invite", Membership: "invite",
ThirdPartyInvite: &common.TPInvite{ ThirdPartyInvite: &common.TPInvite{
Signed: inv.Signed, Signed: inv.Signed,