From cebe7a28c081adaccbc739ecccc33187b0be1f97 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Fri, 1 Jun 2018 12:57:09 +0200 Subject: [PATCH 1/3] Fix onTyping detection FB changed the format of typing notification messages: - update "mtype" from "typ" to "ttyp". - Get thread ID from "to" to "thread_fbid" ("thread" looks the same) --- fbchat/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 2b20d69..ae1af9e 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1529,9 +1529,9 @@ class Client(object): self.onInbox(unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], msg=m) # Typing - elif mtype == "typ": + elif mtype == "ttyp": author_id = str(m.get("from")) - thread_id = str(m.get("to")) + thread_id = str(m.get("thread_fbid")) if thread_id == self.uid: thread_type = ThreadType.USER else: From 1f359f2a721ad5819929f8c14e01f9c842559cf9 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Sun, 3 Jun 2018 22:33:15 +0200 Subject: [PATCH 2/3] Call onTyping on "typ" or "ttyp" messages FB returns "typ" for ONE-TO-ONE conversations and "ttyp" for GROUP conversations. --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index ae1af9e..d99a20b 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1529,7 +1529,7 @@ class Client(object): self.onInbox(unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], msg=m) # Typing - elif mtype == "ttyp": + elif mtype == "typ" or mtype == "ttyp": author_id = str(m.get("from")) thread_id = str(m.get("thread_fbid")) if thread_id == self.uid: From 62e17daf780614cb48dcfaadbd8f4bcd3628eeda Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 4 Jun 2018 23:57:50 +0200 Subject: [PATCH 3/3] `thread_fbid` is not available with `typ`, there `thread_id = author_id` Also enabled tests --- fbchat/client.py | 13 +++++++++---- tests/test_thread_interraction.py | 2 -- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index d99a20b..392f71a 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1531,11 +1531,16 @@ class Client(object): # Typing elif mtype == "typ" or mtype == "ttyp": author_id = str(m.get("from")) - thread_id = str(m.get("thread_fbid")) - if thread_id == self.uid: - thread_type = ThreadType.USER - else: + thread_id = m.get("thread_fbid") + if thread_id: thread_type = ThreadType.GROUP + thread_id = str(thread_id) + else: + thread_type = ThreadType.USER + if author_id == self.uid: + thread_id = m.get("to") + else: + thread_id = author_id typing_status = TypingStatus(m.get("st")) self.onTyping(author_id=author_id, status=typing_status, thread_id=thread_id, thread_type=thread_type, msg=m) diff --git a/tests/test_thread_interraction.py b/tests/test_thread_interraction.py index 7aa744a..9844998 100644 --- a/tests/test_thread_interraction.py +++ b/tests/test_thread_interraction.py @@ -103,10 +103,8 @@ def test_change_color_invalid(client): client.changeThreadColor(InvalidColor()) -@pytest.mark.xfail(reason="Apparently onTyping is broken") @pytest.mark.parametrize("status", TypingStatus) def test_typing_status(client, catch_event, compare, status): with catch_event("onTyping") as x: client.setTypingStatus(status) - # x.wait(40) assert compare(x, status=status)