From 7dc4632cd49a4501736c0f5373ee32c397a91427 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 5 Jul 2020 19:27:40 +0300 Subject: [PATCH] Create new portal if invite fails in pm command. Fixes #188 --- commands.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands.go b/commands.go index a923854..a16848a 100644 --- a/commands.go +++ b/commands.go @@ -759,13 +759,13 @@ func (handler *CommandHandler) CommandPM(ce *CommandEvent) { puppet.Sync(user, contact) portal := user.bridge.GetPortalByJID(database.NewPortalKey(contact.Jid, user.JID)) if len(portal.MXID) > 0 { - _, err := portal.MainIntent().InviteUser(portal.MXID, &mautrix.ReqInviteUser{UserID: user.MXID}) + err := portal.MainIntent().EnsureInvited(portal.MXID, user.MXID) if err != nil { - fmt.Println(err) + portal.log.Warnfln("Failed to invite %s to portal: %v. Creating new portal", user.MXID, err) } else { - ce.Reply("Existing portal room found, invited you to it.") + ce.Reply("You already have a private chat portal with that user at %s", portal.MXID) + return } - return } err := portal.CreateMatrixRoom(user) if err != nil {