From 43f04f0fcb082fb2c7f69617101e6147c81cf0d3 Mon Sep 17 00:00:00 2001 From: Szymon Tokarz Date: Fri, 24 Jan 2014 01:02:07 +0000 Subject: Tlen protocol - Support case when user account is added as contact (show status and status msg on clist) - try to improve fetching avatars and setting own avatar - minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@7846 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tlen/src/tlen_presence.cpp | 45 +++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'protocols/Tlen/src/tlen_presence.cpp') diff --git a/protocols/Tlen/src/tlen_presence.cpp b/protocols/Tlen/src/tlen_presence.cpp index 4d20d08f6a..617ec7e2ca 100644 --- a/protocols/Tlen/src/tlen_presence.cpp +++ b/protocols/Tlen/src/tlen_presence.cpp @@ -72,8 +72,10 @@ void TlenProcessPresence(XmlNode *node, TlenProtocol *proto) else p = NULL; TlenListAddResource(proto, LIST_ROSTER, from, status, statusNode?p:NULL); - if (p) { - db_set_s(hContact, "CList", "StatusMsg", p); + if (p != NULL && *p) { + char* statusMsg_utf8 = mir_utf8encode(p); + db_set_utf(hContact, "CList", "StatusMsg", statusMsg_utf8); + mir_free(statusMsg_utf8); mir_free(p); } else { db_unset(hContact, "CList", "StatusMsg"); @@ -121,8 +123,10 @@ void TlenProcessPresence(XmlNode *node, TlenProtocol *proto) p = TlenTextDecode(statusNode->text); TlenListAddResource(proto, LIST_ROSTER, from, status, p); if ((hContact=TlenHContactFromJID(proto, from)) != NULL) { - if (p) { - db_set_s(hContact, "CList", "StatusMsg", p); + if (p != NULL && *p) { + char* statusMsg_utf8 = mir_utf8encode(p); + db_set_utf(hContact, "CList", "StatusMsg", statusMsg_utf8); + mir_free(statusMsg_utf8); } else { db_unset(hContact, "CList", "StatusMsg"); } @@ -170,6 +174,24 @@ void TlenProcessPresence(XmlNode *node, TlenProtocol *proto) } } +/* change status and status msg on own contact on contact list (if present) */ +void setOwnStatusOnCList(TlenProtocol *proto, int status, char *statusMsg) +{ + ptrA ownJid(db_get_sa(NULL, proto->m_szModuleName, "jid")); + HANDLE hContact = TlenHContactFromJID(proto, ownJid); + if(hContact){ + if (db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != status) + db_set_w(hContact, proto->m_szModuleName, "Status", (WORD)status); + if (statusMsg != NULL && *statusMsg) { + char* statusMsg_utf8 = mir_utf8encode(statusMsg); + db_set_utf(hContact, "CList", "StatusMsg", statusMsg_utf8); + mir_free(statusMsg_utf8); + } else { + db_unset(hContact, "CList", "StatusMsg"); + } + } +} + static void TlenSendPresenceTo(TlenProtocol *proto, int status, char *to) { char *showBody, *statusMsg, *presenceType; @@ -264,6 +286,7 @@ static void TlenSendPresenceTo(TlenProtocol *proto, int status, char *to) } } } + mir_free(statusMsg); statusMsg = ptr; break; default: @@ -272,19 +295,19 @@ static void TlenSendPresenceTo(TlenProtocol *proto, int status, char *to) } proto->m_iStatus = status; if (presenceType) { - if (statusMsg) - TlenSend(proto, "%s", presenceType, statusMsg); + if (statusMsg != NULL && *statusMsg) + TlenSend(proto, "%s", presenceType, ptrA(TlenTextEncode(statusMsg))); else TlenSend(proto, "", presenceType); } else { - if (statusMsg) - TlenSend(proto, "%s%s", showBody, statusMsg); + if (statusMsg != NULL && *statusMsg) + TlenSend(proto, "%s%s", showBody, ptrA(TlenTextEncode(statusMsg))); else TlenSend(proto, "%s", showBody); } - if (ptr) { - mir_free(ptr); - } + + setOwnStatusOnCList(proto, proto->m_iStatus, statusMsg); + LeaveCriticalSection(&proto->modeMsgMutex); } -- cgit v1.2.3