Skip to content

Commit

Permalink
refactor: changed the way message holds files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Nov 6, 2023
1 parent 9ddec9a commit 033a204
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
34 changes: 22 additions & 12 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,26 @@ namespace cache_policy {

};

/**
* @brief The data for a file.
*/
struct message_file_data {
/**
* @brief Name of file to upload (for use server-side in discord's url).
*/
std::string name{};

/**
* @brief File content to upload (raw binary)
*/
std::string content{};

/**
* @brief Mime type of files to upload.
*/
std::string mimetype{};
};

/**
* @brief Represents messages sent and received on Discord
*/
Expand Down Expand Up @@ -1828,19 +1848,9 @@ struct DPP_EXPORT message : public managed, json_interface<message> {
std::vector<sticker> stickers;

/**
* @brief Name of file to upload (for use server-side in discord's url).
*/
std::vector<std::string> filename;

/**
* @brief File content to upload (raw binary)
*/
std::vector<std::string> filecontent;

/**
* @brief Mime type of files to upload.
* @brief An array of file data.
*/
std::vector<std::string> filemimetype;
std::vector<message_file_data> file_data;

/**
* @brief Reference to another message, e.g. a reply
Expand Down
35 changes: 22 additions & 13 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,30 +559,39 @@ message& message::set_type(message_type t)
return *this;
}

message& message::set_filename(const std::string &fn)
{
if (filename.empty()) {
filename.push_back(fn);
message& message::set_filename(const std::string &fn) {
if (file_data.empty()) {
message_file_data data;
data.name = fn;

file_data.push_back(data);
} else {
filename[filename.size() - 1] = fn;
file_data[file_data.size() - 1].name = fn;
}

return *this;
}

message& message::set_file_content(const std::string &fc)
{
if (filecontent.empty()) {
filecontent.push_back(fc);
message& message::set_file_content(const std::string &fc) {
if (file_data.empty()) {
message_file_data data;
data.content = fc;

file_data.push_back(data);
} else {
filecontent[filecontent.size() - 1] = fc;
file_data[file_data.size() - 1].content = fc;
}

return *this;
}

message& message::add_file(const std::string &fn, const std::string &fc, const std::string &fm) {
filename.push_back(fn);
filecontent.push_back(fc);
filemimetype.push_back(fm);
message_file_data data;
data.name = fn;
data.content = fc;
data.mimetype = fm;

file_data.push_back(data);
return *this;
}

Expand Down

0 comments on commit 033a204

Please sign in to comment.