Skip to content

Commit

Permalink
feat(notifications): withdraw (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Feb 7, 2025
1 parent 0a2d9e5 commit b3654da
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Services/Accounts/InstanceAccount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class Tuba.InstanceAccount : API.Account, Streamable {

#if DEV_MODE
app.dev_new_notification.connect (node => {
if (accounts.active.id != this.id) return;

try {
var entity = create_entity<API.Notification> (node);

Expand Down Expand Up @@ -700,18 +702,20 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
new Request.POST ("/api/v1/markers")
.with_account (this)
.with_form_data ("notifications[last_read_id]", up_to_id.to_string ())
.then (() => {})
.exec ();

// Pleroma FE doesn't mark them as read by just updating the marker
if (instance_info != null && instance_info.pleroma != null) {
new Request.POST ("/api/v1/pleroma/notifications/read")
.with_account (this)
.with_form_data ("max_id", up_to_id.to_string ())
.then (() => {})
.exec ();
}

foreach (string notification_id in sent_notifications.keys) {
app.withdraw_notification (notification_id);
}

sent_notifications.clear ();
}
}
Expand Down Expand Up @@ -749,21 +753,22 @@ public class Tuba.InstanceAccount : API.Account, Streamable {
public void send_toast (API.Notification obj) {
if (obj.kind != null && (obj.kind in settings.muted_notification_types)) return;

var id = obj.id;
var id = accounts.active.id;
var others = 0;

if (settings.group_push_notifications && obj.status != null && obj.kind in GROUPED_KINDS) {
id = @"$(obj.status.id)-$(obj.kind)";
id = @"$id-$(obj.status.id)-$(obj.kind)";
if (sent_notifications.has_key (id)) {
others = sent_notifications.get (id) + 1;
}
sent_notifications.set (id, others);
} else {
id = @"$id-$(obj.id)";
}
sent_notifications.set (id, others);

obj.to_toast.begin (this, others, (_obj, res) => {
app.send_notification (id, obj.to_toast.end (res));
});
// sent_notification_ids.add(id);
}


Expand Down

0 comments on commit b3654da

Please sign in to comment.