mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
emit "DC_EVENT_MEMBER_ADDED" and python plugin event "member_added" for securejoin or non-securejoin additions of a contact to a chat. also fixup some docs
This commit is contained in:
@@ -4505,7 +4505,7 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is sent out to the inviter when a joiner successfully joined a group.
|
* (DEPRECATED)
|
||||||
*
|
*
|
||||||
* @param data1 (int) chat_id
|
* @param data1 (int) chat_id
|
||||||
* @param data2 (int) contact_id
|
* @param data2 (int) contact_id
|
||||||
@@ -4513,6 +4513,14 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
|||||||
*/
|
*/
|
||||||
#define DC_EVENT_SECUREJOIN_MEMBER_ADDED 2062
|
#define DC_EVENT_SECUREJOIN_MEMBER_ADDED 2062
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is sent for each member that gets added to a (verified or unverified) chat.
|
||||||
|
*
|
||||||
|
* @param data1 (int) chat_id
|
||||||
|
* @param data2 (int) contact_id
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
#define DC_EVENT_MEMBER_ADDED 2063
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -199,6 +199,10 @@ impl ContextWrapper {
|
|||||||
Event::SecurejoinMemberAdded {
|
Event::SecurejoinMemberAdded {
|
||||||
chat_id,
|
chat_id,
|
||||||
contact_id,
|
contact_id,
|
||||||
|
}
|
||||||
|
| Event::MemberAdded {
|
||||||
|
chat_id,
|
||||||
|
contact_id,
|
||||||
} => {
|
} => {
|
||||||
ffi_cb(
|
ffi_cb(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
- introduced PerAccount and Global hooks that plugins can implement
|
- introduced PerAccount and Global hooks that plugins can implement
|
||||||
|
|
||||||
|
- introduced `member_added()` plugin event.
|
||||||
|
|
||||||
|
|
||||||
0.800.0
|
0.800.0
|
||||||
-------
|
-------
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ for managing global and per-account plugin registration, and performing
|
|||||||
hook calls.
|
hook calls.
|
||||||
|
|
||||||
|
|
||||||
|
Registering a plugin
|
||||||
|
--------------------
|
||||||
|
|
||||||
.. autoclass:: deltachat.register_global_plugin
|
.. autoclass:: deltachat.register_global_plugin
|
||||||
|
|
||||||
.. autoclass:: deltachat.account.Account.add_account_plugin
|
.. autoclass:: deltachat.account.Account.add_account_plugin
|
||||||
|
|||||||
@@ -86,4 +86,9 @@ def register_global_plugin(plugin):
|
|||||||
gm.check_pending()
|
gm.check_pending()
|
||||||
|
|
||||||
|
|
||||||
|
def unregister_global_plugin(plugin):
|
||||||
|
gm = hookspec.Global._get_plugin_manager()
|
||||||
|
gm.unregister(plugin)
|
||||||
|
|
||||||
|
|
||||||
register_global_plugin(eventlogger)
|
register_global_plugin(eventlogger)
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ class Account(object):
|
|||||||
elif name == "DC_EVENT_MSG_DELIVERED":
|
elif name == "DC_EVENT_MSG_DELIVERED":
|
||||||
msg = self.get_message_by_id(ffi_event.data2)
|
msg = self.get_message_by_id(ffi_event.data2)
|
||||||
self._pm.hook.process_message_delivered(message=msg)
|
self._pm.hook.process_message_delivered(message=msg)
|
||||||
|
elif name == "DC_EVENT_MEMBER_ADDED":
|
||||||
|
chat = self.get_chat_by_id(ffi_event.data1)
|
||||||
|
contact = self.get_contact_by_id(ffi_event.data2)
|
||||||
|
self._pm.hook.member_added(chat=chat, contact=contact)
|
||||||
|
|
||||||
# def __del__(self):
|
# def __del__(self):
|
||||||
# self.shutdown()
|
# self.shutdown()
|
||||||
@@ -342,6 +346,13 @@ class Account(object):
|
|||||||
"""
|
"""
|
||||||
return Message.from_db(self, msg_id)
|
return Message.from_db(self, msg_id)
|
||||||
|
|
||||||
|
def get_contact_by_id(self, contact_id):
|
||||||
|
""" return Contact instance or None.
|
||||||
|
:param contact_id: integer id of this contact.
|
||||||
|
:returns: None or :class:`deltachat.contact.Contact` instance.
|
||||||
|
"""
|
||||||
|
return Contact(self._dc_context, contact_id)
|
||||||
|
|
||||||
def get_chat_by_id(self, chat_id):
|
def get_chat_by_id(self, chat_id):
|
||||||
""" return Chat instance.
|
""" return Chat instance.
|
||||||
:param chat_id: integer id of this chat.
|
:param chat_id: integer id of this chat.
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ DC_EVENT_IMEX_FILE_WRITTEN = 2052
|
|||||||
DC_EVENT_SECUREJOIN_INVITER_PROGRESS = 2060
|
DC_EVENT_SECUREJOIN_INVITER_PROGRESS = 2060
|
||||||
DC_EVENT_SECUREJOIN_JOINER_PROGRESS = 2061
|
DC_EVENT_SECUREJOIN_JOINER_PROGRESS = 2061
|
||||||
DC_EVENT_SECUREJOIN_MEMBER_ADDED = 2062
|
DC_EVENT_SECUREJOIN_MEMBER_ADDED = 2062
|
||||||
|
DC_EVENT_MEMBER_ADDED = 2063
|
||||||
DC_EVENT_FILE_COPIED = 2055
|
DC_EVENT_FILE_COPIED = 2055
|
||||||
DC_EVENT_IS_OFFLINE = 2081
|
DC_EVENT_IS_OFFLINE = 2081
|
||||||
DC_EVENT_GET_STRING = 2091
|
DC_EVENT_GET_STRING = 2091
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import sys
|
|||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
from contextlib import contextmanager
|
||||||
import time
|
import time
|
||||||
from deltachat import Account
|
from deltachat import Account
|
||||||
from deltachat.tracker import ConfigureTracker
|
from deltachat.tracker import ConfigureTracker
|
||||||
from deltachat import const
|
from deltachat import const
|
||||||
from deltachat.capi import lib
|
from deltachat.capi import lib
|
||||||
from deltachat.hookspec import PerAccount
|
from deltachat.hookspec import account_hookimpl
|
||||||
from deltachat.eventlogger import FFIEventLogger
|
from deltachat.eventlogger import FFIEventLogger
|
||||||
from _pytest.monkeypatch import MonkeyPatch
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
from ffi_event import FFIEventTracker
|
from ffi_event import FFIEventTracker
|
||||||
@@ -293,14 +294,25 @@ def lp():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def make_plugin_recorder():
|
def make_plugin_recorder():
|
||||||
|
@contextmanager
|
||||||
def make_plugin_recorder(account):
|
def make_plugin_recorder(account):
|
||||||
class HookImpl:
|
class HookImpl:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.calls_member_added = []
|
self.calls_member_added = []
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def member_added(self, chat, member):
|
def member_added(self, chat, contact):
|
||||||
self.calls_member_added.append(dict(chat=chat, member=member))
|
self.calls_member_added.append(dict(chat=chat, contact=contact))
|
||||||
|
|
||||||
|
def get_first(self, name):
|
||||||
|
val = getattr(self, "calls_" + name, None)
|
||||||
|
if val is not None:
|
||||||
|
return val.pop(0)
|
||||||
|
|
||||||
|
with account.temp_plugin(HookImpl()) as plugin:
|
||||||
|
yield plugin
|
||||||
|
|
||||||
|
return make_plugin_recorder
|
||||||
|
|
||||||
|
|
||||||
def wait_configuration_progress(account, min_target, max_target=1001):
|
def wait_configuration_progress(account, min_target, max_target=1001):
|
||||||
|
|||||||
@@ -167,16 +167,17 @@ class TestOfflineChat:
|
|||||||
else:
|
else:
|
||||||
pytest.fail("could not find chat")
|
pytest.fail("could not find chat")
|
||||||
|
|
||||||
def test_add_member_event(self, ac1):
|
def test_add_member_event(self, ac1, make_plugin_recorder):
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
||||||
contact2 = ac1.create_contact("some2@hello.com", name="some2")
|
|
||||||
chat = ac1.create_group_chat(name="title1")
|
chat = ac1.create_group_chat(name="title1")
|
||||||
|
# promote the chat
|
||||||
|
chat.send_text("hello")
|
||||||
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
|
|
||||||
with make_plugin_recorder(ac1) as rec:
|
with make_plugin_recorder(ac1) as rec:
|
||||||
chat.add_contact(contact2)
|
chat.add_contact(contact1)
|
||||||
kwargs = rec.get_first("member_added")
|
kwargs = rec.get_first("member_added")
|
||||||
assert kwargs["chat"] == chat
|
assert kwargs["chat"] == chat
|
||||||
assert kwargs["member"] == contact2
|
assert kwargs["contact"] == contact1
|
||||||
|
|
||||||
def test_group_chat_creation(self, ac1):
|
def test_group_chat_creation(self, ac1):
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
@@ -1129,7 +1130,7 @@ class TestOnlineAccount:
|
|||||||
ac1._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
|
ac1._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
|
||||||
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
|
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_DELETED")
|
||||||
wait_securejoin_inviter_progress(ac1, 1000)
|
wait_securejoin_inviter_progress(ac1, 1000)
|
||||||
ac1._evtracker.get_matching("DC_EVENT_SECUREJOIN_MEMBER_ADDED")
|
ac1._evtracker.get_matching("DC_EVENT_MEMBER_ADDED")
|
||||||
|
|
||||||
def test_qr_verified_group_and_chatting(self, acfactory, lp):
|
def test_qr_verified_group_and_chatting(self, acfactory, lp):
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
@@ -1141,7 +1142,7 @@ class TestOnlineAccount:
|
|||||||
chat2 = ac2.qr_join_chat(qr)
|
chat2 = ac2.qr_join_chat(qr)
|
||||||
assert chat2.id >= 10
|
assert chat2.id >= 10
|
||||||
wait_securejoin_inviter_progress(ac1, 1000)
|
wait_securejoin_inviter_progress(ac1, 1000)
|
||||||
ac1._evtracker.get_matching("DC_EVENT_SECUREJOIN_MEMBER_ADDED")
|
ac1._evtracker.get_matching("DC_EVENT_MEMBER_ADDED")
|
||||||
|
|
||||||
lp.sec("ac2: read member added message")
|
lp.sec("ac2: read member added message")
|
||||||
msg = ac2._evtracker.wait_next_incoming_message()
|
msg = ac2._evtracker.wait_next_incoming_message()
|
||||||
|
|||||||
@@ -1958,6 +1958,10 @@ pub(crate) fn add_contact_to_chat_ex(
|
|||||||
chat_id,
|
chat_id,
|
||||||
msg_id: msg.id,
|
msg_id: msg.id,
|
||||||
});
|
});
|
||||||
|
context.call_cb(Event::MemberAdded {
|
||||||
|
chat_id,
|
||||||
|
contact_id: contact.id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
context.call_cb(Event::MsgsChanged {
|
context.call_cb(Event::MsgsChanged {
|
||||||
chat_id,
|
chat_id,
|
||||||
|
|||||||
@@ -207,4 +207,10 @@ pub enum Event {
|
|||||||
/// @param data2 (int) contact_id
|
/// @param data2 (int) contact_id
|
||||||
#[strum(props(id = "2062"))]
|
#[strum(props(id = "2062"))]
|
||||||
SecurejoinMemberAdded { chat_id: ChatId, contact_id: u32 },
|
SecurejoinMemberAdded { chat_id: ChatId, contact_id: u32 },
|
||||||
|
|
||||||
|
/// This event is sent for each contact added to a chat.
|
||||||
|
/// @param data1 (int) chat_id
|
||||||
|
/// @param data2 (int) contact_id
|
||||||
|
#[strum(props(id = "2063"))]
|
||||||
|
MemberAdded { chat_id: ChatId, contact_id: u32 },
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -750,7 +750,7 @@ pub(crate) fn handle_securejoin_handshake(
|
|||||||
group: field_grpid.to_string(),
|
group: field_grpid.to_string(),
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
context.call_cb(Event::SecurejoinMemberAdded {
|
context.call_cb(Event::MemberAdded {
|
||||||
chat_id: group_chat_id,
|
chat_id: group_chat_id,
|
||||||
contact_id,
|
contact_id,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user