Cut post if append is empty; add ellipsis.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2019-12-28 23:10:49 +01:00
parent bca496c87a
commit bb86f321b5
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 20 additions and 8 deletions

View File

@ -20,10 +20,12 @@
#include <boost/log/trivial.hpp>
#include <string>
#include <string_view>
namespace mastorss
{
using std::string;
using std::string_view;
MastoAPI::MastoAPI(const ProfileData &data)
: _profile{data}
@ -53,16 +55,26 @@ void MastoAPI::post_item(const Item &item)
}()};
status.append("\n\n" + item.link);
const size_t len{status.size()};
const size_t len_append{[&]
{
if (_profile.append.empty())
{
return size_t{};
}
return _profile.append.size() + 2;
}()};
const size_t len_max{_profile.max_size};
constexpr string_view omission = " […]";
if ((len + len_append) > len_max)
{
status.resize(len_max - len_append - omission.size());
status.append(omission);
}
if (!_profile.append.empty())
{
const size_t len{status.size()};
const size_t len_append{_profile.append.size() + 2};
const size_t len_max{_profile.max_size};
if ((len + len_append) > len_max)
{
status.resize(len_max - len_append);
}
status.append("\n\n" + _profile.append);
}