-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chat): display names with /name
- Loading branch information
1 parent
f3a47be
commit 911cef4
Showing
6 changed files
with
139 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use gpui::{div, rgba, IntoElement, ParentElement, Render, Styled, ViewContext}; | ||
use iroh::net::key::PublicKey; | ||
use std::sync::Arc; | ||
|
||
use crate::logic::Logic; | ||
|
||
pub struct Name { | ||
pubkey: PublicKey, | ||
logic: Arc<Logic>, | ||
} | ||
|
||
impl Name { | ||
pub fn new(_cx: &mut ViewContext<Self>, pubkey: PublicKey, logic: Arc<Logic>) -> Self { | ||
Name { pubkey, logic } | ||
} | ||
} | ||
|
||
impl Render for Name { | ||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement { | ||
let name = self.logic.get_name(&self.pubkey); | ||
div().text_color(rgba(0x00000050)).child(name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use iroh::net::key::PublicKey; | ||
use std::collections::HashMap; | ||
|
||
use super::Message; | ||
|
||
pub struct Names { | ||
names: HashMap<PublicKey, String>, | ||
} | ||
|
||
impl Names { | ||
pub fn new() -> Self { | ||
Self { | ||
names: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn apply_about_message(&mut self, pubkey: PublicKey, message: &Message) { | ||
if let Message::AboutMe { name, timestamp: _ } = message { | ||
self.names.insert(pubkey, name.clone()); | ||
} | ||
} | ||
|
||
pub fn get_name(&self, pubkey: &PublicKey) -> Option<&String> { | ||
self.names.get(pubkey) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters