forked from MirrorHub/mautrix-whatsapp
Update whatsmeow and ignore events from @lid users
This commit is contained in:
parent
6ad533c0ae
commit
dcd4ca366c
7 changed files with 49 additions and 9 deletions
|
@ -122,14 +122,16 @@ func (user *User) usernamePtr() *string {
|
||||||
|
|
||||||
func (user *User) agentPtr() *uint8 {
|
func (user *User) agentPtr() *uint8 {
|
||||||
if !user.JID.IsEmpty() {
|
if !user.JID.IsEmpty() {
|
||||||
return &user.JID.Agent
|
zero := uint8(0)
|
||||||
|
return &zero
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) devicePtr() *uint8 {
|
func (user *User) devicePtr() *uint8 {
|
||||||
if !user.JID.IsEmpty() {
|
if !user.JID.IsEmpty() {
|
||||||
return &user.JID.Device
|
device := uint8(user.JID.Device)
|
||||||
|
return &device
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,9 @@ func (formatter *Formatter) ParseWhatsApp(roomID id.RoomID, content *event.Messa
|
||||||
continue
|
continue
|
||||||
} else if jid.Server == types.LegacyUserServer {
|
} else if jid.Server == types.LegacyUserServer {
|
||||||
jid.Server = types.DefaultUserServer
|
jid.Server = types.DefaultUserServer
|
||||||
|
} else if jid.Server != types.DefaultUserServer {
|
||||||
|
// TODO lid support?
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
mxid, displayname := formatter.getMatrixInfoByJID(roomID, jid)
|
mxid, displayname := formatter.getMatrixInfoByJID(roomID, jid)
|
||||||
number := "@" + jid.User
|
number := "@" + jid.User
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -13,7 +13,7 @@ require (
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/tidwall/gjson v1.14.4
|
github.com/tidwall/gjson v1.14.4
|
||||||
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3
|
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3
|
||||||
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73
|
go.mau.fi/whatsmeow v0.0.0-20230808115051-056c25e4b485
|
||||||
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
|
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
|
||||||
golang.org/x/image v0.9.0
|
golang.org/x/image v0.9.0
|
||||||
golang.org/x/net v0.12.0
|
golang.org/x/net v0.12.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -70,8 +70,8 @@ go.mau.fi/libsignal v0.1.0 h1:vAKI/nJ5tMhdzke4cTK1fb0idJzz1JuEIpmjprueC+c=
|
||||||
go.mau.fi/libsignal v0.1.0/go.mod h1:R8ovrTezxtUNzCQE5PH30StOQWWeBskBsWE55vMfY9I=
|
go.mau.fi/libsignal v0.1.0/go.mod h1:R8ovrTezxtUNzCQE5PH30StOQWWeBskBsWE55vMfY9I=
|
||||||
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3 h1:r3Hrayw0CfmkrDhse7SbClYzq0e7/5P3iKpyV+gW16w=
|
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3 h1:r3Hrayw0CfmkrDhse7SbClYzq0e7/5P3iKpyV+gW16w=
|
||||||
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3/go.mod h1:tNxQ2KpD+QhP2MlMfJvFSGSJfDjg4OhIwP7bIK43X/I=
|
go.mau.fi/util v0.0.0-20230805161919-cf42c11d39c3/go.mod h1:tNxQ2KpD+QhP2MlMfJvFSGSJfDjg4OhIwP7bIK43X/I=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73 h1:JK9z+AWKvWXINSqz6wqfF67L/uUMEMJ+Mfw4sVMFnQg=
|
go.mau.fi/whatsmeow v0.0.0-20230808115051-056c25e4b485 h1:AaWJS6eKFOQ606PAvrhFeNco4hZ0ullUdQGPJ+G6HCQ=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20230804210635-04e4e3a38f73/go.mod h1:+ObGpFE6cbbY4hKc1FmQH9MVfqaemmlXGXSnwDvCOyE=
|
go.mau.fi/whatsmeow v0.0.0-20230808115051-056c25e4b485/go.mod h1:Iv3G4uv6+HWtqL7XSLRa2dSy077Bnji14IvqUbG+bRo=
|
||||||
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
|
||||||
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
|
30
portal.go
30
portal.go
|
@ -352,6 +352,10 @@ func (portal *Portal) handleMatrixMessageLoopItem(msg PortalMatrixMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) handleReceipt(receipt *events.Receipt, source *User) {
|
func (portal *Portal) handleReceipt(receipt *events.Receipt, source *User) {
|
||||||
|
if receipt.Sender.Server != types.DefaultUserServer {
|
||||||
|
// TODO handle lids
|
||||||
|
return
|
||||||
|
}
|
||||||
// The order of the message ID array depends on the sender's platform, so we just have to find
|
// The order of the message ID array depends on the sender's platform, so we just have to find
|
||||||
// the last message based on timestamp. Also, timestamps only have second precision, so if
|
// the last message based on timestamp. Also, timestamps only have second precision, so if
|
||||||
// there are many messages at the same second just mark them all as read, because we don't
|
// there are many messages at the same second just mark them all as read, because we don't
|
||||||
|
@ -703,6 +707,11 @@ func (portal *Portal) handleFakeMessage(msg fakeMessage) {
|
||||||
portal.log.Debugfln("Not handling %s (fake): message is duplicate", msg.ID)
|
portal.log.Debugfln("Not handling %s (fake): message is duplicate", msg.ID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if msg.Sender.Server != types.DefaultUserServer {
|
||||||
|
portal.log.Debugfln("Not handling %s (fake): message is from a lid user (%s)", msg.ID, msg.Sender)
|
||||||
|
// TODO handle lids
|
||||||
|
return
|
||||||
|
}
|
||||||
intent := portal.bridge.GetPuppetByJID(msg.Sender).IntentFor(portal)
|
intent := portal.bridge.GetPuppetByJID(msg.Sender).IntentFor(portal)
|
||||||
if !intent.IsCustomPuppet && portal.IsPrivateChat() && msg.Sender.User == portal.Key.Receiver.User && portal.Key.Receiver != portal.Key.JID {
|
if !intent.IsCustomPuppet && portal.IsPrivateChat() && msg.Sender.User == portal.Key.Receiver.User && portal.Key.Receiver != portal.Key.JID {
|
||||||
portal.log.Debugfln("Not handling %s (fake): user doesn't have double puppeting enabled", msg.ID)
|
portal.log.Debugfln("Not handling %s (fake): user doesn't have double puppeting enabled", msg.ID)
|
||||||
|
@ -1046,6 +1055,10 @@ func (portal *Portal) SyncParticipants(source *User, metadata *types.GroupInfo)
|
||||||
participantMap := make(map[types.JID]bool)
|
participantMap := make(map[types.JID]bool)
|
||||||
userIDs := make([]id.UserID, 0, len(metadata.Participants))
|
userIDs := make([]id.UserID, 0, len(metadata.Participants))
|
||||||
for _, participant := range metadata.Participants {
|
for _, participant := range metadata.Participants {
|
||||||
|
if participant.JID.IsEmpty() || participant.JID.Server != types.DefaultUserServer {
|
||||||
|
// TODO handle lids
|
||||||
|
continue
|
||||||
|
}
|
||||||
portal.log.Debugfln("Syncing participant %s (admin: %t)", participant.JID, participant.IsAdmin)
|
portal.log.Debugfln("Syncing participant %s (admin: %t)", participant.JID, participant.IsAdmin)
|
||||||
participantMap[participant.JID] = true
|
participantMap[participant.JID] = true
|
||||||
puppet := portal.bridge.GetPuppetByJID(participant.JID)
|
puppet := portal.bridge.GetPuppetByJID(participant.JID)
|
||||||
|
@ -1167,7 +1180,7 @@ func (portal *Portal) UpdateAvatar(user *User, setBy types.JID, updateInfo bool)
|
||||||
|
|
||||||
if len(portal.MXID) > 0 {
|
if len(portal.MXID) > 0 {
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
if !setBy.IsEmpty() {
|
if !setBy.IsEmpty() && setBy.Server == types.DefaultUserServer {
|
||||||
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
||||||
}
|
}
|
||||||
_, err := intent.SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
_, err := intent.SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
||||||
|
@ -1205,7 +1218,7 @@ func (portal *Portal) UpdateName(name string, setBy types.JID, updateInfo bool)
|
||||||
portal.UpdateBridgeInfo()
|
portal.UpdateBridgeInfo()
|
||||||
} else if len(portal.MXID) > 0 {
|
} else if len(portal.MXID) > 0 {
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
if !setBy.IsEmpty() {
|
if !setBy.IsEmpty() && setBy.Server == types.DefaultUserServer {
|
||||||
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
||||||
}
|
}
|
||||||
_, err := intent.SetRoomName(portal.MXID, name)
|
_, err := intent.SetRoomName(portal.MXID, name)
|
||||||
|
@ -1234,7 +1247,7 @@ func (portal *Portal) UpdateTopic(topic string, setBy types.JID, updateInfo bool
|
||||||
portal.TopicSet = false
|
portal.TopicSet = false
|
||||||
|
|
||||||
intent := portal.MainIntent()
|
intent := portal.MainIntent()
|
||||||
if !setBy.IsEmpty() {
|
if !setBy.IsEmpty() && setBy.Server == types.DefaultUserServer {
|
||||||
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
intent = portal.bridge.GetPuppetByJID(setBy).IntentFor(portal)
|
||||||
}
|
}
|
||||||
_, err := intent.SetRoomTopic(portal.MXID, topic)
|
_, err := intent.SetRoomTopic(portal.MXID, topic)
|
||||||
|
@ -1405,6 +1418,10 @@ func (portal *Portal) ChangeAdminStatus(jids []types.JID, setAdmin bool) id.Even
|
||||||
}
|
}
|
||||||
changed := portal.applyPowerLevelFixes(levels)
|
changed := portal.applyPowerLevelFixes(levels)
|
||||||
for _, jid := range jids {
|
for _, jid := range jids {
|
||||||
|
if jid.Server != types.DefaultUserServer {
|
||||||
|
// TODO handle lids
|
||||||
|
continue
|
||||||
|
}
|
||||||
puppet := portal.bridge.GetPuppetByJID(jid)
|
puppet := portal.bridge.GetPuppetByJID(jid)
|
||||||
changed = levels.EnsureUserLevel(puppet.MXID, newLevel) || changed
|
changed = levels.EnsureUserLevel(puppet.MXID, newLevel) || changed
|
||||||
|
|
||||||
|
@ -1936,7 +1953,8 @@ func (portal *Portal) addReplyMention(content *event.MessageEventContent, sender
|
||||||
if content.Mentions == nil || (sender.IsEmpty() && senderMXID == "") {
|
if content.Mentions == nil || (sender.IsEmpty() && senderMXID == "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if senderMXID == "" {
|
// TODO handle lids
|
||||||
|
if senderMXID == "" && sender.Server == types.DefaultUserServer {
|
||||||
if user := portal.bridge.GetUserByJID(sender); user != nil {
|
if user := portal.bridge.GetUserByJID(sender); user != nil {
|
||||||
senderMXID = user.MXID
|
senderMXID = user.MXID
|
||||||
} else {
|
} else {
|
||||||
|
@ -3244,6 +3262,10 @@ func (portal *Portal) handleMediaRetry(retry *events.MediaRetry, source *User) {
|
||||||
} else {
|
} else {
|
||||||
puppet = portal.bridge.GetPuppetByJID(retry.SenderID)
|
puppet = portal.bridge.GetPuppetByJID(retry.SenderID)
|
||||||
}
|
}
|
||||||
|
if puppet == nil {
|
||||||
|
// TODO handle lids?
|
||||||
|
return
|
||||||
|
}
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
|
|
||||||
retryData, err := whatsmeow.DecryptMediaRetryNotification(retry, meta.Media.Key)
|
retryData, err := whatsmeow.DecryptMediaRetryNotification(retry, meta.Media.Key)
|
||||||
|
|
|
@ -330,6 +330,9 @@ func (puppet *Puppet) updatePortalName() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) SyncContact(source *User, onlyIfNoName, shouldHavePushName bool, reason string) {
|
func (puppet *Puppet) SyncContact(source *User, onlyIfNoName, shouldHavePushName bool, reason string) {
|
||||||
|
if puppet == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if onlyIfNoName && len(puppet.Displayname) > 0 && (!shouldHavePushName || puppet.NameQuality > config.NameQualityPhone) {
|
if onlyIfNoName && len(puppet.Displayname) > 0 && (!shouldHavePushName || puppet.NameQuality > config.NameQualityPhone) {
|
||||||
source.EnqueuePuppetResync(puppet)
|
source.EnqueuePuppetResync(puppet)
|
||||||
return
|
return
|
||||||
|
|
10
user.go
10
user.go
|
@ -896,6 +896,9 @@ func (user *User) HandleEvent(event interface{}) {
|
||||||
user.handleCallStart(v.CallCreator, v.CallID, v.Type, v.Timestamp)
|
user.handleCallStart(v.CallCreator, v.CallID, v.Type, v.Timestamp)
|
||||||
case *events.IdentityChange:
|
case *events.IdentityChange:
|
||||||
puppet := user.bridge.GetPuppetByJID(v.JID)
|
puppet := user.bridge.GetPuppetByJID(v.JID)
|
||||||
|
if puppet == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
portal := user.GetPortalByJID(v.JID)
|
portal := user.GetPortalByJID(v.JID)
|
||||||
if len(portal.MXID) > 0 && user.bridge.Config.Bridge.IdentityChangeNotices {
|
if len(portal.MXID) > 0 && user.bridge.Config.Bridge.IdentityChangeNotices {
|
||||||
text := fmt.Sprintf("Your security code with %s changed.", puppet.Displayname)
|
text := fmt.Sprintf("Your security code with %s changed.", puppet.Displayname)
|
||||||
|
@ -1221,6 +1224,9 @@ const WATypingTimeout = 15 * time.Second
|
||||||
|
|
||||||
func (user *User) handleChatPresence(presence *events.ChatPresence) {
|
func (user *User) handleChatPresence(presence *events.ChatPresence) {
|
||||||
puppet := user.bridge.GetPuppetByJID(presence.Sender)
|
puppet := user.bridge.GetPuppetByJID(presence.Sender)
|
||||||
|
if puppet == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
portal := user.GetPortalByJID(presence.Chat)
|
portal := user.GetPortalByJID(presence.Chat)
|
||||||
if puppet == nil || portal == nil || len(portal.MXID) == 0 {
|
if puppet == nil || portal == nil || len(portal.MXID) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -1341,6 +1347,10 @@ func (user *User) handleGroupUpdate(evt *events.GroupInfo) {
|
||||||
log.Debug().Msg("Ignoring group info update in chat with no portal")
|
log.Debug().Msg("Ignoring group info update in chat with no portal")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if evt.Sender != nil && evt.Sender.Server == types.HiddenUserServer {
|
||||||
|
log.Debug().Str("sender", evt.Sender.String()).Msg("Ignoring group info update from @lid user")
|
||||||
|
return
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case evt.Announce != nil:
|
case evt.Announce != nil:
|
||||||
log.Debug().Msg("Group announcement mode (message send permission) changed")
|
log.Debug().Msg("Group announcement mode (message send permission) changed")
|
||||||
|
|
Loading…
Reference in a new issue