From 83f4cf28119a2b47fe73e46415a6046484258de8 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 31 May 2019 20:51:16 +0300 Subject: [PATCH] Fix crash and add more logging --- commands.go | 2 +- user.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 5a90f31..1282b63 100644 --- a/commands.go +++ b/commands.go @@ -358,7 +358,7 @@ func (handler *CommandHandler) CommandDeleteAllPortals(ce *CommandEvent) { } } customPuppet := handler.bridge.GetPuppetByCustomMXID(ce.User.MXID) - if customPuppet != nil { + if customPuppet != nil && customPuppet.CustomIntent() != nil { intent := customPuppet.CustomIntent() leave = func(portal *Portal) { if len(portal.MXID) > 0 { diff --git a/user.go b/user.go index e564fcb..c48fb6e 100644 --- a/user.go +++ b/user.go @@ -308,6 +308,7 @@ func (user *User) intPostLogin() { } func (user *User) syncPortals(createAll bool) { + user.log.Infoln("Reading chat list") chats := make(ChatList, 0, len(user.Conn.Store.Chats)) portalKeys := make([]database.PortalKey, 0, len(user.Conn.Store.Chats)) for _, chat := range user.Conn.Store.Chats { @@ -325,6 +326,7 @@ func (user *User) syncPortals(createAll bool) { }) portalKeys = append(portalKeys, portal.Key) } + user.log.Infoln("Read chat list, updating user-portal mapping") err := user.SetPortalKeys(portalKeys) if err != nil { user.log.Warnln("Failed to update user-portal mapping:", err) @@ -335,6 +337,7 @@ func (user *User) syncPortals(createAll bool) { limit = len(chats) } now := uint64(time.Now().Unix()) + user.log.Infoln("Syncing portals") for i, chat := range chats { if chat.LastMessageTime+user.bridge.Config.Bridge.SyncChatMaxAge < now { break @@ -348,15 +351,18 @@ func (user *User) syncPortals(createAll bool) { } } } + user.log.Infoln("Finished syncing portals") } func (user *User) syncPuppets() { + user.log.Infoln("Syncing puppet info from contacts") for jid, contact := range user.Conn.Store.Contacts { if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) { puppet := user.bridge.GetPuppetByJID(contact.Jid) puppet.Sync(user, contact) } } + user.log.Infoln("Finished syncing puppet info from contacts") } func (user *User) updateLastConnectionIfNecessary() {