chore: Improve Chat Performance (#35)
* refactor * optimistically update message list * fix * update * handle duplicate messages * update ui * refactor input * update multi line input * clean up
This commit is contained in:
+33
-15
@@ -2,6 +2,8 @@ use chrono::{Local, TimeZone};
|
||||
use gpui::SharedString;
|
||||
use nostr_sdk::prelude::*;
|
||||
|
||||
use crate::room::SendError;
|
||||
|
||||
/// # Message
|
||||
///
|
||||
/// Represents a message in the application.
|
||||
@@ -18,8 +20,9 @@ pub struct Message {
|
||||
pub id: EventId,
|
||||
pub content: String,
|
||||
pub author: Profile,
|
||||
pub mentions: Vec<Profile>,
|
||||
pub created_at: Timestamp,
|
||||
pub mentions: Vec<Profile>,
|
||||
pub errors: Option<Vec<SendError>>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
@@ -42,23 +45,10 @@ impl Message {
|
||||
author,
|
||||
created_at,
|
||||
mentions: vec![],
|
||||
errors: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds or replaces mentions in the message
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `mentions` - New list of mentioned profiles
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The same message with updated mentions
|
||||
pub fn with_mentions(mut self, mentions: impl IntoIterator<Item = Profile>) -> Self {
|
||||
self.mentions.extend(mentions);
|
||||
self
|
||||
}
|
||||
|
||||
/// Formats the message timestamp as a human-readable relative time
|
||||
///
|
||||
/// # Returns
|
||||
@@ -85,6 +75,34 @@ impl Message {
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Adds or replaces mentions in the message
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `mentions` - New list of mentioned profiles
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The same message with updated mentions
|
||||
pub fn with_mentions(mut self, mentions: impl IntoIterator<Item = Profile>) -> Self {
|
||||
self.mentions.extend(mentions);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds or replaces errors in the message
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `errors` - New list of errors
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// The same message with updated errors
|
||||
pub fn with_errors(mut self, errors: Vec<SendError>) -> Self {
|
||||
self.errors = Some(errors);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// # RoomMessage
|
||||
|
||||
Reference in New Issue
Block a user