Correctly display spoilers

This commit is contained in:
bleakgrey 2018-04-23 19:43:29 +03:00
parent c45ef06e92
commit 03e1c87fcf
2 changed files with 25 additions and 4 deletions

View File

@ -4,6 +4,7 @@ public class Tootle.Status{
public int64 id;
public string uri;
public string url;
public string? spoiler_text;
public string content;
public int64 reblogs_count;
public int64 favourites_count;
@ -48,6 +49,9 @@ public class Tootle.Status{
status.reblogs_count = obj.get_int_member ("reblogs_count");
status.favourites_count = obj.get_int_member ("favourites_count");
status.content = escape_html ( obj.get_string_member ("content"));
var spoiler = obj.get_string_member ("spoiler_text");
if (spoiler != "")
status.spoiler_text = escape_html (spoiler);
if(obj.has_member ("reblogged"))
status.reblogged = obj.get_boolean_member ("reblogged");

View File

@ -14,9 +14,12 @@ public class Tootle.StatusWidget : Gtk.Grid {
Gtk.Box counters;
Gtk.Label reblogs;
Gtk.Label favorites;
Gtk.ToggleButton reblog;
Gtk.ToggleButton favorite;
Gtk.Box? spoiler_box;
Gtk.Label? spoiler_content;
Gtk.Button? spoiler_button;
construct {
margin = 6;
@ -60,10 +63,10 @@ public class Tootle.StatusWidget : Gtk.Grid {
counters.add(favorites);
counters.show_all ();
attach(avatar, 1, 1, 1, 3);
attach(avatar, 1, 1, 1, 4);
attach(user, 2, 2, 1, 1);
attach(content, 2, 3, 1, 1);
attach(counters, 2, 4, 1, 1);
attach(content, 2, 4, 1, 1);
attach(counters, 2, 5, 1, 1);
show_all(); //TODO: display conversations
}
@ -88,6 +91,18 @@ public class Tootle.StatusWidget : Gtk.Grid {
attach (label, 2, 0, 2, 1);
}
if (status.spoiler_text != null){
content.hide ();
spoiler_button = new Button.with_label (_("Show content"));
spoiler_button.clicked.connect (() => content.visible = !content.visible);
spoiler_content = new Label (status.spoiler_text);
spoiler_box = new Box (Gtk.Orientation.HORIZONTAL, 6);
spoiler_box.add (spoiler_content);
spoiler_box.add (spoiler_button);
spoiler_box.show_all ();
attach(spoiler_box, 2, 3, 1, 1);
}
destroy.connect (() => {
if(separator != null)
separator.destroy ();
@ -96,6 +111,8 @@ public class Tootle.StatusWidget : Gtk.Grid {
public void highlight (){
content.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
if (spoiler_content != null)
spoiler_content.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
avatar_size = 48;
avatar.show_default (avatar_size);
}