Handle toot links in the app
This commit is contained in:
parent
7917f11f1d
commit
ef878d7330
|
@ -237,9 +237,9 @@ public class Tootle.AccountView : TimelineView {
|
||||||
var url = "%s/api/v1/accounts/%lld".printf (Tootle.accounts.formal.instance, id);
|
var url = "%s/api/v1/accounts/%lld".printf (Tootle.accounts.formal.instance, id);
|
||||||
var msg = new Soup.Message("GET", url);
|
var msg = new Soup.Message("GET", url);
|
||||||
msg.priority = Soup.MessagePriority.HIGH;
|
msg.priority = Soup.MessagePriority.HIGH;
|
||||||
Tootle.network.queue(msg, (sess, mess) => {
|
network.queue (msg, (sess, mess) => {
|
||||||
try{
|
try{
|
||||||
var root = Tootle.network.parse (mess);
|
var root = network.parse (mess);
|
||||||
var acc = Account.parse (root);
|
var acc = Account.parse (root);
|
||||||
Tootle.window.open_view (new AccountView (acc));
|
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 url = "%s/api/v1/accounts/search?limit=1&q=%s".printf (Tootle.accounts.formal.instance, name);
|
||||||
var msg = new Soup.Message("GET", url);
|
var msg = new Soup.Message("GET", url);
|
||||||
msg.priority = Soup.MessagePriority.HIGH;
|
msg.priority = Soup.MessagePriority.HIGH;
|
||||||
Tootle.network.queue(msg, (sess, mess) => {
|
network.queue (msg, (sess, mess) => {
|
||||||
try{
|
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 ();
|
var object = node.get_object ();
|
||||||
if (object != null){
|
if (object != null){
|
||||||
var acc = Account.parse(object);
|
var acc = Account.parse(object);
|
||||||
Tootle.window.open_view (new AccountView (acc));
|
window.open_view (new AccountView (acc));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warning ("No results found for account: "+name); //TODO: toast notifications
|
app.toast (_("User not found"));
|
||||||
}
|
}
|
||||||
catch (GLib.Error e) {
|
catch (GLib.Error e) {
|
||||||
warning ("Can't update feed");
|
|
||||||
warning (e.message);
|
warning (e.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class Tootle.StatusView : AbstractView {
|
||||||
public Soup.Message request_context (){
|
public Soup.Message request_context (){
|
||||||
var url = "%s/api/v1/statuses/%lld/context".printf (Tootle.accounts.formal.instance, root_status.id);
|
var url = "%s/api/v1/statuses/%lld/context".printf (Tootle.accounts.formal.instance, root_status.id);
|
||||||
var msg = new Soup.Message("GET", url);
|
var msg = new Soup.Message("GET", url);
|
||||||
Tootle.network.queue(msg, (sess, mess) => {
|
network.queue (msg, (sess, mess) => {
|
||||||
try{
|
try{
|
||||||
var root = Tootle.network.parse (mess);
|
var root = Tootle.network.parse (mess);
|
||||||
|
|
||||||
|
@ -65,6 +65,26 @@ public class Tootle.StatusView : AbstractView {
|
||||||
return msg;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,12 @@ public class Tootle.RichLabel : Gtk.Label {
|
||||||
if ("/@" in url){
|
if ("/@" in url){
|
||||||
var uri = new Soup.URI (url);
|
var uri = new Soup.URI (url);
|
||||||
var username = url.split("/@")[1];
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue