mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 23:36:30 +03:00
sipmlify plugins and tests and remove superflous core event
This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
import deltachat
|
import deltachat
|
||||||
|
|
||||||
class SimpleEchoPlugin:
|
|
||||||
|
class EchoPlugin:
|
||||||
@deltachat.hookspec.account_hookimpl
|
@deltachat.hookspec.account_hookimpl
|
||||||
def process_incoming_message(self, message):
|
def process_incoming_message(self, message):
|
||||||
print("process_incoming message", message)
|
print("process_incoming message", message)
|
||||||
@@ -20,6 +21,9 @@ class SimpleEchoPlugin:
|
|||||||
print("process_message_delivered", message)
|
print("process_message_delivered", message)
|
||||||
|
|
||||||
|
|
||||||
if __name__ = "__main__":
|
def main(argv=None):
|
||||||
deltachat.run_simple_cmdline(account_plugins=[SimpleEchoPlugin()])
|
deltachat.run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
# content of group_tracking.py
|
# content of group_tracking.py
|
||||||
|
|
||||||
import sys
|
|
||||||
import optparse
|
|
||||||
import deltachat
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
@@ -25,40 +23,9 @@ class GroupTrackingPlugin:
|
|||||||
print("*** member_removed", contact.addr, "from", chat)
|
print("*** member_removed", contact.addr, "from", chat)
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv=None):
|
||||||
p = optparse.OptionParser("simple-echo")
|
deltachat.run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()])
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(sys.argv)
|
main()
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
import threading
|
import threading
|
||||||
import pytest
|
import pytest
|
||||||
import py
|
import py
|
||||||
from echo_and_quit import main
|
import echo_and_quit
|
||||||
|
import group_tracking
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
@@ -21,11 +22,13 @@ def test_echo_quit_plugin(acfactory):
|
|||||||
|
|
||||||
def run_bot():
|
def run_bot():
|
||||||
print("*"*20 + " starting bot")
|
print("*"*20 + " starting bot")
|
||||||
main([
|
print("*"*20 + " bot_ac.dbpath", bot_ac.db_path)
|
||||||
"-l",
|
echo_and_quit.main([
|
||||||
|
"echo",
|
||||||
|
"--show-ffi",
|
||||||
|
"--db", bot_ac.db_path,
|
||||||
"--email", bot_cfg["addr"],
|
"--email", bot_cfg["addr"],
|
||||||
"--password", bot_cfg["mail_pw"],
|
"--password", bot_cfg["mail_pw"],
|
||||||
"--db", bot_ac.db_path
|
|
||||||
])
|
])
|
||||||
|
|
||||||
t = threading.Thread(target=run_bot)
|
t = threading.Thread(target=run_bot)
|
||||||
@@ -39,3 +42,32 @@ def test_echo_quit_plugin(acfactory):
|
|||||||
assert "hello" in reply.text
|
assert "hello" in reply.text
|
||||||
ch1.send_text("/quit")
|
ch1.send_text("/quit")
|
||||||
t.join()
|
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()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from . import capi, const, hookspec
|
from . import capi, const, hookspec
|
||||||
from .capi import ffi
|
from .capi import ffi
|
||||||
from .account import Account # noqa
|
from .account import Account # noqa
|
||||||
from . import eventlogger
|
from . import eventlogger
|
||||||
from .util import lazydecorator
|
|
||||||
|
|
||||||
from pkg_resources import get_distribution, DistributionNotFound
|
from pkg_resources import get_distribution, DistributionNotFound
|
||||||
try:
|
try:
|
||||||
@@ -111,10 +112,10 @@ def run_cmdline(argv=None, account_plugins=None):
|
|||||||
args = parser.parse_args(argv[1:])
|
args = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
assert args.db, "you must specify --db"
|
assert args.db, "you must specify --db"
|
||||||
ac = deltachat.Account(args.db)
|
ac = Account(args.db)
|
||||||
|
|
||||||
if args.show_ffi:
|
if args.show_ffi:
|
||||||
log = deltachat.eventlogger.FFIEventLogger(ac, "echo")
|
log = eventlogger.FFIEventLogger(ac, "echo")
|
||||||
ac.add_account_plugin(log)
|
ac.add_account_plugin(log)
|
||||||
|
|
||||||
if not ac.is_configured():
|
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("mvbox_watch", "0")
|
||||||
ac.set_config("sentbox_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
|
# start IO threads and configure if neccessary
|
||||||
ac.start()
|
ac.start()
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ class Account(object):
|
|||||||
self._shutdown_event = Event()
|
self._shutdown_event = Event()
|
||||||
|
|
||||||
# open database
|
# open database
|
||||||
|
self.db_path = db_path
|
||||||
if hasattr(db_path, "encode"):
|
if hasattr(db_path, "encode"):
|
||||||
db_path = db_path.encode("utf8")
|
db_path = db_path.encode("utf8")
|
||||||
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
||||||
raise ValueError("Could not dc_open: {}".format(db_path))
|
raise ValueError("Could not dc_open: {}".format(db_path))
|
||||||
self.db_path = db_path
|
|
||||||
self._configkeys = self.get_config("sys.config_keys").split()
|
self._configkeys = self.get_config("sys.config_keys").split()
|
||||||
atexit.register(self.shutdown)
|
atexit.register(self.shutdown)
|
||||||
|
|
||||||
|
|||||||
@@ -1980,13 +1980,6 @@ pub(crate) fn add_contact_to_chat_ex(
|
|||||||
msg.param.set_int(Param::Arg2, from_handshake.into());
|
msg.param.set_int(Param::Arg2, from_handshake.into());
|
||||||
|
|
||||||
msg.id = send_msg(context, chat_id, &mut msg)?;
|
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));
|
context.call_cb(Event::ChatModified(chat_id));
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user