diff options
Diffstat (limited to 'libdino/src/entity')
-rw-r--r-- | libdino/src/entity/message.vala | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index 4e6c7f45..e5aad25f 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -70,6 +70,7 @@ public class Message : Object { public int quoted_item_id { get; private set; default=0; } private Gee.List<Xep.FallbackIndication.Fallback> fallbacks = null; + private Gee.List<Xep.MessageMarkup.Span> markups = null; private Database? db; @@ -160,16 +161,53 @@ public class Message : Object { public Gee.List<Xep.FallbackIndication.Fallback> get_fallbacks() { if (fallbacks != null) return fallbacks; + fetch_body_meta(); + return fallbacks; + } + + public Gee.List<Xep.MessageMarkup.Span> get_markups() { + if (markups != null) return markups; + fetch_body_meta(); + + return markups; + } + + public void persist_markups(Gee.List<Xep.MessageMarkup.Span> markups, int message_id) { + this.markups = markups; + + foreach (var span in markups) { + foreach (var ty in span.types) { + db.body_meta.insert() + .value(db.body_meta.info_type, Xep.MessageMarkup.NS_URI) + .value(db.body_meta.message_id, message_id) + .value(db.body_meta.info, Xep.MessageMarkup.span_type_to_str(ty)) + .value(db.body_meta.from_char, span.start_char) + .value(db.body_meta.to_char, span.end_char) + .perform(); + } + } + } + + private void fetch_body_meta() { var fallbacks_by_ns = new HashMap<string, ArrayList<Xep.FallbackIndication.FallbackLocation>>(); - foreach (Qlite.Row row in db.body_meta.select().with(db.body_meta.message_id, "=", id)) { - if (row[db.body_meta.info_type] != Xep.FallbackIndication.NS_URI) continue; + var markups = new ArrayList<Xep.MessageMarkup.Span>(); - string ns_uri = row[db.body_meta.info]; - if (!fallbacks_by_ns.has_key(ns_uri)) { - fallbacks_by_ns[ns_uri] = new ArrayList<Xep.FallbackIndication.FallbackLocation>(); + foreach (Qlite.Row row in db.body_meta.select().with(db.body_meta.message_id, "=", id)) { + switch (row[db.body_meta.info_type]) { + case Xep.FallbackIndication.NS_URI: + string ns_uri = row[db.body_meta.info]; + if (!fallbacks_by_ns.has_key(ns_uri)) { + fallbacks_by_ns[ns_uri] = new ArrayList<Xep.FallbackIndication.FallbackLocation>(); + } + fallbacks_by_ns[ns_uri].add(new Xep.FallbackIndication.FallbackLocation(row[db.body_meta.from_char], row[db.body_meta.to_char])); + break; + case Xep.MessageMarkup.NS_URI: + var types = new ArrayList<Xep.MessageMarkup.SpanType>(); + types.add(Xep.MessageMarkup.str_to_span_type(row[db.body_meta.info])); + markups.add(new Xep.MessageMarkup.Span() { types=types, start_char=row[db.body_meta.from_char], end_char=row[db.body_meta.to_char] }); + break; } - fallbacks_by_ns[ns_uri].add(new Xep.FallbackIndication.FallbackLocation(row[db.body_meta.from_char], row[db.body_meta.to_char])); } var fallbacks = new ArrayList<Xep.FallbackIndication.Fallback>(); @@ -177,7 +215,7 @@ public class Message : Object { fallbacks.add(new Xep.FallbackIndication.Fallback(ns_uri, fallbacks_by_ns[ns_uri].to_array())); } this.fallbacks = fallbacks; - return fallbacks; + this.markups = markups; } public void set_fallbacks(Gee.List<Xep.FallbackIndication.Fallback> fallbacks) { |