diff options
-rw-r--r-- | protocols/WhatsApp/src/chats.cpp | 16 | ||||
-rw-r--r-- | protocols/WhatsApp/src/iq.cpp | 18 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.cpp | 4 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 13 | ||||
-rw-r--r-- | protocols/WhatsApp/src/server.cpp | 12 |
5 files changed, 36 insertions, 27 deletions
diff --git a/protocols/WhatsApp/src/chats.cpp b/protocols/WhatsApp/src/chats.cpp index 3df2a954ee..6ebb94073f 100644 --- a/protocols/WhatsApp/src/chats.cpp +++ b/protocols/WhatsApp/src/chats.cpp @@ -68,22 +68,6 @@ void WhatsAppProto::OnGetChatInfo(const JSONNode &root, void *param) Chat_Event(&gce); } - if (pChatUser->arHistory.getCount()) { - for (auto &it : pChatUser->arHistory) { - CMStringW jid(it->jid), text(Utf2T(it->text)); - - GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE }; - gce.pszID.w = pChatUser->si->ptszID; - gce.dwFlags = GCEF_ADDTOLOG; - gce.pszUID.w = jid; - gce.pszText.w = text; - gce.time = it->timestamp; - gce.bIsMe = (it->jid == m_szJid); - Chat_Event(&gce); - } - pChatUser->arHistory.destroy(); - } - CMStringW wszSubject(root["subject"].as_mstring()); if (!wszSubject.IsEmpty()) { time_t iSubjectTime(root["subjectTime"].as_int()); diff --git a/protocols/WhatsApp/src/iq.cpp b/protocols/WhatsApp/src/iq.cpp index 1e8361cf90..207fa8bd80 100644 --- a/protocols/WhatsApp/src/iq.cpp +++ b/protocols/WhatsApp/src/iq.cpp @@ -234,6 +234,23 @@ void WhatsAppProto::OnNotifyAny(const WANode &node) ///////////////////////////////////////////////////////////////////////////////////////// +void WhatsAppProto::OnReceiveChatState(const WANode &node) +{ + if (auto *pUser = FindUser(node.getAttr("from"))) { + if (node.getChild("composing")) { + pUser->m_timer1 = time(0); + pUser->m_timer2 = 0; + setWord(pUser->hContact, "Status", ID_STATUS_ONLINE); + + CallService(MS_PROTO_CONTACTISTYPING, pUser->hContact, 60); + } + else if (node.getChild("paused")) + CallService(MS_PROTO_CONTACTISTYPING, pUser->hContact, PROTOTYPE_CONTACTTYPING_OFF); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + void WhatsAppProto::OnNotifyDevices(const WANode &node) { if (!mir_strcmp(node.getAttr("jid"), m_szJid)) @@ -499,6 +516,7 @@ void WhatsAppProto::InitPersistentHandlers() m_arPersistent.insert(new WAPersistentHandler("ib", 0, 0, 0, &WhatsAppProto::OnReceiveInfo)); m_arPersistent.insert(new WAPersistentHandler("message", 0, 0, 0, &WhatsAppProto::OnReceiveMessage)); m_arPersistent.insert(new WAPersistentHandler("receipt", 0, 0, 0, &WhatsAppProto::OnReceiveReceipt)); + m_arPersistent.insert(new WAPersistentHandler("chatstates", 0, 0, 0, &WhatsAppProto::OnReceiveChatState)); m_arPersistent.insert(new WAPersistentHandler("stream:error", 0, 0, 0, &WhatsAppProto::OnStreamError)); m_arPersistent.insert(new WAPersistentHandler("success", 0, 0, 0, &WhatsAppProto::OnSuccess)); diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 96e379ed73..25f1671936 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -217,11 +217,13 @@ int WhatsAppProto::SendMsg(MCONTACT hContact, int, const char *pszMsg) return SendTextMessage(jid, pszMsg); } -int WhatsAppProto::UserIsTyping(MCONTACT hContact, int) +int WhatsAppProto::UserIsTyping(MCONTACT hContact, int type) { if (hContact && isOnline()) { ptrA jid(getStringA(hContact, DBKEY_ID)); if (jid && isOnline()) { + WSSendNode( + WANode("chatstates") << CHAR_PARAM("to", jid) << XCHILD((type == PROTOTYPE_SELFTYPING_ON) ? "composing" : "paused")); } } diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index ced5aab79d..4a4ca4676c 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -65,19 +65,12 @@ struct WAPersistentHandler WA_PKT_HANDLER pHandler; }; -struct WAHistoryMessage -{ - CMStringA jid, text; - DWORD timestamp; -}; - struct WAUser { WAUser(MCONTACT _1, const char *_2, bool _3 = false) : hContact(_1), szId(mir_strdup(_2)), - bIsGroupChat(_3), - arHistory(1) + bIsGroupChat(_3) { } @@ -91,8 +84,7 @@ struct WAUser char *szId; bool bInited = false, bIsGroupChat; SESSION_INFO *si = 0; - DWORD m_time1 = 0, m_time2 = 0; - OBJLIST<WAHistoryMessage> arHistory; + time_t m_timer1 = 0, m_timer2 = 0; }; struct WAOwnMessage @@ -358,6 +350,7 @@ class WhatsAppProto : public PROTO<WhatsAppProto> void OnNotifyDevices(const WANode &node); void OnNotifyEncrypt(const WANode &node); void OnReceiveAck(const WANode &node); + void OnReceiveChatState(const WANode &node); void OnReceiveInfo(const WANode &node); void OnReceiveMessage(const WANode &node); void OnReceiveReceipt(const WANode &node); diff --git a/protocols/WhatsApp/src/server.cpp b/protocols/WhatsApp/src/server.cpp index df5671ad5f..6fe9981d5e 100644 --- a/protocols/WhatsApp/src/server.cpp +++ b/protocols/WhatsApp/src/server.cpp @@ -290,6 +290,18 @@ void WhatsAppProto::SendKeepAlive() m_lastRecvTime = now; } + + for (auto &it : m_arUsers) { + if (it->m_timer1 && now - it->m_timer1 > 600) { + it->m_timer1 = 0; + it->m_timer2 = now; + setWord(it->hContact, "Status", ID_STATUS_AWAY); + } + else if (it->m_timer2 && now - it->m_timer2 > 600) { + it->m_timer2 = 0; + setWord(it->hContact, "Status", ID_STATUS_OFFLINE); + } + } } void WhatsAppProto::SendReceipt(const char *pszTo, const char *pszParticipant, const char *pszId, const char *pszType) |