2020-01-20 21:56:06 +01:00
|
|
|
package ext
|
2018-04-11 18:41:51 +03:00
|
|
|
|
|
|
|
import (
|
2019-11-23 18:57:05 +01:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 17:25:34 +01:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2021-04-19 15:09:46 +03:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2018-05-03 09:35:58 +02:00
|
|
|
"github.com/status-im/status-go/signal"
|
2018-04-11 18:41:51 +03:00
|
|
|
)
|
|
|
|
|
2018-04-13 08:52:22 +03:00
|
|
|
// EnvelopeSignalHandler sends signals when envelope is sent or expired.
|
|
|
|
type EnvelopeSignalHandler struct{}
|
|
|
|
|
|
|
|
// EnvelopeSent triggered when envelope delivered atleast to 1 peer.
|
2019-08-09 09:03:10 +02:00
|
|
|
func (h EnvelopeSignalHandler) EnvelopeSent(identifiers [][]byte) {
|
|
|
|
signal.SendEnvelopeSent(identifiers)
|
2018-04-13 08:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// EnvelopeExpired triggered when envelope is expired but wasn't delivered to any peer.
|
2019-08-09 09:03:10 +02:00
|
|
|
func (h EnvelopeSignalHandler) EnvelopeExpired(identifiers [][]byte, err error) {
|
|
|
|
signal.SendEnvelopeExpired(identifiers, err)
|
2018-04-11 18:41:51 +03:00
|
|
|
}
|
2018-06-15 17:12:31 +02:00
|
|
|
|
2018-07-02 09:38:10 +02:00
|
|
|
// MailServerRequestCompleted triggered when the mailserver sends a message to notify that the request has been completed
|
2019-11-23 18:57:05 +01:00
|
|
|
func (h EnvelopeSignalHandler) MailServerRequestCompleted(requestID types.Hash, lastEnvelopeHash types.Hash, cursor []byte, err error) {
|
2018-10-18 12:25:00 +02:00
|
|
|
signal.SendMailServerRequestCompleted(requestID, lastEnvelopeHash, cursor, err)
|
2018-06-15 17:12:31 +02:00
|
|
|
}
|
|
|
|
|
2018-07-02 09:38:10 +02:00
|
|
|
// MailServerRequestExpired triggered when the mailserver request expires
|
2019-11-23 18:57:05 +01:00
|
|
|
func (h EnvelopeSignalHandler) MailServerRequestExpired(hash types.Hash) {
|
2018-06-15 17:12:31 +02:00
|
|
|
signal.SendMailServerRequestExpired(hash)
|
|
|
|
}
|
2019-07-01 11:39:51 +02:00
|
|
|
|
|
|
|
// PublisherSignalHandler sends signals on protocol events
|
|
|
|
type PublisherSignalHandler struct{}
|
|
|
|
|
|
|
|
func (h PublisherSignalHandler) DecryptMessageFailed(pubKey string) {
|
|
|
|
signal.SendDecryptMessageFailed(pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h PublisherSignalHandler) BundleAdded(identity string, installationID string) {
|
|
|
|
signal.SendBundleAdded(identity, installationID)
|
|
|
|
}
|
|
|
|
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 17:25:34 +01:00
|
|
|
func (h PublisherSignalHandler) NewMessages(response *protocol.MessengerResponse) {
|
|
|
|
signal.SendNewMessages(response)
|
2019-07-01 12:00:46 +02:00
|
|
|
}
|
2021-04-19 15:09:46 +03:00
|
|
|
|
2021-08-03 15:27:15 -04:00
|
|
|
func (h PublisherSignalHandler) Stats(stats types.StatsSummary) {
|
|
|
|
signal.SendStats(stats)
|
|
|
|
}
|
|
|
|
|
2021-04-19 15:09:46 +03:00
|
|
|
// MessengerSignalHandler sends signals on messenger events
|
|
|
|
type MessengerSignalsHandler struct{}
|
|
|
|
|
|
|
|
// MessageDelivered passes information that message was delivered
|
|
|
|
func (m MessengerSignalsHandler) MessageDelivered(chatID string, messageID string) {
|
|
|
|
signal.SendMessageDelivered(chatID, messageID)
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:39:52 +01:00
|
|
|
// BackupPerformed passes information that a backup was performed
|
|
|
|
func (m MessengerSignalsHandler) BackupPerformed(lastBackup uint64) {
|
|
|
|
signal.SendBackupPerformed(lastBackup)
|
|
|
|
}
|
|
|
|
|
2021-04-19 15:09:46 +03:00
|
|
|
// MessageDelivered passes info about community that was requested before
|
|
|
|
func (m MessengerSignalsHandler) CommunityInfoFound(community *communities.Community) {
|
|
|
|
signal.SendCommunityInfoFound(community)
|
|
|
|
}
|
2021-03-25 16:15:22 +01:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) MessengerResponse(response *protocol.MessengerResponse) {
|
|
|
|
PublisherSignalHandler{}.NewMessages(response)
|
|
|
|
}
|
2021-09-28 14:41:35 -04:00
|
|
|
|
2021-11-09 17:16:19 -04:00
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestStarted(requestID string, numBatches int) {
|
|
|
|
signal.SendHistoricMessagesRequestStarted(requestID, numBatches)
|
2021-09-28 14:41:35 -04:00
|
|
|
}
|
|
|
|
|
2021-11-09 17:16:19 -04:00
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestBatchProcessed(requestID string, batchIndex int, numBatches int) {
|
|
|
|
signal.SendHistoricMessagesRequestBatchProcessed(requestID, batchIndex, numBatches)
|
2021-09-28 14:41:35 -04:00
|
|
|
}
|
|
|
|
|
2021-11-09 17:16:19 -04:00
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestFailed(requestID string, err error) {
|
|
|
|
signal.SendHistoricMessagesRequestFailed(requestID, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestCompleted(requestID string) {
|
|
|
|
signal.SendHistoricMessagesRequestCompleted(requestID)
|
2021-09-28 14:41:35 -04:00
|
|
|
}
|
2022-03-21 15:18:36 +01:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchivesProtocolEnabled() {
|
|
|
|
signal.SendHistoryArchivesProtocolEnabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchivesProtocolDisabled() {
|
|
|
|
signal.SendHistoryArchivesProtocolDisabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) CreatingHistoryArchives(communityID string) {
|
|
|
|
signal.SendCreatingHistoryArchives(communityID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) NoHistoryArchivesCreated(communityID string, from int, to int) {
|
|
|
|
signal.SendNoHistoryArchivesCreated(communityID, from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchivesCreated(communityID string, from int, to int) {
|
|
|
|
signal.SendHistoryArchivesCreated(communityID, from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchivesSeeding(communityID string) {
|
|
|
|
signal.SendHistoryArchivesSeeding(communityID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchivesUnseeded(communityID string) {
|
|
|
|
signal.SendHistoryArchivesUnseeded(communityID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) HistoryArchiveDownloaded(communityID string, from int, to int) {
|
|
|
|
signal.SendHistoryArchiveDownloaded(communityID, from, to)
|
|
|
|
}
|