appstate.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 events
  7. import (
  8. "time"
  9. "go.mau.fi/whatsmeow/appstate"
  10. "go.mau.fi/whatsmeow/proto/waSyncAction"
  11. "go.mau.fi/whatsmeow/types"
  12. )
  13. // Contact is emitted when an entry in the user's contact list is modified from another device.
  14. type Contact struct {
  15. JID types.JID // The contact who was modified.
  16. Timestamp time.Time // The time when the modification happened.'
  17. Action *waSyncAction.ContactAction // The new contact info.
  18. FromFullSync bool // Whether the action is emitted because of a fullSync
  19. }
  20. // PushName is emitted when a message is received with a different push name than the previous value cached for the same user.
  21. type PushName struct {
  22. JID types.JID // The user whose push name changed.
  23. JIDAlt types.JID
  24. Message *types.MessageInfo // The message where this change was first noticed.
  25. OldPushName string // The previous push name from the local cache.
  26. NewPushName string // The new push name that was included in the message.
  27. }
  28. // BusinessName is emitted when a message is received with a different verified business name than the previous value cached for the same user.
  29. type BusinessName struct {
  30. JID types.JID
  31. Message *types.MessageInfo // This is only present if the change was detected in a message.
  32. OldBusinessName string
  33. NewBusinessName string
  34. }
  35. // Pin is emitted when a chat is pinned or unpinned from another device.
  36. type Pin struct {
  37. JID types.JID // The chat which was pinned or unpinned.
  38. Timestamp time.Time // The time when the (un)pinning happened.
  39. Action *waSyncAction.PinAction // Whether the chat is now pinned or not.
  40. FromFullSync bool // Whether the action is emitted because of a fullSync
  41. }
  42. // Star is emitted when a message is starred or unstarred from another device.
  43. type Star struct {
  44. ChatJID types.JID // The chat where the message was pinned.
  45. SenderJID types.JID // In group chats, the user who sent the message (except if the message was sent by the user).
  46. IsFromMe bool // Whether the message was sent by the user.
  47. MessageID string // The message which was starred or unstarred.
  48. Timestamp time.Time // The time when the (un)starring happened.
  49. Action *waSyncAction.StarAction // Whether the message is now starred or not.
  50. FromFullSync bool // Whether the action is emitted because of a fullSync
  51. }
  52. // DeleteForMe is emitted when a message is deleted (for the current user only) from another device.
  53. type DeleteForMe struct {
  54. ChatJID types.JID // The chat where the message was deleted.
  55. SenderJID types.JID // In group chats, the user who sent the message (except if the message was sent by the user).
  56. IsFromMe bool // Whether the message was sent by the user.
  57. MessageID string // The message which was deleted.
  58. Timestamp time.Time // The time when the deletion happened.
  59. Action *waSyncAction.DeleteMessageForMeAction // Additional information for the deletion.
  60. FromFullSync bool // Whether the action is emitted because of a fullSync
  61. }
  62. // Mute is emitted when a chat is muted or unmuted from another device.
  63. type Mute struct {
  64. JID types.JID // The chat which was muted or unmuted.
  65. Timestamp time.Time // The time when the (un)muting happened.
  66. Action *waSyncAction.MuteAction // The current mute status of the chat.
  67. FromFullSync bool // Whether the action is emitted because of a fullSync
  68. }
  69. // Archive is emitted when a chat is archived or unarchived from another device.
  70. type Archive struct {
  71. JID types.JID // The chat which was archived or unarchived.
  72. Timestamp time.Time // The time when the (un)archiving happened.
  73. Action *waSyncAction.ArchiveChatAction // The current archival status of the chat.
  74. FromFullSync bool // Whether the action is emitted because of a fullSync
  75. }
  76. // MarkChatAsRead is emitted when a whole chat is marked as read or unread from another device.
  77. type MarkChatAsRead struct {
  78. JID types.JID // The chat which was marked as read or unread.
  79. Timestamp time.Time // The time when the marking happened.
  80. Action *waSyncAction.MarkChatAsReadAction // Whether the chat was marked as read or unread, and info about the most recent messages.
  81. FromFullSync bool // Whether the action is emitted because of a fullSync
  82. }
  83. // ClearChat is emitted when a chat is cleared on another device. This is different from DeleteChat.
  84. type ClearChat struct {
  85. JID types.JID // The chat which was cleared.
  86. Timestamp time.Time // The time when the clear happened.
  87. Action *waSyncAction.ClearChatAction // Information about the clear.
  88. FromFullSync bool // Whether the action is emitted because of a fullSync
  89. }
  90. // DeleteChat is emitted when a chat is deleted on another device.
  91. type DeleteChat struct {
  92. JID types.JID // The chat which was deleted.
  93. Timestamp time.Time // The time when the deletion happened.
  94. Action *waSyncAction.DeleteChatAction // Information about the deletion.
  95. FromFullSync bool // Whether the action is emitted because of a fullSync
  96. }
  97. // PushNameSetting is emitted when the user's push name is changed from another device.
  98. type PushNameSetting struct {
  99. Timestamp time.Time // The time when the push name was changed.
  100. Action *waSyncAction.PushNameSetting // The new push name for the user.
  101. FromFullSync bool // Whether the action is emitted because of a fullSync
  102. }
  103. // UnarchiveChatsSetting is emitted when the user changes the "Keep chats archived" setting from another device.
  104. type UnarchiveChatsSetting struct {
  105. Timestamp time.Time // The time when the setting was changed.
  106. Action *waSyncAction.UnarchiveChatsSetting // The new settings.
  107. FromFullSync bool // Whether the action is emitted because of a fullSync
  108. }
  109. // UserStatusMute is emitted when the user mutes or unmutes another user's status updates.
  110. type UserStatusMute struct {
  111. JID types.JID // The user who was muted or unmuted
  112. Timestamp time.Time // The timestamp when the action happened
  113. Action *waSyncAction.UserStatusMuteAction // The new mute status
  114. FromFullSync bool // Whether the action is emitted because of a fullSync
  115. }
  116. // LabelEdit is emitted when a label is edited from any device.
  117. type LabelEdit struct {
  118. Timestamp time.Time // The time when the label was edited.
  119. LabelID string // The label id which was edited.
  120. Action *waSyncAction.LabelEditAction // The new label info.
  121. FromFullSync bool // Whether the action is emitted because of a fullSync
  122. }
  123. // LabelAssociationChat is emitted when a chat is labeled or unlabeled from any device.
  124. type LabelAssociationChat struct {
  125. JID types.JID // The chat which was labeled or unlabeled.
  126. Timestamp time.Time // The time when the (un)labeling happened.
  127. LabelID string // The label id which was added or removed.
  128. Action *waSyncAction.LabelAssociationAction // The current label status of the chat.
  129. FromFullSync bool // Whether the action is emitted because of a fullSync
  130. }
  131. // LabelAssociationMessage is emitted when a message is labeled or unlabeled from any device.
  132. type LabelAssociationMessage struct {
  133. JID types.JID // The chat which was labeled or unlabeled.
  134. Timestamp time.Time // The time when the (un)labeling happened.
  135. LabelID string // The label id which was added or removed.
  136. MessageID string // The message id which was labeled or unlabeled.
  137. Action *waSyncAction.LabelAssociationAction // The current label status of the message.
  138. FromFullSync bool // Whether the action is emitted because of a fullSync
  139. }
  140. // AppState is emitted directly for new data received from app state syncing.
  141. // You should generally use the higher-level events like events.Contact and events.Mute.
  142. type AppState struct {
  143. Index []string
  144. *waSyncAction.SyncActionValue
  145. }
  146. // AppStateSyncComplete is emitted when app state is resynced.
  147. type AppStateSyncComplete struct {
  148. Name appstate.WAPatchName
  149. }