fix #164 add MEMBER_REMOVED event and member_removed plugin python hook

This commit is contained in:
holger krekel
2020-03-04 14:34:26 +01:00
parent 36b50436d7
commit d66829702f
8 changed files with 92 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import print_function
import atexit
from contextlib import contextmanager
import queue
from threading import Event
import os
from array import array
@@ -15,7 +16,6 @@ from .message import Message
from .contact import Contact
from .tracker import ImexTracker
from . import hookspec, iothreads
from queue import Queue
class MissingCredentials(ValueError):
@@ -49,7 +49,7 @@ class Account(object):
hook.account_init(account=self, db_path=db_path)
self._threads = iothreads.IOThreads(self)
self._hook_event_queue = Queue()
self._hook_event_queue = queue.Queue()
self._in_use_iter_events = False
self._shutdown_event = Event()
@@ -578,6 +578,16 @@ class Account(object):
hook = hookspec.Global._get_plugin_manager().hook
hook.account_after_shutdown(account=self, dc_context=dc_context)
def _handle_current_events(self):
""" handle all currently queued events and then return. """
while 1:
try:
event = self._hook_event_queue.get(block=False)
except queue.Empty:
break
else:
event.call_hook()
def iter_events(self, timeout=None):
""" yield hook events until shutdown.
@@ -614,6 +624,10 @@ class Account(object):
chat = self.get_chat_by_id(ffi_event.data1)
contact = self.get_contact_by_id(ffi_event.data2)
return "member_added", dict(chat=chat, contact=contact)
elif name == "DC_EVENT_MEMBER_REMOVED":
chat = self.get_chat_by_id(ffi_event.data1)
contact = self.get_contact_by_id(ffi_event.data2)
return "member_removed", dict(chat=chat, contact=contact)
return None, {}

View File

@@ -100,6 +100,7 @@ DC_EVENT_SECUREJOIN_INVITER_PROGRESS = 2060
DC_EVENT_SECUREJOIN_JOINER_PROGRESS = 2061
DC_EVENT_SECUREJOIN_MEMBER_ADDED = 2062
DC_EVENT_MEMBER_ADDED = 2063
DC_EVENT_MEMBER_REMOVED = 2064
DC_EVENT_FILE_COPIED = 2055
DC_EVENT_IS_OFFLINE = 2081
DC_EVENT_GET_STRING = 2091

View File

@@ -56,6 +56,10 @@ class PerAccount:
def member_added(self, chat, contact):
""" Called for each contact added to a chat. """
@account_hookspec
def member_removed(self, chat, contact):
""" Called for each contact removed from a chat. """
class Global:
""" global hook specifications using a per-process singleton