Private
Public Access
1
0

Add sender annotations

This commit is contained in:
2025-05-03 23:19:15 -07:00
parent dd91746310
commit 786d982ce0
9 changed files with 109 additions and 24 deletions

View File

@@ -3,10 +3,11 @@ using Gee;
private class TranscriptDrawingArea : Widget
{
public bool show_sender = true;
private SortedSet<Message> _messages = new TreeSet<Message>();
private ArrayList<ChatItemLayout> _chat_items = new ArrayList<ChatItemLayout>();
private const float bubble_padding = 10.0f;
private const float bubble_margin = 18.0f;
public TranscriptDrawingArea() {
@@ -32,7 +33,7 @@ private class TranscriptDrawingArea : Widget
// compute total message layout height
float total_height = 0.0f;
_chat_items.foreach((chat_item) => {
total_height += chat_item.get_height() + bubble_padding;
total_height += chat_item.get_height() + chat_item.vertical_padding;
return true;
});
@@ -50,9 +51,12 @@ private class TranscriptDrawingArea : Widget
}
public override void snapshot(Snapshot snapshot) {
var container_width = get_width();
float y_offset = 0;
_chat_items.foreach((chat_item) => {
var container_width = get_width();
// Draw each item in reverse order, since the messages are in reverse order
for (int i = _chat_items.size - 1; i >= 0; i--) {
var chat_item = _chat_items[i];
var item_width = chat_item.get_width();
var item_height = chat_item.get_height();
@@ -73,38 +77,45 @@ private class TranscriptDrawingArea : Widget
chat_item.draw(snapshot);
snapshot.restore();
y_offset -= item_height + bubble_padding;
return true;
});
y_offset -= item_height + chat_item.vertical_padding;
}
}
private void recompute_message_layouts() {
var container_width = get_width();
float max_width = container_width * 0.90f;
_chat_items.clear();
var reversed_messages = _messages
.order_by((a, b) => b.date.compare(a.date)); // reverse order
DateTime? last_date = null;
reversed_messages.foreach((message) => {
// Remember everything in here is backwards.
if (last_date == null) {
last_date = message.date;
} else if (last_date.difference(message.date) > (TimeSpan.MINUTE * 25)) {
var date_item = new DateItemLayout(last_date.to_local().format("%b %d, %Y at %H:%M"), this, max_width);
_chat_items.add(date_item);
last_date = message.date;
string? last_sender = null;
ArrayList<ChatItemLayout> items = new ArrayList<ChatItemLayout>();
_messages.foreach((message) => {
// Date Annotation
DateTime date = message.date;
if (last_date != null && date.difference(last_date) > (TimeSpan.MINUTE * 25)) {
var date_item = new DateItemLayout(date.to_local().format("%b %d, %Y at %H:%M"), this, max_width);
items.add(date_item);
last_date = date;
}
// Sender Annotation
if (show_sender && !message.from_me && last_sender != message.sender) {
var sender_bubble = new SenderAnnotationLayout(message.sender, max_width, this);
items.add(sender_bubble);
}
// Text Bubble
var text_bubble = new TextBubbleLayout(message, this, max_width);
_chat_items.add(text_bubble);
text_bubble.vertical_padding = (last_sender == message.sender) ? 0.0f : 10.0f;
items.add(text_bubble);
last_sender = message.sender;
last_date = date;
return true;
});
_chat_items.clear();
_chat_items.add_all(items);
queue_draw();
queue_resize();