Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added expire and issued timestamps in attachment #1065

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,20 @@ struct DPP_EXPORT attachment {
* @return true if remixed
*/
bool is_remix() const;

/**
* @brief Returns expiration timestamp for attachment's URL
*
* @return timestamp of URL expiration
*/
time_t get_expire_time() const;

/**
* @brief Returns creation timestamp for attachment's URL
*
* @return timestamp of URL creation
*/
time_t get_issued_time() const;
};

/**
Expand Down
32 changes: 32 additions & 0 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,38 @@ bool attachment::is_remix() const {
return flags & a_is_remix;
}

time_t attachment::get_expire_time() const {
size_t attr_position = url.find('?');
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
/*If no attributes were sent in url, we do not need to parse more*/
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
if(url.npos == attr_position){
return 0;
}
std::string attributes = url.substr(attr_position+1);
std::vector<std::string> attr_list = utility::tokenize(attributes,"&");
Jaskowicz1 marked this conversation as resolved.
Show resolved Hide resolved
auto ex_attr = std::find_if(attr_list.begin(), attr_list.end(),[](const std::string& s){return s.substr(0,3) == "ex=";});
if(attr_list.end() == ex_attr){
return 0;
}
/*Erase 'ex=' prefix before parsing*/
return std::stol(ex_attr->substr(3),nullptr,16);
}

time_t attachment::get_issued_time() const {
size_t attr_position = url.find('?');
/*No attributes were sent in url, so we do not need to parse more*/
if(url.npos == attr_position){
return 0;
}
std::string attributes = url.substr(attr_position+1);
std::vector<std::string> attr_list = utility::tokenize(attributes,"&");
auto is_attr = std::find_if(attr_list.begin(), attr_list.end(),[](const std::string& s){return s.substr(0,3) == "is=";});
if(attr_list.end() == is_attr){
return 0;
}
/*Erase 'is=' prefix before parsing*/
return std::stol(is_attr->substr(3),nullptr,16);
}

json message::to_json(bool with_id, bool is_interaction_response) const {
/* This is the basics. once it works, expand on it. */
json j({
Expand Down
Loading