diff options
-rwxr-xr-x | external/messenger.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/external/messenger.py b/external/messenger.py index 1ce6383..684f7a0 100755 --- a/external/messenger.py +++ b/external/messenger.py @@ -85,18 +85,17 @@ class MessengerBridgeClient(fbchat.Client): # ---- SEPARATE THREADS FOR INITIAL SYNC & CLIENT LISTEN ---- -class InitialSyncThread(threading.Thread): - def __init__(self, client, bridge, threads, *args, **kwargs): - super(InitialSyncThread, self).__init__(*args, **kwargs) +class SyncerThread(threading.Thread): + def __init__(self, client, bridge, thread_queue, *args, **kwargs): + super(SyncerThread, self).__init__(*args, **kwargs) self.client = client self.bridge = bridge - self.threads = threads + self.thread_queue = thread_queue def run(self): - sys.stderr.write("(python) fb thread list: {}\n".format(self.threads)) - - for thread in self.threads: + while True: + thread = self.thread_queue.get(block=True) sys.stderr.write("(python) fb thread: {}\n".format(thread)) self.bridge.setup_joined_thread(thread) @@ -242,7 +241,11 @@ class MessengerBridge: if thread.type == ThreadType.USER: self.getUserId(thread) - InitialSyncThread(self.client, self, threads).start() + self.sync_thread_queue = queue.Queue(100) + SyncerThread(self.client, self, self.sync_thread_queue).start() + for thread in threads: + self.sync_thread_queue.put(thread) + ClientListenThread(self.client).start() elif ty == CLOSE: @@ -332,7 +335,7 @@ class MessengerBridge: self.my_joined_rooms[thread_id] = True thread = self.client.fetchThreadInfo(thread_id)[thread_id] - self.setup_joined_thread(thread) + self.sync_thread_queue.put(thread) def setup_joined_thread(self, thread): sys.stderr.write("(python) setup_joined_thread {}".format(thread)) |