Skip to content

Commit

Permalink
feat: Announcements (#417)
Browse files Browse the repository at this point in the history
* feat: Announcements

* fix: statement

* chore: lint

* feat: respect settings
  • Loading branch information
GeopJr authored Aug 6, 2023
1 parent 5c4467b commit 343acf4
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-text-justify-left-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-cat-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-brain-augemnted-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-lightbulb-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-important-small-symbolic.svg</file>
<!-- <file preprocess="xml-stripblanks">icons/scalable/actions/tuba-language-symbolic.svg</file> -->

<file>gtk/help-overlay.ui</file>
Expand All @@ -78,6 +80,7 @@
<file>ui/views/sidebar/view.ui</file>
<file>ui/views/sidebar/account.ui</file>
<file>ui/views/sidebar/item.ui</file>
<file>ui/widgets/announcement.ui</file>
<file>ui/widgets/status.ui</file>
<file>ui/widgets/votebox.ui</file>
<file>ui/dialogs/new_account.ui</file>
Expand Down
2 changes: 2 additions & 0 deletions data/icons/scalable/actions/tuba-important-small-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/icons/scalable/actions/tuba-lightbulb-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,7 @@ video > overlay > revealer > controls {
border-radius: 100%;
padding: 3px;
}

.attention {
color: @yellow_4;
}
154 changes: 154 additions & 0 deletions data/ui/widgets/announcement.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<template class="TubaWidgetsAnnouncement" parent="GtkListBoxRow">
<property name="child">
<object class="GtkBox">
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<property name="margin_top">15</property>
<property name="margin_bottom">18</property>
<property name="hexpand">1</property>
<property name="orientation">horizontal</property>
<property name="spacing">14</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="AdwAvatar" id="avatar">
<property name="size">48</property>
<property name="valign">start</property>
<property name="visible">true</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="vexpand">1</property>
<property name="spacing">6</property>
<property name="valign">start</property>
<child>
<object class="GtkFlowBox">
<property name="selection-mode">none</property>
<property name="column_spacing">6</property>
<!-- Lower values leave space between items -->
<property name="max_children_per_line">100</property>
<child>
<object class="GtkFlowBoxChild">
<property name="focusable">0</property>
<child>
<object class="TubaWidgetsRichLabel" id="name_label">
<property name="visible">True</property>
<property name="ellipsize">False</property>
<property name="use-markup">False</property>
<property name="smaller-emoji-pixel-size">True</property>
<style>
<class name="font-bold" />
<class name="ttl-name-button" />
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkFlowBoxChild">
<property name="can-target">0</property>
<child>
<object class="GtkLabel" id="handle_label">
<property name="label" translatable="no">Handle</property>
<property name="ellipsize">end</property>
<property name="single_line_mode">1</property>
<property name="xalign">0</property>
<property name="hexpand">1</property>
<style>
<class name="body" />
<class name="dim-label" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="margin_start">6</property>
<property name="spacing">3</property>
<child>
<object class="GtkImage" id="attention_indicator">
<property name="visible">0</property>
<property name="icon_name">tuba-important-small-symbolic</property>
<property name="icon_size">1</property>
<property name="tooltip_text" translatable="yes">Unread</property>
<style>
<class name="attention" />
</style>
</object>
</child>
<child>
<object class="GtkImage" id="edited_indicator">
<property name="visible">0</property>
<property name="icon_name">tuba-paper-small-symbolic</property>
<property name="icon_size">1</property>
<property name="tooltip_text" translatable="yes">Edited</property>
<style>
<class name="dim-label" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="date_label">
<property name="label" translatable="no">Yesterday</property>
<property name="xalign">0</property>
<style>
<class name="body" />
<class name="dim-label" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>

<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<style>
<class name="ttl-status-content" />
</style>
<child>
<object class="TubaWidgetsMarkupView" id="content">
<property name="visible">True</property>
<property name="hexpand">False</property>
</object>
</child>
</object>
</child>

<child>
<object class="GtkFlowBox" id="emoji_reactions">
<property name="margin-top">16</property>
<property name="visible">0</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<!-- Lower values leave space between items -->
<property name="max_children_per_line">100</property>
</object>
</child>
</object>
</child>
</object>
</property>
<style>
<class name="ttl-post" />
</style>
</template>
</interface>
32 changes: 32 additions & 0 deletions src/API/Announcement.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Tuba.API.Announcement : Entity, Widgetizable {
public string id { get; set; }
public string content { get; set; }
public bool published { get; set; default=true; }
public string published_at { get; set; }
public string updated_at { get; set; }
public bool read { get; set; default=true; }
public Gee.ArrayList<API.Emoji>? emojis { get; set; }
public Gee.ArrayList<API.EmojiReaction>? reactions { get; set; default = null; }

public Gee.HashMap<string, string>? emojis_map {
owned get {
return gen_emojis_map ();
}
}

private Gee.HashMap<string, string>? gen_emojis_map () {
var res = new Gee.HashMap<string, string> ();
if (emojis != null && emojis.size > 0) {
emojis.@foreach (e => {
res.set (e.shortcode, e.url);
return true;
});
}

return res;
}

public override Gtk.Widget to_widget () {
return new Widgets.Announcement (this);
}
}
4 changes: 4 additions & 0 deletions src/API/Instance.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
public class Tuba.API.Instance : Entity {
public string uri { get; set; default=""; }
public string title { get; set; default=""; }
public string thumbnail { get; set; default=null; }

public Gee.ArrayList<string>? languages { get; set; }
public API.Mastodon.Configurations? configuration { get; set; default = null; }
public int64 max_toot_chars { get; set; default = 0; }
Expand Down
1 change: 1 addition & 0 deletions src/API/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sources += files(
'Account.vala',
'AccountField.vala',
'Announcement.vala',
# 'Akkoma.vala', # uneeded for now
'Attachment.vala',
'BookWyrm.vala',
Expand Down
10 changes: 10 additions & 0 deletions src/Services/Accounts/Mastodon/Account.vala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ public class Tuba.Mastodon.Account : InstanceAccount {
}
};

public static Place PLACE_ANNOUNCEMENTS = new Place () { // vala-lint=naming-convention

icon = "tuba-lightbulb-symbolic",
title = _("Announcements"),
open_func = (win) => {
win.open_view (set_as_sidebar_item (new Views.Announcements ()));
}
};

public override void register_known_places (GLib.ListStore places) {
places.append (PLACE_HOME);
// places.append (PLACE_SEARCH);
Expand All @@ -144,6 +153,7 @@ public class Tuba.Mastodon.Account : InstanceAccount {

places.append (PLACE_HASHTAGS);
places.append (PLACE_FOLLOW_REQUESTS);
places.append (PLACE_ANNOUNCEMENTS);
}

construct {
Expand Down
10 changes: 10 additions & 0 deletions src/Views/Announcements.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Tuba.Views.Announcements : Views.Timeline {
public Announcements () {
Object (
url: "/api/v1/announcements?with_dismissed=true",
label: _("Announcements"),
icon: "tuba-lightbulb-symbolic"
);
accepts = typeof (API.Announcement);
}
}
1 change: 1 addition & 0 deletions src/Views/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sources += files(
'Announcements.vala',
'Base.vala',
'Bookmarks.vala',
'ContentBase.vala',
Expand Down
Loading

0 comments on commit 343acf4

Please sign in to comment.