mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
rustfmt
This commit is contained in:
41
src/chat.rs
41
src/chat.rs
@@ -983,7 +983,7 @@ pub struct ChatInfo {
|
|||||||
/// Wether the chat is muted
|
/// Wether the chat is muted
|
||||||
///
|
///
|
||||||
/// The exact time its muted can be found out via the `chat.mute_duration` property
|
/// The exact time its muted can be found out via the `chat.mute_duration` property
|
||||||
pub is_muted:bool,
|
pub is_muted: bool,
|
||||||
// ToDo:
|
// ToDo:
|
||||||
// - [ ] deaddrop,
|
// - [ ] deaddrop,
|
||||||
// - [ ] summary,
|
// - [ ] summary,
|
||||||
@@ -1926,7 +1926,7 @@ pub enum MuteDuration {
|
|||||||
|
|
||||||
impl MuteDuration {
|
impl MuteDuration {
|
||||||
// TODO use serde compatible functions?
|
// TODO use serde compatible functions?
|
||||||
fn serialize (&self) -> i64 {
|
fn serialize(&self) -> i64 {
|
||||||
match &self {
|
match &self {
|
||||||
MuteDuration::NotMuted => 0,
|
MuteDuration::NotMuted => 0,
|
||||||
MuteDuration::Forever => 1,
|
MuteDuration::Forever => 1,
|
||||||
@@ -1934,7 +1934,7 @@ impl MuteDuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize (value: i64) -> MuteDuration {
|
fn deserialize(value: i64) -> MuteDuration {
|
||||||
match value {
|
match value {
|
||||||
0 => MuteDuration::NotMuted,
|
0 => MuteDuration::NotMuted,
|
||||||
1 => MuteDuration::Forever,
|
1 => MuteDuration::Forever,
|
||||||
@@ -1943,19 +1943,18 @@ impl MuteDuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_muted (
|
pub fn set_muted(context: &Context, chat_id: ChatId, duration: MuteDuration) -> Result<(), Error> {
|
||||||
context: &Context,
|
|
||||||
chat_id: ChatId,
|
|
||||||
duration: MuteDuration
|
|
||||||
) -> Result<(), Error>{
|
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
ensure!(!chat_id.is_special(), "Invalid chat ID");
|
ensure!(!chat_id.is_special(), "Invalid chat ID");
|
||||||
if real_group_exists(context, chat_id) && sql::execute(
|
if real_group_exists(context, chat_id)
|
||||||
context,
|
&& sql::execute(
|
||||||
&context.sql,
|
context,
|
||||||
"UPDATE chats SET muted_until=? WHERE id=?;",
|
&context.sql,
|
||||||
params![duration.serialize(), chat_id],
|
"UPDATE chats SET muted_until=? WHERE id=?;",
|
||||||
).is_ok() {
|
params![duration.serialize(), chat_id],
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
context.call_cb(Event::ChatModified(chat_id));
|
context.call_cb(Event::ChatModified(chat_id));
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
@@ -2868,13 +2867,23 @@ mod tests {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
// Timed in the future
|
// Timed in the future
|
||||||
set_muted(&t.ctx, chat_id, MuteDuration::MutedUntilTimestamp(time() + 3600)).unwrap();
|
set_muted(
|
||||||
|
&t.ctx,
|
||||||
|
chat_id,
|
||||||
|
MuteDuration::MutedUntilTimestamp(time() + 3600),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Chat::load_from_db(&t.ctx, chat_id).unwrap().is_muted(),
|
Chat::load_from_db(&t.ctx, chat_id).unwrap().is_muted(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
// Time in the past
|
// Time in the past
|
||||||
set_muted(&t.ctx, chat_id, MuteDuration::MutedUntilTimestamp(time() - 3600)).unwrap();
|
set_muted(
|
||||||
|
&t.ctx,
|
||||||
|
chat_id,
|
||||||
|
MuteDuration::MutedUntilTimestamp(time() - 3600),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Chat::load_from_db(&t.ctx, chat_id).unwrap().is_muted(),
|
Chat::load_from_db(&t.ctx, chat_id).unwrap().is_muted(),
|
||||||
false
|
false
|
||||||
|
|||||||
Reference in New Issue
Block a user