pub struct CompactMessage {
pub at: u64,
pub attachments: TinyVec<CompactAttachment>,
pub reactions: TinyVec<CompactReaction>,
pub reply: Option<Box<CompactReply>>,
pub extras: Option<Box<MessageExtras>>,
pub expiration_secs: u32,
pub npub_idx: u16,
pub flags: MessageFlags,
/* private fields */
}Expand description
Memory-efficient message: binary ids, interned npubs and emoji, packed flags, and the fields most messages never carry (a reply, edits, a link preview, custom emoji, bot targets) behind two optional boxes. 96 bytes inline.
Fields§
§at: u64Timestamp in milliseconds (full precision for sub-second ordering)
attachments: TinyVec<CompactAttachment>File attachments
reactions: TinyVec<CompactReaction>Emoji reactions
reply: Option<Box<CompactReply>>What this message replies to, when it does
extras: Option<Box<MessageExtras>>Edit history, link preview, custom emoji and bot targets, when any are present
expiration_secs: u32NIP-40 expiry as unix SECONDS (0 = permanent). Inline: the self-destruct sweep scans it across every message.
npub_idx: u16Index into NpubInterner for sender’s npub (NO_NPUB if none)
flags: MessageFlagsPacked boolean flags (mine, pending, failed, replied_to_has_attachment)
Implementations§
Source§impl CompactMessage
impl CompactMessage
Sourcepub fn edit_history(&self) -> Vec<EditEntry>
pub fn edit_history(&self) -> Vec<EditEntry>
The edit history, oldest first; empty when never edited.
pub fn preview_metadata(&self) -> Option<SiteMetadata>
pub fn set_preview_metadata(&mut self, metadata: Option<SiteMetadata>)
Sourcepub fn content(&self) -> &str
pub fn content(&self) -> &str
Also the newest revision of the edit history; change it through an edit.
Sourcepub fn id_hex(&self) -> String
pub fn id_hex(&self) -> String
Get the message ID as a string (hex for event IDs, “pending-…” for pending)
Sourcepub fn replied_to_hex(&self) -> String
pub fn replied_to_hex(&self) -> String
Get the replied-to ID as a hex string, or empty if none
Sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Get timestamp as milliseconds (for compatibility with frontend)
Sourcepub fn apply_edit(
&mut self,
new_content: String,
edited_at: u64,
emoji_tags: Vec<EmojiTag>,
text_spans: Vec<TextSpan>,
interner: &mut NpubInterner,
)
pub fn apply_edit( &mut self, new_content: String, edited_at: u64, emoji_tags: Vec<EmojiTag>, text_spans: Vec<TextSpan>, interner: &mut NpubInterner, )
Apply an edit to this message.
emoji_tags are the NIP-30 custom-emoji tags resolved from the new
content; they’re adopted only when this edit is the newest revision so
an out-of-order older edit can’t clobber the live content’s emoji.
Sourcepub fn replied_to_has_attachment(&self) -> Option<bool>
pub fn replied_to_has_attachment(&self) -> Option<bool>
Get replied_to_has_attachment from flags
Sourcepub fn add_reaction(
&mut self,
reaction: Reaction,
interner: &mut NpubInterner,
) -> bool
pub fn add_reaction( &mut self, reaction: Reaction, interner: &mut NpubInterner, ) -> bool
Add a reaction to this message
(see MAX_REACTION_GROUPS for the distinct-emoji ceiling)
Sourcepub fn remove_reaction(&mut self, reaction_id: &str) -> bool
pub fn remove_reaction(&mut self, reaction_id: &str) -> bool
Remove a reaction by its hex event id. Returns true if one was removed.
pub fn is_mine(&self) -> bool
pub fn is_pending(&self) -> bool
pub fn is_failed(&self) -> bool
pub fn set_pending(&mut self, value: bool)
pub fn set_failed(&mut self, value: bool)
pub fn set_mine(&mut self, value: bool)
Source§impl CompactMessage
impl CompactMessage
Sourcepub fn from_message(msg: &Message, interner: &mut NpubInterner) -> Self
pub fn from_message(msg: &Message, interner: &mut NpubInterner) -> Self
Convert from a regular Message (borrowed), interning npubs
Sourcepub fn from_message_owned(msg: Message, interner: &mut NpubInterner) -> Self
pub fn from_message_owned(msg: Message, interner: &mut NpubInterner) -> Self
Convert from a regular Message (owned), moving its strings rather than copying them.
Sourcepub fn to_message(&self, interner: &NpubInterner) -> Message
pub fn to_message(&self, interner: &NpubInterner) -> Message
Convert back to a regular Message, resolving npubs and emoji from the interner
Trait Implementations§
Source§impl Clone for CompactMessage
impl Clone for CompactMessage
Source§impl Debug for CompactMessage
impl Debug for CompactMessage
Auto Trait Implementations§
impl Forget for CompactMessage
impl Freeze for CompactMessage
impl Move for CompactMessage
impl RefUnwindSafe for CompactMessage
impl Send for CompactMessage
impl Sync for CompactMessage
impl Unpin for CompactMessage
impl UnsafeUnpin for CompactMessage
impl UnwindSafe for CompactMessage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more