Handle toot links in the app

This commit is contained in:
bleakgrey 2018-06-02 11:37:28 +03:00
parent 7917f11f1d
commit ef878d7330
3 changed files with 35 additions and 11 deletions

View File

@ -237,9 +237,9 @@ public class Tootle.AccountView : TimelineView {
var url = "%s/api/v1/accounts/%lld".printf (Tootle.accounts.formal.instance, id);
var msg = new Soup.Message("GET", url);
msg.priority = Soup.MessagePriority.HIGH;
Tootle.network.queue(msg, (sess, mess) => {
network.queue (msg, (sess, mess) => {
try{
var root = Tootle.network.parse (mess);
var root = network.parse (mess);
var acc = Account.parse (root);
Tootle.window.open_view (new AccountView (acc));
}
@ -254,19 +254,18 @@ public class Tootle.AccountView : TimelineView {
var url = "%s/api/v1/accounts/search?limit=1&q=%s".printf (Tootle.accounts.formal.instance, name);
var msg = new Soup.Message("GET", url);
msg.priority = Soup.MessagePriority.HIGH;
Tootle.network.queue(msg, (sess, mess) => {
network.queue (msg, (sess, mess) => {
try{
var node = Tootle.network.parse_array (mess).get_element (0);
var node = network.parse_array (mess).get_element (0);
var object = node.get_object ();
if (object != null){
var acc = Account.parse(object);
Tootle.window.open_view (new AccountView (acc));
window.open_view (new AccountView (acc));
}
else
warning ("No results found for account: "+name); //TODO: toast notifications
app.toast (_("User not found"));
}
catch (GLib.Error e) {
warning ("Can't update feed");
warning (e.message);
}
});

View File

@ -33,7 +33,7 @@ public class Tootle.StatusView : AbstractView {
public Soup.Message request_context (){
var url = "%s/api/v1/statuses/%lld/context".printf (Tootle.accounts.formal.instance, root_status.id);
var msg = new Soup.Message("GET", url);
Tootle.network.queue(msg, (sess, mess) => {
network.queue (msg, (sess, mess) => {
try{
var root = Tootle.network.parse (mess);
@ -65,6 +65,26 @@ public class Tootle.StatusView : AbstractView {
return msg;
}
public static void open_from_link (string q){
var url = "%s/api/v1/search?q=%s&resolve=true".printf (accounts.formal.instance, q);
var msg = new Soup.Message("GET", url);
msg.priority = Soup.MessagePriority.HIGH;
network.queue (msg, (sess, mess) => {
try{
var root = network.parse (mess);
var statuses = root.get_array_member ("statuses");
var object = statuses.get_element (0).get_object ();
if (object != null){
var st = Status.parse (object);
window.open_view (new StatusView (ref st));
}
else
app.toast (_("Toot not found"));
}
catch (GLib.Error e) {
warning (e.message);
}
});
}
}

View File

@ -40,7 +40,12 @@ public class Tootle.RichLabel : Gtk.Label {
if ("/@" in url){
var uri = new Soup.URI (url);
var username = url.split("/@")[1];
AccountView.open_from_name ("@" + username + "@" + uri.get_host ());
if ("/" in username)
StatusView.open_from_link (url);
else
AccountView.open_from_name ("@" + username + "@" + uri.get_host ());
return true;
}