group.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Copyright (c) 2021 Tulir Asokan
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package types
  7. import (
  8. "time"
  9. )
  10. type GroupMemberAddMode string
  11. const (
  12. GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
  13. GroupMemberAddModeAllMember GroupMemberAddMode = "all_member_add"
  14. )
  15. // GroupInfo contains basic information about a group chat on WhatsApp.
  16. type GroupInfo struct {
  17. JID JID
  18. OwnerJID JID
  19. OwnerPN JID
  20. GroupName
  21. GroupTopic
  22. GroupLocked
  23. GroupAnnounce
  24. GroupEphemeral
  25. GroupIncognito
  26. GroupParent
  27. GroupLinkedParent
  28. GroupIsDefaultSub
  29. GroupMembershipApprovalMode
  30. AddressingMode AddressingMode
  31. GroupCreated time.Time
  32. CreatorCountryCode string
  33. ParticipantVersionID string
  34. Participants []GroupParticipant
  35. ParticipantCount int
  36. MemberAddMode GroupMemberAddMode
  37. // Suspended indicates whether the group is currently paused/suspended.
  38. Suspended bool
  39. }
  40. type GroupMembershipApprovalMode struct {
  41. IsJoinApprovalRequired bool
  42. }
  43. type GroupParent struct {
  44. IsParent bool
  45. DefaultMembershipApprovalMode string // request_required
  46. }
  47. type GroupLinkedParent struct {
  48. LinkedParentJID JID
  49. }
  50. type GroupIsDefaultSub struct {
  51. IsDefaultSubGroup bool
  52. }
  53. // GroupName contains the name of a group along with metadata of who set it and when.
  54. type GroupName struct {
  55. Name string
  56. NameSetAt time.Time
  57. NameSetBy JID
  58. NameSetByPN JID
  59. }
  60. // GroupTopic contains the topic (description) of a group along with metadata of who set it and when.
  61. type GroupTopic struct {
  62. Topic string
  63. TopicID string
  64. TopicSetAt time.Time
  65. TopicSetBy JID
  66. TopicSetByPN JID
  67. TopicDeleted bool
  68. }
  69. // GroupLocked specifies whether the group info can only be edited by admins.
  70. type GroupLocked struct {
  71. IsLocked bool
  72. }
  73. // GroupAnnounce specifies whether only admins can send messages in the group.
  74. type GroupAnnounce struct {
  75. IsAnnounce bool
  76. AnnounceVersionID string
  77. }
  78. type GroupIncognito struct {
  79. IsIncognito bool
  80. }
  81. // GroupParticipant contains info about a participant of a WhatsApp group chat.
  82. type GroupParticipant struct {
  83. // The primary JID that should be used to send messages to this participant.
  84. // Always equals either the LID or phone number.
  85. JID JID
  86. PhoneNumber JID
  87. LID JID
  88. IsAdmin bool
  89. IsSuperAdmin bool
  90. // This is only present for anonymous users in announcement groups, it's an obfuscated phone number
  91. DisplayName string
  92. // When creating groups, adding some participants may fail.
  93. // In such cases, the error code will be here.
  94. Error int
  95. AddRequest *GroupParticipantAddRequest
  96. }
  97. type GroupParticipantAddRequest struct {
  98. Code string
  99. Expiration time.Time
  100. }
  101. // GroupEphemeral contains the group's disappearing messages settings.
  102. type GroupEphemeral struct {
  103. IsEphemeral bool
  104. DisappearingTimer uint32
  105. }
  106. type GroupDelete struct {
  107. Deleted bool
  108. DeleteReason string
  109. }
  110. type GroupLinkChangeType string
  111. const (
  112. GroupLinkChangeTypeParent GroupLinkChangeType = "parent_group"
  113. GroupLinkChangeTypeSub GroupLinkChangeType = "sub_group"
  114. GroupLinkChangeTypeSibling GroupLinkChangeType = "sibling_group"
  115. )
  116. type GroupUnlinkReason string
  117. const (
  118. GroupUnlinkReasonDefault GroupUnlinkReason = "unlink_group"
  119. GroupUnlinkReasonDelete GroupUnlinkReason = "delete_parent"
  120. )
  121. type GroupLinkTarget struct {
  122. JID JID
  123. GroupName
  124. GroupIsDefaultSub
  125. }
  126. type GroupLinkChange struct {
  127. Type GroupLinkChangeType
  128. UnlinkReason GroupUnlinkReason
  129. Group GroupLinkTarget
  130. }
  131. type GroupParticipantRequest struct {
  132. JID JID
  133. RequestedAt time.Time
  134. }