mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23:09 -06:00
Load user profile in a separate function
This commit is contained in:
parent
4bda6dca79
commit
5d8d2d948f
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue