aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-10 17:46:38 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-10 17:46:38 +0200
commit54e09fcd55fcfc460ae1c254dba49c1a8d49b6ea (patch)
tree2b5e85332087c52dc7947f0c23625d38a2caffbb
parent8af5901fb893c3fc25b31bf484a90b47d1c24c2c (diff)
Matrix: show unread message for room event if latest event is not a message, better youtube search
-rw-r--r--src/plugins/Matrix.cpp36
-rw-r--r--src/plugins/Youtube.cpp2
2 files changed, 21 insertions, 17 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index d59e6d5..ad30d2d 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -31,13 +31,14 @@ namespace QuickMedia {
static const char* OTHERS_ROOM_TAG = "tld.name.others";
// Filter without account data. TODO: We include pinned events but limit events to 1. That means if the last event is a pin,
// then we cant see room message preview. TODO: Fix this somehow.
+ // TODO: What about state events in initial sync in timeline? such as user display name change.
static const char* INITIAL_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"types\":[\"m.room.message\",\"m.room.pinned_events\"],\"limit\":1,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\",\"qm.last_read_message_timestamp\"],\"lazy_load_members\":true}}}";
static const char* ADDITIONAL_MESSAGES_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":20,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true}}}";
static const char* CONTINUE_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"types\":[\"m.fully_read\",\"m.tag\",\"qm.last_read_message_timestamp\"],\"lazy_load_members\":true}}}";
static std::string capitalize(const std::string &str) {
if(str.size() >= 1)
- return QuickMedia::to_upper(str[0]) + str.substr(1);
+ return to_upper(str[0]) + str.substr(1);
else
return "";
}
@@ -582,16 +583,14 @@ namespace QuickMedia {
read_marker_message_timestamp = qm_read_marker;
std::shared_ptr<Message> last_new_message = get_last_message_by_timestamp(new_messages);
- if(!last_new_message)
- return;
auto last_message_it = last_message_by_room.find(room);
if(last_message_it != last_message_by_room.end()) {
- if(last_new_message->timestamp > last_message_it->second->timestamp)
+ if(last_new_message && last_new_message->timestamp > last_message_it->second->timestamp)
last_message_it->second = last_new_message;
else
last_new_message = last_message_it->second;
- } else {
+ } else if(last_new_message) {
last_message_by_room[room] = last_new_message;
}
@@ -599,32 +598,37 @@ namespace QuickMedia {
// TODO: Test if this also works with construct and other homeservers
Message *last_unread_message = nullptr;
- if(read_marker_message_timestamp != 0 && last_new_message->timestamp > read_marker_message_timestamp)
- last_unread_message = last_new_message.get();
- else if(read_marker_message_timestamp == 0 && !my_user_read_marker.empty() && last_new_message->event_id.find(':') != std::string::npos && last_new_message->event_id > my_user_read_marker)
- last_unread_message = last_new_message.get();
+ if(last_new_message) {
+ if(read_marker_message_timestamp != 0 && last_new_message->timestamp > read_marker_message_timestamp)
+ last_unread_message = last_new_message.get();
+ else if(read_marker_message_timestamp == 0 && !my_user_read_marker.empty() && last_new_message->event_id.find(':') != std::string::npos && last_new_message->event_id > my_user_read_marker)
+ last_unread_message = last_new_message.get();
- if(!last_unread_message && read_marker_message_timestamp == 0)
- last_unread_message = last_new_message.get();
+ if(!last_unread_message && read_marker_message_timestamp == 0)
+ last_unread_message = last_new_message.get();
+ }
//assert(room_body_item);
if(!room->body_item)
return;
- if(last_unread_message && !sync_is_cache) {
+ if(!sync_is_cache && (last_unread_message || room->unread_notification_count > 0)) {
bool is_window_focused = program->is_window_focused();
RoomData *current_room = program->get_current_chat_room();
Body *chat_body = chat_page ? chat_page->chat_body : nullptr;
bool set_room_as_unread = !is_window_focused || room != current_room || (!chat_body || chat_body->is_bottom_cut_off()) || (chat_page && !chat_page->messages_tab_visible);
std::string room_desc;
- if(set_room_as_unread)
+ if(last_unread_message && set_room_as_unread) {
room_desc += "Unread: ";
- room_desc += extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_unread_message), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(last_unread_message);
+ room_desc += extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_unread_message), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(last_unread_message);
+ }
int unread_notification_count = room->unread_notification_count;
if(unread_notification_count > 0 && set_room_as_unread) {
- room_desc += "\n** " + std::to_string(unread_notification_count) + " unread mention(s) **"; // TODO: Better notification?
+ if(!room_desc.empty())
+ room_desc += '\n';
+ room_desc += "** " + std::to_string(unread_notification_count) + " unread mention(s) **"; // TODO: Better notification?
room->body_item->set_description_color(get_current_theme().attention_alert_text_color);
} else {
room->body_item->set_description_color(get_current_theme().faded_text_color);
@@ -636,7 +640,7 @@ namespace QuickMedia {
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);
- } else {
+ } else if(last_new_message) {
room->body_item->set_description(extract_first_line_remove_newline_elipses(matrix->message_get_author_displayname(last_new_message.get()), AUTHOR_MAX_LENGTH) + ": " + message_to_room_description_text(last_new_message.get()));
room->body_item->set_description_color(get_current_theme().faded_text_color);
}
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index a386a70..ce1c153 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -769,7 +769,7 @@ namespace QuickMedia {
return SearchResult::OK;
// TODO: Find this search url from youtube.com/... searchbox.js, and the url to that script from youtube.com/ html
- std::string url = "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&hl=en&gl=us&sugexp=rdcfrc%2Ccfro%3D1%2Cfp.cfr%3D1&gs_rn=64&gs_ri=youtube&ds=yt&cp=4&gs_id=f&xhr=t&xssi=t&q=";
+ std::string url = "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&hl=en&gl=us&sugexp=rdcfrc%2Ccfro%3D1%2Cfp.cfr%3D1&gs_rn=64&gs_ri=youtube&ds=yt&cp=34&gs_id=f&xhr=t&xssi=t&q=";
url += url_param_encode(str);
if(!video_id.empty())
url += "&video_id=" + video_id;