Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(status): doas #281

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/style-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
.ttl-post.direct:hover {
background-color: lighter(alpha(@warning_bg_color, .1));
}

.ttl-post.doas:hover {
background-color: lighter(alpha(@purple_2, .1));
}
8 changes: 8 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ flowboxchild {
background-color: darker(alpha(@warning_bg_color, .1));
}

.ttl-post.doas {
background-color: alpha(@purple_2, .1);
}

.ttl-post.doas:hover {
background-color: darker(alpha(@purple_2, .1));
}

.ttl-post-actions {
margin-bottom: -12px;
}
Expand Down
5 changes: 4 additions & 1 deletion src/API/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public class Tuba.API.Status : Entity, Widgetizable {
message ("[OBJ] Destroyed "+uri);
}

public InstanceAccount? doas { get; set; default=null; }
public string? doas_id { get; set; default=null; }

public string id { get; set; }
public API.Account account { get; set; }
public string uri { get; set; }
Expand Down Expand Up @@ -163,7 +166,7 @@ public class Tuba.API.Status : Entity, Widgetizable {
}

public Request action (string action) {
var req = new Request.POST (@"/api/v1/statuses/$(formal.id)/$action").with_account (accounts.active);
var req = new Request.POST (@"/api/v1/statuses/$(doas != null ? doas_id : formal.id)/$action").with_account (doas ?? accounts.active);
req.priority = Soup.MessagePriority.HIGH;
return req;
}
Expand Down
95 changes: 95 additions & 0 deletions src/Widgets/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class Tuba.Widgets.Status : ListBoxRow {
private GLib.SimpleActionGroup action_group;
private SimpleAction edit_history_simple_action;
private SimpleAction stats_simple_action;
private SimpleAction doas_simple_action;

public bool is_conversation_open { get; set; default = false; }

Expand Down Expand Up @@ -180,8 +181,12 @@ public class Tuba.Widgets.Status : ListBoxRow {
stats_simple_action = new SimpleAction ("status-stats", null);
stats_simple_action.activate.connect (view_stats);

doas_simple_action = new SimpleAction ("doas", null);
doas_simple_action.activate.connect (doas);

action_group = new GLib.SimpleActionGroup ();
action_group.add_action_entries (action_entries, this);
action_group.add_action(doas_simple_action);
action_group.add_action(stats_simple_action);
action_group.add_action(edit_history_simple_action);

Expand Down Expand Up @@ -251,6 +256,10 @@ public class Tuba.Widgets.Status : ListBoxRow {
stats_menu_item.set_attribute_value("hidden-when", "action-disabled");
menu_model.append_item (stats_menu_item);

var doas_menu_item = new MenuItem(_("doas"), "status.doas");
doas_menu_item.set_attribute_value("hidden-when", "action-disabled");
menu_model.append_item (doas_menu_item);

var edit_history_menu_item = new MenuItem(_("View Edit History"), "status.edit-history");
edit_history_menu_item.set_attribute_value("hidden-when", "action-disabled");
menu_model.append_item (edit_history_menu_item);
Expand Down Expand Up @@ -279,6 +288,89 @@ public class Tuba.Widgets.Status : ListBoxRow {
app.main_window.open_view (new Views.StatusStats (status.formal.id));
}

private void doas () {
var preferences_page = new Adw.PreferencesPage();
var preferences_group = new Adw.PreferencesGroup() {
title = "Select an account to act as:"
};

preferences_page.add (preferences_group);

var clamp = new Adw.Clamp () {
child = preferences_page,
tightening_threshold = 100,
valign = Align.START
};
var scroller = new Gtk.ScrolledWindow () {
hexpand = true,
vexpand = true
};
scroller.child = clamp;

var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var headerbar = new Adw.HeaderBar() {
css_classes = { "flat" }
};

box.append(headerbar);
box.append(scroller);

var dialog = new Adw.Window() {
modal = true,
title = "doas",
transient_for = app.main_window,
content = box,
default_width = 460,
default_height = 520
};

accounts.saved.foreach (acc => {
if (acc == this.status.formal.doas || (acc == accounts.active && this.status.formal.doas == null)) return true;
var account_avi = new Widgets.Avatar () {
account = acc
};
var account_row = new Adw.ActionRow () {
title = acc.handle,
activatable = true
};
account_row.add_prefix (account_avi);
account_row.activated.connect (() => {
if (acc == accounts.active) {
this.remove_css_class ("doas");
this.status.formal.doas = null;
dialog.close ();
} else {
new Request.GET ("/api/v2/search")
.with_account (acc)
.with_param ("q", this.status.formal.url)
.with_param ("resolve", "true")
.then ((sess, msg, in_stream) => {
var parser = Network.get_parser_from_inputstream(in_stream);
var root = network.parse (parser);
var statuses = root.get_array_member ("statuses");
var node = statuses.get_element (0);
if (node != null){
var status = API.Status.from (node);
this.status.formal.doas = acc;
this.status.formal.doas_id = status.formal.id;
this.add_css_class ("doas");
} else {
this.remove_css_class ("doas");
this.status.formal.doas = null;
}
dialog.close ();
})
.exec ();
}
});

preferences_group.add (account_row);
return true;
});

dialog.show ();
}

private void on_edit (API.Status x) {
this.status.patch(x);
bind ();
Expand Down Expand Up @@ -450,6 +542,7 @@ public class Tuba.Widgets.Status : ListBoxRow {
}

const string[] ALLOWED_CARD_TYPES = { "link", "video" };
const string[] DOAS_ALLOWED_LIST = { "unlisted", "public" };
protected virtual void bind () {
this.content.instance_emojis = status.formal.emojis_map;
this.content.content = status.formal.content;
Expand All @@ -474,6 +567,8 @@ public class Tuba.Widgets.Status : ListBoxRow {

if (change_background_on_direct && status.formal.visibility == "direct") this.add_css_class ("direct");

doas_simple_action.set_enabled(status.formal.visibility in DOAS_ALLOWED_LIST && accounts.saved.size > 1);

avatar.account = status.formal.account;
reactions = status.formal.compat_status_reactions;

Expand Down
Loading