props.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. "encoding/json"
  19. "github.com/Rhymen/go-whatsapp"
  20. )
  21. type ProtocolProps struct {
  22. WebPresence bool `json:"webPresence"`
  23. NotificationQuery bool `json:"notificationQuery"`
  24. FacebookCrashLog bool `json:"fbCrashlog"`
  25. Bucket string `json:"bucket"`
  26. GIFSearch string `json:"gifSearch"`
  27. Spam bool `json:"SPAM"`
  28. SetBlock bool `json:"SET_BLOCK"`
  29. MessageInfo bool `json:"MESSAGE_INFO"`
  30. MaxFileSize int `json:"maxFileSize"`
  31. Media int `json:"media"`
  32. GroupNameLength int `json:"maxSubject"`
  33. GroupDescriptionLength int `json:"groupDescLength"`
  34. MaxParticipants int `json:"maxParticipants"`
  35. VideoMaxEdge int `json:"videoMaxEdge"`
  36. ImageMaxEdge int `json:"imageMaxEdge"`
  37. ImageMaxKilobytes int `json:"imageMaxKBytes"`
  38. Edit int `json:"edit"`
  39. FwdUIStartTimestamp int `json:"fwdUiStartTs"`
  40. GroupsV3 int `json:"groupsV3"`
  41. RestrictGroups int `json:"restrictGroups"`
  42. AnnounceGroups int `json:"announceGroups"`
  43. }
  44. type ProtocolPropsHandler interface {
  45. whatsapp.Handler
  46. HandleProtocolProps(ProtocolProps)
  47. }
  48. func (ext *ExtendedConn) handleMessageProps(message []byte) {
  49. var event ProtocolProps
  50. err := json.Unmarshal(message, &event)
  51. if err != nil {
  52. ext.jsonParseError(err)
  53. return
  54. }
  55. for _, handler := range ext.handlers {
  56. protocolPropsHandler, ok := handler.(ProtocolPropsHandler)
  57. if !ok {
  58. continue
  59. }
  60. if ext.shouldCallSynchronously(protocolPropsHandler) {
  61. protocolPropsHandler.HandleProtocolProps(event)
  62. } else {
  63. go protocolPropsHandler.HandleProtocolProps(event)
  64. }
  65. }
  66. }