Skip to content

add chatlist changed event #2850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### API Changes
- add `DC_EVENT_CHAT_LIST_CHANGED` event

### Changes
- add chatlist changed event

## 1.68.0

### Fixes
Expand Down
8 changes: 8 additions & 0 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5301,6 +5301,14 @@ void dc_event_unref(dc_event_t* event);
*/
#define DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED 2021

/**
* Chatlist changed and ui should reload it (reordering, entry added or removed)
*
* This event is fired when the ordering or contents of the chatlist change,
* for changes in individual chat list items listen to `IncomingMsg`, `MsgsNoticed`, `MsgDelivered`, `MsgFailed`, `MsgRead` and `ChatModified`
*/
#define DC_EVENT_CHAT_LIST_CHANGED 2025


/**
* Contact(s) created, renamed, verified, blocked or deleted.
Expand Down
5 changes: 4 additions & 1 deletion deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
| EventType::Error(_)
| EventType::ConnectivityChanged
| EventType::SelfavatarChanged
| EventType::ChatListChanged
| EventType::ErrorSelfNotInGroup(_) => 0,
EventType::MsgsChanged { chat_id, .. }
| EventType::IncomingMsg { chat_id, .. }
Expand Down Expand Up @@ -491,7 +492,8 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
| EventType::MsgsNoticed(_)
| EventType::ConnectivityChanged
| EventType::SelfavatarChanged
| EventType::ChatModified(_) => 0,
| EventType::ChatModified(_)
| EventType::ChatListChanged => 0,
EventType::MsgsChanged { msg_id, .. }
| EventType::IncomingMsg { msg_id, .. }
| EventType::MsgDelivered { msg_id, .. }
Expand Down Expand Up @@ -534,6 +536,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
| EventType::MsgFailed { .. }
| EventType::MsgRead { .. }
| EventType::ChatModified(_)
| EventType::ChatListChanged
| EventType::ContactsChanged(_)
| EventType::LocationChanged(_)
| EventType::ImexProgress(_)
Expand Down
2 changes: 2 additions & 0 deletions examples/repl/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async fn reset_tables(context: &Context, bits: i32) {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context.emit_event(EventType::ChatListChanged);
}

async fn poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<()> {
Expand Down Expand Up @@ -167,6 +168,7 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context.emit_event(EventType::ChatListChanged);
}
true
}
Expand Down
6 changes: 6 additions & 0 deletions examples/repl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ fn receive_event(event: EventType) {
yellow.paint(format!("Received CHAT_MODIFIED({})", chat))
);
}
EventType::ChatListChanged(chat) => {
info!(
"{}",
yellow.paint("Received CHAT_LIST_CHANGED")
);
}
_ => {
info!("Received {:?}", event);
}
Expand Down
11 changes: 10 additions & 1 deletion src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl ChatId {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context.emit_event(EventType::ChatListChanged);
Ok(chat_id)
}

Expand Down Expand Up @@ -301,10 +302,12 @@ impl ChatId {
Chattype::Group => {
info!(context, "Can't block groups yet, deleting the chat");
self.delete(context).await?;
context.emit_event(EventType::ChatListChanged);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emitting the event is already done in delete()

}
Chattype::Mailinglist => {
if self.set_blocked(context, Blocked::Yes).await? {
context.emit_event(EventType::ChatModified(self));
context.emit_event(EventType::ChatListChanged);
}
}
}
Expand Down Expand Up @@ -345,6 +348,7 @@ impl ChatId {

if self.set_blocked(context, Blocked::Not).await? {
context.emit_event(EventType::ChatModified(self));
context.emit_event(EventType::ChatListChanged);
}

Ok(())
Expand Down Expand Up @@ -489,6 +493,7 @@ impl ChatId {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
});
context.emit_event(EventType::ChatListChanged);

Ok(())
}
Expand Down Expand Up @@ -546,6 +551,7 @@ impl ChatId {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
});
context.emit_event(EventType::ChatListChanged);

job::kill_action(context, Action::Housekeeping).await?;
let j = job::Job::new(Action::Housekeeping, 0, Params::new(), 10);
Expand Down Expand Up @@ -1992,7 +1998,8 @@ pub async fn get_chat_msgs(
context.emit_event(EventType::MsgsChanged {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
})
});
context.emit_event(EventType::ChatListChanged);
}
}
}
Expand Down Expand Up @@ -2292,6 +2299,7 @@ pub async fn create_group_chat(
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
});
context.emit_event(EventType::ChatListChanged);

if protect == ProtectionStatus::Protected {
// this part is to stay compatible to verified groups,
Expand Down Expand Up @@ -2349,6 +2357,7 @@ pub async fn create_broadcast_list(context: &Context) -> Result<ChatId> {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
});
context.emit_event(EventType::ChatListChanged);
Ok(chat_id)
}

Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ impl Context {
msg_id: MsgId::new(0),
chat_id: ChatId::new(0),
});
self.emit_event(EventType::ChatListChanged);
ret
}
Config::Displayname => {
Expand Down
8 changes: 6 additions & 2 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,16 @@ impl Contact {

/// Block the given contact.
pub async fn block(context: &Context, id: u32) -> Result<()> {
set_block_contact(context, id, true).await
set_block_contact(context, id, true).await?;
context.emit_event(EventType::ChatListChanged);
Ok(())
}

/// Unblock the given contact.
pub async fn unblock(context: &Context, id: u32) -> Result<()> {
set_block_contact(context, id, false).await
set_block_contact(context, id, false).await?;
context.emit_event(EventType::ChatListChanged);
Ok(())
}

/// Add a single contact as a result of an _explicit_ user action.
Expand Down
2 changes: 2 additions & 0 deletions src/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ pub async fn schedule_ephemeral_task(context: &Context) {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context1.emit_event(EventType::ChatListChanged);
});
*context.ephemeral_task.write().await = Some(ephemeral_task);
} else {
Expand All @@ -430,6 +431,7 @@ pub async fn schedule_ephemeral_task(context: &Context) {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context.emit_event(EventType::ChatListChanged);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ pub enum EventType {
timer: EphemeralTimer,
},

// Chatlist changed and ui should reload it (reordering, entry added or removed)
//
// This event is fired when the ordering or contents of the chatlist change,
// for changes in individual chat list items listen to `IncomingMsg`, `MsgsNoticed`, `MsgDelivered`, `MsgFailed`, `MsgRead` and `ChatModified`
Comment on lines +253 to +254
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "or contents" mean that the event is also fired if something within a chatlist item changed (like, a read receipt was received for the last message you sent and now two green checkmarks are shown)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I'm open for suggestion on how to make this more clear

#[strum(props(id = "2025"))]
ChatListChanged,

/// Contact(s) created, renamed, blocked or deleted.
///
/// @param data1 (int) If set, this is the contact_id of an added contact that should be selected.
Expand Down
1 change: 1 addition & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
chat_id: ChatId::new(0),
msg_id: MsgId::new(0),
});
context.emit_event(EventType::ChatListChanged);
job::kill_action(context, Action::Housekeeping).await?;
job::add(
context,
Expand Down
4 changes: 4 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ fn receive_event(event: &Event) {
"{}",
green.paint(format!("Received CHAT_MODIFIED({})", chat))
),
EventType::ChatListChanged => format!(
"{}",
green.paint("Received CHAT_LIST_CHANGED()")
),
_ => format!("Received {:?}", event),
};
let context_names = CONTEXT_NAMES.read().unwrap();
Expand Down