Skip to content

Commit

Permalink
Call update_device_chats automatically during configure (#1957)
Browse files Browse the repository at this point in the history
update_device_chats() takes about 2 seconds on a modern device (Android) because the
welcome image file has to be written to the disk as a blob. The problem
was that this was done after the progress bar had vanished and before
anything else happened so that I thought that something had gone wrong
multiple times.

The UIs have to remove update_device_chats(), too..
  • Loading branch information
Hocuri authored Oct 15, 2020
1 parent 18e9073 commit 07e4762
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

- breaking change: `dc_update_device_chats()` was removed. This is now done automatically during configure.

- Added a `bot` config. Currently, it only prevents filling the device chats automatically.

## 1.46.0

- breaking change: `dc_configure()` report errors in
Expand Down
19 changes: 1 addition & 18 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ char* dc_get_blobdir (const dc_context_t* context);
* https://github.com/cracker0dks/basicwebrtc which some UIs have native support for.
* The type `jitsi:` may be handled by external apps.
* If no type is prefixed, the videochat is handled completely in a browser.
* - `bot` = Set to "1" if this is a bot. E.g. prevents adding the "Device messages" and "Saved messages" chats.
*
* If you want to retrieve a value, use dc_get_config().
*
Expand Down Expand Up @@ -984,24 +985,6 @@ void dc_set_draft (dc_context_t* context, uint32_t ch
*/
uint32_t dc_add_device_msg (dc_context_t* context, const char* label, dc_msg_t* msg);


/**
* Init device-messages and saved-messages chat.
* This function adds the device-chat and saved-messages chat
* and adds one or more welcome or update-messages.
* The ui can add messages on its own using dc_add_device_msg() -
* for ordering, either before or after or even without calling this function.
*
* Chat and message creation is done only once.
* So if the user has manually deleted things, they won't be re-created
* (however, not seen device messages are added and may re-create the device-chat).
*
* @memberof dc_context_t
* @param context The context object.
*/
void dc_update_device_chats (dc_context_t* context);


/**
* Check if a device-message with a given label was ever added.
* Device-messages can be added dc_add_device_msg().
Expand Down
15 changes: 0 additions & 15 deletions deltachat-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,21 +807,6 @@ pub unsafe extern "C" fn dc_add_device_msg(
.to_u32()
}

#[no_mangle]
pub unsafe extern "C" fn dc_update_device_chats(context: *mut dc_context_t) {
if context.is_null() {
eprintln!("ignoring careless call to dc_update_device_chats()");
return;
}
let ctx = &mut *context;

block_on(async move {
ctx.update_device_chats()
.await
.unwrap_or_log_default(&ctx, "Failed to add device message")
})
}

#[no_mangle]
pub unsafe extern "C" fn dc_was_device_msg_ever_added(
context: *mut dc_context_t,
Expand Down
3 changes: 0 additions & 3 deletions examples/repl/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
msg.set_text(Some(arg1.to_string()));
chat::add_device_msg(&context, None, Some(&mut msg)).await?;
}
"updatedevicechats" => {
context.update_device_chats().await?;
}
"listmedia" => {
ensure!(sel_chat.is_some(), "No chat selected.");

Expand Down
1 change: 1 addition & 0 deletions python/src/deltachat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def run_cmdline(argv=None, account_plugins=None):
ac.set_config("mvbox_move", "0")
ac.set_config("mvbox_watch", "0")
ac.set_config("sentbox_watch", "0")
ac.set_config("bot", "1")
configtracker = ac.configure()
configtracker.wait_finish()

Expand Down
3 changes: 3 additions & 0 deletions python/src/deltachat/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ def get_chats(self):
def get_deaddrop_chat(self):
return Chat(self, const.DC_CHAT_ID_DEADDROP)

def get_device_chat(self):
return Contact(self, const.DC_CONTACT_ID_DEVICE).create_chat()

def get_message_by_id(self, msg_id):
""" return Message instance.
:param msg_id: integer id of this message.
Expand Down
2 changes: 2 additions & 0 deletions python/src/deltachat/testplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ def wait_configure_and_start_io(self):
for acc in self._accounts:
if hasattr(acc, "_configtracker"):
acc._configtracker.wait_finish()
acc._evtracker.consume_events()
acc.get_device_chat().mark_noticed()
del acc._configtracker
acc.set_config("bcc_self", "0")
if acc.is_configured() and not acc.is_started():
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ pub enum Config {
#[strum(serialize = "sys.config_keys")]
SysConfigKeys,

Bot,

/// Whether we send a warning if the password is wrong (set to false when we send a warning
/// because we do not want to send a second warning)
#[strum(props(default = "0"))]
Expand Down
4 changes: 4 additions & 0 deletions src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
DC_LP_AUTH_NORMAL as i32
};

let ctx2 = ctx.clone();
let update_device_chats_handle = task::spawn(async move { ctx2.update_device_chats().await });

// Step 1: Load the parameters and check email-address and password

if oauth2 {
Expand Down Expand Up @@ -357,6 +360,7 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
.await;

progress!(ctx, 940);
update_device_chats_handle.await?;

Ok(())
}
Expand Down
13 changes: 5 additions & 8 deletions src/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::borrow::Cow;
use strum::EnumProperty;
use strum_macros::EnumProperty;

use crate::blob::BlobObject;
use crate::chat;
use crate::chat::ProtectionStatus;
use crate::constants::{Viewtype, DC_CONTACT_ID_SELF};
Expand All @@ -15,6 +14,7 @@ use crate::error::{bail, Error};
use crate::message::Message;
use crate::param::Param;
use crate::stock::StockMessage::{DeviceMessagesHint, WelcomeMessage};
use crate::{blob::BlobObject, config::Config};

/// Stock strings
///
Expand Down Expand Up @@ -423,16 +423,13 @@ impl Context {
.await
}

pub async fn update_device_chats(&self) -> Result<(), Error> {
// check for the LAST added device message - if it is present, we can skip message creation.
// this is worthwhile as this function is typically called
// by the UI on every program start or even on every opening of the chatlist.
if chat::was_device_msg_ever_added(&self, "core-welcome").await? {
pub(crate) async fn update_device_chats(&self) -> Result<(), Error> {
if self.get_config_bool(Config::Bot).await {
return Ok(());
}

// create saved-messages chat;
// we do this only once, if the user has deleted the chat, he can recreate it manually.
// create saved-messages chat; we do this only once, if the user has deleted the chat,
// he can recreate it manually (make sure we do not re-add it when configure() was called a second time)
if !self.sql.get_raw_config_bool(&self, "self-chat-added").await {
self.sql
.set_raw_config_bool(&self, "self-chat-added", true)
Expand Down

0 comments on commit 07e4762

Please sign in to comment.