aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobufa <bobufa@users.noreply.github.com>2018-06-19 18:07:00 +0200
committerbobufa <bobufa@users.noreply.github.com>2018-08-13 22:04:47 +0200
commit3ea00446fb5893804243f5b1a1aa89817b7bc19a (patch)
tree3be25cfd7b807cd6db4846e6fe1b6e404a58a1f4
parentab0bc7f04d156db9e398c3f8c4f8bdfc11dd7458 (diff)
downloaddino-3ea00446fb5893804243f5b1a1aa89817b7bc19a.tar.gz
dino-3ea00446fb5893804243f5b1a1aa89817b7bc19a.zip
refactor conversation item management (accumulate them in libdino)
-rw-r--r--libdino/CMakeLists.txt1
-rw-r--r--libdino/src/application.vala1
-rw-r--r--libdino/src/entity/file_transfer.vala20
-rw-r--r--libdino/src/plugin/interfaces.vala26
-rw-r--r--libdino/src/plugin/registry.vala21
-rw-r--r--libdino/src/service/content_item_accumulator.vala224
-rw-r--r--libdino/src/service/file_manager.vala37
-rw-r--r--libdino/src/service/message_storage.vala32
-rw-r--r--main/CMakeLists.txt8
-rw-r--r--main/src/ui/conversation_summary/chat_state_populator.vala4
-rw-r--r--main/src/ui/conversation_summary/content_item_widget_factory.vala224
-rw-r--r--main/src/ui/conversation_summary/content_populator.vala99
-rw-r--r--main/src/ui/conversation_summary/conversation_view.vala35
-rw-r--r--main/src/ui/conversation_summary/date_separator_populator.vala4
-rw-r--r--main/src/ui/conversation_summary/default_file_display.vala95
-rw-r--r--main/src/ui/conversation_summary/default_message_display.vala58
-rw-r--r--main/src/ui/conversation_summary/file_populator.vala54
-rw-r--r--main/src/ui/conversation_summary/image_display.vala137
-rw-r--r--main/src/ui/conversation_summary/message_populator.vala81
-rw-r--r--main/src/ui/conversation_summary/message_textview.vala4
-rw-r--r--main/src/ui/conversation_summary/slashme_message_display.vala79
-rw-r--r--plugins/http-files/src/manager.vala19
-rw-r--r--plugins/http-files/src/plugin.vala2
23 files changed, 660 insertions, 605 deletions
diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt
index 62c73eca..429fc1f3 100644
--- a/libdino/CMakeLists.txt
+++ b/libdino/CMakeLists.txt
@@ -29,6 +29,7 @@ SOURCES
src/service/blocking_manager.vala
src/service/chat_interaction.vala
src/service/connection_manager.vala
+ src/service/content_item_accumulator.vala
src/service/conversation_manager.vala
src/service/counterpart_interaction_manager.vala
src/service/database.vala
diff --git a/libdino/src/application.vala b/libdino/src/application.vala
index 370618b2..0edd6df6 100644
--- a/libdino/src/application.vala
+++ b/libdino/src/application.vala
@@ -38,6 +38,7 @@ public interface Dino.Application : GLib.Application {
ChatInteraction.start(stream_interactor);
FileManager.start(stream_interactor, db);
NotificationEvents.start(stream_interactor);
+ ContentItemAccumulator.start(stream_interactor);
create_actions();
diff --git a/libdino/src/entity/file_transfer.vala b/libdino/src/entity/file_transfer.vala
index e2542e74..93ba782f 100644
--- a/libdino/src/entity/file_transfer.vala
+++ b/libdino/src/entity/file_transfer.vala
@@ -23,7 +23,21 @@ public class FileTransfer : Object {
public DateTime? local_time { get; set; }
public Encryption encryption { get; set; }
- public InputStream input_stream { get; set; }
+ private InputStream? input_stream_ = null;
+ public InputStream input_stream {
+ get {
+ if (input_stream_ == null) {
+ File file = File.new_for_path(Path.build_filename(storage_dir, path ?? file_name));
+ try {
+ input_stream_ = file.read();
+ } catch (Error e) { }
+ }
+ return input_stream_;
+ }
+ set {
+ input_stream_ = value;
+ }
+ }
public OutputStream output_stream { get; set; }
public string file_name { get; set; }
@@ -41,9 +55,11 @@ public class FileTransfer : Object {
public string info { get; set; }
private Database? db;
+ private string storage_dir;
- public FileTransfer.from_row(Database db, Qlite.Row row) {
+ public FileTransfer.from_row(Database db, Qlite.Row row, string storage_dir) {
this.db = db;
+ this.storage_dir = storage_dir;
id = row[db.file_transfer.id];
account = db.get_account_by_id(row[db.file_transfer.account_id]); // TODO don’t have to generate acc new
diff --git a/libdino/src/plugin/interfaces.vala b/libdino/src/plugin/interfaces.vala
index 62260076..2378feb7 100644
--- a/libdino/src/plugin/interfaces.vala
+++ b/libdino/src/plugin/interfaces.vala
@@ -75,15 +75,16 @@ public interface ConversationTitlebarWidget : Object {
public abstract interface ConversationItemPopulator : Object {
public abstract string id { get; }
public abstract void init(Conversation conversation, ConversationItemCollection summary, WidgetType type);
- public virtual void populate_timespan(Conversation conversation, DateTime from, DateTime to) { }
- public virtual void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { }
public abstract void close(Conversation conversation);
}
+public abstract interface ConversationAdditionPopulator : ConversationItemPopulator {
+ public virtual void populate_timespan(Conversation conversation, DateTime from, DateTime to) { }
+}
+
public abstract class MetaConversationItem : Object {
+ public virtual string populator_id { get; set; }
public virtual Jid? jid { get; set; default=null; }
- public virtual string color { get; set; default=null; }
- public virtual string display_name { get; set; default=null; }
public virtual bool dim { get; set; default=false; }
public virtual DateTime? sort_time { get; set; default=null; }
public virtual double seccondary_sort_indicator { get; set; }
@@ -103,21 +104,4 @@ public interface ConversationItemCollection : Object {
public signal void remove_item(MetaConversationItem item);
}
-public interface MessageDisplayProvider : Object {
- public abstract string id { get; set; }
- public abstract double priority { get; set; }
- public abstract bool can_display(Entities.Message? message);
- public abstract MetaConversationItem? get_item(Entities.Message message, Entities.Conversation conversation);
-}
-
-public interface FileWidget : Object {
- public abstract Object? get_widget(WidgetType type);
-}
-
-public interface FileDisplayProvider : Object {
- public abstract double priority { get; }
- public abstract bool can_display(Entities.Message? message);
- public abstract FileWidget? get_item(Entities.Message? message);
-}
-
}
diff --git a/libdino/src/plugin/registry.vala b/libdino/src/plugin/registry.vala
index 7b4410aa..2b496288 100644
--- a/libdino/src/plugin/registry.vala
+++ b/libdino/src/plugin/registry.vala
@@ -7,8 +7,7 @@ public class Registry {
internal ArrayList<AccountSettingsEntry> account_settings_entries = new ArrayList<AccountSettingsEntry>();
internal ArrayList<ContactDetailsProvider> contact_details_entries = new ArrayList<ContactDetailsProvider>();
internal Map<string, TextCommand> text_commands = new HashMap<string, TextCommand>();
- internal Gee.List<MessageDisplayProvider> message_displays = new ArrayList<MessageDisplayProvider>();
- internal Gee.List<ConversationItemPopulator> conversation_item_populators = new ArrayList<ConversationItemPopulator>();
+ internal Gee.List<ConversationAdditionPopulator> conversation_addition_populators = new ArrayList<ConversationAdditionPopulator>();
internal Gee.Collection<ConversationTitlebarEntry> conversation_titlebar_entries = new Gee.TreeSet<ConversationTitlebarEntry>((a, b) => {
if (a.order < b.order) {
return -1;
@@ -70,22 +69,12 @@ public class Registry {
}
}
- public bool register_message_display(MessageDisplayProvider provider) {
- lock (message_displays) {
- foreach(MessageDisplayProvider p in message_displays) {
- if (p.id == provider.id) return false;
- }
- message_displays.add(provider);
- return true;
- }
- }
-
- public bool register_conversation_item_populator(ConversationItemPopulator populator) {
- lock (conversation_item_populators) {
- foreach(ConversationItemPopulator p in conversation_item_populators) {
+ public bool register_conversation_addition_populator(ConversationAdditionPopulator populator) {
+ lock (conversation_addition_populators) {
+ foreach(ConversationItemPopulator p in conversation_addition_populators) {
if (p.id == populator.id) return false;
}
- conversation_item_populators.add(populator);
+ conversation_addition_populators.add(populator);
return true;
}
}
diff --git a/libdino/src/service/content_item_accumulator.vala b/libdino/src/service/content_item_accumulator.vala
new file mode 100644
index 00000000..9fc852b2
--- /dev/null
+++ b/libdino/src/service/content_item_accumulator.vala
@@ -0,0 +1,224 @@
+using Gee;
+
+using Dino.Entities;
+using Xmpp;
+
+namespace Dino {
+
+public class ContentItemAccumulator : StreamInteractionModule, Object {
+ public static ModuleIdentity<ContentItemAccumulator> IDENTITY = new ModuleIdentity<ContentItemAccumulator>("content_item_accumulator");
+ public string id { get { return IDENTITY.id; } }
+
+ public signal void new_item();
+
+ private StreamInteractor stream_interactor;
+ private Gee.List<ContentFilter> filters = new ArrayList<ContentFilter>();
+ private HashMap<ContentItemCollection, Conversation> collection_conversations = new HashMap<ContentItemCollection, Conversation>();
+
+ public static void start(StreamInteractor stream_interactor) {
+ ContentItemAccumulator m = new ContentItemAccumulator(stream_interactor);
+ stream_interactor.add_module(m);
+ }
+
+ public ContentItemAccumulator(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+
+ stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_new_message);
+ stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(on_new_message);
+ stream_interactor.get_module(FileManager.IDENTITY).received_file.connect(insert_file_transfer);
+ }
+
+ public void init(Conversation conversation, ContentItemCollection item_collection) {
+ collection_conversations[item_collection] = conversation;
+ }
+
+ public Gee.List<ContentItem> populate_latest(ContentItemCollection item_collection, Conversation conversation, int n) {
+ Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(ContentItem.compare);
+
+ Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation, n);
+ if (messages != null) {
+ foreach (Entities.Message message in messages) {
+ items.add(new MessageItem(message, conversation));
+ }
+ }
+ Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_latest_transfers(conversation.account, conversation.counterpart, n);
+ foreach (FileTransfer transfer in transfers) {
+ items.add(new FileItem(transfer));
+ }
+
+ BidirIterator<ContentItem> iter = items.bidir_iterator();
+ iter.last();
+ int i = 0;
+ while (i < n && iter.has_previous()) {
+ iter.previous();
+ i++;
+ }
+ Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
+ do {
+ ret.add(iter.get());
+ } while(iter.next());
+ return ret;
+ }
+
+ public Gee.List<ContentItem> populate_before(ContentItemCollection item_collection, Conversation conversation, ContentItem item, int n) {
+ Gee.TreeSet<ContentItem> items = new Gee.TreeSet<ContentItem>(ContentItem.compare);
+
+ Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before_message(conversation, item.display_time, n);
+ if (messages != null) {
+ foreach (Entities.Message message in messages) {
+ items.add(new MessageItem(message, conversation));
+ }
+ }
+ Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_transfers_before(conversation.account, conversation.counterpart, item.display_time, n);
+ foreach (FileTransfer transfer in transfers) {
+ items.add(new FileItem(transfer));
+ }
+
+ BidirIterator<ContentItem> iter = items.bidir_iterator();
+ iter.last();
+ int i = 0;
+ while (i < n && iter.has_previous()) {
+ iter.previous();
+ i++;
+ }
+ Gee.List<ContentItem> ret = new ArrayList<ContentItem>();
+ do {
+ ret.add(iter.get());
+ } while(iter.next());
+ return ret;
+ }
+
+ public void populate_after(Conversation conversation, ContentItem item, int n) {
+
+ }
+
+ public void add_filter(ContentFilter content_filter) {
+ filters.add(content_filter);
+ }
+
+ private void on_new_message(Message message, Conversation conversation) {
+ foreach (ContentItemCollection collection in collection_conversations.keys) {
+ if (collection_conversations[collection].equals(conversation)) {
+ MessageItem item = new MessageItem(message, conversation);
+ insert_item(collection, item);
+ }
+ }
+ }
+
+ private void insert_file_transfer(FileTransfer file_transfer) {
+ foreach (ContentItemCollection collection in collection_conversations.keys) {
+ Conversation conversation = collection_conversations[collection];
+ if (conversation.account.equals(file_transfer.account) && conversation.counterpart.equals_bare(file_transfer.counterpart)) {
+ FileItem item = new FileItem(file_transfer);
+ insert_item(collection, item);
+ }
+ }
+ }
+
+ private void insert_item(ContentItemCollection item_collection, ContentItem content_item) {
+ bool insert = true;
+ foreach (ContentFilter filter in filters) {
+ if (filter.discard(content_item)) {
+ insert = false;
+ }
+ }
+ if (insert) {
+ item_collection.insert_item(content_item);
+ }
+ }
+}
+
+public interface ContentItemCollection : Object {
+ public abstract void insert_item(ContentItem item);
+ public abstract void remove_item(ContentItem item);
+}
+
+public interface ContentFilter : Object {
+ public abstract bool discard(ContentItem content_item);
+}
+
+public abstract class ContentItem : Object {
+ public virtual string type_ { get; set; }
+ public virtual Jid? jid { get; set; default=null; }
+ public virtual DateTime? sort_time { get; set; default=null; }
+ public virtual double seccondary_sort_indicator { get; set; }
+ public virtual DateTime? display_time { get; set; default=null; }
+ public virtual Encryption? encryption { get; set; default=null; }
+ public virtual Entities.Message.Marked? mark { get; set; default=null; }
+
+ public static int compare(ContentItem a, ContentItem b) {
+ int res = a.sort_time.compare(b.sort_time);
+ if (res == 0) {
+ res = a.display_time.compare(b.display_time);
+ }
+ if (res == 0) {
+ res = a.seccondary_sort_indicator - b.seccondary_sort_indicator > 0 ? 1 : -1;
+ }
+ return res;
+ }
+}
+
+public class MessageItem : ContentItem {
+ public const string TYPE = "message";
+ public override string type_ { get; set; default=TYPE; }
+
+ public Message message;
+ public Conversation conversation;
+
+ public MessageItem(Message message, Conversation conversation) {
+ this.message = message;
+ this.conversation = conversation;
+
+ this.jid = message.from;
+ this.sort_time = message.local_time;
+ this.seccondary_sort_indicator = message.id + 0.0845;
+ this.display_time = message.time;
+ this.encryption = message.encryption;
+ this.mark = message.marked;
+
+ WeakRef weak_message = WeakRef(message);
+ message.notify["marked"].connect(() => {
+ Message? m = weak_message.get() as Message;
+ if (m == null) return;
+ mark = m.marked;
+ });
+ }
+}
+
+public class FileItem : ContentItem {
+ public const string TYPE = "file";
+ public override string type_ { get; set; default=TYPE; }
+
+ public FileTransfer file_transfer;
+ public Conversation conversation;
+
+ public FileItem(FileTransfer file_transfer) {
+ this.file_transfer = file_transfer;
+
+ this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? file_transfer.account.bare_jid.with_resource(file_transfer.account.resourcepart) : file_transfer.counterpart;
+ this.sort_time = file_transfer.time;
+ this.seccondary_sort_indicator = file_transfer.id + 0.2903;
+ this.display_time = file_transfer.time;
+ this.encryption = file_transfer.encryption;
+ this.mark = file_to_message_state(file_transfer.state);
+ file_transfer.notify["state"].connect_after(() => {
+ this.mark = file_to_message_state(file_transfer.state);
+ });
+ }
+
+ private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
+ switch (state) {
+ case FileTransfer.State.IN_PROCESS:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.COMPLETE:
+ return Entities.Message.Marked.NONE;
+ case FileTransfer.State.NOT_STARTED:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.FAILED:
+ return Entities.Message.Marked.WONTSEND;
+ }
+ assert_not_reached();
+ }
+}
+
+}
diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala
index 3def24af..667076dd 100644
--- a/libdino/src/service/file_manager.vala
+++ b/libdino/src/service/file_manager.vala
@@ -78,6 +78,37 @@ public class FileManager : StreamInteractionModule, Object {
return false;
}
+ public Gee.List<FileTransfer> get_latest_transfers(Account account, Jid counterpart, int n) {
+ Qlite.QueryBuilder select = db.file_transfer.select()
+ .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(counterpart))
+ .with(db.file_transfer.account_id, "=", account.id)
+ .order_by(db.file_transfer.local_time, "DESC")
+ .limit(n);
+
+ Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
+ foreach (Qlite.Row row in select) {
+ FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
+ ret.insert(0, file_transfer);
+ }
+ return ret;
+ }
+
+ public Gee.List<FileTransfer> get_transfers_before(Account account, Jid counterpart, DateTime before, int n) {
+ Qlite.QueryBuilder select = db.file_transfer.select()
+ .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(counterpart))
+ .with(db.file_transfer.account_id, "=", account.id)
+ .with(db.file_transfer.local_time, "<", (long)before.to_unix())
+ .order_by(db.file_transfer.local_time, "DESC")
+ .limit(n);
+
+ Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
+ foreach (Qlite.Row row in select) {
+ FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
+ ret.insert(0, file_transfer);
+ }
+ return ret;
+ }
+
public Gee.List<FileTransfer> get_file_transfers(Account account, Jid counterpart, DateTime after, DateTime before) {
Qlite.QueryBuilder select = db.file_transfer.select()
.with(db.file_transfer.counterpart_id, "=", db.get_jid_id(counterpart))
@@ -88,11 +119,7 @@ public class FileManager : StreamInteractionModule, Object {
Gee.List<FileTransfer> ret = new ArrayList<FileTransfer>();
foreach (Qlite.Row row in select) {
- FileTransfer file_transfer = new FileTransfer.from_row(db, row);
- File file = File.new_for_path(Path.build_filename(get_storage_dir(), file_transfer.path ?? file_transfer.file_name));
- try {
- file_transfer.input_stream = file.read();
- } catch (Error e) { }
+ FileTransfer file_transfer = new FileTransfer.from_row(db, row, get_storage_dir());
ret.insert(0, file_transfer);
}
return ret;
diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala
index 35e05074..906693a3 100644
--- a/libdino/src/service/message_storage.vala
+++ b/libdino/src/service/message_storage.vala
@@ -51,23 +51,23 @@ public class MessageStorage : StreamInteractionModule, Object {
return null;
}
- public Gee.List<Message>? get_messages_before_message(Conversation? conversation, Message message, int count = 20) {
- SortedSet<Message>? before = messages[conversation].head_set(message);
- if (before != null && before.size >= count) {
- Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
- Iterator<Message> iter = before.iterator();
- iter.next();
- for (int from_index = before.size - count; iter.has_next() && from_index > 0; from_index--) iter.next();
- while(iter.has_next()) {
- Message m = iter.get();
- ret.add(m);
- iter.next();
- }
- return ret;
- } else {
- Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, message.local_time);
+ public Gee.List<Message>? get_messages_before_message(Conversation? conversation, DateTime before, int count = 20) {
+// SortedSet<Message>? before = messages[conversation].head_set(message);
+// if (before != null && before.size >= count) {
+// Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func);
+// Iterator<Message> iter = before.iterator();
+// iter.next();
+// for (int from_index = before.size - count; iter.has_next() && from_index > 0; from_index--) iter.next();
+// while(iter.has_next()) {
+// Message m = iter.get();
+// ret.add(m);
+// iter.next();
+// }
+// return ret;
+// } else {
+ Gee.List<Message> db_messages = db.get_messages(conversation.counterpart, conversation.account, Util.get_message_type_for_conversation(conversation), count, before);
return db_messages;
- }
+// }
}
public Message? get_message_by_id(string stanza_id, Conversation conversation) {
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 9c5b06ff..d5f16992 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -100,16 +100,12 @@ SOURCES
src/ui/conversation_selector/list.vala
src/ui/conversation_selector/view.vala
src/ui/conversation_summary/chat_state_populator.vala
+ src/ui/conversation_summary/content_item_widget_factory.vala
+ src/ui/conversation_summary/content_populator.vala
src/ui/conversation_summary/conversation_item_skeleton.vala
src/ui/conversation_summary/conversation_view.vala
src/ui/conversation_summary/date_separator_populator.vala
- src/ui/conversation_summary/default_file_display.vala
- src/ui/conversation_summary/default_message_display.vala
- src/ui/conversation_summary/file_populator.vala
- src/ui/conversation_summary/image_display.vala
- src/ui/conversation_summary/message_populator.vala
src/ui/conversation_summary/message_textview.vala
- src/ui/conversation_summary/slashme_message_display.vala
src/ui/conversation_summary/subscription_notification.vala
src/ui/conversation_titlebar/menu_entry.vala
src/ui/conversation_titlebar/occupants_entry.vala
diff --git a/main/src/ui/conversation_summary/chat_state_populator.vala b/main/src/ui/conversation_summary/chat_state_populator.vala
index 1ea52a6d..d07ab743 100644
--- a/main/src/ui/conversation_summary/chat_state_populator.vala
+++ b/main/src/ui/conversation_summary/chat_state_populator.vala
@@ -6,7 +6,7 @@ using Xmpp;
namespace Dino.Ui.ConversationSummary {
-class ChatStatePopulator : Plugins.ConversationItemPopulator, Object {
+class ChatStatePopulator : Plugins.ConversationItemPopulator, Plugins.ConversationAdditionPopulator, Object {
public string id { get { return "chat_state"; } }
@@ -43,8 +43,6 @@ class ChatStatePopulator : Plugins.ConversationItemPopulator, Object {
public void populate_timespan(Conversation conversation, DateTime from, DateTime to) { }
- public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { }
-
private void update_chat_state(Account account, Jid jid) {
HashMap<Jid, string>? states = stream_interactor.get_module(CounterpartInteractionManager.IDENTITY).get_chat_states(current_conversation);
diff --git a/main/src/ui/conversation_summary/content_item_widget_factory.vala b/main/src/ui/conversation_summary/content_item_widget_factory.vala
new file mode 100644
index 00000000..8a2bf136
--- /dev/null
+++ b/main/src/ui/conversation_summary/content_item_widget_factory.vala
@@ -0,0 +1,224 @@
+using Gee;
+using Gdk;
+using Gtk;
+
+using Dino.Entities;
+
+namespace Dino.Ui.ConversationSummary {
+
+public class ContentItemWidgetFactory : Object {
+
+ private StreamInteractor stream_interactor;
+ private HashMap<string, WidgetGenerator> generators = new HashMap<string, WidgetGenerator>();
+
+ public ContentItemWidgetFactory(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+
+ generators[MessageItem.TYPE] = new MessageItemWidgetGenerator(stream_interactor);
+ generators[FileItem.TYPE] = new FileItemWidgetGenerator(stream_interactor);
+ }
+
+ public Widget? get_widget(ContentItem item) {
+ WidgetGenerator? generator = generators[item.type_];
+ if (generator != null) {
+ return (Widget?) generator.get_widget(item);
+ }
+ return null;
+ }
+
+ public void register_widget_generator(WidgetGenerator generator) {
+ generators[generator.handles_type] = generator;
+ }
+}
+
+public interface WidgetGenerator : Object {
+ public abstract string handles_type { get; set; }
+ public abstract Object get_widget(ContentItem item);
+}
+
+public class MessageItemWidgetGenerator : WidgetGenerator, Object {
+
+ public string handles_type { get; set; default=FileItem.TYPE; }
+
+ private StreamInteractor stream_interactor;
+
+ public MessageItemWidgetGenerator(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+ }
+
+ public Object get_widget(ContentItem item) {
+ MessageItem message_item = item as MessageItem;
+ Conversation conversation = message_item.conversation;
+ Message message = message_item.message;
+
+ MessageTextView text_view = new MessageTextView() { vexpand=true, visible = true };
+
+ if (message_item.message.body.has_prefix("/me")) {
+ text_view.add_text(message.body.substring(3));
+ } else {
+ text_view.add_text(message.body);
+ }
+ if (conversation.type_ == Conversation.Type.GROUPCHAT) {
+ text_view.highlight_word(conversation.nickname);
+ }
+ if (message_item.message.body.has_prefix("/me")) {
+ 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, Util.is_dark_theme(text_view));
+ TextTag nick_tag = text_view.buffer.create_tag(null, foreground: @"#$color");
+ TextIter iter;
+ text_view.buffer.get_start_iter(out iter);
+ text_view.buffer.insert_with_tags(ref iter, display_name, display_name.length, nick_tag);
+
+ text_view.style_updated.connect(() => update_style(stream_interactor, message, conversation, nick_tag, text_view));
+ text_view.realize.connect(() => update_style(stream_interactor, message, conversation, nick_tag, text_view));
+ }
+ return text_view;
+ }
+
+ public static void update_style(StreamInteractor stream_interactor, Message message, Conversation conversation, TextTag nick_tag, TextView text_view) {
+ string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view));
+ nick_tag.foreground = "#" + color;
+ }
+}
+
+public class FileItemWidgetGenerator : WidgetGenerator, Object {
+
+ public StreamInteractor stream_interactor;
+ public string handles_type { get; set; default=FileItem.TYPE; }
+
+ private const int MAX_HEIGHT = 300;
+ private const int MAX_WIDTH = 600;
+
+ public FileItemWidgetGenerator(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+ }
+
+ public Object get_widget(ContentItem item) {
+ FileItem file_item = item as FileItem;
+ FileTransfer transfer = file_item.file_transfer;
+ if (transfer.mime_type != null && transfer.mime_type.has_prefix("image")) {
+ return getImageWidget(transfer);
+ } else {
+ return getDefaultWidget(transfer);
+ }
+ }
+
+ private Widget getImageWidget(FileTransfer file_transfer) {
+ Image image = new Image() { halign=Align.START, visible = true };
+ Gdk.Pixbuf pixbuf;
+ try {
+ pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_file().get_path());
+ } catch (Error error) {
+ return null;
+ }
+
+ int max_scaled_height = MAX_HEIGHT * image.scale_factor;
+ if (pixbuf.height > max_scaled_height) {
+ pixbuf = pixbuf.scale_simple((int) ((double) max_scaled_height / pixbuf.height * pixbuf.width), max_scaled_height, Gdk.InterpType.BILINEAR);
+ }
+ int max_scaled_width = MAX_WIDTH * image.scale_factor;
+ if (pixbuf.width > max_scaled_width) {
+ pixbuf = pixbuf.scale_simple(max_scaled_width, (int) ((double) max_scaled_width / pixbuf.width * pixbuf.height), Gdk.InterpType.BILINEAR);
+ }
+ pixbuf = crop_corners(pixbuf, 3 * image.get_scale_factor());
+ Util.image_set_from_scaled_pixbuf(image, pixbuf);
+ Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
+
+ Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
+ Widget toolbar = builder.get_object("main") as Widget;
+ Util.force_background(toolbar, "rgba(0, 0, 0, 0.5)");
+ Util.force_css(toolbar, "* { padding: 3px; border-radius: 3px; }");
+
+ Label url_label = builder.get_object("url_label") as Label;
+ Util.force_color(url_label, "#eee");
+
+ if (file_transfer.file_name != null && file_transfer.file_name != "") {
+ string caption = file_transfer.file_name;
+ url_label.label = caption;
+ } else {
+ url_label.visible = false;
+ }
+
+ Image open_image = builder.get_object("open_image") as Image;
+ Util.force_css(open_image, "*:not(:hover) { color: #eee; }");
+ Button open_button = builder.get_object("open_button") as Button;
+ Util.force_css(open_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
+ open_button.clicked.connect(() => {
+ try{
+ AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null);
+ } catch (Error err) {
+ print("Tried to open file://" + file_transfer.get_file().get_path() + " " + err.message + "\n");
+ }
+ });
+
+ Revealer toolbar_revealer = new Revealer() { transition_type=RevealerTransitionType.CROSSFADE, transition_duration=400, visible=true };
+ toolbar_revealer.add(toolbar);
+
+ Grid grid = new Grid() { visible=true };
+ grid.attach(toolbar_revealer, 0, 0, 1, 1);
+ grid.attach(image, 0, 0, 1, 1);
+
+ EventBox event_box = new EventBox() { halign=Align.START, visible=true };
+ event_box.add(grid);
+ event_box.enter_notify_event.connect(() => { toolbar_revealer.reveal_child = true; return false; });
+ event_box.leave_notify_event.connect(() => { toolbar_revealer.reveal_child = false; return false; });
+
+ return event_box;
+ }
+
+ private static Gdk.Pixbuf crop_corners(Gdk.Pixbuf pixbuf, double radius = 3) {
+ Cairo.Context ctx = new Cairo.Context(new Cairo.ImageSurface(Cairo.Format.ARGB32, pixbuf.width, pixbuf.height));
+ Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0);
+ double degrees = Math.PI / 180.0;
+ ctx.new_sub_path();
+ ctx.arc(pixbuf.width - radius, radius, radius, -90 * degrees, 0 * degrees);
+ ctx.arc(pixbuf.width - radius, pixbuf.height - radius, radius, 0 * degrees, 90 * degrees);
+ ctx.arc(radius, pixbuf.height - radius, radius, 90 * degrees, 180 * degrees);
+ ctx.arc(radius, radius, radius, 180 * degrees, 270 * degrees);
+ ctx.close_path();
+ ctx.clip();
+ ctx.paint();
+ return Gdk.pixbuf_get_from_surface(ctx.get_target(), 0, 0, pixbuf.width, pixbuf.height);
+ }
+
+ private Widget getDefaultWidget(FileTransfer file_transfer) {
+ Box main_box = new Box(Orientation.HORIZONTAL, 4) { halign=Align.START, visible=true };
+ string? icon_name = ContentType.get_generic_icon_name(file_transfer.mime_type);
+ Image content_type_image = new Image.from_icon_name(icon_name, IconSize.DND) { visible=true };
+ main_box.add(content_type_image);
+
+ Box right_box = new Box(Orientation.VERTICAL, 0) { visible=true };
+ Label name_label = new Label(file_transfer.file_name) { xalign=0, yalign=0, visible=true};
+ right_box.add(name_label);
+ Label mime_label = new Label("<span size='small'>" + _("File") + ": " + file_transfer.mime_type + "</span>") { use_markup=true, xalign=0, yalign=1, visible=true};
+ mime_label.get_style_context().add_class("dim-label");
+ right_box.add(mime_label);
+ main_box.add(right_box);
+
+ EventBox event_box = new EventBox() { halign=Align.START, visible=true };
+ event_box.add(main_box);
+
+ event_box.enter_notify_event.connect((event) => {
+ event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
+ return false;
+ });
+ event_box.leave_notify_event.connect((event) => {
+ event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
+ return false;
+ });
+ event_box.button_release_event.connect((event_button) => {
+ if (event_button.button == 1) {
+ try{
+ AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null);
+ } catch (Error err) {
+ print("Tried to open " + file_transfer.get_file().get_path());
+ }
+ }
+ return false;
+ });
+
+ return event_box;
+ }
+}
+
+}
diff --git a/main/src/ui/conversation_summary/content_populator.vala b/main/src/ui/conversation_summary/content_populator.vala
new file mode 100644
index 00000000..9fb83419
--- /dev/null
+++ b/main/src/ui/conversation_summary/content_populator.vala
@@ -0,0 +1,99 @@
+using Gee;
+using Gtk;
+
+using Xmpp;
+using Dino.Entities;
+
+namespace Dino.Ui.ConversationSummary {
+
+public class ContentProvider : ContentItemCollection, Object {
+
+ private StreamInteractor stream_interactor;
+ private ContentItemWidgetFactory widget_factory;
+ private Conversation? current_conversation;
+ private Plugins.ConversationItemCollection? item_collection;
+
+ public ContentProvider(StreamInteractor stream_interactor) {
+ this.stream_interactor = stream_interactor;
+ this.widget_factory = new ContentItemWidgetFactory(stream_interactor);
+ }
+
+ public void init(Plugins.ConversationItemCollection item_collection, Conversation conversation, Plugins.WidgetType type) {
+ current_conversation = conversation;
+ this.item_collection = item_collection;
+ stream_interactor.get_module(ContentItemAccumulator.IDENTITY).init(conversation, this);
+ }
+
+ public void close(Conversation conversation) { }
+
+ public void insert_item(ContentItem item) {
+ item_collection.insert_item(new ContentMetaItem(item, widget_factory));
+ }
+
+ public void remove_item(ContentItem item) { }
+
+
+ public Gee.List<ContentMetaItem> populate_latest(Conversation conversation, int n) {
+ Gee.List<ContentItem> items = stream_interactor.get_module(ContentItemAccumulator.IDENTITY).populate_latest(this, conversation, n);
+ Gee.List<ContentMetaItem> ret = new ArrayList<ContentMetaItem>();
+ foreach (ContentItem item in items) {
+ ret.add(new ContentMetaItem(item, widget_factory));
+ }
+ return ret;
+ }
+
+ public Gee.List<ContentMetaItem> populate_before(Conversation conversation, Plugins.MetaConversationItem before_item, int n) {
+ Gee.List<ContentMetaItem> ret = new ArrayList<ContentMetaItem>();
+ ContentMetaItem? content_meta_item = before_item as ContentMetaItem;
+ if (content_meta_item != null) {
+ Gee.List<ContentItem> items = stream_interactor.get_module(ContentItemAccumulator.IDENTITY).populate_before(this, conversation, content_meta_item.content_item, n);
+ foreach (ContentItem item in items) {
+ ret.add(new ContentMetaItem(item, widget_factory));
+ }
+ }
+ return ret;
+ }
+}
+
+public class ContentMetaItem : Plugins.MetaConversationItem {
+ public override Jid? jid { get; set; }
+ public override DateTime? sort_time { get; set; }
+ public override DateTime? display_time { get; set; }
+ public override Encryption? encryption { get; set; }
+
+ public ContentItem content_item;
+ private ContentItemWidgetFactory widget_factory;
+
+ public ContentMetaItem(ContentItem content_item, ContentItemWidgetFactory widget_factory) {
+ this.jid = content_item.jid;
+ this.sort_time = content_item.sort_time;
+ this.seccondary_sort_indicator = content_item.seccondary_sort_indicator;
+ this.display_time = content_item.display_time;
+ this.encryption = content_item.encryption;
+ this.mark = content_item.mark;
+
+ WeakRef weak_item = WeakRef(content_item);
+ content_item.notify["mark"].connect(() => {
+ ContentItem? ci = weak_item.get() as ContentItem;
+ if (ci == null) return;
+ this.mark = ci.mark;
+ });
+
+ this.can_merge = true;
+ this.requires_avatar = true;
+ this.requires_header = true;
+
+ this.content_item = content_item;
+ this.widget_factory = widget_factory;
+ }
+
+ public override bool can_merge { get; set; default=true; }
+ public override bool requires_avatar { get; set; default=true; }
+ public override bool requires_header { get; set; default=true; }
+
+ public override Object? get_widget(Plugins.WidgetType type) {
+ return widget_factory.get_widget(content_item);
+ }
+}
+
+}
diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala
index fac53b7d..bb696572 100644
--- a/main/src/ui/conversation_summary/conversation_view.vala
+++ b/main/src/ui/conversation_summary/conversation_view.vala
@@ -19,11 +19,10 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
private StreamInteractor stream_interactor;
private Gee.TreeSet<Plugins.MetaConversationItem> meta_items = new TreeSet<Plugins.MetaConversationItem>(sort_meta_items);
- private Gee.Map<Plugins.MetaConversationItem, Gee.List<Plugins.MetaConversationItem>> meta_after_items = new Gee.HashMap<Plugins.MetaConversationItem, Gee.List<Plugins.MetaConversationItem>>();
private Gee.HashMap<Plugins.MetaConversationItem, ConversationItemSkeleton> item_item_skeletons = new Gee.HashMap<Plugins.MetaConversationItem, ConversationItemSkeleton>();
private Gee.HashMap<Plugins.MetaConversationItem, Widget> widgets = new Gee.HashMap<Plugins.MetaConversationItem, Widget>();
private Gee.List<ConversationItemSkeleton> item_skeletons = new Gee.ArrayList<ConversationItemSkeleton>();
- private MessagePopulator message_item_populator;
+ private ContentProvider content_populator;
private SubscriptionNotitication subscription_notification;
private double? was_value;
@@ -39,16 +38,15 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify);
scrolled.vadjustment.notify["value"].connect(on_value_notify);
- message_item_populator = new MessagePopulator(stream_interactor);
+ content_populator = new ContentProvider(stream_interactor);
subscription_notification = new SubscriptionNotitication(stream_interactor);
insert_item.connect(on_insert_item);
remove_item.connect(on_remove_item);
Application app = GLib.Application.get_default() as Application;
- app.plugin_registry.register_conversation_item_populator(new ChatStatePopulator(stream_interactor));
- app.plugin_registry.register_conversation_item_populator(new FilePopulator(stream_interactor));
- app.plugin_registry.register_conversation_item_populator(new DateSeparatorPopulator(stream_interactor));
+ app.plugin_registry.register_conversation_addition_populator(new ChatStatePopulator(stream_interactor));
+ app.plugin_registry.register_conversation_addition_populator(new DateSeparatorPopulator(stream_interactor));
Timeout.add_seconds(60, () => {
foreach (ConversationItemSkeleton item_skeleton in item_skeletons) {
@@ -78,7 +76,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
private void initialize_for_conversation_(Conversation? conversation) {
Dino.Application app = Dino.Application.get_default();
if (this.conversation != null) {
- foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) {
+ foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_addition_populators) {
populator.close(conversation);
}
}
@@ -90,11 +88,14 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
animate = false;
Timeout.add(20, () => { animate = true; return false; });
- foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) {
+ foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_addition_populators) {
populator.init(conversation, this, Plugins.WidgetType.GTK);
}
- message_item_populator.init(conversation, this);
- message_item_populator.populate_latest(conversation, 40);
+ content_populator.init(this, conversation, Plugins.WidgetType.GTK);
+ Gee.List<ContentMetaItem> items = content_populator.populate_latest(conversation, 40);
+ foreach (ContentMetaItem item in items) {
+ on_insert_item(item);
+ }
Idle.add(() => { on_value_notify(); return false; });
subscription_notification.init(conversation, this);
@@ -110,7 +111,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
}
}
- public void on_remove_item(Plugins.MetaConversationItem item) {
+ private void on_remove_item(Plugins.MetaConversationItem item) {
lock (meta_items) {
ConversationItemSkeleton? skeleton = item_item_skeletons[item];
if (skeleton.items.size > 1) {
@@ -202,11 +203,11 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
if (index == 0) {
Dino.Application app = Dino.Application.get_default();
if (item_skeletons.size == 1) {
- foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) {
+ foreach (Plugins.ConversationAdditionPopulator populator in app.plugin_registry.conversation_addition_populators) {
populator.populate_timespan(conversation, item.sort_time, new DateTime.now_utc());
}
} else {
- foreach (Plugins.ConversationItemPopulator populator in app.plugin_registry.conversation_item_populators) {
+ foreach (Plugins.ConversationAdditionPopulator populator in app.plugin_registry.conversation_addition_populators) {
populator.populate_timespan(conversation, item.sort_time, meta_items.higher(item).sort_time);
}
}
@@ -253,7 +254,12 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
private void load_earlier_messages() {
was_value = scrolled.vadjustment.value;
if (!reloading_mutex.trylock()) return;
- if (meta_items.size > 0) message_item_populator.populate_before(conversation, meta_items.first(), 20);
+ if (meta_items.size > 0) {
+ Gee.List<ContentMetaItem> items = content_populator.populate_before(conversation, meta_items.first(), 20);
+ foreach (ContentMetaItem item in items) {
+ on_insert_item(item);
+ }
+ }
}
private static int sort_meta_items(Plugins.MetaConversationItem a, Plugins.MetaConversationItem b) {
@@ -276,7 +282,6 @@ public class ConversationView : Box, Plugins.ConversationItemCollection {
private void clear() {
meta_items.clear();
- meta_after_items.clear();
item_skeletons.clear();
item_item_skeletons.clear();
widgets.clear();
diff --git a/main/src/ui/conversation_summary/date_separator_populator.vala b/main/src/ui/conversation_summary/date_separator_populator.vala
index 34005ab6..6a1ba782 100644
--- a/main/src/ui/conversation_summary/date_separator_populator.vala
+++ b/main/src/ui/conversation_summary/date_separator_populator.vala
@@ -6,7 +6,7 @@ using Xmpp;
namespace Dino.Ui.ConversationSummary {
-class DateSeparatorPopulator : Plugins.ConversationItemPopulator, Object {
+class DateSeparatorPopulator : Plugins.ConversationItemPopulator, Plugins.ConversationAdditionPopulator, Object {
public string id { get { return "date_separator"; } }
@@ -35,8 +35,6 @@ class DateSeparatorPopulator : Plugins.ConversationItemPopulator, Object {
public void populate_timespan(Conversation conversation, DateTime after, DateTime before) { }
- public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { }
-
private void on_insert_item(Plugins.MetaConversationItem item) {
if (item.display_time == null) return;
diff --git a/main/src/ui/conversation_summary/default_file_display.vala b/main/src/ui/conversation_summary/default_file_display.vala
deleted file mode 100644
index 1547440b..00000000
--- a/main/src/ui/conversation_summary/default_file_display.vala
+++ /dev/null
@@ -1,95 +0,0 @@
-using Gdk;
-using Gtk;
-
-using Dino.Entities;
-using Xmpp;
-
-namespace Dino.Ui.ConversationSummary {
-
-public class DefaultFileDisplay : Plugins.MetaConversationItem {
- public override Jid? jid { get; set; }
- public override DateTime? sort_time { get; set; }
- public override DateTime? display_time { get; set; }
- public override Encryption? encryption { get; set; }
- public override Entities.Message.Marked? mark { get; set; }
-
- public override bool can_merge { get; set; default=true; }
- public override bool requires_avatar { get; set; default=true; }
- public override bool requires_header { get; set; default=true; }
-
- private const int MAX_HEIGHT = 300;
- private const int MAX_WIDTH = 600;
-
- private StreamInteractor stream_interactor;
- private FileTransfer file_transfer;
-
- public DefaultFileDisplay(StreamInteractor stream_interactor, FileTransfer file_transfer) {
- this.stream_interactor = stream_interactor;
- this.file_transfer = file_transfer;
-
- this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? file_transfer.account.bare_jid.with_resource(file_transfer.account.resourcepart) : file_transfer.counterpart;
- this.sort_time = file_transfer.time;
- this.seccondary_sort_indicator = file_transfer.id + 0.2903;
- this.display_time = file_transfer.time;
- this.encryption = file_transfer.encryption;
- this.mark = file_to_message_state(file_transfer.state);
- file_transfer.notify["state"].connect_after(() => {
- this.mark = file_to_message_state(file_transfer.state);
- });
- }
-
- public override Object? get_widget(Plugins.WidgetType widget_type) {
- Box main_box = new Box(Orientation.HORIZONTAL, 4) { halign=Align.START, visible=true };
- string? icon_name = ContentType.get_generic_icon_name(file_transfer.mime_type);
- Image content_type_image = new Image.from_icon_name(icon_name, IconSize.DND) { visible=true };
- main_box.add(content_type_image);
-
- Box right_box = new Box(Orientation.VERTICAL, 0) { visible=true };
- Label name_label = new Label(file_transfer.file_name) { xalign=0, yalign=0, visible=true};
- right_box.add(name_label);
- Label mime_label = new Label("<span size='small'>" + _("File") + ": " + file_transfer.mime_type + "</span>") { use_markup=true, xalign=0, yalign=1, visible=true};
- mime_label.get_style_context().add_class("dim-label");
- right_box.add(mime_label);
- main_box.add(right_box);
-
- EventBox event_box = new EventBox() { halign=Align.START, visible=true };
- event_box.add(main_box);
-
- event_box.enter_notify_event.connect((event) => {
- event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
- return false;
- });
- event_box.leave_notify_event.connect((event) => {
- event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
- return false;
- });
- event_box.button_release_event.connect((event_button) => {
- if (event_button.button == 1) {
- try{
- AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null);
- } catch (Error err) {
- print("Tried to open " + file_transfer.get_file().get_path());
- }
- }
- return false;
- });
-
- return event_box;
- }
-
- private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
- switch (state) {
- case FileTransfer.State.IN_PROCESS:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.COMPLETE:
- return Entities.Message.Marked.NONE;
- case FileTransfer.State.NOT_STARTED:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.FAILED:
- return Entities.Message.Marked.WONTSEND;
- }
- assert_not_reached();
- }
-}
-
-}
diff --git a/main/src/ui/conversation_summary/default_message_display.vala b/main/src/ui/conversation_summary/default_message_display.vala
deleted file mode 100644
index 519e5107..00000000
--- a/main/src/ui/conversation_summary/default_message_display.vala
+++ /dev/null
@@ -1,58 +0,0 @@
-using Dino.Entities;
-using Xmpp;
-
-namespace Dino.Ui.ConversationSummary {
-
-public class DefaultMessageDisplay : Plugins.MessageDisplayProvider, Object {
- public string id { get; set; default="default"; }
- public double priority { get; set; default=0; }
-
- public StreamInteractor stream_interactor;
-
- public DefaultMessageDisplay(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
- }
-
- public bool can_display(Entities.Message? message) { return true; }
-
- public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
- return new MetaMessageItem(stream_interactor, message, conversation);
- }
-}
-
-public class MetaMessageItem : Plugins.MetaConversationItem {
- public override Jid? jid { get; set; }
- public override DateTime? sort_time { get; set; }
- public override DateTime? display_time { get; set; }
- public override Encryption? encryption { get; set; }
-
- private StreamInteractor stream_interactor;
- private Conversation conversation;
- private Message message;
-
- public MetaMessageItem(StreamInteractor stream_interactor, Message message, Conversation conversation) {
- this.stream_interactor = stream_interactor;
- this.conversation = conversation;
- this.message = message;
- this.jid = message.from;
- this.sort_time = message.local_time;
- this.seccondary_sort_indicator = message.id + 0.2085;
- this.display_time = message.time;
- this.encryption = message.encryption;
- }
-
- public override bool can_merge { get; set; default=true; }
- public override bool requires_avatar { get; set; default=true; }
- public override bool requires_header { get; set; default=true; }
-
- public override Object? get_widget(Plugins.WidgetType widget_type) {
- MessageTextView text_view = new MessageTextView() { visible = true };
- text_view.add_text(message.body);
- if (conversation.type_ == Conversation.Type.GROUPCHAT) {
- text_view.highlight_word(conversation.nickname);
- }
- return text_view;
- }
-}
-
-}
diff --git a/main/src/ui/conversation_summary/file_populator.vala b/main/src/ui/conversation_summary/file_populator.vala
deleted file mode 100644
index af7bc992..00000000
--- a/main/src/ui/conversation_summary/file_populator.vala
+++ /dev/null
@@ -1,54 +0,0 @@
-using Gee;
-using Gtk;
-
-using Dino.Entities;
-using Xmpp;
-
-namespace Dino.Ui.ConversationSummary {
-
-class FilePopulator : Plugins.ConversationItemPopulator, Object {
-
- public string id { get { return "file"; } }
-
- private StreamInteractor? stream_interactor;
- private Conversation? current_conversation;
- private Plugins.ConversationItemCollection? item_collection;
-
- public FilePopulator(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
-
- stream_interactor.get_module(FileManager.IDENTITY).received_file.connect((file_transfer) => {
- if (current_conversation != null && current_conversation.account.equals(file_transfer.account) && current_conversation.counterpart.equals_bare(file_transfer.counterpart)) {
- insert_file(file_transfer);
- }
- });
- }
-
- public void init(Conversation conversation, Plugins.ConversationItemCollection item_collection, Plugins.WidgetType type) {
- current_conversation = conversation;
- this.item_collection = item_collection;
- }
-
- public void close(Conversation conversation) { }
-
- public void populate_timespan(Conversation conversation, DateTime from, DateTime to) {
- Gee.List<FileTransfer> transfers = stream_interactor.get_module(FileManager.IDENTITY).get_file_transfers(conversation.account, conversation.counterpart, from, to);
- foreach (FileTransfer transfer in transfers) {
- insert_file(transfer);
- }
- }
-
- public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { }
-
- private void insert_file(FileTransfer transfer) {
- Plugins.MetaConversationItem item = null;
- if (transfer.mime_type != null && transfer.mime_type.has_prefix("image")) {
- item = new ImageDisplay(stream_interactor, transfer);
- } else {
- item = new DefaultFileDisplay(stream_interactor, transfer);
- }
- item_collection.insert_item(item);
- }
-}
-
-}
diff --git a/main/src/ui/conversation_summary/image_display.vala b/main/src/ui/conversation_summary/image_display.vala
deleted file mode 100644
index 15880836..00000000
--- a/main/src/ui/conversation_summary/image_display.vala
+++ /dev/null
@@ -1,137 +0,0 @@
-using Gtk;
-
-using Dino.Entities;
-using Xmpp;
-
-namespace Dino.Ui.ConversationSummary {
-
-public class ImageDisplay : Plugins.MetaConversationItem {
- public override Jid? jid { get; set; }
- public override DateTime? sort_time { get; set; }
- public override DateTime? display_time { get; set; }
- public override Encryption? encryption { get; set; }
- public override Entities.Message.Marked? mark { get; set; }
-
- public override bool can_merge { get; set; default=true; }
- public override bool requires_avatar { get; set; default=true; }
- public override bool requires_header { get; set; default=true; }
-
- private const int MAX_HEIGHT = 300;
- private const int MAX_WIDTH = 600;
-
- private StreamInteractor stream_interactor;
- private FileTransfer file_transfer;
-
- public ImageDisplay(StreamInteractor stream_interactor, FileTransfer file_transfer) {
- this.stream_interactor = stream_interactor;
- this.file_transfer = file_transfer;
-
- this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? file_transfer.account.bare_jid.with_resource(file_transfer.account.resourcepart) : file_transfer.counterpart;
- this.sort_time = file_transfer.time;
- this.seccondary_sort_indicator = file_transfer.id + 0.2903;
- this.display_time = file_transfer.time;
- this.encryption = file_transfer.encryption;
- this.mark = file_to_message_state(file_transfer.state);
- file_transfer.notify["state"].connect_after(() => {
- this.mark = file_to_message_state(file_transfer.state);
- });
- }
-
- public override Object? get_widget(Plugins.WidgetType widget_type) {
- Image image = new Image() { halign=Align.START, visible = true };
- Gdk.Pixbuf pixbuf;
- try {
- pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_file().get_path());
- } catch (Error error) {
- return null;
- }
-
- int max_scaled_height = MAX_HEIGHT * image.scale_factor;
- if (pixbuf.height > max_scaled_height) {
- pixbuf = pixbuf.scale_simple((int) ((double) max_scaled_height / pixbuf.height * pixbuf.width), max_scaled_height, Gdk.InterpType.BILINEAR);
- }
- int max_scaled_width = MAX_WIDTH * image.scale_factor;
- if (pixbuf.width > max_scaled_width) {
- pixbuf = pixbuf.scale_simple(max_scaled_width, (int) ((double) max_scaled_width / pixbuf.width * pixbuf.height), Gdk.InterpType.BILINEAR);
- }
- pixbuf = crop_corners(pixbuf, 3 * image.get_scale_factor());
- Util.image_set_from_scaled_pixbuf(image, pixbuf);
- Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
-
- Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
- Widget toolbar = builder.get_object("main") as Widget;
- Util.force_background(toolbar, "rgba(0, 0, 0, 0.5)");
- Util.force_css(toolbar, "* { padding: 3px; border-radius: 3px; }");
-
- Label url_label = builder.get_object("url_label") as Label;
- Util.force_color(url_label, "#eee");
- update_info(url_label, file_transfer.file_name);
-
- Image open_image = builder.get_object("open_image") as Image;
- Util.force_css(open_image, "*:not(:hover) { color: #eee; }");
- Button open_button = builder.get_object("open_button") as Button;
- Util.force_css(open_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
- open_button.clicked.connect(() => {
- try{
- AppInfo.launch_default_for_uri(file_transfer.get_file().get_uri(), null);
- } catch (Error err) {
- print("Tried to open file://" + file_transfer.get_file().get_path() + " " + err.message + "\n");
- }
- });
-
- Revealer toolbar_revealer = new Revealer() { transition_type=RevealerTransitionType.CROSSFADE, transition_duration=400, visible=true };
- toolbar_revealer.add(toolbar);
-
- Grid grid = new Grid() { visible=true };
- grid.attach(toolbar_revealer, 0, 0, 1, 1);
- grid.attach(image, 0, 0, 1, 1);
-
- EventBox event_box = new EventBox() { halign=Align.START, visible=true };
- event_box.add(grid);
- event_box.enter_notify_event.connect(() => { toolbar_revealer.reveal_child = true; return false; });
- event_box.leave_notify_event.connect(() => { toolbar_revealer.reveal_child = false; return false; });
-
- return event_box;
- }
-
- private static Gdk.Pixbuf crop_corners(Gdk.Pixbuf pixbuf, double radius = 3) {
- Cairo.Context ctx = new Cairo.Context(new Cairo.ImageSurface(Cairo.Format.ARGB32, pixbuf.width, pixbuf.height));
- Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0);
- double degrees = Math.PI / 180.0;
- ctx.new_sub_path();
- ctx.arc(pixbuf.width - radius, radius, radius, -90 * degrees, 0 * degrees);
- ctx.arc(pixbuf.width - radius, pixbuf.height - radius, radius, 0 * degrees, 90 * degrees);
- ctx.arc(radius, pixbuf.height - radius, radius, 90 * degrees, 180 * degrees);
- ctx.arc(radius, radius, radius, 180 * degrees, 270 * degrees);
- ctx.close_path();
- ctx.clip();
- ctx.paint();
- return Gdk.pixbuf_get_from_surface(ctx.get_target(), 0, 0, pixbuf.width, pixbuf.height);
- }
-
- private void update_info(Label url_label, string? info) {
- string url = info ?? "";
- if (url.has_prefix("https://")) url = url.substring(8);
- if (url.has_prefix("http://")) url = url.substring(7);
- if (url.has_prefix("www.")) url = url.substring(4);
- string[] slash_split = url.split("/");
- if (slash_split.length > 2) url = slash_split[0] + "/…/" + slash_split[slash_split.length - 1];
- url_label.label = url;
- }
-
- private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
- switch (state) {
- case FileTransfer.State.IN_PROCESS:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.COMPLETE:
- return Entities.Message.Marked.NONE;
- case FileTransfer.State.NOT_STARTED:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.FAILED:
- return Entities.Message.Marked.WONTSEND;
- }
- assert_not_reached();
- }
-}
-
-}
diff --git a/main/src/ui/conversation_summary/message_populator.vala b/main/src/ui/conversation_summary/message_populator.vala
deleted file mode 100644
index b342306b..00000000
--- a/main/src/ui/conversation_summary/message_populator.vala
+++ /dev/null
@@ -1,81 +0,0 @@
-using Gee;
-using Gtk;
-
-using Dino.Entities;
-
-namespace Dino.Ui.ConversationSummary {
-
-public class MessagePopulator : Object {
-
- private StreamInteractor? stream_interactor;
- private Conversation? current_conversation;
- private Plugins.ConversationItemCollection? item_collection;
- private HashMap<Plugins.MetaConversationItem, Message> meta_message = new HashMap<Plugins.MetaConversationItem, Message>();
-
- public MessagePopulator(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
-
- Application app = GLib.Application.get_default() as Application;
- app.plugin_registry.register_message_display(new DefaultMessageDisplay(stream_interactor));
- app.plugin_registry.register_message_display(new SlashmeMessageDisplay(stream_interactor));
-
-
- stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(handle_message);
- stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_message);
- }
-
- public void init(Conversation conversation, Plugins.ConversationItemCollection item_collection) {
- current_conversation = conversation;
- this.item_collection = item_collection;
- }
-
- public void close(Conversation conversation) { }
-
- public void populate_latest(Conversation conversation, int n) {
- Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation, n);
- if (messages != null) {
- foreach (Entities.Message message in messages) {
- handle_message(message, conversation);
- }
- }
- }
-
- public void populate_before(Conversation conversation, Plugins.MetaConversationItem item, int n) {
- Gee.List<Entities.Message>? messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages_before_message(conversation, meta_message[item], n);
- if (messages != null) {
- foreach (Entities.Message message in messages) {
- handle_message(message, conversation);
- }
- }
- }
-
- private void handle_message(Message message, Conversation conversation) {
- if (!conversation.equals(current_conversation)) return;
-
- Plugins.MessageDisplayProvider? best_provider = null;
- double priority = -1;
- Application app = GLib.Application.get_default() as Application;
- foreach (Plugins.MessageDisplayProvider provider in app.plugin_registry.message_displays) {
- if (provider.can_display(message) && provider.priority > priority) {
- best_provider = provider;
- priority = provider.priority;
- }
- }
- Plugins.MetaConversationItem? meta_item = best_provider.get_item(message, conversation);
- if (meta_item == null) return;
- meta_message[meta_item] = message;
-
- meta_item.mark = message.marked;
- WeakRef weak_meta_item = WeakRef(meta_item);
- WeakRef weak_message = WeakRef(message);
- message.notify["marked"].connect(() => {
- Plugins.MetaConversationItem? mi = weak_meta_item.get() as Plugins.MetaConversationItem;
- Message? m = weak_message.get() as Message;
- if (mi == null || m == null) return;
- mi.mark = m.marked;
- });
- item_collection.insert_item(meta_item);
- }
-}
-
-}
diff --git a/main/src/ui/conversation_summary/message_textview.vala b/main/src/ui/conversation_summary/message_textview.vala
index 0b5ed6e4..0c38c269 100644
--- a/main/src/ui/conversation_summary/message_textview.vala
+++ b/main/src/ui/conversation_summary/message_textview.vala
@@ -60,7 +60,7 @@ public class MessageTextView : TextView {
TextIter end_iter;
buffer.get_iter_at_offset(out start_iter, start);
buffer.get_iter_at_offset(out end_iter, end);
- buffer.apply_tag_by_name("semibold", start_iter, end_iter);
+ buffer.apply_tag(bold_tag, start_iter, end_iter);
}
}
@@ -125,7 +125,7 @@ public class MessageTextView : TextView {
TextIter end_iter;
buffer.get_iter_at_offset(out start_iter, absolute_start + start);
buffer.get_iter_at_offset(out end_iter, absolute_start + end);
- buffer.apply_tag_by_name("url", start_iter, end_iter);
+ buffer.apply_tag(link_tag, start_iter, end_iter);
}
}
diff --git a/main/src/ui/conversation_summary/slashme_message_display.vala b/main/src/ui/conversation_summary/slashme_message_display.vala
deleted file mode 100644
index 1ee20748..00000000
--- a/main/src/ui/conversation_summary/slashme_message_display.vala
+++ /dev/null
@@ -1,79 +0,0 @@
-using Gtk;
-
-using Dino.Entities;
-using Xmpp;
-
-namespace Dino.Ui.ConversationSummary {
-
-public class SlashmeMessageDisplay : Plugins.MessageDisplayProvider, Object {
- public string id { get; set; default="slashme"; }
- public double priority { get; set; default=1; }
-
- public StreamInteractor stream_interactor;
-
- public SlashmeMessageDisplay(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
- }
-
- public bool can_display(Entities.Message? message) {
- return message.body.has_prefix("/me");
- }
-
- public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
- return new MetaSlashmeItem(stream_interactor, message, conversation);
- }
-}
-
-public class MetaSlashmeItem : Plugins.MetaConversationItem {
- public override Jid? jid { get; set; }
- public override DateTime? sort_time { get; set; }
- public override DateTime? display_time { get; set; }
- public override Encryption? encryption { get; set; }
-
- private StreamInteractor stream_interactor;
- private Conversation conversation;
- private Message message;
- private TextTag nick_tag;
- private MessageTextView text_view;
-
- public MetaSlashmeItem(StreamInteractor stream_interactor, Message message, Conversation conversation) {
- this.stream_interactor = stream_interactor;
- this.conversation = conversation;
- this.message = message;
- this.jid = message.from;
- this.sort_time = message.local_time;
- this.seccondary_sort_indicator = message.id + 0.0845;
- this.display_time = message.time;
- this.encryption = message.encryption;
- }
-
- public override bool can_merge { get; set; default=false; }
- public override bool requires_avatar { get; set; default=true; }
- public override bool requires_header { get; set; default=false; }
-
- public override Object? get_widget(Plugins.WidgetType widget_type) {
- text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true };
- if (conversation.type_ == Conversation.Type.GROUPCHAT) {
- text_view.highlight_word(conversation.nickname);
- }
-
- 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, Util.is_dark_theme(text_view));
- nick_tag = text_view.buffer.create_tag("nick", foreground: "#" + color);
- TextIter iter;
- text_view.buffer.get_start_iter(out iter);
- text_view.buffer.insert_with_tags(ref iter, display_name, display_name.length, nick_tag);
- text_view.add_text(message.body.substring(3));
-
- text_view.style_updated.connect(update_style);
- text_view.realize.connect(update_style);
- return text_view;
- }
-
- private void update_style() {
- string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.real_jid ?? message.from, Util.is_dark_theme(text_view));
- nick_tag.foreground = "#" + color;
- }
-}
-
-}
diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala
index 7335b89a..78c244e3 100644
--- a/plugins/http-files/src/manager.vala
+++ b/plugins/http-files/src/manager.vala
@@ -81,22 +81,19 @@ public class Manager : StreamInteractionModule, FileSender, Object {
}
}
-public class FileMessageFilterDisplay : Plugins.MessageDisplayProvider, Object {
- public string id { get; set; default="file_message_filter"; }
- public double priority { get; set; default=10; }
-
+public class FileMessageFilter : ContentFilter, Object {
public Database db;
- public FileMessageFilterDisplay(Dino.Database db) {
+ public FileMessageFilter(Dino.Database db) {
this.db = db;
}
- public bool can_display(Entities.Message? message) {
- return message_is_file(db, message);
- }
-
- public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
- return null;
+ public bool discard(ContentItem content_item) {
+ if (content_item.type_ == MessageItem.TYPE) {
+ MessageItem message_item = content_item as MessageItem;
+ return message_is_file(db, message_item.message);
+ }
+ return false;
}
}
diff --git a/plugins/http-files/src/plugin.vala b/plugins/http-files/src/plugin.vala
index 1fc0c9fd..c57ee3dc 100644
--- a/plugins/http-files/src/plugin.vala
+++ b/plugins/http-files/src/plugin.vala
@@ -19,7 +19,7 @@ public class Plugin : RootInterface, Object {
});
app.stream_interactor.get_module(FileManager.IDENTITY).add_provider(file_provider);
- app.plugin_registry.register_message_display(new FileMessageFilterDisplay(app.db));
+ app.stream_interactor.get_module(ContentItemAccumulator.IDENTITY).add_filter(new FileMessageFilter(app.db));
}
public void shutdown() {