Add some logs and match whatsapp

This commit is contained in:
Annie Elequin 2021-09-17 12:28:01 -04:00
parent e76923481d
commit 0e4aa26abb

View File

@ -194,18 +194,22 @@ func (portal *Portal) handleMessageLoop() {
for msg := range portal.messages { for msg := range portal.messages {
if len(portal.MXID) == 0 { if len(portal.MXID) == 0 {
if msg.timestamp+MaxMessageAgeToCreatePortal < uint64(time.Now().Unix()) { if msg.timestamp+MaxMessageAgeToCreatePortal < uint64(time.Now().Unix()) {
portal.log.Debugln("Not creating portal room for incoming message as the message is too old.") portal.log.Debugln("Not creating portal room for incoming message: message is too old")
continue
} else if !portal.shouldCreateRoom(msg) {
portal.log.Debugln("Not creating portal room for incoming message: message is not a chat message")
continue continue
} }
portal.log.Debugln("Creating Matrix room from incoming message") portal.log.Debugln("Creating Matrix room from incoming message")
err := portal.CreateMatrixRoom(msg.source) err := portal.CreateMatrixRoom(msg.source)
if err != nil { if err != nil {
portal.log.Errorln("Failed to create portal room:", err) portal.log.Errorln("Failed to create portal room:", err)
return continue
} }
portal.syncDoublePuppetDetailsAfterCreate(msg.source)
} }
portal.backfillLock.Lock() portal.backfillLock.Lock()
portal.handleMessage(msg) portal.handleMessage(msg, false)
portal.backfillLock.Unlock() portal.backfillLock.Unlock()
} }
} }
@ -936,11 +940,12 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
return err return err
} }
portal.log.Infoln("Creating Matrix room. Info source:", user.MXID) portal.log.Infoln("Creating Matrix room. Info source:", user.MXID, " portal MXID: ", portal.MXID)
var metadata *groupme.Group var metadata *groupme.Group
return nil return nil
if portal.IsPrivateChat() { if portal.IsPrivateChat() {
portal.log.Debugln("isPrivateChat")
puppet := portal.bridge.GetPuppetByJID(portal.Key.JID) puppet := portal.bridge.GetPuppetByJID(portal.Key.JID)
meta, err := portal.bridge.StateStore.TryGetMemberRaw("", puppet.MXID) meta, err := portal.bridge.StateStore.TryGetMemberRaw("", puppet.MXID)
if err { if err {
@ -961,15 +966,14 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
// portal.Name = "WhatsApp Status Broadcast" // portal.Name = "WhatsApp Status Broadcast"
// portal.Topic = "WhatsApp status updates from your contacts" // portal.Topic = "WhatsApp status updates from your contacts"
} else { } else {
portal.log.Debugln("else: it's not a private chat")
var err error var err error
metadata, err = user.Client.ShowGroup(context.TODO(), groupme.ID(portal.Key.JID)) metadata, err = user.Conn.GetGroupMetaData(portal.Key.JID)
if err == nil { if err == nil && metadata.Status == 0 {
portal.Name = metadata.Name portal.Name = metadata.Name
portal.Topic = metadata.Description portal.Topic = metadata.Topic
portal.UpdateAvatar(user, metadata.ImageURL, false)
} else {
portal.log.Warnln("Cannot fetch group metadata for new portal")
} }
portal.UpdateAvatar(user, nil, false)
} }
bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo() bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo()