From 25709caed2452caf8f4507d2a50d18b0d4e8bb1f Mon Sep 17 00:00:00 2001 From: GeopJr Date: Sat, 1 Jul 2023 04:02:24 +0300 Subject: [PATCH] feat(Profile): bot badge (#336) * feat(Profile): bot badge * chore: initial visible false --- data/gresource.xml | 1 + .../actions/tuba-brain-augemnted-symbolic.svg | 2 + data/style.css | 4 ++ data/ui/views/profile_header.ui | 27 +++++++--- src/API/Account.vala | 1 + src/Views/Profile.vala | 49 ++++++++++++++++--- 6 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 data/icons/scalable/actions/tuba-brain-augemnted-symbolic.svg diff --git a/data/gresource.xml b/data/gresource.xml index 4386d95c8..6045ee205 100644 --- a/data/gresource.xml +++ b/data/gresource.xml @@ -62,6 +62,7 @@ icons/scalable/actions/tuba-explore2-large-symbolic.svg icons/scalable/actions/tuba-text-justify-left-symbolic.svg icons/scalable/actions/tuba-cat-symbolic.svg + icons/scalable/actions/tuba-brain-augemnted-symbolic.svg gtk/help-overlay.ui diff --git a/data/icons/scalable/actions/tuba-brain-augemnted-symbolic.svg b/data/icons/scalable/actions/tuba-brain-augemnted-symbolic.svg new file mode 100644 index 000000000..473fb805d --- /dev/null +++ b/data/icons/scalable/actions/tuba-brain-augemnted-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/style.css b/data/style.css index ddf040168..6e1c91e0c 100644 --- a/data/style.css +++ b/data/style.css @@ -30,6 +30,10 @@ flowboxchild { margin: 8px; } +.cover-badge.only-icon { + padding: 6px; +} + .ttl-flat-button { padding: 0px; margin: 0px; diff --git a/data/ui/views/profile_header.ui b/data/ui/views/profile_header.ui index 481433a6d..565130f15 100644 --- a/data/ui/views/profile_header.ui +++ b/data/ui/views/profile_header.ui @@ -23,18 +23,33 @@ - - Follows you - 0 + end start - 48 - 0 + 48 + 6 + 0 + + + tuba-brain-augemnted-symbolic + Bot + 0 + + + + + Follows you + 0 + 0 + + diff --git a/src/API/Account.vala b/src/API/Account.vala index 977dc418a..3235e9d07 100644 --- a/src/API/Account.vala +++ b/src/API/Account.vala @@ -22,6 +22,7 @@ public class Tuba.API.Account : Entity, Widgetizable { public string header { get; set; } public string avatar { get; set; } public string url { get; set; } + public bool bot { get; set; default=false; } public string created_at { get; set; } public Gee.ArrayList? emojis { get; set; } public int64 followers_count { get; set; } diff --git a/src/Views/Profile.vala b/src/Views/Profile.vala index ac229551b..27bb613b2 100644 --- a/src/Views/Profile.vala +++ b/src/Views/Profile.vala @@ -9,7 +9,6 @@ public class Tuba.Views.Profile : Views.Timeline { public string source { get; set; default = "statuses"; } protected Cover cover; - protected Label cover_badge; protected MenuButton menu_button; protected SimpleAction media_action; @@ -23,7 +22,6 @@ public class Tuba.Views.Profile : Views.Timeline { construct { cover = build_cover (); - cover_badge = cover.cover_badge; cover.rsbtn.rs = this.rs; column_view.prepend (cover); } @@ -79,7 +77,9 @@ public class Tuba.Views.Profile : Views.Timeline { protected class Cover : Box { [GtkChild] unowned Widgets.BackgroundWrapper background; - [GtkChild] public unowned Label cover_badge; + [GtkChild] unowned Label cover_badge; + [GtkChild] unowned Image cover_bot_badge; + [GtkChild] unowned Box cover_badge_box; [GtkChild] public unowned ListBox info; [GtkChild] unowned Widgets.EmojiLabel display_name; [GtkChild] unowned Label handle; @@ -87,6 +87,42 @@ public class Tuba.Views.Profile : Views.Timeline { [GtkChild] unowned Widgets.MarkupView note; [GtkChild] public unowned Widgets.RelationshipButton rsbtn; + public string cover_badge_label { + get { + return cover_badge.label; + } + + set { + var has_label = value != ""; + cover_badge.visible = has_label; + cover_badge.label = value; + + update_cover_badge (); + } + } + + public bool is_bot { + get { + return cover_bot_badge.visible; + } + + set { + cover_bot_badge.visible = value; + + update_cover_badge (); + } + } + + private void update_cover_badge () { + cover_badge_box.visible = cover_badge.visible || is_bot; + + if (is_bot && !cover_badge.visible) { + cover_badge_box.add_css_class ("only-icon"); + } else { + cover_badge_box.remove_css_class ("only-icon"); + } + } + public void bind (API.Account account) { display_name.instance_emojis = account.emojis_map; display_name.content = account.display_name; @@ -94,6 +130,8 @@ public class Tuba.Views.Profile : Views.Timeline { avatar.account = account; note.instance_emojis = account.emojis_map; note.content = account.note; + cover_bot_badge.visible = account.bot; + update_cover_badge (); if (account.id != accounts.active.id) rsbtn.visible = true; @@ -299,7 +337,6 @@ public class Tuba.Views.Profile : Views.Timeline { blocking_action.change_state.connect (v => { var block = v.get_boolean (); var q = block ? _("Block \"%s\"?") : _("Unblock \"%s\"?"); - warning (q); var confirmed = app.question ( q.printf (profile.handle), @@ -383,9 +420,7 @@ public class Tuba.Views.Profile : Views.Timeline { label = _("Follows you"); } - cover_badge.label = label; - cover_badge.visible = label != ""; - + cover.cover_badge_label = label; invalidate_actions (false); }