Successfully receiving messages from groupme

This commit is contained in:
Brandon Watson 2023-09-08 13:00:18 -05:00
parent 86c6bab1eb
commit 2074d45d9d
3 changed files with 37 additions and 20 deletions

View File

@ -160,7 +160,8 @@ func (bridge *GMBridge) GetPortalByGMID(key database.PortalKey) *Portal {
defer bridge.portalsLock.Unlock() defer bridge.portalsLock.Unlock()
portal, ok := bridge.portalsByGMID[key] portal, ok := bridge.portalsByGMID[key]
if !ok { if !ok {
return bridge.loadDBPortal(bridge.DB.Portal.GetByGMID(key), &key) dbPortal := bridge.DB.Portal.GetByGMID(key)
return bridge.loadDBPortal(dbPortal, &key)
} }
return portal return portal
} }

View File

@ -169,48 +169,50 @@ func (portal *Portal) SyncDM(user *User, dm *groupme.Chat) {
} }
if len(portal.MXID) == 0 { if len(portal.MXID) == 0 {
puppet := user.bridge.GetPuppetByGMID(portal.Key.GMID)
// "" for overall user not related to one group // "" for overall user not related to one group
puppet.Sync(user, &groupme.Member{ puppet := portal.bridge.GetPuppetByGMID(portal.Key.GMID)
UserID: dm.OtherUser.ID, meta, err := portal.bridge.StateStore.TryGetMember("", puppet.MXID)
Nickname: dm.OtherUser.Name, if err {
ImageURL: dm.OtherUser.AvatarURL, println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
}, false, false) user.log.Warn("Cannot find user information")
if portal.bridge.Config.Bridge.PrivateChatPortalMeta || portal.bridge.Config.Bridge.Encryption.Default { return
portal.Name = puppet.Displayname }
portal.AvatarURL = puppet.AvatarURL
portal.Avatar = puppet.Avatar if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
portal.Name = meta.Displayname
portal.AvatarURL = meta.AvatarURL.ParseOrIgnore()
portal.Avatar = meta.AvatarURL.ParseOrIgnore().String()
} else { } else {
portal.Name = "" portal.Name = ""
} }
portal.Topic = "GroupMe private chat" portal.Topic = "GroupMe private chat"
err := portal.createMatrixRoom(user) e := portal.createMatrixRoom(user)
if err != nil { if e != nil {
portal.log.Errorln("Failed to create portal room:", err) portal.log.Errorln("Failed to create portal room:", err)
return return
} }
customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID) customPuppet := portal.bridge.GetPuppetByGMID(user.GMID)
if customPuppet != nil && customPuppet.CustomIntent() != nil { if customPuppet != nil && customPuppet.CustomIntent() != nil {
_ = customPuppet.CustomIntent().EnsureJoined(portal.MXID) _ = customPuppet.CustomIntent().EnsureJoined(portal.MXID)
} }
if portal.bridge.Config.Bridge.Encryption.Default { if portal.bridge.Config.Bridge.Encryption.Default {
err = portal.bridge.Bot.EnsureJoined(portal.MXID) e = portal.bridge.Bot.EnsureJoined(portal.MXID)
if err != nil { if e != nil {
portal.log.Errorln("Failed to join created portal with bridge bot for e2be:", err) 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}}) user.UpdateDirectChats(map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}})
} else { } else {
portal.ensureUserInvited(user) portal.ensureUserInvited(user)
} }
if portal.IsPrivateChat() { //if portal.IsPrivateChat() {
return // return
} //}
update := false update := false
update = portal.UpdateName(dm.OtherUser.Name, "", false) || update update = portal.UpdateName(dm.OtherUser.Name, "", false) || update
@ -862,6 +864,10 @@ func (portal *Portal) createMatrixRoom(user *User) error {
invite := []id.UserID{user.MXID} 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 { if portal.bridge.Config.Bridge.Encryption.Default {
initialState = append(initialState, &event.Event{ initialState = append(initialState, &event.Event{
Type: event.StateEncryption, Type: event.StateEncryption,
@ -988,6 +994,12 @@ func (portal *Portal) ensureMXIDInvited(mxid id.UserID) {
} }
func (portal *Portal) ensureUserInvited(user *User) bool { 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()) return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat())
} }

View File

@ -527,6 +527,10 @@ func (user *User) handleMessageLoop() {
ImageURL: msg.data.AvatarURL, ImageURL: msg.data.AvatarURL,
}, false, false) }, false, false)
} }
//err := puppet.IntentFor(portal).EnsureJoined(portal.MXID)
//if err != nil {
// user.log.Warnln("Unable to ensure user puppet joined")
//}
portal.messages <- msg portal.messages <- msg
case <-user.syncStart: case <-user.syncStart:
user.log.Debugln("Processing of incoming messages is locked") user.log.Debugln("Processing of incoming messages is locked")