1
0
mirror of https://gitlab.gnome.org/World/tootle synced 2025-02-17 03:51:11 +01:00

Unscrew previous commit

This commit is contained in:
Bleak Grey 2020-07-28 21:38:37 +03:00
parent 9e3d854148
commit 6e129ed663
4 changed files with 128 additions and 143 deletions

View File

@ -96,7 +96,7 @@ public class Tootle.Dialogs.ListEditor: Gtk.Window {
new Request.GET (@"/api/v1/lists/$(list.id)/accounts")
.with_account (accounts.active)
// .with_context (this) //FIXME this
.with_ctx (this)
.on_error (on_error)
.then ((sess, msg) => {
Network.parse_array (msg, node => {
@ -146,7 +146,7 @@ public class Tootle.Dialogs.ListEditor: Gtk.Window {
search_req = new Request.GET ("/api/v1/accounts/search")
.with_account (accounts.active)
// .with_context (this) //FIXME this
.with_ctx (this)
.with_param ("resolve", "false")
.with_param ("limit", "8")
.with_param ("following", "true")

View File

@ -46,7 +46,7 @@ public class Tootle.Dialogs.MainWindow: Gtk.Window, ISavedWindow {
add_timeline_view (new Views.Home (), app.ACCEL_TIMELINE_0, 0);
add_timeline_view (new Views.Notifications (), app.ACCEL_TIMELINE_1, 1);
add_timeline_view (new Views.Local (), app.ACCEL_TIMELINE_2, 2);
add_timeline_view (new Views.Lists (), app.ACCEL_TIMELINE_3, 3);
add_timeline_view (new Views.Federated (), app.ACCEL_TIMELINE_3, 3);
settings.bind_property ("dark-theme", Gtk.Settings.get_default (), "gtk-application-prefer-dark-theme", BindingFlags.SYNC_CREATE);
settings.notify["post-text-size"].connect (() => on_zoom_level_changed ());

View File

@ -48,16 +48,6 @@ public class Tootle.Request : Soup.Message {
return this;
}
public Request then (owned Network.SuccessCallback cb) {
this.cb = (s, m) => {
Idle.add (() => {
cb (s, m);
return false;
});
};
return this;
}
public Request on_error (owned Network.ErrorCallback cb) {
this.error_cb = (owned) cb;
return this;
@ -118,11 +108,6 @@ public class Tootle.Request : Soup.Message {
return this;
}
public Request exec () {
this.priority = MessagePriority.HIGH;
return this.queue ();
}
public async Request await () throws Error {
string? error = null;
this.error_cb = (code, reason) => {
@ -132,7 +117,7 @@ public class Tootle.Request : Soup.Message {
this.cb = (sess, msg) => {
await.callback ();
};
this.queue ();
this.exec ();
yield;
if (error != null)

View File

@ -3,164 +3,164 @@ using Gdk;
public class Tootle.Views.Timeline : IAccountListener, IStreamListener, Views.Base {
public string url { get; construct set; }
public bool is_public { get; construct set; default = false; }
public Type accepts { get; set; default = typeof (API.Status); }
public string url { get; construct set; }
public bool is_public { get; construct set; default = false; }
public Type accepts { get; set; default = typeof (API.Status); }
protected InstanceAccount? account = null;
protected InstanceAccount? account = null;
public bool is_last_page { get; set; default = false; }
public string? page_next { get; set; }
public string? page_prev { get; set; }
public string? stream = null;
public bool is_last_page { get; set; default = false; }
public string? page_next { get; set; }
public string? page_prev { get; set; }
public string? stream = null;
construct {
app.refresh.connect (on_refresh);
status_button.clicked.connect (on_refresh);
account_listener_init ();
construct {
app.refresh.connect (on_refresh);
status_button.clicked.connect (on_refresh);
account_listener_init ();
on_status_added.connect (add_status);
on_status_removed.connect (remove_status);
}
~Timeline () {
streams.unsubscribe (stream, this);
}
on_status_added.connect (add_status);
on_status_removed.connect (remove_status);
}
~Timeline () {
streams.unsubscribe (stream, this);
}
public virtual bool is_status_owned (API.Status status) {
return status.is_owned ();
}
public virtual bool is_status_owned (API.Status status) {
return status.is_owned ();
}
public void prepend (Widget? w) {
append (w, true);
}
public void prepend (Widget? w) {
append (w, true);
}
public virtual void append (Widget? w, bool first = false) {
if (w == null) {
warning ("Attempted to add an empty widget");
return;
}
public virtual void append (Widget? w, bool first = false) {
if (w == null) {
warning ("Attempted to add an empty widget");
return;
}
if (first)
content_list.prepend (w);
else
content_list.insert (w, -1);
}
if (first)
content_list.prepend (w);
else
content_list.insert (w, -1);
}
public override void clear () {
this.page_prev = null;
this.page_next = null;
this.is_last_page = false;
base.clear ();
}
public override void clear () {
this.page_prev = null;
this.page_next = null;
this.is_last_page = false;
base.clear ();
}
public void get_pages (string? header) {
page_next = page_prev = null;
if (header == null)
return;
public void get_pages (string? header) {
page_next = page_prev = null;
if (header == null)
return;
var pages = header.split (",");
foreach (var page in pages) {
var sanitized = page
.replace ("<","")
.replace (">", "")
.split (";")[0];
var pages = header.split (",");
foreach (var page in pages) {
var sanitized = page
.replace ("<","")
.replace (">", "")
.split (";")[0];
if ("rel=\"prev\"" in page)
page_prev = sanitized;
else
page_next = sanitized;
}
if ("rel=\"prev\"" in page)
page_prev = sanitized;
else
page_next = sanitized;
}
is_last_page = page_prev != null & page_next == null;
}
is_last_page = page_prev != null & page_next == null;
}
public virtual string get_req_url () {
if (page_next != null)
return page_next;
return url;
}
public virtual string get_req_url () {
if (page_next != null)
return page_next;
return url;
}
public virtual Request append_params (Request req) {
if (page_next == null)
return req.with_param ("limit", @"$(settings.timeline_page_size)");
else
return req;
}
public virtual Request append_params (Request req) {
if (page_next == null)
return req.with_param ("limit", @"$(settings.timeline_page_size)");
else
return req;
}
public virtual void on_request_finish () {}
public virtual bool request () {
public virtual bool request () {
var req = append_params (new Request.GET (get_req_url ()))
.with_account (account)
.with_ctx (this)
.then ((sess, msg) => {
Network.parse_array (msg, node => {
try {
var e = Entity.from_json (accepts, node);
var w = e as Widgetizable;
append (w.to_widget ());
}
catch (Error e) {
warning (@"Timeline item parse error: $(e.message)");
}
});
Network.parse_array (msg, node => {
try {
var e = Entity.from_json (accepts, node);
var w = e as Widgetizable;
append (w.to_widget ());
}
catch (Error e) {
warning (@"Timeline item parse error: $(e.message)");
}
});
get_pages (mess.response_headers.get_one ("Link"));
on_content_changed ();
on_request_finish ();
})
get_pages (msg.response_headers.get_one ("Link"));
on_content_changed ();
on_request_finish ();
})
.on_error (on_error);
req.exec ();
return GLib.Source.REMOVE;
}
}
public virtual void on_refresh () {
status_button.sensitive = false;
clear ();
status_message = STATUS_LOADING;
GLib.Idle.add (request);
}
public virtual void on_refresh () {
status_button.sensitive = false;
clear ();
status_message = STATUS_LOADING;
GLib.Idle.add (request);
}
public virtual string? get_stream_url () {
return null;
}
public virtual string? get_stream_url () {
return null;
}
public virtual void on_account_changed (InstanceAccount? acc) {
account = acc;
reconnect_stream ();
on_refresh ();
}
public virtual void on_account_changed (InstanceAccount? acc) {
account = acc;
reconnect_stream ();
on_refresh ();
}
public void reconnect_stream () {
public void reconnect_stream () {
streams.unsubscribe (stream, this);
streams.subscribe (get_stream_url (), this, out stream);
}
streams.subscribe (get_stream_url (), this, out stream);
}
protected override void on_bottom_reached () {
if (is_last_page) {
info ("Last page reached");
return;
}
request ();
}
protected override void on_bottom_reached () {
if (is_last_page) {
info ("Last page reached");
return;
}
request ();
}
protected virtual void add_status (API.Status status) {
var allow_update = true;
if (is_public)
allow_update = settings.public_live_updates;
protected virtual void add_status (API.Status status) {
var allow_update = true;
if (is_public)
allow_update = settings.public_live_updates;
if (settings.live_updates && allow_update)
prepend (status.to_widget ());
}
if (settings.live_updates && allow_update)
prepend (status.to_widget ());
}
protected virtual void remove_status (string id) {
if (settings.live_updates) {
content.get_children ().@foreach (w => {
var sw = w as Widgets.Status;
if (sw != null && sw.status.id == id)
sw.destroy ();
});
}
}
protected virtual void remove_status (string id) {
if (settings.live_updates) {
content.get_children ().@foreach (w => {
var sw = w as Widgets.Status;
if (sw != null && sw.status.id == id)
sw.destroy ();
});
}
}
}