Skip to content

Commit

Permalink
feat(notifications): moderation_warning (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Nov 17, 2024
1 parent 78234f8 commit b010ce6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-heart-filled-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-birthday-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-transparent-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/tuba-police-badge2-symbolic.svg</file>
<!-- <file preprocess="xml-stripblanks">icons/scalable/actions/tuba-language-symbolic.svg</file> -->

<file>gtk/help-overlay.ui</file>
Expand Down
2 changes: 2 additions & 0 deletions data/icons/scalable/actions/tuba-police-badge2-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 34 additions & 9 deletions src/API/Notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public class Tuba.API.Notification : Entity, Widgetizable {
}
}

public class ModerationWarning : Entity {
public string id { get; set; }
}

public string id { get; set; }
public API.Account account { get; set; }
public string? kind { get; set; default = null; }
Expand All @@ -65,6 +69,7 @@ public class Tuba.API.Notification : Entity, Widgetizable {
public string? emoji { get; set; default = null; }
public string? emoji_url { get; set; default = null; }
public API.Admin.Report? report { get; set; default = null; }
public ModerationWarning? moderation_warning { get; set; default = null; }

// the docs claim that 'relationship_severance_event'
// is the one used but that is not true
Expand All @@ -76,6 +81,10 @@ public class Tuba.API.Notification : Entity, Widgetizable {
case InstanceAccount.KIND_SEVERED_RELATIONSHIPS:
Host.open_url (@"$(accounts.active.instance)/severed_relationships");
break;
case InstanceAccount.KIND_MODERATION_WARNING:
string dispute_id = this.moderation_warning == null ? "" : this.moderation_warning.id;
Host.open_url (@"$(accounts.active.instance)/disputes/strikes/$dispute_id");
break;
case InstanceAccount.KIND_ADMIN_REPORT:
if (report != null) {
if (accounts.active.admin_mode) {
Expand Down Expand Up @@ -133,6 +142,8 @@ public class Tuba.API.Notification : Entity, Widgetizable {
case InstanceAccount.KIND_SEVERED_RELATIONSHIPS:
RelationshipSeveranceEvent? t_event = event == null ? relationship_severance_event : event;
return create_basic_card ("tuba-heart-broken-symbolic", t_event.to_string ());
case InstanceAccount.KIND_MODERATION_WARNING:
return create_basic_card ("tuba-police-badge2-symbolic", _("Your account has received a moderation warning"));
case InstanceAccount.KIND_ADMIN_REPORT:
return create_basic_card ("tuba-build-alt-symbolic", report.to_string (this.created_at));
case InstanceAccount.KIND_ANNUAL_REPORT:
Expand Down Expand Up @@ -194,7 +205,7 @@ public class Tuba.API.Notification : Entity, Widgetizable {
kind_actor_name = _("%s (& %d others)").printf (account.display_name, others);
}

issuer.describe_kind (kind, out res_kind, kind_actor_name, emoji);
issuer.describe_kind (kind, out res_kind, kind_actor_name, null, emoji);
var toast = new GLib.Notification (res_kind.description);
if (status != null) {
var body = "";
Expand All @@ -203,15 +214,29 @@ public class Tuba.API.Notification : Entity, Widgetizable {
}

if (should_show_buttons) {
string var_string = account.url;
if (status != null && status.url != null) {
var_string = status.url;
}
switch (kind) {
case InstanceAccount.KIND_SEVERED_RELATIONSHIPS:
case InstanceAccount.KIND_ADMIN_REPORT:
case InstanceAccount.KIND_ADMIN_SIGNUP:
case InstanceAccount.KIND_ANNUAL_REPORT:
case InstanceAccount.KIND_MODERATION_WARNING:
toast.set_default_action ("app.goto-notifications");
break;
case InstanceAccount.KIND_FOLLOW_REQUEST:
toast.set_default_action ("app.open-follow-requests");
break;
default:
string var_string = account.url;
if (status != null && status.url != null) {
var_string = status.url;
}

toast.set_default_action_and_target_value (
"app.open-status-url",
new Variant.string (var_string)
);
toast.set_default_action_and_target_value (
"app.open-status-url",
new Variant.string (var_string)
);
break;
}

switch (kind) {
case InstanceAccount.KIND_MENTION:
Expand Down
5 changes: 5 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Tuba {
{ "back-home", back_home_activated },
{ "scroll-page-down", scroll_view_page_down },
{ "scroll-page-up", scroll_view_page_up },
{ "goto-notifications", goto_notifications },
{ "open-status-url", open_status_url, "s" },
{ "answer-follow-request", answer_follow_request, "(ssb)" },
{ "follow-back", follow_back, "(ss)" },
Expand Down Expand Up @@ -123,6 +124,10 @@ namespace Tuba {
);
}

private void goto_notifications () {
Mastodon.Account.PLACE_NOTIFICATIONS.open_func (app.main_window);
}

private void open_status_url (GLib.SimpleAction action, GLib.Variant? value) {
if (value == null || accounts.active == null) return;

Expand Down
12 changes: 12 additions & 0 deletions src/Services/Accounts/InstanceAccount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
public const string KIND_PLEROMA_REACTION = "pleroma:emoji_reaction";
public const string KIND_REACTION = "reaction";
public const string KIND_ANNUAL_REPORT = "annual_report";
public const string KIND_MODERATION_WARNING = "moderation_warning";

public string uuid { get; set; }
public bool admin_mode { get; set; default=false; }
Expand Down Expand Up @@ -349,6 +350,16 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
null
};
break;
case KIND_MODERATION_WARNING:
result = {
"tuba-police-badge2-symbolic",
// translators: this is used for notifications,
// when you receive a warning from
// your server's admins
_("Your account has received a moderation warning"),
null
};
break;
case KIND_ADMIN_REPORT:
result = {
"tuba-build-alt-symbolic",
Expand All @@ -363,6 +374,7 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
// translators: the variable is a string user name,
// this is used for per-account notifications
_("%s just posted").printf (actor_name),
null
};
break;
case KIND_PLEROMA_REACTION:
Expand Down

0 comments on commit b010ce6

Please sign in to comment.