refactor: Client keys and Identity (#61)
* . * . * . * . * refactor client keys * . * . * refactor * . * . * . * update new account
This commit is contained in:
@@ -7,6 +7,7 @@ publish.workspace = true
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
global = { path = "../global" }
|
||||
identity = { path = "../identity" }
|
||||
settings = { path = "../settings" }
|
||||
|
||||
gpui.workspace = true
|
||||
|
||||
@@ -9,6 +9,7 @@ use global::shared_state;
|
||||
use gpui::{
|
||||
App, AppContext, Context, Entity, EventEmitter, Global, Subscription, Task, WeakEntity, Window,
|
||||
};
|
||||
use identity::Identity;
|
||||
use itertools::Itertools;
|
||||
use nostr_sdk::prelude::*;
|
||||
use room::RoomKind;
|
||||
@@ -77,7 +78,7 @@ impl ChatRegistry {
|
||||
let mut subscriptions = smallvec![];
|
||||
|
||||
// When the ChatRegistry is created, load all rooms from the local database
|
||||
subscriptions.push(cx.observe_new::<ChatRegistry>(|this, window, cx| {
|
||||
subscriptions.push(cx.observe_new::<Self>(|this, window, cx| {
|
||||
if let Some(window) = window {
|
||||
this.load_rooms(window, cx);
|
||||
}
|
||||
@@ -162,7 +163,7 @@ impl ChatRegistry {
|
||||
/// 4. Creates Room entities for each unique room
|
||||
pub fn load_rooms(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let client = &shared_state().client;
|
||||
let Some(public_key) = shared_state().identity().map(|i| i.public_key()) else {
|
||||
let Some(public_key) = Identity::get_global(cx).profile().map(|i| i.public_key()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -288,7 +289,7 @@ impl ChatRegistry {
|
||||
pub fn event_to_message(&mut self, event: Event, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let id = room_hash(&event);
|
||||
let author = event.pubkey;
|
||||
let Some(public_key) = shared_state().identity().map(|i| i.public_key()) else {
|
||||
let Some(public_key) = Identity::get_global(cx).profile().map(|i| i.public_key()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use common::profile::RenderProfile;
|
||||
use common::{compare, room_hash};
|
||||
use global::shared_state;
|
||||
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task, Window};
|
||||
use identity::Identity;
|
||||
use itertools::Itertools;
|
||||
use nostr_sdk::prelude::*;
|
||||
use settings::AppSettings;
|
||||
@@ -165,8 +166,8 @@ impl Room {
|
||||
/// # Returns
|
||||
///
|
||||
/// The Profile of the first member in the room
|
||||
pub fn first_member(&self, _cx: &App) -> Profile {
|
||||
let Some(account) = shared_state().identity() else {
|
||||
pub fn first_member(&self, cx: &App) -> Profile {
|
||||
let Some(account) = Identity::get_global(cx).profile() else {
|
||||
return shared_state().person(&self.members[0]);
|
||||
};
|
||||
|
||||
@@ -250,7 +251,7 @@ impl Room {
|
||||
/// - For a direct message: the other person's avatar
|
||||
/// - For a group chat: None
|
||||
pub fn display_image(&self, cx: &App) -> SharedString {
|
||||
let proxy = AppSettings::get_global(cx).settings().proxy_user_avatars;
|
||||
let proxy = AppSettings::get_global(cx).settings.proxy_user_avatars;
|
||||
|
||||
if let Some(picture) = self.picture.as_ref() {
|
||||
picture.clone()
|
||||
@@ -550,9 +551,9 @@ impl Room {
|
||||
&self,
|
||||
content: &str,
|
||||
replies: Option<&Vec<Message>>,
|
||||
_cx: &App,
|
||||
cx: &App,
|
||||
) -> Option<Message> {
|
||||
let author = shared_state().identity()?;
|
||||
let author = Identity::get_global(cx).profile()?;
|
||||
let public_key = author.public_key();
|
||||
let builder = EventBuilder::private_msg_rumor(public_key, content);
|
||||
|
||||
@@ -633,7 +634,7 @@ impl Room {
|
||||
let subject = self.subject.clone();
|
||||
let picture = self.picture.clone();
|
||||
let public_keys = Arc::clone(&self.members);
|
||||
let backup = AppSettings::get_global(cx).settings().backup_messages;
|
||||
let backup = AppSettings::get_global(cx).settings.backup_messages;
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let signer = shared_state().client.signer().await?;
|
||||
|
||||
Reference in New Issue
Block a user