Allow pinning/unpinning toots (#83)

Close #24
This commit is contained in:
Çağatay Yiğit Şahin 2018-10-24 12:00:40 +03:00 committed by Bleak Grey
parent 21e0089cf8
commit 68ee41dc1a
2 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,7 @@ public class Tootle.Status {
public bool favorited = false;
public bool sensitive = false;
public bool muted = false;
public bool pinned = false;
public StatusVisibility visibility;
public Status? reblog;
public Mention[]? mentions;
@ -56,6 +57,8 @@ public class Tootle.Status {
status.favorited = obj.get_boolean_member ("favourited");
if (obj.has_member ("muted"))
status.muted = obj.get_boolean_member ("muted");
if (obj.has_member ("pinned"))
status.pinned = obj.get_boolean_member ("pinned");
if (obj.has_member ("reblog") && obj.get_null_member("reblog") != true)
status.reblog = Status.parse (obj.get_object_member ("reblog"));
@ -148,6 +151,21 @@ public class Tootle.Status {
network.queue (msg);
}
public void set_pinned (bool pin = true){
var action = pin ? "pin" : "unpin";
var msg = new Soup.Message("POST", "%s/api/v1/statuses/%lld/%s".printf (Tootle.accounts.formal.instance, id, action));
msg.priority = Soup.MessagePriority.HIGH;
msg.finished.connect (() => {
pinned = pin;
updated ();
if (pin)
Tootle.app.toast (_("Pinned!"));
else
Tootle.app.toast (_("Unpinned"));
});
Tootle.network.queue (msg);
}
public void poof (){
var msg = new Soup.Message("DELETE", "%s/api/v1/statuses/%lld".printf (accounts.formal.instance, id));
msg.priority = Soup.MessagePriority.HIGH;

View File

@ -271,8 +271,11 @@ public class Tootle.StatusWidget : Gtk.EventBox {
var menu = new Gtk.Menu ();
var is_muted = status.muted;
var is_pinned = status.pinned;
var item_muting = new Gtk.MenuItem.with_label (is_muted ? _("Unmute Conversation") : _("Mute Conversation"));
item_muting.activate.connect (() => status.set_muted (!is_muted));
var item_pin = new Gtk.MenuItem.with_label (is_pinned ? _("Unpin from Profile") : _("Pin on Profile"));
item_pin.activate.connect (() => status.set_pinned (!is_pinned));
var item_delete = new Gtk.MenuItem.with_label (_("Delete"));
item_delete.activate.connect (() => status.poof ());
var item_open_link = new Gtk.MenuItem.with_label (_("Open in Browser"));
@ -286,6 +289,7 @@ public class Tootle.StatusWidget : Gtk.EventBox {
});
if (this.status.is_owned ()) {
menu.add (item_pin);
menu.add (item_delete);
menu.add (new Gtk.SeparatorMenuItem ());
}