-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: status-im/status-desktop#6690
- Loading branch information
Showing
22 changed files
with
1,270 additions
and
613 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package discord | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/status-im/status-go/protocol/protobuf" | ||
) | ||
|
||
type ErrorType uint | ||
|
||
const ( | ||
NoError ErrorType = iota | ||
Warning | ||
Error | ||
) | ||
|
||
type Channel struct { | ||
ID string `json:"id"` | ||
CategoryName string `json:"category"` | ||
CategoryID string `json:"categoryId"` | ||
Name string `json:"name"` | ||
Description string `json:"topic"` | ||
FilePath string `json:"filePath"` | ||
} | ||
|
||
type Category struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type ExportedData struct { | ||
Channel Channel `json:"channel"` | ||
Messages []*protobuf.DiscordMessage `json:"messages"` | ||
} | ||
|
||
type ExtractedData struct { | ||
Categories map[string]*Category | ||
ExportedData []*ExportedData | ||
OldestMessageTimestamp int | ||
} | ||
|
||
type ImportError struct { | ||
// This code is used to distinguish between errors | ||
// that are considered "criticial" and those that are not. | ||
// | ||
// Critical errors are the ones that prevent the imported community | ||
// from functioning properly. For example, if the creation of the community | ||
// or its categories and channels fails, this is a critical error. | ||
// | ||
// Non-critical errors are the ones that would not prevent the imported | ||
// community from functioning. For example, if the channel data to be imported | ||
// has no messages, or is not parsable. | ||
Code ErrorType `json:"code"` | ||
Message string `json:"message"` | ||
} | ||
|
||
func (d ImportError) Error() string { | ||
return fmt.Sprintf("%d: %s", d.Code, d.Message) | ||
} |
Oops, something went wrong.