From 68ee41dc1a243a4290e5fae5c08cb5bc663dbade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20Yi=C4=9Fit=20=C5=9Eahin?= Date: Wed, 24 Oct 2018 12:00:40 +0300 Subject: [PATCH] Allow pinning/unpinning toots (#83) Close #24 --- src/API/Status.vala | 18 ++++++++++++++++++ src/Widgets/StatusWidget.vala | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/API/Status.vala b/src/API/Status.vala index a67cd7e..0761257 100644 --- a/src/API/Status.vala +++ b/src/API/Status.vala @@ -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; diff --git a/src/Widgets/StatusWidget.vala b/src/Widgets/StatusWidget.vala index c16c81b..ec40000 100644 --- a/src/Widgets/StatusWidget.vala +++ b/src/Widgets/StatusWidget.vala @@ -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 ()); }