| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <CacheStructs.h> |
| 8 |
#include <QDateTime> |
| 9 |
#include <QPixmap> |
| 10 |
#include <mtx/events.hpp> |
| 11 |
|
| 12 |
namespace mtx::events::collections { |
| 13 |
struct TimelineEvents; |
| 14 |
struct StateEvents; |
| 15 |
} |
| 16 |
|
| 17 |
struct DescInfo; |
| 18 |
|
| 19 |
namespace cache { |
| 20 |
|
| 21 |
QString |
| 22 |
displayName(const QString &room_id, const QString &user_id); |
| 23 |
} |
| 24 |
|
| 25 |
class QComboBox; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
struct RelatedInfo |
| 30 |
{ |
| 31 |
using MsgType = mtx::events::MessageType; |
| 32 |
MsgType type; |
| 33 |
QString room; |
| 34 |
QString quoted_body, quoted_formatted_body; |
| 35 |
std::string related_event; |
| 36 |
QString quoted_user; |
| 37 |
}; |
| 38 |
|
| 39 |
namespace utils { |
| 40 |
|
| 41 |
std::string |
| 42 |
stripReplyFromBody(const std::string &body); |
| 43 |
|
| 44 |
|
| 45 |
std::string |
| 46 |
stripReplyFromFormattedBody(const std::string &formatted_body); |
| 47 |
|
| 48 |
RelatedInfo |
| 49 |
stripReplyFallbacks(const mtx::events::collections::TimelineEvents &event, |
| 50 |
std::string id, |
| 51 |
QString room_id_); |
| 52 |
|
| 53 |
bool |
| 54 |
codepointIsEmoji(uint code); |
| 55 |
|
| 56 |
QString |
| 57 |
replaceEmoji(const QString &body); |
| 58 |
|
| 59 |
QString |
| 60 |
localUser(); |
| 61 |
|
| 62 |
float |
| 63 |
scaleFactor(); |
| 64 |
|
| 65 |
void |
| 66 |
setScaleFactor(float factor); |
| 67 |
|
| 68 |
|
| 69 |
QString |
| 70 |
descriptiveTime(const QDateTime &then); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
DescInfo |
| 75 |
getMessageDescription(const mtx::events::collections::TimelineEvents &event, |
| 76 |
const QString &localUser, |
| 77 |
const QString &displayName); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
QString |
| 82 |
firstChar(const QString &input); |
| 83 |
|
| 84 |
|
| 85 |
QString |
| 86 |
humanReadableFileSize(uint64_t bytes); |
| 87 |
|
| 88 |
|
| 89 |
QPixmap |
| 90 |
scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source); |
| 91 |
|
| 92 |
|
| 93 |
template<typename ContainerT, typename PredicateT> |
| 94 |
void |
| 95 |
erase_if(ContainerT &items, const PredicateT &predicate) |
| 96 |
{ |
| 97 |
for (auto it = items.begin(); it != items.end();) { |
| 98 |
if (predicate(*it)) |
| 99 |
it = items.erase(it); |
| 100 |
else |
| 101 |
++it; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
int |
| 107 |
levenshtein_distance(const std::string &s1, const std::string &s2); |
| 108 |
|
| 109 |
QPixmap |
| 110 |
scaleImageToPixmap(const QImage &img, int size); |
| 111 |
|
| 112 |
|
| 113 |
QString |
| 114 |
mxcToHttp(const QUrl &url, const QString &server, int port); |
| 115 |
|
| 116 |
|
| 117 |
QString |
| 118 |
humanReadableFingerprint(const std::string &ed25519); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
template<typename RoomMessageT> |
| 123 |
QString |
| 124 |
getMessageBody(const RoomMessageT &event) |
| 125 |
{ |
| 126 |
if (event.content.format.empty()) |
| 127 |
return QString::fromStdString(event.content.body).toHtmlEscaped(); |
| 128 |
|
| 129 |
if (event.content.format != mtx::common::FORMAT_MSG_TYPE) |
| 130 |
return QString::fromStdString(event.content.body).toHtmlEscaped(); |
| 131 |
|
| 132 |
return QString::fromStdString(event.content.formatted_body); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
QString |
| 137 |
linkifyMessage(const QString &body); |
| 138 |
|
| 139 |
|
| 140 |
QString |
| 141 |
markdownToHtml(const QString &text, bool rainbowify = false, bool noExtensions = false); |
| 142 |
|
| 143 |
QString |
| 144 |
escapeMentionMarkdown(QString input); |
| 145 |
|
| 146 |
|
| 147 |
QString |
| 148 |
escapeBlacklistedHtml(const QString &data); |
| 149 |
|
| 150 |
|
| 151 |
QString |
| 152 |
linkColor(); |
| 153 |
|
| 154 |
|
| 155 |
uint32_t |
| 156 |
hashQString(const QString &input); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
QColor |
| 161 |
generateContrastingHexColor(const QString &input, const QColor &background); |
| 162 |
|
| 163 |
|
| 164 |
qreal |
| 165 |
computeContrast(const qreal &one, const qreal &two); |
| 166 |
|
| 167 |
|
| 168 |
qreal |
| 169 |
luminance(const QColor &col); |
| 170 |
|
| 171 |
|
| 172 |
void |
| 173 |
centerWidget(QWidget *widget, QWindow *parent); |
| 174 |
|
| 175 |
void |
| 176 |
restoreCombobox(QComboBox *combo, const QString &value); |
| 177 |
|
| 178 |
|
| 179 |
QImage |
| 180 |
readImageFromFile(const QString &filename); |
| 181 |
|
| 182 |
|
| 183 |
QImage |
| 184 |
readImage(const QByteArray &data); |
| 185 |
|
| 186 |
bool |
| 187 |
isReply(const mtx::events::collections::TimelineEvents &e); |
| 188 |
|
| 189 |
void |
| 190 |
removeDirectFromRoom(QString roomid); |
| 191 |
|
| 192 |
void |
| 193 |
markRoomAsDirect(QString roomid, std::vector<RoomMember> members); |
| 194 |
|
| 195 |
std::vector<std::string> |
| 196 |
roomVias(const std::string &roomid); |
| 197 |
|
| 198 |
void |
| 199 |
updateSpaceVias(); |
| 200 |
|
| 201 |
void |
| 202 |
removeExpiredEvents(); |
| 203 |
|
| 204 |
QString |
| 205 |
glitchText(const QString &text); |
| 206 |
|
| 207 |
QString |
| 208 |
graduallyGlitchText(const QString &text); |
| 209 |
|
| 210 |
struct MatrixUriParseResult |
| 211 |
{ |
| 212 |
QString sigil1, mxid1, sigil2, mxid2, action; |
| 213 |
std::vector<std::string> vias; |
| 214 |
}; |
| 215 |
|
| 216 |
std::optional<MatrixUriParseResult> |
| 217 |
parseMatrixUri(QString uri); |
| 218 |
|
| 219 |
void |
| 220 |
markFileAsFromWeb(const QString &file); |
| 221 |
} |