public class Tuba.Views.Conversations : Views.Timeline {
	public Conversations () {
		Object (
			url: "/api/v1/conversations",
			// translators: same as mastodon web / aka direct or private messages (but not really)
			label: _("Conversations"),
			icon: "tuba-mail-unread-symbolic",
			// translators: empty state label
			empty_state_title: _("No Conversations")
		);
	}


	construct {
		accepts = typeof (API.Conversation);
		stream_event[InstanceAccount.EVENT_CONVERSATION].connect (on_new_post);
	}

	public override bool should_hide (Entity entity) {
		var conversation_entity = entity as API.Conversation;
		if (conversation_entity != null && conversation_entity.last_status != null) {
			return base.should_hide (conversation_entity.last_status);
		}

		return false;
	}

	public override string? get_stream_url () {
		return account != null
			? @"$(account.tuba_streaming_url)/api/v1/streaming?stream=direct&access_token=$(account.access_token)"
			: null;
	}

	public override void on_content_changed () {
		for (uint i = 0; i < model.get_n_items (); i++) {
			var convo_obj = (API.Conversation) model.get_item (i);
			if (convo_obj.last_status == null) {
				safely_remove ((int) i);
			}
		}
		base.on_content_changed ();
	}

	public override void on_delete_post (Streamable.Event ev) {
		try {
			var convo_id = ev.get_string ();

			for (uint i = 0; i < model.get_n_items (); i++) {
				var convo_obj = (API.Conversation) model.get_item (i);
				if (convo_obj.last_status != null && convo_obj.last_status.id == convo_id) {
					safely_remove ((int) i);
					break;
				}
			}
		} catch (Error e) {
			warning (@"Error getting String from json: $(e.message)");
		}
	}
}
