aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp72
-rw-r--r--src/QuickMedia.cpp7
-rw-r--r--src/plugins/Matrix.cpp1
3 files changed, 63 insertions, 17 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 08ef690..2134a44 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -20,11 +20,13 @@ namespace QuickMedia {
dirty(false),
dirty_description(false),
dirty_author(false),
+ dirty_timestamp(false),
thumbnail_is_local(false),
title_color(sf::Color::White),
author_color(sf::Color::White),
userdata(nullptr),
- last_drawn_time(0)
+ last_drawn_time(0),
+ timestamp(0)
{
if(!_title.empty())
set_title(std::move(_title));
@@ -41,6 +43,7 @@ namespace QuickMedia {
dirty = other.dirty;
dirty_description = other.dirty_description;
dirty_author = other.dirty_author;
+ dirty_timestamp = other.dirty_timestamp;
thumbnail_is_local = other.thumbnail_is_local;
if(other.title_text)
title_text = std::make_unique<Text>(*other.title_text);
@@ -54,12 +57,17 @@ namespace QuickMedia {
author_text = std::make_unique<Text>(*other.author_text);
else
author_text = nullptr;
+ if(other.timestamp_text)
+ timestamp_text = std::make_unique<sf::Text>(*other.timestamp_text);
+ else
+ timestamp_text = nullptr;
replies = other.replies;
post_number = other.post_number;
title_color = other.title_color;
author_color = other.author_color;
userdata = other.userdata;
last_drawn_time = other.last_drawn_time;
+ timestamp = other.timestamp;
}
Body::Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font) :
@@ -460,6 +468,34 @@ namespace QuickMedia {
body_item->author_text->setFillColor(body_item->author_color);
body_item->author_text->updateGeometry();
}
+
+ if(body_item->dirty_timestamp) {
+ body_item->dirty_timestamp = false;
+
+ //time_t time_now = time(NULL);
+ //struct tm *now_tm = localtime(&time_now);
+
+ time_t message_timestamp = body_item->get_timestamp() / 1000;
+ struct tm *message_tm = localtime(&message_timestamp);
+
+ //bool is_same_year = message_tm->tm_year == now_tm->tm_year;
+
+ char time_str[128] = {0};
+ /*
+ if(is_same_year)
+ strftime(time_str, sizeof(time_str) - 1, "%a %b %d %H:%M:%S", message_tm);
+ else
+ strftime(time_str, sizeof(time_str) - 1, "%a %b %d %H:%M:%S %Y", message_tm);
+ */
+ strftime(time_str, sizeof(time_str) - 1, "%H:%M:%S", message_tm);
+
+ if(body_item->timestamp_text)
+ body_item->timestamp_text->setString(time_str);
+ else
+ body_item->timestamp_text = std::make_unique<sf::Text>(time_str, *font, 14);
+
+ body_item->timestamp_text->setFillColor(sf::Color(185, 190, 198));
+ }
}
void Body::clear_body_item_cache(BodyItem *body_item) {
@@ -475,6 +511,10 @@ namespace QuickMedia {
body_item->author_text.reset();
body_item->dirty_author = true;
}
+ if(body_item->timestamp_text) {
+ body_item->timestamp_text.reset();
+ body_item->dirty_timestamp = true;
+ }
}
void Body::draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size) {
@@ -552,7 +592,7 @@ namespace QuickMedia {
}
}
- if(!item->get_author().empty()) {
+ if(item->author_text) {
item->author_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 6.0f));
item->author_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
item->author_text->draw(window);
@@ -575,14 +615,14 @@ namespace QuickMedia {
//title_text.setString(item->title);
//title_text.setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y));
//window.draw(title_text);
- if(!item->get_title().empty()) {
+ if(item->title_text) {
item->title_text->setFillColor(item->title_color);
item->title_text->setPosition(std::floor(item_pos.x + text_offset_x), std::floor(item_pos.y + padding_y - 8.0f));
item->title_text->setMaxWidth(size.x - text_offset_x - image_padding_x * 2.0f);
item->title_text->draw(window);
}
- if(!item->get_description().empty()) {
+ if(item->description_text) {
float height_offset = 0.0f;
if(!item->get_title().empty()) {
height_offset = item->title_text->getHeight();
@@ -592,6 +632,11 @@ namespace QuickMedia {
item->description_text->draw(window);
}
+ if(item->timestamp_text) {
+ item->timestamp_text->setPosition(std::floor(item_pos.x + size.x - item->timestamp_text->getLocalBounds().width - padding_x), std::floor(item_pos.y + padding_y - 18.0f));
+ window.draw(*item->timestamp_text);
+ }
+
if(!content_progress.isObject())
return;
@@ -622,19 +667,14 @@ namespace QuickMedia {
item_height += item->description_text->getHeight() - 2.0f;
}
if(draw_thumbnails && !item->thumbnail_url.empty()) {
- std::shared_ptr<ThumbnailData> item_thumbnail;
- auto item_thumbnail_it = item_thumbnail_textures.find(item->thumbnail_url);
- if(item_thumbnail_it == item_thumbnail_textures.end()) {
- item_thumbnail = std::make_shared<ThumbnailData>();
- item_thumbnail_textures.insert(std::make_pair(item->thumbnail_url, item_thumbnail));
- } else {
- item_thumbnail = item_thumbnail_it->second;
- }
-
float image_height = image_fallback.getSize().y;
- if(item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE && item_thumbnail->texture.getNativeHandle() != 0) {
- auto image_size = item_thumbnail->texture.getSize();
- image_height = std::min(image_max_height, (float)image_size.y);
+ auto item_thumbnail_it = item_thumbnail_textures.find(item->thumbnail_url);
+ if(item_thumbnail_it != item_thumbnail_textures.end()) {
+ std::shared_ptr<ThumbnailData> &item_thumbnail = item_thumbnail_it->second;
+ if(item_thumbnail->loading_state == LoadingState::APPLIED_TO_TEXTURE && item_thumbnail->texture.getNativeHandle() != 0) {
+ auto image_size = item_thumbnail->texture.getSize();
+ image_height = std::min(image_max_height, (float)image_size.y);
+ }
}
item_height = std::max(item_height, image_height);
}
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 6c3bc34..f18c0ce 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3383,7 +3383,7 @@ namespace QuickMedia {
message->mentions_me = false;
// TODO: What if the message or username begins with "-"? also make the notification image be the avatar of the user
std::string desc = "QuickMedia Matrix\n\n" + message->body;
- show_notification(matrix->message_get_author_displayname(message.get()), desc.c_str());
+ show_notification(matrix->message_get_author_displayname(message.get()) + " (" + room->name + ")", desc);
}
}
@@ -3866,6 +3866,11 @@ namespace QuickMedia {
chat_input.set_text("");
chat_state = ChatState::NAVIGATING;
currently_operating_on_item = nullptr;
+ if(typing) {
+ fprintf(stderr, "Stopped typing\n");
+ typing = false;
+ typing_futures.push_back(std::async(typing_async_func, false, current_room_id));
+ }
}
//chat_input.on_event(event);
chat_input.process_event(event);
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index d4fdd03..8f3f679 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -201,6 +201,7 @@ namespace QuickMedia {
auto body_item = BodyItem::create("");
body_item->set_author(messages[i]->user->display_name);
body_item->set_description(messages[i]->body);
+ body_item->set_timestamp(messages[i]->timestamp);
if(!messages[i]->thumbnail_url.empty())
body_item->thumbnail_url = messages[i]->thumbnail_url;
else if(!messages[i]->url.empty() && messages[i]->type == MessageType::IMAGE)