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()
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
}

View File

@ -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())
}

View File

@ -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")