C6ZDDCL46FXQ7W2UEDZ62YJWI5LUEI4ONHQWU3CHWRVTYSLWRDWAC
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
dependencies = [
"cfg-if 0.1.10",
"cloudabi 0.0.3",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "parking_lot_core"
fn download_thumbnail_for_event(tevent: &TimelineEvent) -> Option<(bool, Uri)> {
if let Some(thumbnail_url) = tevent.thumbnail_url() {
if make_content_path(&thumbnail_url).exists() {
Some((true, thumbnail_url))
} else {
Some((false, thumbnail_url))
}
} else if let (Some(content_size), Some(content_url)) =
(tevent.content_size(), tevent.content_url())
{
if make_content_path(&content_url).exists() {
Some((true, content_url))
} else if content_size < 1000 * 1000 {
Some((false, content_url))
} else {
None
}
} else {
None
}
}
if let MembershipChange::Left = membership_change {
for ids in self.display_name_to_user_id.values_mut() {
if let Some(index) = ids.iter().position(|id| id == &user_id) {
ids.remove(index);
match membership_change {
MembershipChange::Left
| MembershipChange::Banned
| MembershipChange::Kicked
| MembershipChange::KickedAndBanned => {
if let Some(name) = member.display_name() {
if let Some(ids) = self.display_name_to_user_id.get_mut(name) {
if let Some(index) = ids.iter().position(|id| id == &user_id) {
ids.remove(index);
}
}
} else if let MembershipChange::Joined = membership_change {
// This unwrap is safe since we add a member if they don't exist beforehand
if let Some(name) = self.members.get(&user_id).unwrap().display_name() {
let ids = self
.display_name_to_user_id
.entry(name.to_string())
.or_insert_with(|| vec![user_id.clone()]);
MembershipChange::Joined | MembershipChange::Unbanned => {
if let Some(name) = member.display_name() {
let ids = self
.display_name_to_user_id
.entry(name.to_string())
.or_default();
} else if let MembershipChange::ProfileChanged {
displayname_changed,
avatar_url_changed: _,
} = membership_change
{
if displayname_changed {
if let Some(Some(name)) = prev_displayname {
if let Some(ids) = self.display_name_to_user_id.get_mut(&name) {
if let Some(index) = ids.iter().position(|id| id == &user_id) {
ids.remove(index);
MembershipChange::ProfileChanged {
displayname_changed,
avatar_url_changed: _,
} => {
if displayname_changed {
if let Some(name) = prev_displayname {
if let Some(ids) = self.display_name_to_user_id.get_mut(&name) {
if let Some(index) = ids.iter().position(|id| id == &user_id) {
ids.remove(index);
}
}
// This unwrap is safe since we add a member if they don't exist beforehand
if let Some(name) = self.members.get(&user_id).unwrap().display_name() {
if let Some(ids) = self.display_name_to_user_id.get_mut(name) {
ids.push(user_id);
if let Some(name) = member.display_name() {
if let Some(ids) = self.display_name_to_user_id.get_mut(name) {
ids.push(user_id);
}
pub fn download_or_read_thumbnail(&self) -> Option<(bool, Uri)> {
if let Some(thumbnail_url) = self.thumbnail_url() {
Some((
if make_content_path(&thumbnail_url).exists() {
true
} else {
false
},
thumbnail_url,
))
} else if let (Some(ContentType::Image), Some(content_size), Some(content_url)) =
(self.content_type(), self.content_size(), self.content_url())
{
if make_content_path(&content_url).exists() {
Some((true, content_url))
} else if content_size < 1000 * 1000 {
Some((false, content_url))
} else {
None
}
} else {
None
}
}
Command::perform(
Client::get_events_around(inner, room_id, event_id),
|result| match result {
Ok(response) => super::Message::MainScreen(
Message::MatrixGetEventsAroundResponse(Box::new(response)),
),
Err(err) => super::Message::MatrixError(Box::new(err)),
},
)
}
return Command::batch(thumbnail_urls.into_iter().map(
|(is_in_cache, thumbnail_url)| {
if is_in_cache {
Command::perform(
async move {
(
async {
Ok(ImageHandle::from_memory(
tokio::fs::read(media::make_content_path(
&thumbnail_url,
))
.await?,
))
}
.await,
thumbnail_url,
)
},
|(result, thumbnail_url)| match result {
Ok(thumbnail) => {
super::Message::MainScreen(Message::DownloadedThumbnail {
thumbnail,
thumbnail_url,
})
}
Err(err) => super::Message::MatrixError(Box::new(err)),
},
)
} else {
let inner = client.inner();
fn make_download_content_com(
inner: ruma_client::Client,
content_url: Uri,
) -> Command<super::Message> {
Command::perform(
async move {
let download_result =
Client::download_content(inner, content_url.clone()).await;
Command::perform(
async move {
let download_result =
Client::download_content(inner, thumbnail_url.clone()).await;
match download_result {
Ok(raw_data) => {
let path = media::make_content_path(&content_url);
let server_media_dir = media::make_content_folder(&content_url);
tokio::fs::create_dir_all(server_media_dir).await?;
tokio::fs::write(path, raw_data.as_slice())
.await
.map(|_| (content_url, raw_data))
.map_err(|e| e.into())
}
Err(err) => Err(err),
}
},
|result| match result {
Ok((content_url, raw_data)) => {
super::Message::MainScreen(Message::DownloadedThumbnail {
thumbnail_url: content_url,
thumbnail: ImageHandle::from_memory(raw_data),
})
match download_result {
Ok(raw_data) => {
let path = media::make_content_path(&thumbnail_url);
let server_media_dir =
media::make_content_folder(&thumbnail_url);
tokio::fs::create_dir_all(server_media_dir).await?;
tokio::fs::write(path, raw_data.as_slice())
.await
.map(|_| (thumbnail_url, raw_data))
.map_err(|e| e.into())
}
Err(err) => Err(err),
}
},
|result| match result {
Ok((thumbnail_url, raw_data)) => {
super::Message::MainScreen(Message::DownloadedThumbnail {
thumbnail_url,
thumbnail: ImageHandle::from_memory(raw_data),
})
}
Err(err) => super::Message::MatrixError(Box::new(err)),
},
)
Err(err) => super::Message::MatrixError(Box::new(err)),
},
)
}
fn make_read_thumbnail_com(thumbnail_url: Uri) -> Command<super::Message> {
Command::perform(
async move {
(
async {
Ok(ImageHandle::from_memory(
tokio::fs::read(media::make_content_path(&thumbnail_url)).await?,
))
}
.await,
thumbnail_url,
)
return make_get_events_around_command(inner, room_id, event_id);
return Command::perform(
Client::get_events_around(inner, room_id, event_id),
|result| match result {
Ok(response) => super::Message::MainScreen(
Message::MatrixGetEventsAroundResponse(Box::new(
response,
)),
),
Err(err) => super::Message::MatrixError(Box::new(err)),
},
);
return Command::batch(thumbnail_urls.into_iter().map(
|(is_in_cache, thumbnail_url)| {
if is_in_cache {
make_read_thumbnail_com(thumbnail_url)
} else {
make_download_content_com(self.client.inner(), thumbnail_url)
}
},
));
return make_thumbnail_commands(&self.client, thumbnail_urls);
return Command::batch(thumbnail_urls.into_iter().map(
|(is_in_cache, thumbnail_url)| {
if is_in_cache {
make_read_thumbnail_com(thumbnail_url)
} else {
make_download_content_com(self.client.inner(), thumbnail_url)
}
},
));
return make_thumbnail_commands(&self.client, thumbnail_urls);