2017-12-01 01:28:51 +00:00
|
|
|
using Gee;
|
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
using Xmpp;
|
|
|
|
|
|
|
|
namespace Dino.Ui.ConversationSummary {
|
|
|
|
|
2018-06-19 16:07:00 +00:00
|
|
|
class DateSeparatorPopulator : Plugins.ConversationItemPopulator, Plugins.ConversationAdditionPopulator, Object {
|
2017-12-01 01:28:51 +00:00
|
|
|
|
|
|
|
public string id { get { return "date_separator"; } }
|
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
private Conversation? current_conversation;
|
|
|
|
private Plugins.ConversationItemCollection? item_collection;
|
|
|
|
private Gee.TreeSet<DateTime> insert_times;
|
|
|
|
|
|
|
|
public DateSeparatorPopulator(StreamInteractor stream_interactor) {
|
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(Conversation conversation, Plugins.ConversationItemCollection item_collection, Plugins.WidgetType type) {
|
|
|
|
current_conversation = conversation;
|
|
|
|
this.item_collection = item_collection;
|
2019-05-25 19:57:23 +00:00
|
|
|
item_collection.inserted_item.connect(on_inserted_item);
|
2017-12-01 01:28:51 +00:00
|
|
|
this.insert_times = new TreeSet<DateTime>((a, b) => {
|
|
|
|
return a.compare(b);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void close(Conversation conversation) {
|
2019-05-25 19:57:23 +00:00
|
|
|
item_collection.inserted_item.disconnect(on_inserted_item);
|
2017-12-01 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void populate_timespan(Conversation conversation, DateTime after, DateTime before) { }
|
|
|
|
|
2019-05-25 19:57:23 +00:00
|
|
|
private void on_inserted_item(Plugins.MetaConversationItem item) {
|
2020-01-22 00:24:14 +00:00
|
|
|
if (!(item is ContentMetaItem)) return;
|
2017-12-01 01:28:51 +00:00
|
|
|
|
2020-12-04 18:11:27 +00:00
|
|
|
DateTime time = item.time.to_local();
|
2017-12-01 01:28:51 +00:00
|
|
|
DateTime msg_date = new DateTime.local(time.get_year(), time.get_month(), time.get_day_of_month(), 0, 0, 0);
|
|
|
|
if (!insert_times.contains(msg_date)) {
|
|
|
|
if (insert_times.lower(msg_date) != null) {
|
|
|
|
item_collection.insert_item(new MetaDateItem(msg_date.to_utc()));
|
|
|
|
} else if (insert_times.size > 0) {
|
|
|
|
item_collection.insert_item(new MetaDateItem(insert_times.first().to_utc()));
|
|
|
|
}
|
|
|
|
insert_times.add(msg_date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MetaDateItem : Plugins.MetaConversationItem {
|
2020-12-04 18:11:27 +00:00
|
|
|
public override DateTime time { get; set; }
|
2017-12-01 01:28:51 +00:00
|
|
|
|
|
|
|
public MetaDateItem(DateTime date) {
|
2020-12-04 18:11:27 +00:00
|
|
|
this.time = date;
|
2017-12-01 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
public override Object? get_widget(Plugins.ConversationItemWidgetInterface outer, Plugins.WidgetType widget_type) {
|
2023-01-31 13:46:02 +00:00
|
|
|
return new DateSeparator() { model = new ViewModel.CompatDateSeparatorModel(time) };
|
2017-12-01 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 20:49:59 +00:00
|
|
|
public override Gee.List<Plugins.MessageAction>? get_item_actions(Plugins.WidgetType type) { return null; }
|
2017-12-01 01:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|