aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_summary/conversation_item.vala
blob: a99025ab60322bf70ec1da01f34eef5ca5448949 (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
using Dino.Entities;

namespace Dino.Ui.ConversationSummary {

public enum MessageKind {
    TEXT,
    ME_COMMAND
}

public MessageKind get_message_kind(Message message) {
    if (message.body.has_prefix("/me ")) {
        return MessageKind.ME_COMMAND;
    } else {
        return MessageKind.TEXT;
    }
}

public interface ConversationItem : Gtk.Widget {
    public abstract bool merge(Entities.Message message);

    public static ConversationItem create_for_message(StreamInteractor stream_interactor, Conversation conversation, Message message) {
        switch (get_message_kind(message)) {
            case MessageKind.TEXT:
                return new MergedMessageItem(stream_interactor, conversation, message);
            case MessageKind.ME_COMMAND:
                return new SlashMeItem(stream_interactor, conversation, message);
        }
        assert_not_reached();
    }
}

}