Load user profile in a separate function

This commit is contained in:
Brendan Abolivier 2017-08-25 12:33:27 +01:00
parent 4bda6dca79
commit 5d8d2d948f
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -67,21 +67,11 @@ func SendMembership(
return *reqErr return *reqErr
} }
localpart, serverName, err := gomatrixserverlib.SplitID('@', stateKey) profile, err := loadProfile(stateKey, cfg, accountDB)
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
} }
var profile *authtypes.Profile
if serverName == cfg.Matrix.ServerName {
profile, err = accountDB.GetProfileByLocalpart(localpart)
if err != nil {
return httputil.LogThenError(req, err)
}
} else {
profile = &authtypes.Profile{}
}
builder := gomatrixserverlib.EventBuilder{ builder := gomatrixserverlib.EventBuilder{
Sender: device.UserID, Sender: device.UserID,
RoomID: roomID, RoomID: roomID,
@ -125,6 +115,22 @@ func SendMembership(
} }
} }
func loadProfile(userID string, cfg config.Dendrite, accountDB *accounts.Database) (*authtypes.Profile, error) {
localpart, serverName, err := gomatrixserverlib.SplitID('@', userID)
if err != nil {
return nil, err
}
var profile *authtypes.Profile
if serverName == cfg.Matrix.ServerName {
profile, err = accountDB.GetProfileByLocalpart(localpart)
} else {
profile = &authtypes.Profile{}
}
return profile, err
}
// getMembershipStateKey extracts the target user ID of a membership change. // getMembershipStateKey extracts the target user ID of a membership change.
// For "join" and "leave" this will be the ID of the user making the change. // For "join" and "leave" this will be the ID of the user making the change.
// For "ban", "unban", "kick" and "invite" the target user ID will be in the JSON request body. // For "ban", "unban", "kick" and "invite" the target user ID will be in the JSON request body.