Skip to content

Commit

Permalink
feat: Reset bad history index, home replicas
Browse files Browse the repository at this point in the history
TODO:
- Making bookmarks & OkuNet posts
- Viewing bookmarks in sidebar
- Setting up an OkuNet identity
- Viewing OkuNet profiles
- Following & blocking OkuNet users
  • Loading branch information
emmyoh committed Oct 26, 2024
1 parent 7bef619 commit b77493a
Show file tree
Hide file tree
Showing 22 changed files with 3,558 additions and 3,310 deletions.
8 changes: 8 additions & 0 deletions data/hicolor/scalable/actions/folder-remote-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions data/hicolor/scalable/actions/note-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions data/hicolor/scalable/actions/user-home-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
<file preprocess="xml-stripblanks">ticket-special-symbolic.svg</file>
<file preprocess="xml-stripblanks">ticket-symbolic.svg</file>
<file preprocess="xml-stripblanks">copy-symbolic.svg</file>
<file preprocess="xml-stripblanks">user-home-symbolic.svg</file>
<file preprocess="xml-stripblanks">note-symbolic.svg</file>
<file preprocess="xml-stripblanks">folder-remote-symbolic.svg</file>
</gresource>
</gresources>
10 changes: 8 additions & 2 deletions src/database/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ pub struct BrowserDatabase {

impl BrowserDatabase {
pub fn new() -> miette::Result<Self> {
Ok(Self {
let database = Self {
database: native_db::Builder::new()
.create(&MODELS, &*DATABASE_PATH)
.into_diagnostic()?,
history_sender: tokio::sync::watch::channel(()).0,
})
};
if database.get_history_records()?.len() as u64
!= HISTORY_RECORD_INDEX_READER.searcher().num_docs()
{
database.rebuild_history_record_index()?;
}
Ok(database)
}

pub fn search(
Expand Down
14 changes: 14 additions & 0 deletions src/database/history_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ impl BrowserDatabase {
.collect())
}

pub fn rebuild_history_record_index(&self) -> miette::Result<()> {
let mut index_writer = HISTORY_RECORD_INDEX_WRITER
.clone()
.try_lock_owned()
.into_diagnostic()?;
index_writer.delete_all_documents().into_diagnostic()?;
self.get_history_records()?
.into_par_iter()
.filter_map(|x| index_writer.add_document(x.into()).ok())
.collect::<Vec<_>>();
index_writer.commit().into_diagnostic()?;
Ok(())
}

pub fn upsert_history_record(
&self,
history_record: HistoryRecord,
Expand Down
13 changes: 12 additions & 1 deletion src/replica_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod imp {
pub struct ReplicaItem {
pub(crate) id: RefCell<String>,
pub(crate) writable: RefCell<bool>,
pub(crate) home: RefCell<bool>,
}

#[glib::object_subclass]
Expand All @@ -33,6 +34,7 @@ pub mod imp {
vec![
ParamSpecString::builder("id").readwrite().build(),
ParamSpecBoolean::builder("writable").readwrite().build(),
ParamSpecBoolean::builder("home").readwrite().build(),
]
});
PROPERTIES.as_ref()
Expand All @@ -48,6 +50,10 @@ pub mod imp {
let writable = value.get::<bool>().unwrap();
self.writable.set(writable);
}
"home" => {
let home = value.get::<bool>().unwrap();
self.home.set(home);
}
_ => unimplemented!(),
}
}
Expand All @@ -57,6 +63,7 @@ pub mod imp {
match pspec.name() {
"id" => obj.id().to_value(),
"writable" => obj.writable().to_value(),
"home" => obj.home().to_value(),
_ => unimplemented!(),
}
}
Expand All @@ -74,10 +81,14 @@ impl ReplicaItem {
pub fn writable(&self) -> bool {
self.imp().writable.borrow().clone()
}
pub fn new(id: String, writable: bool) -> Self {
pub fn home(&self) -> bool {
*self.imp().home.borrow()
}
pub fn new(id: String, writable: bool, home: bool) -> Self {
let replica_item = glib::Object::builder::<Self>()
.property("id", id)
.property("writable", writable)
.property("home", home)
.build();

replica_item
Expand Down
48 changes: 45 additions & 3 deletions src/widgets/replica_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub mod imp {
pub struct ReplicaRow {
pub(crate) id: RefCell<String>,
pub(crate) writable: RefCell<bool>,
pub(crate) icon: gtk::Image,
pub(crate) home: RefCell<bool>,
pub(crate) home_button: gtk::Button,
pub(crate) open_button: gtk::Button,
pub(crate) read_ticket_button: gtk::Button,
pub(crate) write_ticket_button: gtk::Button,
Expand Down Expand Up @@ -80,6 +81,7 @@ pub mod imp {
vec![
ParamSpecString::builder("id").build(),
ParamSpecBoolean::builder("writable").build(),
ParamSpecBoolean::builder("home").build(),
]
});
PROPERTIES.as_ref()
Expand All @@ -95,6 +97,10 @@ pub mod imp {
let writable = value.get::<bool>().unwrap();
self.obj().set_writable(writable);
}
"home" => {
let home = value.get::<bool>().unwrap();
self.obj().set_home(home);
}
_ => unimplemented!(),
}
}
Expand All @@ -103,6 +109,7 @@ pub mod imp {
match pspec.name() {
"id" => self.obj().id().to_value(),
"writable" => self.obj().writable().to_value(),
"home" => self.obj().home().to_value(),
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -133,7 +140,26 @@ impl ReplicaRow {
pub fn setup(&self) {
let imp = self.imp();

imp.icon.set_icon_name(Some("folder"));
imp.home_button.set_icon_name("user-home-symbolic");
imp.home_button.add_css_class("circular");
imp.home_button.set_vexpand(false);
imp.home_button.set_hexpand(false);
imp.home_button.set_valign(gtk::Align::Center);
imp.home_button.connect_clicked(clone!(
#[weak(rename_to = this)]
self,
move |_| {
if let Some(node) = NODE.get() {
let new_home_replica = match this.home() {
false => Some(NamespaceId::from_str(&this.id()).unwrap()),
true => None,
};
if let Err(e) = node.set_home_replica(new_home_replica) {
error!("{}", e);
}
}
}
));

imp.open_button.set_icon_name("external-link-symbolic");
imp.open_button.add_css_class("circular");
Expand Down Expand Up @@ -350,7 +376,7 @@ impl ReplicaRow {
let content_box: gtk::Box = self.child().and_downcast().unwrap();
content_box.set_hexpand(true);

self.add_prefix(&imp.icon);
self.add_prefix(&imp.home_button);
self.add_suffix(&imp.button_box);
self.set_title_lines(1);
self.add_css_class("caption");
Expand All @@ -365,6 +391,10 @@ impl ReplicaRow {
self.imp().writable.borrow().clone()
}

pub fn home(&self) -> bool {
self.imp().home.borrow().clone()
}

pub fn set_id(&self, id: &str) {
let imp = self.imp();

Expand All @@ -378,4 +408,16 @@ impl ReplicaRow {
imp.writable.replace(writable);
imp.write_ticket_button.set_visible(writable);
}

pub fn set_home(&self, home: bool) {
let imp = self.imp();

imp.home.replace(home);
let (old_class, new_class) = match home {
true => ("accent", "warning"),
false => ("warning", "accent"),
};
imp.home_button.remove_css_class(old_class);
imp.home_button.add_css_class(new_class);
}
}
Loading

0 comments on commit b77493a

Please sign in to comment.