mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fix #164 add MEMBER_REMOVED event and member_removed plugin python hook
This commit is contained in:
@@ -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, {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user