Add DC_EVENT_SELFAVATAR_CHANGED (#2742)

* Add DC_EVENT_SELFAVATAR_CHANGED

* Add test.

Unfortunately I can't easily also test that the avatar is not copied
from unencrypted messages:

In the second encrypted message, the avatar would not be sent again
then, because we only send avatars once a day or so.

* Unfortunately I can't easily also test that the avatar is not copied from unencrypted messages:

In the second encrypted message, the avatar would not be sent again
then, because we only send avatars once a day or so.
This commit is contained in:
Hocuri
2021-10-18 10:42:16 +02:00
committed by GitHub
parent 41ec380b55
commit 6613fa67ee
8 changed files with 105 additions and 9 deletions

View File

@@ -34,6 +34,9 @@ use crate::message::{update_msg_state, Message, MessageState, MsgId};
use crate::mimeparser::MimeMessage;
use crate::param::{Param, Params};
#[allow(non_upper_case_globals)]
pub const AVATAR_900x900_BYTES: &[u8] = include_bytes!("../test-data/image/avatar900x900.png");
type EventSink =
dyn Fn(Event) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> + Send + Sync + 'static;
@@ -587,6 +590,21 @@ impl EvTracker {
}
}
}
pub async fn get_matching<F: Fn(EventType) -> bool>(&self, event_matcher: F) -> EventType {
const TIMEOUT: Duration = Duration::from_secs(20);
loop {
let event = async_std::future::timeout(TIMEOUT, self.recv())
.await
.unwrap()
.unwrap();
if event_matcher(event.clone()) {
return event;
}
}
}
}
impl Deref for EvTracker {