Skip to content
This repository has been archived by the owner on Feb 2, 2025. It is now read-only.

Commit

Permalink
feat: eliminate repetitions when adding elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Rirusha committed Nov 29, 2024
1 parent 47b8675 commit e16fd15
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/folder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ namespace Foldy.Folder {
public static void add_folder_categories (string folder_id, string[] folder_categories) {
var builder = new StrvBuilder ();

builder.addv (get_folder_categories (folder_id));
builder.addv (folder_categories);
var current_categories = get_folder_categories (folder_id);

builder.addv (current_categories);
foreach (string category in folder_categories) {
if (!(category in current_categories)) {
builder.add (category);
}
}

set_folder_categories (folder_id, builder.end ());
}
Expand Down Expand Up @@ -94,8 +100,14 @@ namespace Foldy.Folder {
public static void add_folder_apps (string folder_id, string[] folder_apps) {
var builder = new StrvBuilder ();

builder.addv (get_folder_apps (folder_id));
builder.addv (folder_apps);
var current_apps = get_folder_apps (folder_id);

builder.addv (current_apps);
foreach (string app in folder_apps) {
if (!(app in current_apps)) {
builder.add (app);
}
}

set_folder_apps (folder_id, builder.end ());
}
Expand Down Expand Up @@ -126,8 +138,14 @@ namespace Foldy.Folder {
public static void add_folder_excluded_apps (string folder_id, string[] folder_excluded_apps) {
var builder = new StrvBuilder ();

builder.addv (get_folder_apps (folder_id));
builder.addv (folder_excluded_apps);
var current_excluded_apps = get_folder_apps (folder_id);

builder.addv (current_excluded_apps);
foreach (string excluded_app in folder_excluded_apps) {
if (!(excluded_app in current_excluded_apps)) {
builder.add (excluded_app);
}
}

set_folder_apps (folder_id, builder.end ());
}
Expand Down

0 comments on commit e16fd15

Please sign in to comment.