aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--src/plugins/Youtube.cpp66
2 files changed, 39 insertions, 31 deletions
diff --git a/TODO b/TODO
index ea1b02b..bce0bf4 100644
--- a/TODO
+++ b/TODO
@@ -141,4 +141,6 @@ Remove display names from reactions if there are many reactions, and instead gro
Make reaction and deleted message provisional.
Allow removing reactions.
When fetching previous messages in matrix, fetching until there are 0 messages or until there is at least 1 visible item. This is needed because right now we could fetch 10 messages, all which are delete/edit/react and it will look like there are no more messages to fetch to the user.
-QuickMedia crashes if you enter a room that you have left before. This could happen if cache is loaded that has a room that is then getting removed when sync is finished. \ No newline at end of file
+QuickMedia crashes if you enter a room that you have left before. This could happen if cache is loaded that has a room that is then getting removed when sync is finished.
+Removing a reaction should be shown as "removed reaction: <reaction text>" in the room description instead of "Message deleted".
+Limit size of Entry and scroll content instead. \ No newline at end of file
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index e04c51f..ddaae21 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -6,30 +6,36 @@
namespace QuickMedia {
// This is a common setup of text in the youtube json
- static const char* yt_json_get_text(const Json::Value &json, const char *root_name) {
+ static std::optional<std::string> yt_json_get_text(const Json::Value &json, const char *root_name) {
if(!json.isObject())
- return nullptr;
+ return std::nullopt;
const Json::Value &text_json = json[root_name];
if(!text_json.isObject())
- return nullptr;
+ return std::nullopt;
const Json::Value &simple_text_json = text_json["simpleText"];
if(simple_text_json.isString()) {
return simple_text_json.asCString();
} else {
const Json::Value &runs_json = text_json["runs"];
- if(runs_json.isArray() && !runs_json.empty()) {
- const Json::Value &first_runs_json = runs_json[0];
- if(first_runs_json.isObject()) {
- const Json::Value &text_json = first_runs_json["text"];
- if(text_json.isString())
- return text_json.asCString();
- }
+ if(!runs_json.isArray() || runs_json.empty())
+ return std::nullopt;
+
+ std::string result;
+ for(const Json::Value &first_runs_json : runs_json) {
+ if(!first_runs_json.isObject())
+ continue;
+
+ const Json::Value &text_json = first_runs_json["text"];
+ if(text_json.isString())
+ result += text_json.asString();
}
+ if(!result.empty())
+ return result;
}
- return nullptr;
+ return std::nullopt;
}
static std::shared_ptr<BodyItem> parse_common_video_item(const Json::Value &video_item_json, std::unordered_set<std::string> &added_videos) {
@@ -41,14 +47,14 @@ namespace QuickMedia {
if(added_videos.find(video_id_str) != added_videos.end())
return nullptr;
- const char *title = yt_json_get_text(video_item_json, "title");
+ std::optional<std::string> title = yt_json_get_text(video_item_json, "title");
if(!title)
return nullptr;
- const char *date = yt_json_get_text(video_item_json, "publishedTimeText");
- const char *view_count_text = yt_json_get_text(video_item_json, "viewCountText");
- const char *owner_text = yt_json_get_text(video_item_json, "shortBylineText");
- const char *length = yt_json_get_text(video_item_json, "lengthText");
+ std::optional<std::string> date = yt_json_get_text(video_item_json, "publishedTimeText");
+ std::optional<std::string> view_count_text = yt_json_get_text(video_item_json, "viewCountText");
+ std::optional<std::string> owner_text = yt_json_get_text(video_item_json, "shortBylineText");
+ std::optional<std::string> length = yt_json_get_text(video_item_json, "lengthText");
if(!length) {
const Json::Value &thumbnail_overlays_json = video_item_json["thumbnailOverlays"];
if(thumbnail_overlays_json.isArray() && !thumbnail_overlays_json.empty()) {
@@ -58,24 +64,24 @@ namespace QuickMedia {
}
}
- auto body_item = BodyItem::create(title);
+ auto body_item = BodyItem::create(title.value());
std::string desc;
if(view_count_text)
- desc += view_count_text;
+ desc += view_count_text.value();
if(date) {
if(!desc.empty())
desc += " • ";
- desc += date;
+ desc += date.value();
}
if(length) {
if(!desc.empty())
desc += '\n';
- desc += length;
+ desc += length.value();
}
if(owner_text) {
if(!desc.empty())
desc += '\n';
- desc += owner_text;
+ desc += owner_text.value();
}
body_item->set_description(std::move(desc));
body_item->url = "https://www.youtube.com/watch?v=" + video_id_str;
@@ -145,26 +151,26 @@ namespace QuickMedia {
if(!channel_id_json.isString())
return nullptr;
- const char *title = yt_json_get_text(channel_renderer_json, "title");
+ std::optional<std::string> title = yt_json_get_text(channel_renderer_json, "title");
if(!title)
return nullptr;
- const char *description = yt_json_get_text(channel_renderer_json, "descriptionSnippet");
- const char *video_count = yt_json_get_text(channel_renderer_json, "videoCountText");
- const char *subscribers = yt_json_get_text(channel_renderer_json, "subscriberCountText");
+ std::optional<std::string> description = yt_json_get_text(channel_renderer_json, "descriptionSnippet");
+ std::optional<std::string> video_count = yt_json_get_text(channel_renderer_json, "videoCountText");
+ std::optional<std::string> subscribers = yt_json_get_text(channel_renderer_json, "subscriberCountText");
const Json::Value &thumbnail_json = channel_renderer_json["thumbnail"];
std::optional<Thumbnail> thumbnail = yt_json_get_largest_thumbnail(thumbnail_json);
- auto body_item = BodyItem::create(title);
+ auto body_item = BodyItem::create(title.value());
std::string desc;
if(subscribers)
- desc += subscribers;
+ desc += subscribers.value();
if(video_count) {
if(!desc.empty())
desc += " • ";
- desc += video_count;
- if(strcmp(video_count, "1") == 0)
+ desc += video_count.value();
+ if(strcmp(video_count.value().c_str(), "1") == 0)
desc += " video";
else
desc += " videos";
@@ -172,7 +178,7 @@ namespace QuickMedia {
if(description) {
if(!desc.empty())
desc += '\n';
- desc += description;
+ desc += description.value();
}
body_item->set_description(std::move(desc));
body_item->url = "https://www.youtube.com/channel/" + channel_id_json.asString();