From 2074d45d9d676cf217fcdeb4fa3215c416dcc814 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 8 Sep 2023 13:00:18 -0500 Subject: [PATCH] Successfully receiving messages from groupme --- main.go | 3 ++- portal.go | 50 +++++++++++++++++++++++++++++++------------------- user.go | 4 ++++ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 35889bb..3e7262e 100644 --- a/main.go +++ b/main.go @@ -160,7 +160,8 @@ func (bridge *GMBridge) GetPortalByGMID(key database.PortalKey) *Portal { defer bridge.portalsLock.Unlock() portal, ok := bridge.portalsByGMID[key] if !ok { - return bridge.loadDBPortal(bridge.DB.Portal.GetByGMID(key), &key) + dbPortal := bridge.DB.Portal.GetByGMID(key) + return bridge.loadDBPortal(dbPortal, &key) } return portal } diff --git a/portal.go b/portal.go index 6360ee2..603f967 100644 --- a/portal.go +++ b/portal.go @@ -169,48 +169,50 @@ func (portal *Portal) SyncDM(user *User, dm *groupme.Chat) { } if len(portal.MXID) == 0 { - puppet := user.bridge.GetPuppetByGMID(portal.Key.GMID) + // "" for overall user not related to one group - puppet.Sync(user, &groupme.Member{ - UserID: dm.OtherUser.ID, - Nickname: dm.OtherUser.Name, - ImageURL: dm.OtherUser.AvatarURL, - }, false, false) - if portal.bridge.Config.Bridge.PrivateChatPortalMeta || portal.bridge.Config.Bridge.Encryption.Default { - portal.Name = puppet.Displayname - portal.AvatarURL = puppet.AvatarURL - portal.Avatar = puppet.Avatar + puppet := portal.bridge.GetPuppetByGMID(portal.Key.GMID) + meta, err := portal.bridge.StateStore.TryGetMember("", puppet.MXID) + if err { + println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + user.log.Warn("Cannot find user information") + return + } + + if portal.bridge.Config.Bridge.PrivateChatPortalMeta { + portal.Name = meta.Displayname + portal.AvatarURL = meta.AvatarURL.ParseOrIgnore() + portal.Avatar = meta.AvatarURL.ParseOrIgnore().String() } else { portal.Name = "" } portal.Topic = "GroupMe private chat" - err := portal.createMatrixRoom(user) - if err != nil { + e := portal.createMatrixRoom(user) + if e != nil { portal.log.Errorln("Failed to create portal room:", err) return } - customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID) + customPuppet := portal.bridge.GetPuppetByGMID(user.GMID) if customPuppet != nil && customPuppet.CustomIntent() != nil { _ = customPuppet.CustomIntent().EnsureJoined(portal.MXID) } if portal.bridge.Config.Bridge.Encryption.Default { - err = portal.bridge.Bot.EnsureJoined(portal.MXID) - if err != nil { + e = portal.bridge.Bot.EnsureJoined(portal.MXID) + if e != nil { portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err) } } - user.UpdateDirectChats(map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}}) } else { portal.ensureUserInvited(user) } - if portal.IsPrivateChat() { - return - } + //if portal.IsPrivateChat() { + // return + //} update := false update = portal.UpdateName(dm.OtherUser.Name, "", false) || update @@ -862,6 +864,10 @@ func (portal *Portal) createMatrixRoom(user *User) error { invite := []id.UserID{user.MXID} + // TODO only do this if not double puppeting + userPuppet := portal.bridge.GetPuppetByGMID(portal.Key.Receiver) + invite = append(invite, userPuppet.MXID) + if portal.bridge.Config.Bridge.Encryption.Default { initialState = append(initialState, &event.Event{ Type: event.StateEncryption, @@ -988,6 +994,12 @@ func (portal *Portal) ensureMXIDInvited(mxid id.UserID) { } func (portal *Portal) ensureUserInvited(user *User) bool { + portal.userMXIDAction(user, portal.ensureMXIDInvited) + + customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID) + if customPuppet != nil && customPuppet.CustomIntent() != nil { + _ = customPuppet.CustomIntent().EnsureJoined(portal.MXID) + } return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat()) } diff --git a/user.go b/user.go index 4860fab..8d06d17 100644 --- a/user.go +++ b/user.go @@ -527,6 +527,10 @@ func (user *User) handleMessageLoop() { ImageURL: msg.data.AvatarURL, }, false, false) } + //err := puppet.IntentFor(portal).EnsureJoined(portal.MXID) + //if err != nil { + // user.log.Warnln("Unable to ensure user puppet joined") + //} portal.messages <- msg case <-user.syncStart: user.log.Debugln("Processing of incoming messages is locked")