aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 070b8fe..e374dfb 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -18,12 +18,12 @@
#include "../include/ImageUtils.hpp"
#include "../include/base64_url.hpp"
#include "../include/Entry.hpp"
+#include "../include/NetUtils.hpp"
#include <assert.h>
#include <cmath>
#include <string.h>
#include <signal.h>
-#include <regex>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Window/Clipboard.hpp>
@@ -3225,8 +3225,6 @@ namespace QuickMedia {
const float chat_input_padding_x = 15.0f;
const float chat_input_padding_y = 15.0f;
- std::regex url_extract_regex("(http(s?):\\/\\/)?([a-zA-Z0-9\\-_]+\\.)+[a-zA-Z]+[^\\s.,]+");
-
Body url_selection_body(this, font.get(), bold_font.get(), cjk_font.get());
sf::Clock read_marker_timer;
@@ -3476,36 +3474,40 @@ namespace QuickMedia {
if(tabs[selected_tab].type == ChatTabType::MESSAGES && event.key.code == sf::Keyboard::Enter) {
BodyItem *selected = tabs[selected_tab].body->get_selected();
if(selected) {
- if(!selected->url.empty()) {
- const char *content_type = link_get_content_type(selected->url);
+ std::string selected_url = selected->url;
+ if(selected_url.empty() && selected->embedded_item)
+ selected_url = selected->embedded_item->url;
+ if(!selected_url.empty()) {
+ const char *content_type = link_get_content_type(selected_url);
if(content_type && (strcmp(content_type, "audio") == 0 || strcmp(content_type, "video") == 0 || strcmp(content_type, "image") == 0)) {
page_stack.push(PageType::CHAT);
watched_videos.clear();
current_page = PageType::VIDEO_CONTENT;
+ bool is_audio = strcmp(content_type, "audio") == 0;
+ bool prev_no_video = no_video;
+ no_video = is_audio;
// TODO: Add title
- video_content_page(video_page.get(), selected->url, "No title");
+ video_content_page(video_page.get(), selected_url, "No title");
+ no_video = prev_no_video;
redraw = true;
continue;
}
- launch_url(selected->url.c_str());
+ launch_url(selected_url);
continue;
}
// TODO: If content type is a file, show file-manager prompt where it should be saved and asynchronously save it instead
- // TODO: Change this when messages are not stored in the description
const std::string &message_str = selected->get_description();
- auto urls_begin = std::sregex_iterator(message_str.begin(), message_str.end(), url_extract_regex);
- auto urls_end = std::sregex_iterator();
- size_t num_urls = std::distance(urls_begin, urls_end);
- if(num_urls == 1) {
- launch_url(urls_begin->str());
- } else if(num_urls > 1) {
+ std::vector<std::string> urls = extract_urls(message_str);
+ if(urls.size() == 1) {
+ launch_url(urls[0]);
+ } else if(urls.size() > 1) {
chat_state = ChatState::URL_SELECTION;
url_selection_body.clear_items();
- for(auto it = urls_begin; it != urls_end; ++it) {
- auto body_item = BodyItem::create(it->str());
+ for(const std::string &url : urls) {
+ auto body_item = BodyItem::create(url);
url_selection_body.items.push_back(std::move(body_item));
}
}