diff --git a/python/examples/echo_and_quit.py b/python/examples/echo_and_quit.py index cf9ee8c27..2795923f1 100644 --- a/python/examples/echo_and_quit.py +++ b/python/examples/echo_and_quit.py @@ -3,7 +3,8 @@ import deltachat -class SimpleEchoPlugin: + +class EchoPlugin: @deltachat.hookspec.account_hookimpl def process_incoming_message(self, message): print("process_incoming message", message) @@ -20,6 +21,9 @@ class SimpleEchoPlugin: print("process_message_delivered", message) -if __name__ = "__main__": - deltachat.run_simple_cmdline(account_plugins=[SimpleEchoPlugin()]) +def main(argv=None): + deltachat.run_cmdline(argv=argv, account_plugins=[EchoPlugin()]) + +if __name__ == "__main__": + main() diff --git a/python/examples/group_tracking.py b/python/examples/group_tracking.py index 3e4390d3a..d8e159e93 100644 --- a/python/examples/group_tracking.py +++ b/python/examples/group_tracking.py @@ -1,8 +1,6 @@ # content of group_tracking.py -import sys -import optparse import deltachat @@ -25,40 +23,9 @@ class GroupTrackingPlugin: print("*** member_removed", contact.addr, "from", chat) -def main(argv): - p = optparse.OptionParser("simple-echo") - p.add_option("-l", action="store_true", help="show ffi") - p.add_option("--db", type="str", help="database file") - p.add_option("--email", type="str", help="email address") - p.add_option("--password", type="str", help="password") - - opts, posargs = p.parse_args(argv) - - assert opts.db, "you must specify --db" - ac = deltachat.Account(opts.db) - - if opts.l: - log = deltachat.eventlogger.FFIEventLogger(ac, "group-tracking") - ac.add_account_plugin(log) - - if not ac.is_configured(): - assert opts.email and opts.password, ( - "you must specify --email and --password" - ) - ac.set_config("addr", opts.email) - ac.set_config("mail_pw", opts.password) - ac.set_config("mvbox_watch", "0") - ac.set_config("sentbox_watch", "0") - - ac.add_account_plugin(GroupTrackingPlugin()) - - # start IO threads and configure if neccessary - ac.start() - - print("{}: waiting for message".format(ac.get_config("addr"))) - - ac.wait_shutdown() +def main(argv=None): + deltachat.run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()]) if __name__ == "__main__": - main(sys.argv) + main() diff --git a/python/examples/test_examples.py b/python/examples/test_examples.py index a9f47b02b..66d28e828 100644 --- a/python/examples/test_examples.py +++ b/python/examples/test_examples.py @@ -2,7 +2,8 @@ import threading import pytest import py -from echo_and_quit import main +import echo_and_quit +import group_tracking @pytest.fixture(scope='session') @@ -21,11 +22,13 @@ def test_echo_quit_plugin(acfactory): def run_bot(): print("*"*20 + " starting bot") - main([ - "-l", + print("*"*20 + " bot_ac.dbpath", bot_ac.db_path) + echo_and_quit.main([ + "echo", + "--show-ffi", + "--db", bot_ac.db_path, "--email", bot_cfg["addr"], "--password", bot_cfg["mail_pw"], - "--db", bot_ac.db_path ]) t = threading.Thread(target=run_bot) @@ -39,3 +42,32 @@ def test_echo_quit_plugin(acfactory): assert "hello" in reply.text ch1.send_text("/quit") t.join() + + +@pytest.mark.skip(reason="not implemented") +def test_group_tracking_plugin(acfactory): + bot_ac, bot_cfg = acfactory.get_online_config() + + def run_bot(): + print("*"*20 + " starting bot") + print("*"*20 + " bot_ac.dbpath", bot_ac.db_path) + group_tracking.main([ + "group-tracking", + "--show-ffi", bot_ac.db_path, + "--db", bot_ac.db_path, + "--email", bot_cfg["addr"], + "--password", bot_cfg["mail_pw"], + ]) + + t = threading.Thread(target=run_bot) + t.setDaemon(1) + t.start() + + ac1 = acfactory.get_one_online_account() + bot_contact = ac1.create_contact(bot_cfg["addr"]) + ch1 = ac1.create_chat_by_contact(bot_contact) + ch1.send_text("hello") + ch1.add_contact(ac1.create_contact("x@example.org")) + + # XXX wait for bot to receive things + t.join() diff --git a/python/src/deltachat/__init__.py b/python/src/deltachat/__init__.py index 13ac63f75..f1e140685 100644 --- a/python/src/deltachat/__init__.py +++ b/python/src/deltachat/__init__.py @@ -1,8 +1,9 @@ +import sys + from . import capi, const, hookspec from .capi import ffi from .account import Account # noqa from . import eventlogger -from .util import lazydecorator from pkg_resources import get_distribution, DistributionNotFound try: @@ -111,10 +112,10 @@ def run_cmdline(argv=None, account_plugins=None): args = parser.parse_args(argv[1:]) assert args.db, "you must specify --db" - ac = deltachat.Account(args.db) + ac = Account(args.db) if args.show_ffi: - log = deltachat.eventlogger.FFIEventLogger(ac, "echo") + log = eventlogger.FFIEventLogger(ac, "echo") ac.add_account_plugin(log) if not ac.is_configured(): @@ -126,7 +127,8 @@ def run_cmdline(argv=None, account_plugins=None): ac.set_config("mvbox_watch", "0") ac.set_config("sentbox_watch", "0") - ac.add_account_plugin(SimpleEchoPlugin()) + for plugin in account_plugins or []: + ac.add_account_plugin(plugin) # start IO threads and configure if neccessary ac.start() diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 80f68449a..5c23cbc28 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -54,11 +54,11 @@ class Account(object): self._shutdown_event = Event() # open database + self.db_path = db_path if hasattr(db_path, "encode"): db_path = db_path.encode("utf8") if not lib.dc_open(self._dc_context, db_path, ffi.NULL): raise ValueError("Could not dc_open: {}".format(db_path)) - self.db_path = db_path self._configkeys = self.get_config("sys.config_keys").split() atexit.register(self.shutdown) diff --git a/src/chat.rs b/src/chat.rs index 576185e7b..b1772b741 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1980,13 +1980,6 @@ pub(crate) fn add_contact_to_chat_ex( msg.param.set_int(Param::Arg2, from_handshake.into()); msg.id = send_msg(context, chat_id, &mut msg)?; - } else { - // send an event for unpromoted groups - // XXX probably not neccessary because ChatModified should suffice - context.call_cb(Event::MsgsChanged { - chat_id, - msg_id: MsgId::new(0), - }); } context.call_cb(Event::ChatModified(chat_id)); Ok(true)