This commit is contained in:
2024-10-27 15:57:32 +07:00
parent eb6e3e52df
commit 0518389f50
17 changed files with 306 additions and 349 deletions

View File

@@ -281,18 +281,33 @@ pub async fn get_group(id: String, state: State<'_, Nostr>) -> Result<String, St
#[tauri::command]
#[specta::specta]
pub async fn get_all_groups(id: String, state: State<'_, Nostr>) -> Result<Vec<RichEvent>, String> {
pub async fn get_all_newsfeeds(
id: String,
state: State<'_, Nostr>,
) -> Result<Vec<RichEvent>, String> {
let client = &state.client;
let public_key = PublicKey::parse(&id).map_err(|e| e.to_string())?;
let filter = Filter::new().kind(Kind::FollowSet).author(public_key);
match client
.fetch_events(vec![filter], Some(Duration::from_secs(3)))
let groups = Filter::new().kind(Kind::FollowSet).author(public_key);
let contacts = Filter::new()
.kind(Kind::ContactList)
.author(public_key)
.limit(1);
let remote_events = client
.fetch_events(vec![groups], Some(Duration::from_secs(3)))
.await
{
Ok(events) => Ok(process_event(client, events, false).await),
Err(e) => Err(e.to_string()),
}
.map_err(|e| e.to_string())?;
let contact_events = client
.fetch_events(vec![contacts], Some(Duration::from_secs(3)))
.await
.map_err(|e| e.to_string())?;
let events = remote_events.merge(contact_events);
let alt_events = process_event(client, events, false).await;
Ok(alt_events)
}
#[tauri::command]

View File

@@ -47,7 +47,17 @@ pub async fn create_column(
main_window: Window,
) -> Result<String, String> {
match app_handle.get_webview(&column.label) {
Some(_) => Ok(column.label),
Some(webview) => {
if let Err(e) = webview.set_size(LogicalSize::new(column.width, column.height)) {
return Err(e.to_string());
}
if let Err(e) = webview.set_position(LogicalPosition::new(column.x, column.y)) {
return Err(e.to_string());
}
Ok(column.label)
}
None => {
let path = PathBuf::from(column.url);
let webview_url = WebviewUrl::App(path);
@@ -145,28 +155,15 @@ pub async fn close_column(label: String, app_handle: tauri::AppHandle) -> Result
#[tauri::command]
#[specta::specta]
pub async fn update_column(
label: String,
width: f32,
height: f32,
x: f32,
y: f32,
app_handle: tauri::AppHandle,
) -> Result<(), String> {
match app_handle.get_webview(&label) {
Some(webview) => {
if let Err(e) = webview.set_size(LogicalSize::new(width, height)) {
return Err(e.to_string());
}
pub async fn close_all_columns(app_handle: tauri::AppHandle) -> Result<(), String> {
let mut webviews = app_handle.webviews();
webviews.remove("main");
if let Err(e) = webview.set_position(LogicalPosition::new(x, y)) {
return Err(e.to_string());
}
Ok(())
}
None => Err("Cannot update, column not found.".into()),
for webview in webviews.values() {
webview.close().unwrap()
}
Ok(())
}
#[tauri::command]

View File

@@ -97,7 +97,7 @@ fn main() {
get_all_profiles,
set_group,
get_group,
get_all_groups,
get_all_newsfeeds,
set_interest,
get_interest,
get_all_interests,
@@ -129,9 +129,9 @@ fn main() {
event_to_bech32,
user_to_bech32,
create_column,
update_column,
reload_column,
close_column,
close_all_columns,
open_window,
]);
@@ -288,48 +288,46 @@ fn main() {
let _ = client
.handle_notifications(|notification| async {
#[allow(clippy::collapsible_match)]
if let RelayPoolNotification::Message { message, .. } = notification {
if let RelayMessage::Event {
event,
subscription_id,
} = message
{
// Handle events from notification subscription
if subscription_id == notification_id {
// Send native notification
if allow_notification {
let author = client
.database()
.profile(event.pubkey)
.await
.unwrap_or_else(|_| {
DatabaseProfile::new(event.pubkey, Metadata::new())
});
if let RelayPoolNotification::Event {
event,
subscription_id,
..
} = notification
{
// Handle events from notification subscription
if subscription_id == notification_id {
// Send native notification
if allow_notification {
let author = client
.database()
.profile(event.pubkey)
.await
.unwrap_or_else(|_| {
DatabaseProfile::new(event.pubkey, Metadata::new())
});
send_event_notification(
&event,
author.metadata(),
&handle_clone,
);
}
} else if event.kind != Kind::RelayList {
let payload = RichEvent {
raw: event.as_json(),
parsed: if event.kind == Kind::TextNote {
Some(parse_event(&event.content).await)
} else {
None
},
};
send_event_notification(
&event,
author.metadata(),
&handle_clone,
);
}
} else if event.kind != Kind::RelayList {
let payload = RichEvent {
raw: event.as_json(),
parsed: if event.kind == Kind::TextNote {
Some(parse_event(&event.content).await)
} else {
None
},
};
if let Err(e) = handle_clone.emit_to(
EventTarget::labeled(subscription_id.to_string()),
"event",
payload,
) {
println!("Emitter error: {}", e)
}
if let Err(e) = handle_clone.emit_to(
EventTarget::labeled(subscription_id.to_string()),
"event",
payload,
) {
println!("Emitter error: {}", e)
}
}
}