aboutsummaryrefslogtreecommitdiff
path: root/client/src/entity/conversation.vala
blob: 2da6dce3155c1f308e89528c2cdbc5fd214dc6b8 (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
45
46
47
48
49
50
51
52
namespace Dino.Entities {
public class Conversation : Object {

    public signal void object_updated(Conversation conversation);

    public enum Encryption {
        UNENCRYPTED,
        PGP
    }

    public enum Type {
        CHAT,
        GROUPCHAT
    }

    public int id { get; set; }
    public Account account { get; private set; }
    public Jid counterpart { get; private set; }
    public bool active { get; set; }
    public DateTime last_active { get; set; }
    public Encryption encryption { get; set; }
    public Type? type_ { get; set; }
    public Message read_up_to { get; set; }

    public Conversation(Jid jid, Account account) {
        this.counterpart = jid;
        this.account = account;
        this.active = false;
        this.last_active = new DateTime.from_unix_utc(0);
        this.encryption = Encryption.UNENCRYPTED;
    }

    public Conversation.with_id(Jid jid, Account account, int id) {
        this.counterpart = jid;
        this.account = account;
        this.id = id;
    }

    public bool equals(Conversation? conversation) {
        if (conversation == null) return false;
        return equals_func(this, conversation);
    }

    public static bool equals_func(Conversation conversation1, Conversation conversation2) {
        return conversation1.counterpart.equals(conversation2.counterpart) && conversation1.account.equals(conversation2.account);
    }

    public static uint hash_func(Conversation conversation) {
        return conversation.counterpart.to_string().hash() ^ conversation.account.bare_jid.to_string().hash();
    }
}
}