change defer to plain function, add judgement of whether user is a normal user or an app service user before autoJoinRooms.

This commit is contained in:
Neboer 2022-10-25 20:16:17 +08:00
parent 4f19de6730
commit 8b5b1e78fc

View file

@ -973,8 +973,9 @@ func completeRegistration(
} }
sessions.addCompletedRegistration(sessionID, result) sessions.addCompletedRegistration(sessionID, result)
defer func() { // POST register behaviour: check if the user is a normal user.
// POST register behavior: add user to room specified in the configuration "auto_join_rooms" // If the user is a normal user, add user to room specified in the configuration "auto_join_rooms".
if accType != userapi.AccountTypeAppService && appserviceID == "" {
for room := range cfg.AutoJoinRooms { for room := range cfg.AutoJoinRooms {
err := addUserToRoom(context.Background(), clientRsApi, cfg.AutoJoinRooms[room], username, err := addUserToRoom(context.Background(), clientRsApi, cfg.AutoJoinRooms[room], username,
userutil.MakeUserID(username, cfg.Matrix.ServerName)) userutil.MakeUserID(username, cfg.Matrix.ServerName))
@ -982,7 +983,7 @@ func completeRegistration(
log.WithError(err).Errorf("user %s failed to auto-join room %s", username, cfg.AutoJoinRooms[room]) log.WithError(err).Errorf("user %s failed to auto-join room %s", username, cfg.AutoJoinRooms[room])
} }
} }
}() }
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusOK, Code: http.StatusOK,