parent
eaff505f15
commit
43504f6ef7
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::uint_fast64_t;
|
using std::uint_fast64_t;
|
||||||
|
using std::uint_fast16_t;
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
|
|
||||||
namespace Mastodon
|
namespace Mastodon
|
||||||
|
@ -115,6 +116,23 @@ public:
|
||||||
*/
|
*/
|
||||||
typedef std::map<Easy::notification_type, bool> alertmap;
|
typedef std::map<Easy::notification_type, bool> alertmap;
|
||||||
|
|
||||||
|
class Account;
|
||||||
|
class Application;
|
||||||
|
class Attachment;
|
||||||
|
class Card;
|
||||||
|
class Context;
|
||||||
|
class Emoji;
|
||||||
|
class Instance;
|
||||||
|
class List;
|
||||||
|
class Mention;
|
||||||
|
class Notification;
|
||||||
|
class Relationship;
|
||||||
|
class Report;
|
||||||
|
class Results;
|
||||||
|
class Status;
|
||||||
|
class Tag;
|
||||||
|
class PushSubscription;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class to hold the `Link`-header.
|
* @brief Class to hold the `Link`-header.
|
||||||
*
|
*
|
||||||
|
@ -219,6 +237,20 @@ public:
|
||||||
static const string strtime_local(const system_clock::time_point &timepoint,
|
static const string strtime_local(const system_clock::time_point &timepoint,
|
||||||
const string &format);
|
const string &format);
|
||||||
|
|
||||||
|
// #### simple calls ####
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sends a toot.
|
||||||
|
*
|
||||||
|
* @param status The status to send
|
||||||
|
* @param error @ref error "Error code". If the URL has permanently
|
||||||
|
* changed, 13 is returned and answer is set to the new
|
||||||
|
* URL.
|
||||||
|
*
|
||||||
|
* @return The new Easy::Status
|
||||||
|
*/
|
||||||
|
const Status send_toot(const Status &status, uint_fast16_t error = 0);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Base class for all entities.
|
* @brief Base class for all entities.
|
||||||
*/
|
*/
|
||||||
|
@ -357,23 +389,6 @@ public:
|
||||||
mutable bool _was_set;
|
mutable bool _was_set;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Account;
|
|
||||||
class Application;
|
|
||||||
class Attachment;
|
|
||||||
class Card;
|
|
||||||
class Context;
|
|
||||||
class Emoji;
|
|
||||||
class Instance;
|
|
||||||
class List;
|
|
||||||
class Mention;
|
|
||||||
class Notification;
|
|
||||||
class Relationship;
|
|
||||||
class Report;
|
|
||||||
class Results;
|
|
||||||
class Status;
|
|
||||||
class Tag;
|
|
||||||
class PushSubscription;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline static const string strtime
|
inline static const string strtime
|
||||||
(const system_clock::time_point &timepoint,
|
(const system_clock::time_point &timepoint,
|
||||||
|
|
|
@ -62,7 +62,7 @@ const std::chrono::duration<double> Attachment::duration() const
|
||||||
return std::chrono::duration<double>(sec);
|
return std::chrono::duration<double>(sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string Attachment::file()
|
const string Attachment::file() const
|
||||||
{
|
{
|
||||||
return get_string("file");
|
return get_string("file");
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace Mastodon
|
||||||
*
|
*
|
||||||
* @since 0.17.0
|
* @since 0.17.0
|
||||||
*/
|
*/
|
||||||
const string file();
|
const string file() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Sets file to upload
|
* @brief Sets file to upload
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
/* This file is part of mastodon-cpp.
|
||||||
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "easy.hpp"
|
||||||
|
#include "macros.hpp"
|
||||||
|
#include "easy/entities/status.hpp"
|
||||||
|
#include "easy/entities/attachment.hpp"
|
||||||
|
|
||||||
|
using namespace Mastodon;
|
||||||
|
|
||||||
|
const Easy::Status Easy::send_toot(const Status &status, uint_fast16_t error)
|
||||||
|
{
|
||||||
|
API::parametermap parameters;
|
||||||
|
string answer;
|
||||||
|
error = 0;
|
||||||
|
|
||||||
|
if (!status.content().empty())
|
||||||
|
{
|
||||||
|
parameters.insert({ "status", { status.content() }});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ttdebug << "ERROR: Easy::Status::content can not be empty.\n";
|
||||||
|
error = 11;
|
||||||
|
return Status();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.in_reply_to_id() != 0)
|
||||||
|
{
|
||||||
|
parameters.insert({ "in_reply_to_id",
|
||||||
|
{ std::to_string(status.in_reply_to_id()) }});
|
||||||
|
}
|
||||||
|
if (status.sensitive())
|
||||||
|
{
|
||||||
|
parameters.insert({ "sensitive", { "true" }});
|
||||||
|
}
|
||||||
|
if (!status.spoiler_text().empty())
|
||||||
|
{
|
||||||
|
parameters.insert({ "spoiler_text", { status.spoiler_text() }});
|
||||||
|
}
|
||||||
|
if (status.visibility() != visibility_type::Undefined)
|
||||||
|
{
|
||||||
|
string visibility;
|
||||||
|
switch (status.visibility())
|
||||||
|
{
|
||||||
|
case visibility_type::Direct:
|
||||||
|
visibility = "direct";
|
||||||
|
break;
|
||||||
|
case visibility_type::Private:
|
||||||
|
visibility = "private";
|
||||||
|
break;
|
||||||
|
case visibility_type::Unlisted:
|
||||||
|
visibility = "unlisted";
|
||||||
|
break;
|
||||||
|
case visibility_type::Public:
|
||||||
|
visibility = "public";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
parameters.insert({ "visibility", { visibility }});
|
||||||
|
}
|
||||||
|
if (!status.language().empty())
|
||||||
|
{
|
||||||
|
parameters.insert({ "language", { status.language() }});
|
||||||
|
}
|
||||||
|
if (!status.media_attachments().empty())
|
||||||
|
{
|
||||||
|
std::vector<string> media_ids;
|
||||||
|
for (const Attachment &att : status.media_attachments())
|
||||||
|
{
|
||||||
|
API::parametermap param_att;
|
||||||
|
if (!att.file().empty())
|
||||||
|
{
|
||||||
|
param_att.insert({ "file", { att.file() }});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ttdebug << "ERROR: Easy::Attachment::file can not be empty.\n";
|
||||||
|
error = 11;
|
||||||
|
return Status();
|
||||||
|
}
|
||||||
|
if (!att.description().empty())
|
||||||
|
{
|
||||||
|
param_att.insert({ "description", { att.description() }});
|
||||||
|
}
|
||||||
|
if (!att.focus().empty())
|
||||||
|
{
|
||||||
|
param_att.insert({ "focus",
|
||||||
|
{ std::to_string(att.focus()[0]) + ',' +
|
||||||
|
std::to_string(att.focus()[1]) }});
|
||||||
|
}
|
||||||
|
|
||||||
|
error = post(API::v1::media, param_att, answer);
|
||||||
|
if (error == 0)
|
||||||
|
{
|
||||||
|
Attachment attachment(answer);
|
||||||
|
media_ids.push_back(std::to_string(attachment.id()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ttdebug << "ERROR: Could not upload file.\n";
|
||||||
|
return Status();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters.insert({ "media_ids", media_ids });
|
||||||
|
}
|
||||||
|
|
||||||
|
error = post(API::v1::statuses, parameters, answer);
|
||||||
|
if (error == 0)
|
||||||
|
{
|
||||||
|
return Status(answer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Status();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue