@@ -241,23 +241,34 @@ func (helper *CryptoHelper) loginBot(ctx context.Context) (*mautrix.Client, bool
241241 // Create a new client instance with the default AS settings (including as_token),
242242 // the Login call will then override the access token in the client.
243243 client := helper .bridge .AS .NewMautrixClient (helper .bridge .AS .BotMXID ())
244+
245+ initialDeviceDisplayName := fmt .Sprintf ("%s bridge" , helper .bridge .Bridge .Network .GetName ().DisplayName )
246+ if helper .bridge .Config .AppService .MSC4190 {
247+ helper .log .Debug ().Msg ("Creating bot device with msc4190" )
248+ err = client .CreateDeviceMSC4190 (ctx , deviceID , initialDeviceDisplayName )
249+ if err != nil {
250+ return nil , deviceID != "" , fmt .Errorf ("failed to create device for bridge bot: %w" , err )
251+ }
252+ helper .store .DeviceID = client .DeviceID
253+ return client , deviceID != "" , nil
254+ }
255+
244256 flows , err := client .GetLoginFlows (ctx )
245257 if err != nil {
246258 return nil , deviceID != "" , fmt .Errorf ("failed to get supported login flows: %w" , err )
247259 } else if ! flows .HasFlow (mautrix .AuthTypeAppservice ) {
248260 return nil , deviceID != "" , fmt .Errorf ("homeserver does not support appservice login" )
249261 }
262+
250263 resp , err := client .Login (ctx , & mautrix.ReqLogin {
251264 Type : mautrix .AuthTypeAppservice ,
252265 Identifier : mautrix.UserIdentifier {
253266 Type : mautrix .IdentifierTypeUser ,
254267 User : string (helper .bridge .AS .BotMXID ()),
255268 },
256- DeviceID : deviceID ,
257- StoreCredentials : true ,
258-
259- // TODO find proper bridge name
260- InitialDeviceDisplayName : "Megabridge" , // fmt.Sprintf("%s bridge", helper.bridge.ProtocolName),
269+ DeviceID : deviceID ,
270+ StoreCredentials : true ,
271+ InitialDeviceDisplayName : initialDeviceDisplayName ,
261272 })
262273 if err != nil {
263274 return nil , deviceID != "" , fmt .Errorf ("failed to log in as bridge bot: %w" , err )
0 commit comments