use std::sync::Arc;
use chrono::{DateTime, Utc};
use gpui_kit::Image;
use serde::{Deserialize, Serialize};
use teams_core::{
AnnouncementBanner, Draft, FileKind, FileReference, HostedImage, LinkPreview, MentionInput,
MessageExtras, OBJECT_MARK, UploadedFile,
};
use store::MessageImportance;
use crate::remote_image::RemoteImage;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InlineImage {
pub name: String,
pub image: Arc a 0 {
// Derived from the body, so every html() of one message gives the same text.
let id = code_block_id(html, index);
linked.push_str(&format!(
" uuid::Uuid {
use std::hash::{Hash, Hasher};
let mut hasher = std::hash::DefaultHasher::new();
(html, index).hash(&mut hasher);
let high = hasher.finish();
high.hash(&mut hasher);
uuid::Uuid::from_u64_pair(high, hasher.finish())
}
impl Outgoing {
/// Without list and quote markers, for previews.
pub fn text(&self) -> String {
self.draft.plain_text()
}
/// The body before mentions become `"
));
}
Some(OutgoingImage::Remote(remote)) => html.push_str(&remote.html()),
None => {}
}
}
link_code_blocks(&teams_core::emoticon_tags(
&html,
crate::emoticons::send_tag,
))
}
pub fn has_attachments(&self) -> bool {
!self.images.is_empty() || !self.files.is_empty()
}
pub fn extras(&self) -> MessageExtras {
MessageExtras {
importance: self.importance.stored(),
kept: Vec::new(),
images: self
.images
.iter()
.filter_map(|outgoing| match outgoing {
OutgoingImage::Inline(inline) => Some(HostedImage {
content_type: inline.image.format.mime_type().to_owned(),
bytes: Arc::new(inline.image.bytes.clone()),
}),
OutgoingImage::Remote(_) => None,
})
.collect(),
files: self
.files
.iter()
.map(|file| file.reference.clone())
.collect(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn each_code_block_gets_its_own_teams_marker() {
let html = "
x
";
let linked = link_code_blocks(html);
let ids: Vec<&str> = linked
.split("itemid=\"codeBlockEditor-")
.skip(1)
.map(|rest| &rest[..36])
.collect();
assert_eq!(ids.len(), 2);
assert_ne!(ids[0], ids[1]);
for id in &ids {
assert!(linked.contains(&format!(
"<pre yno code
no code
"); } }