Add option to automatically enable custom puppeting with shared secret login

This commit is contained in:
Tulir Asokan
2019-12-30 20:21:04 +02:00
parent 0b51d84646
commit ec0e60c71c
6 changed files with 61 additions and 3 deletions

28
user.go
View File

@@ -365,9 +365,35 @@ func (user *User) PostLogin() {
go user.intPostLogin()
}
func (user *User) tryAutomaticDoublePuppeting(){
if len(user.bridge.Config.Bridge.LoginSharedSecret) == 0 {
// Automatic login not enabled
return
}
puppet := user.bridge.GetPuppetByJID(user.JID)
if len(puppet.CustomMXID) > 0 {
// Custom puppet already enabled
return
}
accessToken, err := puppet.loginWithSharedSecret(user.MXID)
if err != nil {
user.log.Warnln("Failed to login with shared secret:", err)
return
}
err = puppet.SwitchCustomMXID(accessToken, user.MXID)
if err != nil {
puppet.log.Warnln("Failed to switch to auto-logined custom puppet:", err)
return
}
user.log.Infoln("Successfully automatically enabled custom puppet")
}
func (user *User) intPostLogin() {
user.createCommunity()
defer user.syncLock.Unlock()
user.createCommunity()
user.tryAutomaticDoublePuppeting()
select {
case <-user.chatListReceived: