aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_summary/slashme_item.vala
blob: 2056d2d1cce0f5278bd965b449832bede53c5a61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Gdk;
using Gtk;

using Dino.Entities;

namespace Dino.Ui.ConversationSummary {

public class SlashMeItem : MessageItem {

    private Box box = new Box(Orientation.VERTICAL, 0) { visible=true, vexpand=true };
    private MessageTextView textview = new MessageTextView() { visible=true };
    private string text;
    private TextTag nick_tag;

    public SlashMeItem(StreamInteractor stream_interactor, Conversation conversation, Message message) {
        base(stream_interactor, conversation, message);
        box.set_center_widget(textview);
        set_title_widget(box);
        text = message.body.substring(3);

        string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
        string color = Util.get_name_hex_color(stream_interactor, conversation.account, conversation.counterpart, false);
        nick_tag = textview.buffer.create_tag("nick", foreground: "#" + color);
        TextIter iter;
        textview.buffer.get_start_iter(out iter);
        textview.buffer.insert_with_tags(ref iter, display_name, display_name.length, nick_tag);
        textview.add_text(text);
        add_message(message);

        textview.style_updated.connect(update_display_style);
        update_display_style();
    }

    public override bool merge(Message message) {
        return false;
    }

    private void update_display_style() {
        string color = Util.get_name_hex_color(stream_interactor, conversation.account, messages[0].real_jid ?? messages[0].from, Util.is_dark_theme(textview));
        nick_tag.foreground = "#" + color;
    }
}

}