protomessage.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
  2. // Copyright (C) 2019 Tulir Asokan
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package whatsappExt
  17. import (
  18. "github.com/Rhymen/go-whatsapp"
  19. "github.com/Rhymen/go-whatsapp/binary/proto"
  20. )
  21. type MessageRevokeHandler interface {
  22. whatsapp.Handler
  23. HandleMessageRevoke(key MessageRevocation)
  24. }
  25. type MessageRevocation struct {
  26. Id string
  27. RemoteJid string
  28. FromMe bool
  29. Participant string
  30. }
  31. func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
  32. protoMsg := message.GetMessage().GetProtocolMessage()
  33. if protoMsg != nil && protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
  34. key := protoMsg.GetKey()
  35. deletedMessage := MessageRevocation{
  36. Id: key.GetId(),
  37. RemoteJid: key.GetRemoteJid(),
  38. FromMe: key.GetFromMe(),
  39. Participant: key.GetParticipant(),
  40. }
  41. for _, handler := range ext.handlers {
  42. mrHandler, ok := handler.(MessageRevokeHandler)
  43. if !ok {
  44. continue
  45. }
  46. if ext.shouldCallSynchronously(mrHandler) {
  47. mrHandler.HandleMessageRevoke(deletedMessage)
  48. } else {
  49. go mrHandler.HandleMessageRevoke(deletedMessage)
  50. }
  51. }
  52. }
  53. }