From 0d49bd8d08db93ffa6b61adb98932ad61864c6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Wed, 5 Dec 2018 10:45:14 +0100 Subject: [PATCH] Portal.CreateMatrixRoom: ensure the user exists In the log some message show up with `/_matrix/client/r0/createRoom code=403 wrapped=M_FORBIDDEN: Application service has not registered this user`. This is caused by the handling of text messages coming from unknown users: mautrix-whatsapp/vendor/github.com/Rhymen/go-whatsapp/handler.go:106 mautrix-whatsapp/user.go:250 mautrix-whatsapp/portal.go:551 Hence, before creating a Matrix room, we must ensure the user for this room exists. --- portal.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/portal.go b/portal.go index 10a9803..41e0be7 100644 --- a/portal.go +++ b/portal.go @@ -455,6 +455,11 @@ func (portal *Portal) CreateMatrixRoom(invite []string) error { return nil } + intent := portal.MainIntent() + if err := intent.EnsureRegistered(); err != nil { + return err + } + name := portal.Name topic := portal.Topic isPrivateChat := false @@ -464,7 +469,7 @@ func (portal *Portal) CreateMatrixRoom(invite []string) error { isPrivateChat = true } - resp, err := portal.MainIntent().CreateRoom(&gomatrix.ReqCreateRoom{ + resp, err := intent.CreateRoom(&gomatrix.ReqCreateRoom{ Visibility: "private", Name: name, Topic: topic,