2018-04-19 19:03:28 +00:00
|
|
|
using Gtk;
|
|
|
|
|
2022-11-13 20:57:43 +00:00
|
|
|
public class Tooth.Views.Thread : Views.ContentBase, AccountHolder {
|
2018-04-19 19:03:28 +00:00
|
|
|
|
2021-07-23 11:41:03 +00:00
|
|
|
protected InstanceAccount? account { get; set; }
|
|
|
|
public API.Status root_status { get; set; }
|
|
|
|
protected unowned Widgets.Status root_widget;
|
2020-10-24 10:54:37 +00:00
|
|
|
|
|
|
|
public Thread (API.Status status) {
|
|
|
|
Object (
|
|
|
|
root_status: status,
|
2023-02-15 22:35:09 +00:00
|
|
|
status_loading: true,
|
2020-10-24 10:54:37 +00:00
|
|
|
label: _("Conversation")
|
|
|
|
);
|
2021-07-23 11:41:03 +00:00
|
|
|
construct_account_holder ();
|
|
|
|
}
|
|
|
|
~Thread () {
|
|
|
|
message ("Destroying Thread");
|
|
|
|
destruct_account_holder ();
|
2020-10-24 10:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void on_account_changed (InstanceAccount? acc) {
|
|
|
|
account = acc;
|
|
|
|
request ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void connect_threads () {
|
|
|
|
Widgets.Status? last_w = null;
|
|
|
|
string? last_id = null;
|
|
|
|
|
2021-07-23 11:41:03 +00:00
|
|
|
for (var w = content.get_row_at_index (0) as Widgets.Status;
|
|
|
|
w != null;
|
|
|
|
w = w.get_next_sibling () as Widgets.Status) {
|
2022-11-27 01:32:16 +00:00
|
|
|
w.is_conversation_open = true;
|
2021-07-23 11:41:03 +00:00
|
|
|
|
2020-10-24 10:54:37 +00:00
|
|
|
var id = w.status.formal.in_reply_to_id;
|
|
|
|
|
|
|
|
if (id == last_id) {
|
|
|
|
Widgets.Status.ThreadRole.connect_posts (last_w, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
last_w = w;
|
|
|
|
last_id = w.status.formal.id;
|
2021-07-23 11:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var w = content.get_row_at_index (0) as Widgets.Status;
|
|
|
|
w != null;
|
|
|
|
w = w.get_next_sibling () as Widgets.Status) {
|
2020-10-24 10:54:37 +00:00
|
|
|
|
|
|
|
w.install_thread_line ();
|
2023-01-15 03:54:51 +00:00
|
|
|
w.content.selectable = true;
|
2021-07-23 11:41:03 +00:00
|
|
|
}
|
2020-10-24 10:54:37 +00:00
|
|
|
|
|
|
|
root_widget.thread_line.hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void request () {
|
|
|
|
new Request.GET (@"/api/v1/statuses/$(root_status.id)/context")
|
|
|
|
.with_account (account)
|
|
|
|
.with_ctx (this)
|
|
|
|
.then ((sess, msg) => {
|
|
|
|
var root = network.parse (msg);
|
|
|
|
|
|
|
|
var ancestors = root.get_array_member ("ancestors");
|
|
|
|
ancestors.foreach_element ((array, i, node) => {
|
2021-07-23 11:41:03 +00:00
|
|
|
var e = entity_cache.lookup_or_insert (node, typeof (API.Status));
|
|
|
|
model.append (e);
|
2020-10-24 10:54:37 +00:00
|
|
|
});
|
|
|
|
|
2021-07-23 11:41:03 +00:00
|
|
|
model.append (root_status);
|
|
|
|
uint root_index;
|
|
|
|
model.find (root_status, out root_index);
|
|
|
|
root_widget = content.get_row_at_index ((int)root_index) as Widgets.Status;
|
2020-10-24 10:54:37 +00:00
|
|
|
root_widget.expand_root ();
|
|
|
|
|
|
|
|
var descendants = root.get_array_member ("descendants");
|
|
|
|
descendants.foreach_element ((array, i, node) => {
|
2021-07-23 11:41:03 +00:00
|
|
|
var e = entity_cache.lookup_or_insert (node, typeof (API.Status));
|
|
|
|
model.append (e);
|
2020-10-24 10:54:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
connect_threads ();
|
|
|
|
on_content_changed ();
|
|
|
|
|
2021-07-23 11:41:03 +00:00
|
|
|
//FIXME: scroll to expanded post
|
|
|
|
// int x,y;
|
|
|
|
// translate_coordinates (root_widget, 0, header.get_allocated_height (), out x, out y);
|
|
|
|
// scrolled.vadjustment.value = (double)(y*-1);
|
2020-10-24 10:54:37 +00:00
|
|
|
})
|
|
|
|
.exec ();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void open_from_link (string q) {
|
|
|
|
new Request.GET ("/api/v1/search")
|
|
|
|
.with_account ()
|
|
|
|
.with_param ("q", q)
|
|
|
|
.with_param ("resolve", "true")
|
|
|
|
.then ((sess, msg) => {
|
|
|
|
var root = network.parse (msg);
|
|
|
|
var statuses = root.get_array_member ("statuses");
|
|
|
|
var node = statuses.get_element (0);
|
|
|
|
if (node != null){
|
|
|
|
var status = API.Status.from (node);
|
2021-07-23 11:41:03 +00:00
|
|
|
app.main_window.open_view (new Views.Thread (status));
|
2020-10-24 10:54:37 +00:00
|
|
|
}
|
|
|
|
else
|
2021-07-23 11:41:03 +00:00
|
|
|
Host.open_uri (q);
|
2020-10-24 10:54:37 +00:00
|
|
|
})
|
|
|
|
.exec ();
|
|
|
|
}
|
2019-03-12 08:12:53 +00:00
|
|
|
|
2018-06-02 08:37:28 +00:00
|
|
|
}
|