reorg
This commit is contained in:
73
src/models/conversation.vala
Normal file
73
src/models/conversation.vala
Normal file
@@ -0,0 +1,73 @@
|
||||
using GLib;
|
||||
|
||||
public class Conversation : Object {
|
||||
public string id { get; set; default = ""; }
|
||||
public string last_message_preview { get; set; default = ""; }
|
||||
public int64 date { get; set; default = 0; }
|
||||
public string[] participants { get; set; default = new string[0]; }
|
||||
public int unread_count { get; set; default = 0; }
|
||||
|
||||
public bool is_unread { get { return unread_count > 0; } }
|
||||
|
||||
public string display_name {
|
||||
owned get {
|
||||
if (_display_name != null && _display_name.length > 0) {
|
||||
return _display_name;
|
||||
}
|
||||
|
||||
if (participants.length == 1) {
|
||||
return participants[0];
|
||||
}
|
||||
|
||||
if (participants.length > 1) {
|
||||
return string.join(", ", participants);
|
||||
}
|
||||
|
||||
return "Untitled";
|
||||
}
|
||||
}
|
||||
|
||||
private string? _display_name = null;
|
||||
|
||||
public Conversation.from_variant (Variant dict) {
|
||||
id = "";
|
||||
last_message_preview = "";
|
||||
participants = new string[0];
|
||||
|
||||
if (dict.get_type_string() != "a{sv}") {
|
||||
warning("Expected dictionary variant, got %s", dict.get_type_string());
|
||||
return;
|
||||
}
|
||||
|
||||
// Safe extraction with type checking
|
||||
Variant? id_variant = dict.lookup_value("id", VariantType.STRING);
|
||||
if (id_variant != null) {
|
||||
id = id_variant.get_string();
|
||||
}
|
||||
|
||||
Variant? display_name_variant = dict.lookup_value("display_name", VariantType.STRING);
|
||||
if (display_name_variant != null) {
|
||||
_display_name = display_name_variant.get_string();
|
||||
}
|
||||
|
||||
Variant? last_message_variant = dict.lookup_value("last_message_preview", VariantType.STRING);
|
||||
if (last_message_variant != null) {
|
||||
last_message_preview = last_message_variant.get_string();
|
||||
}
|
||||
|
||||
Variant? date_variant = dict.lookup_value("date", VariantType.INT64);
|
||||
if (date_variant != null) {
|
||||
date = date_variant.get_int64();
|
||||
}
|
||||
|
||||
Variant? participants_variant = dict.lookup_value("participants", new VariantType("as"));
|
||||
if (participants_variant != null) {
|
||||
participants = participants_variant.dup_strv();
|
||||
}
|
||||
|
||||
Variant? unread_count_variant = dict.lookup_value("unread_count", VariantType.INT32);
|
||||
if (unread_count_variant != null) {
|
||||
unread_count = unread_count_variant.get_int32();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user