2020-01-20 20:56:06 +00:00
|
|
|
package ext
|
2018-04-11 15:41:51 +00:00
|
|
|
|
|
|
|
import (
|
2019-11-23 17:57:05 +00: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 16:25:34 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2021-04-19 12:09:46 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
feat: introduce messenger APIs to extract discord channels
As part of the new Discord <-> Status Community Import functionality,
we're adding an API that extracts all discord categories and channels
from a previously exported discord export file.
These APIs can be used in clients to show the user what categories and
channels will be imported later on.
There are two APIs:
1. `Messenger.ExtractDiscordCategoriesAndChannels(filesToimport
[]string) (*MessengerResponse, map[string]*discord.ImportError)`
This takes a list of exported discord export (JSON) files (typically one per
channel), reads them, and extracts the categories and channels into
dedicated data structures (`[]DiscordChannel` and `[]DiscordCategory`)
It also returns the oldest message timestamp found in all extracted
channels.
The API is synchronous and returns the extracted data as
a `*MessengerResponse`. This allows to make the API available
status-go's RPC interface.
The error case is a `map[string]*discord.ImportError` where each key
is a file path of a JSON file that we tried to extract data from, and
the value a `discord.ImportError` which holds an error message and an
error code, allowing for distinguishing between "critical" errors and
"non-critical" errors.
2. `Messenger.RequestExtractDiscordCategoriesAndChannels(filesToImport
[]string)`
This is the asynchronous counterpart to
`ExtractDiscordCategoriesAndChannels`. The reason this API has been
added is because discord servers can have a lot of message and
channel data, which causes `ExtractDiscordCategoriesAndChannels` to
block the thread for too long, making apps potentially feel like they
are stuck.
This API runs inside a go routine, eventually calls
`ExtractDiscordCategoriesAndChannels`, and then emits a newly
introduced `DiscordCategoriesAndChannelsExtractedSignal` that clients
can react to.
Failure of extraction has to be determined by the
`discord.ImportErrors` emitted by the signal.
**A note about exported discord history files**
We expect users to export their discord histories via the
[DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter/wiki/GUI%2C-CLI-and-Formats-explained#exportguild)
tool. The tool allows to export the data in different formats, such as
JSON, HTML and CSV.
We expect users to have their data exported as JSON.
Closes: https://github.com/status-im/status-desktop/issues/6690
2022-07-13 09:33:53 +00:00
|
|
|
"github.com/status-im/status-go/protocol/discord"
|
2022-11-30 09:41:35 +00:00
|
|
|
"github.com/status-im/status-go/protocol/wakusync"
|
2018-05-03 07:35:58 +00:00
|
|
|
"github.com/status-im/status-go/signal"
|
2018-04-11 15:41:51 +00:00
|
|
|
)
|
|
|
|
|
2018-04-13 05:52:22 +00: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 07:03:10 +00:00
|
|
|
func (h EnvelopeSignalHandler) EnvelopeSent(identifiers [][]byte) {
|
|
|
|
signal.SendEnvelopeSent(identifiers)
|
2018-04-13 05:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EnvelopeExpired triggered when envelope is expired but wasn't delivered to any peer.
|
2019-08-09 07:03:10 +00:00
|
|
|
func (h EnvelopeSignalHandler) EnvelopeExpired(identifiers [][]byte, err error) {
|
|
|
|
signal.SendEnvelopeExpired(identifiers, err)
|
2018-04-11 15:41:51 +00:00
|
|
|
}
|
2018-06-15 15:12:31 +00:00
|
|
|
|
2018-07-02 07:38:10 +00:00
|
|
|
// MailServerRequestCompleted triggered when the mailserver sends a message to notify that the request has been completed
|
2019-11-23 17:57:05 +00:00
|
|
|
func (h EnvelopeSignalHandler) MailServerRequestCompleted(requestID types.Hash, lastEnvelopeHash types.Hash, cursor []byte, err error) {
|
2018-10-18 10:25:00 +00:00
|
|
|
signal.SendMailServerRequestCompleted(requestID, lastEnvelopeHash, cursor, err)
|
2018-06-15 15:12:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 07:38:10 +00:00
|
|
|
// MailServerRequestExpired triggered when the mailserver request expires
|
2019-11-23 17:57:05 +00:00
|
|
|
func (h EnvelopeSignalHandler) MailServerRequestExpired(hash types.Hash) {
|
2018-06-15 15:12:31 +00:00
|
|
|
signal.SendMailServerRequestExpired(hash)
|
|
|
|
}
|
2019-07-01 09:39:51 +00: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 16:25:34 +00:00
|
|
|
func (h PublisherSignalHandler) NewMessages(response *protocol.MessengerResponse) {
|
|
|
|
signal.SendNewMessages(response)
|
2019-07-01 10:00:46 +00:00
|
|
|
}
|
2021-04-19 12:09:46 +00:00
|
|
|
|
2021-08-03 19:27:15 +00:00
|
|
|
func (h PublisherSignalHandler) Stats(stats types.StatsSummary) {
|
|
|
|
signal.SendStats(stats)
|
|
|
|
}
|
|
|
|
|
2021-04-19 12:09:46 +00: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 15:39:52 +00:00
|
|
|
// BackupPerformed passes information that a backup was performed
|
|
|
|
func (m MessengerSignalsHandler) BackupPerformed(lastBackup uint64) {
|
|
|
|
signal.SendBackupPerformed(lastBackup)
|
|
|
|
}
|
|
|
|
|
2021-04-19 12:09:46 +00:00
|
|
|
// MessageDelivered passes info about community that was requested before
|
|
|
|
func (m MessengerSignalsHandler) CommunityInfoFound(community *communities.Community) {
|
|
|
|
signal.SendCommunityInfoFound(community)
|
|
|
|
}
|
2021-03-25 15:15:22 +00:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) MessengerResponse(response *protocol.MessengerResponse) {
|
|
|
|
PublisherSignalHandler{}.NewMessages(response)
|
|
|
|
}
|
2021-09-28 18:41:35 +00:00
|
|
|
|
2022-11-24 21:09:17 +00:00
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestStarted(numBatches int) {
|
|
|
|
signal.SendHistoricMessagesRequestStarted(numBatches)
|
2021-09-28 18:41:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 21:09:17 +00:00
|
|
|
func (m *MessengerSignalsHandler) HistoryRequestCompleted() {
|
|
|
|
signal.SendHistoricMessagesRequestCompleted()
|
2021-09-28 18:41:35 +00:00
|
|
|
}
|
2022-03-21 14:18:36 +00: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)
|
|
|
|
}
|
2022-08-02 23:08:01 +00:00
|
|
|
|
2022-12-01 14:02:17 +00:00
|
|
|
func (m *MessengerSignalsHandler) DownloadingHistoryArchivesStarted(communityID string) {
|
|
|
|
signal.SendDownloadingHistoryArchivesStarted(communityID)
|
|
|
|
}
|
|
|
|
|
2022-12-02 12:45:41 +00:00
|
|
|
func (m *MessengerSignalsHandler) ImportingHistoryArchiveMessages(communityID string) {
|
|
|
|
signal.SendImportingHistoryArchiveMessages(communityID)
|
|
|
|
}
|
|
|
|
|
2022-09-15 07:59:02 +00:00
|
|
|
func (m *MessengerSignalsHandler) DownloadingHistoryArchivesFinished(communityID string) {
|
|
|
|
signal.SendDownloadingHistoryArchivesFinished(communityID)
|
|
|
|
}
|
|
|
|
|
2022-08-02 23:08:01 +00:00
|
|
|
func (m *MessengerSignalsHandler) StatusUpdatesTimedOut(statusUpdates *[]protocol.UserStatus) {
|
|
|
|
signal.SendStatusUpdatesTimedOut(statusUpdates)
|
|
|
|
}
|
feat: introduce messenger APIs to extract discord channels
As part of the new Discord <-> Status Community Import functionality,
we're adding an API that extracts all discord categories and channels
from a previously exported discord export file.
These APIs can be used in clients to show the user what categories and
channels will be imported later on.
There are two APIs:
1. `Messenger.ExtractDiscordCategoriesAndChannels(filesToimport
[]string) (*MessengerResponse, map[string]*discord.ImportError)`
This takes a list of exported discord export (JSON) files (typically one per
channel), reads them, and extracts the categories and channels into
dedicated data structures (`[]DiscordChannel` and `[]DiscordCategory`)
It also returns the oldest message timestamp found in all extracted
channels.
The API is synchronous and returns the extracted data as
a `*MessengerResponse`. This allows to make the API available
status-go's RPC interface.
The error case is a `map[string]*discord.ImportError` where each key
is a file path of a JSON file that we tried to extract data from, and
the value a `discord.ImportError` which holds an error message and an
error code, allowing for distinguishing between "critical" errors and
"non-critical" errors.
2. `Messenger.RequestExtractDiscordCategoriesAndChannels(filesToImport
[]string)`
This is the asynchronous counterpart to
`ExtractDiscordCategoriesAndChannels`. The reason this API has been
added is because discord servers can have a lot of message and
channel data, which causes `ExtractDiscordCategoriesAndChannels` to
block the thread for too long, making apps potentially feel like they
are stuck.
This API runs inside a go routine, eventually calls
`ExtractDiscordCategoriesAndChannels`, and then emits a newly
introduced `DiscordCategoriesAndChannelsExtractedSignal` that clients
can react to.
Failure of extraction has to be determined by the
`discord.ImportErrors` emitted by the signal.
**A note about exported discord history files**
We expect users to export their discord histories via the
[DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter/wiki/GUI%2C-CLI-and-Formats-explained#exportguild)
tool. The tool allows to export the data in different formats, such as
JSON, HTML and CSV.
We expect users to have their data exported as JSON.
Closes: https://github.com/status-im/status-desktop/issues/6690
2022-07-13 09:33:53 +00:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) DiscordCategoriesAndChannelsExtracted(categories []*discord.Category, channels []*discord.Channel, oldestMessageTimestamp int64, errors map[string]*discord.ImportError) {
|
|
|
|
signal.SendDiscordCategoriesAndChannelsExtracted(categories, channels, oldestMessageTimestamp, errors)
|
|
|
|
}
|
2022-09-29 11:50:23 +00:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) DiscordCommunityImportProgress(importProgress *discord.ImportProgress) {
|
|
|
|
signal.SendDiscordCommunityImportProgress(importProgress)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) DiscordCommunityImportFinished(id string) {
|
|
|
|
signal.SendDiscordCommunityImportFinished(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) DiscordCommunityImportCancelled(id string) {
|
|
|
|
signal.SendDiscordCommunityImportCancelled(id)
|
|
|
|
}
|
2022-11-30 09:41:35 +00:00
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) SendWakuFetchingBackupProgress(response *wakusync.WakuBackedUpDataResponse) {
|
|
|
|
signal.SendWakuFetchingBackupProgress(response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) SendWakuBackedUpProfile(response *wakusync.WakuBackedUpDataResponse) {
|
|
|
|
signal.SendWakuBackedUpProfile(response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MessengerSignalsHandler) SendWakuBackedUpSettings(response *wakusync.WakuBackedUpDataResponse) {
|
|
|
|
signal.SendWakuBackedUpSettings(response)
|
|
|
|
}
|