Skip to content

Commit

Permalink
fix(Lists): *oma (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeopJr authored Dec 10, 2024
1 parent 6eac5ed commit 28336ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
31 changes: 25 additions & 6 deletions src/Dialogs/ListEdit.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
}
}

public static RepliesPolicy from_string (string policy) {
public static RepliesPolicy from_string (string? policy) {
switch (policy) {
case "list":
return LIST;
Expand Down Expand Up @@ -155,11 +155,19 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
if (list.title != list_title || RepliesPolicy.from_string (list.replies_policy) != replies_policy_active || list.exclusive != is_exclusive) {
var replies_policy_string = replies_policy_active.to_string ();

var builder = new Json.Builder ();
builder.begin_object ();
builder.set_member_name ("title");
builder.add_string_value (list_title);
builder.set_member_name ("replies_policy");
builder.add_string_value (replies_policy_string);
builder.set_member_name ("exclusive");
builder.add_boolean_value (is_exclusive);
builder.end_object ();

new Request.PUT (@"/api/v1/lists/$(list.id)")
.with_account (accounts.active)
.with_param ("title", list_title)
.with_param ("replies_policy", replies_policy_string)
.with_param ("exclusive", is_exclusive.to_string ())
.body_json (builder)
.then (() => {
list.title = list_title;
list.replies_policy = replies_policy_string;
Expand All @@ -169,9 +177,20 @@ public class Tuba.Dialogs.ListEdit : Adw.PreferencesDialog {
}

if (memebers_to_be_removed.size > 0) {
var id_array = Request.array2string (memebers_to_be_removed, "account_ids");
new Request.DELETE (@"/api/v1/lists/$(list.id)/accounts?$id_array")
var ids_builder = new Json.Builder ();
ids_builder.begin_object ();
ids_builder.set_member_name ("account_ids");
ids_builder.begin_array ();
memebers_to_be_removed.foreach (e => {
ids_builder.add_string_value (e);
return true;
});
ids_builder.end_array ();
ids_builder.end_object ();

new Request.DELETE (@"/api/v1/lists/$(list.id)/accounts")
.with_account (accounts.active)
.body_json (ids_builder)
.exec ();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/Views/Lists.vala
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,15 @@ public class Tuba.Views.Lists : Views.Timeline {
}

public void create_list (string list_name) {
var builder = new Json.Builder ();
builder.begin_object ();
builder.set_member_name ("title");
builder.add_string_value (list_name);
builder.end_object ();

new Request.POST ("/api/v1/lists")
.with_account (accounts.active)
.with_param ("title", list_name)
.body_json (builder)
.then ((in_stream) => {
var parser = Network.get_parser_from_inputstream (in_stream);
var node = network.parse_node (parser);
Expand Down
11 changes: 10 additions & 1 deletion src/Views/Profile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,20 @@ public class Tuba.Views.Profile : Views.Accounts {
public void handle_list_edit (API.List list, Adw.ActionRow row, Adw.ToastOverlay toast_overlay, RowButton button) {
row.sensitive = false;

var endpoint = @"/api/v1/lists/$(list.id)/accounts?account_ids[]=$(profile.account.id)";
var builder = new Json.Builder ();
builder.begin_object ();
builder.set_member_name ("account_ids");
builder.begin_array ();
builder.add_string_value (profile.account.id);
builder.end_array ();
builder.end_object ();

var endpoint = @"/api/v1/lists/$(list.id)/accounts";
var req = button.remove ? new Request.DELETE (endpoint) : new Request.POST (endpoint);
req
.with_account (accounts.active)
.with_ctx (this)
.body_json (builder)
.on_error (on_error)
.then (() => {
var toast_msg = "";
Expand Down

0 comments on commit 28336ca

Please sign in to comment.