Compare commits
1 Commits
master
...
feat/nativ
| Author | SHA1 | Date | |
|---|---|---|---|
| a6e88d8e42 |
@@ -11,8 +11,9 @@ use gpui::{
|
|||||||
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton,
|
Focusable, InteractiveElement, IntoElement, ListAlignment, ListOffset, ListState, MouseButton,
|
||||||
ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, SharedUri,
|
ObjectFit, ParentElement, PathPromptOptions, Render, SharedString, SharedUri,
|
||||||
StatefulInteractiveElement, Styled, StyledImage, Subscription, Task, WeakEntity, Window, div,
|
StatefulInteractiveElement, Styled, StyledImage, Subscription, SystemNotification,
|
||||||
img, list, px, red, relative, svg, white,
|
SystemNotificationAction, Task, WeakEntity, Window, div, img, list, px, red, relative, svg,
|
||||||
|
white,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -275,30 +276,44 @@ impl ChatPanel {
|
|||||||
|
|
||||||
/// Subscribe to room events
|
/// Subscribe to room events
|
||||||
fn subscribe_room_events(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn subscribe_room_events(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if let Some(room) = self.room.upgrade() {
|
let Some(room) = self.room.upgrade() else {
|
||||||
self.subscriptions.push(cx.subscribe_in(
|
return;
|
||||||
&room,
|
};
|
||||||
window,
|
|
||||||
move |this, _room, event, window, cx| {
|
self.subscriptions.push(cx.subscribe_in(
|
||||||
match event {
|
&room,
|
||||||
RoomEvent::Incoming(message) => {
|
window,
|
||||||
if message.rumor.kind == Kind::Reaction {
|
move |this, _room, event, window, cx| {
|
||||||
this.insert_reaction(&message.rumor, cx);
|
match event {
|
||||||
} else {
|
RoomEvent::Incoming(message) => {
|
||||||
this.insert_message(message, false, cx);
|
if message.rumor.kind == Kind::Reaction {
|
||||||
|
this.insert_reaction(&message.rumor, cx);
|
||||||
|
} else {
|
||||||
|
this.insert_message(message, false, cx);
|
||||||
|
|
||||||
|
if !window.is_window_active() {
|
||||||
|
cx.show_system_notification(SystemNotification {
|
||||||
|
tag: "message".into(),
|
||||||
|
title: "New Message".into(),
|
||||||
|
body: "You have a new message.".into(),
|
||||||
|
actions: vec![SystemNotificationAction {
|
||||||
|
id: "open".into(),
|
||||||
|
label: "Open".into(),
|
||||||
|
}],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RoomEvent::Reload => {
|
}
|
||||||
// Defer to avoid re-entrant read on Room while
|
RoomEvent::Reload => {
|
||||||
// emit_refresh holds a write lock (via refresh_rooms).
|
// Defer to avoid re-entrant read on Room while
|
||||||
cx.defer_in(window, |this, window, cx| {
|
// emit_refresh holds a write lock (via refresh_rooms).
|
||||||
this.get_messages(window, cx);
|
cx.defer_in(window, |this, window, cx| {
|
||||||
});
|
this.get_messages(window, cx);
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
},
|
};
|
||||||
));
|
},
|
||||||
}
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load all messages belonging to this room
|
/// Load all messages belonging to this room
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ fn main() {
|
|||||||
// Load embedded fonts in assets/fonts
|
// Load embedded fonts in assets/fonts
|
||||||
load_embedded_fonts(cx);
|
load_embedded_fonts(cx);
|
||||||
|
|
||||||
|
// Set app identity
|
||||||
|
cx.set_app_identity(APP_ID, CLIENT_NAME);
|
||||||
|
|
||||||
// Register the `quit` function
|
// Register the `quit` function
|
||||||
cx.on_action(quit);
|
cx.on_action(quit);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user