diff options
author | George Hazan <george.hazan@gmail.com> | 2015-02-08 21:06:03 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-02-08 21:06:03 +0000 |
commit | cc9402b1daabb0a27065e5eb704948cc2f74f7df (patch) | |
tree | 8d12ae7f91d18346d367cecd1ee4443e09d623a0 /protocols/WhatsApp | |
parent | f3a873e47ed64d570fd6c678a1d815b13711d017 (diff) |
bunch of small fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@12057 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp')
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 4 | ||||
-rw-r--r-- | protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 4 | ||||
-rw-r--r-- | protocols/WhatsApp/src/avatars.cpp | 37 | ||||
-rw-r--r-- | protocols/WhatsApp/src/chat.cpp | 33 | ||||
-rw-r--r-- | protocols/WhatsApp/src/contacts.cpp | 2 | ||||
-rw-r--r-- | protocols/WhatsApp/src/proto.h | 3 |
6 files changed, 63 insertions, 20 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index 16fafbf871..40d9970751 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -710,7 +710,7 @@ void WAConnection::sendGetGroups() throw (WAException) m_pMutex->unlock();
}
-void WAConnection::sendGetPicture(const std::string &jid, const std::string &type) throw (WAException)
+void WAConnection::sendGetPicture(const char *jid, const char *type) throw (WAException)
{
std::string id = makeId("iq_");
this->pending_server_requests[id] = new IqResultGetPhotoHandler(this, jid);
@@ -852,7 +852,7 @@ void WAConnection::sendQueryLastOnline(const std::string &jid) throw (WAExceptio << XATTR("id", id) << XATTR("type", "get") << XATTR("to", jid) << XATTR("xmlns", "jabber:iq:last"));
}
-void WAConnection::sendSetPicture(const std::string &jid, std::vector<unsigned char>* data, std::vector<unsigned char>* preview) throw (WAException)
+void WAConnection::sendSetPicture(const char *jid, std::vector<unsigned char>* data, std::vector<unsigned char>* preview) throw (WAException)
{
std::string id = this->makeId("set_photo_");
this->pending_server_requests[id] = new IqResultSetPhotoHandler(this, jid);
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h index bddfe1ccd7..957fcf7dfc 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h @@ -405,8 +405,8 @@ public: void sendRemoveParticipants(const std::string &gjid, const std::vector<std::string> &participant) throw (WAException);
void sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException);
void sendStatusUpdate(std::string& status) throw (WAException);
- void sendGetPicture(const std::string &jid, const std::string &type) throw (WAException);
- void sendSetPicture(const std::string &jid, std::vector<unsigned char>* data, std::vector<unsigned char>* preview) throw (WAException);
+ void sendGetPicture(const char *jid, const char *type) throw (WAException);
+ void sendSetPicture(const char *jid, std::vector<unsigned char>* data, std::vector<unsigned char>* preview) throw (WAException);
void sendDeleteAccount() throw(WAException);
};
diff --git a/protocols/WhatsApp/src/avatars.cpp b/protocols/WhatsApp/src/avatars.cpp index 8bdfe9212b..2694b278b6 100644 --- a/protocols/WhatsApp/src/avatars.cpp +++ b/protocols/WhatsApp/src/avatars.cpp @@ -4,7 +4,7 @@ INT_PTR WhatsAppProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) {
PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam;
- ptrA id(getStringA(AI->hContact, WHATSAPP_KEY_ID));
+ ptrA id(getStringA(AI->hContact, isChatRoom(AI->hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID));
if (id == NULL)
return GAIR_NOAVATAR;
@@ -14,10 +14,10 @@ INT_PTR WhatsAppProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) ptrA szAvatarId(getStringA(AI->hContact, WHATSAPP_KEY_AVATAR_ID));
if (szAvatarId == NULL || (wParam & GAIF_FORCE) != 0)
- if (AI->hContact != NULL && m_pConnection != NULL) {
- m_pConnection->sendGetPicture((const char*)id, "image");
- return GAIR_WAITFOR;
- }
+ if (AI->hContact != NULL && m_pConnection != NULL) {
+ m_pConnection->sendGetPicture(id, "preview");
+ return GAIR_WAITFOR;
+ }
debugLogA("No avatar");
return GAIR_NOAVATAR;
@@ -50,7 +50,7 @@ std::tstring WhatsAppProto::GetAvatarFileName(MCONTACT hContact) std::string jid;
if (hContact != NULL) {
- ptrA szId(getStringA(hContact, "ID"));
+ ptrA szId(getStringA(hContact, isChatRoom(hContact) ? "ChatRoomID" : WHATSAPP_KEY_ID));
if (szId == NULL)
return _T("");
@@ -81,12 +81,11 @@ static std::vector<unsigned char>* sttFileToMem(const TCHAR *ptszFileName) return result;
}
-INT_PTR WhatsAppProto::SetMyAvatar(WPARAM wParam, LPARAM lParam)
+int WhatsAppProto::InternalSetAvatar(MCONTACT hContact, const char *szJid, const TCHAR *ptszFileName)
{
- if (!isOnline())
+ if (!isOnline() || ptszFileName == NULL)
return 1;
- const TCHAR *ptszFileName = (const TCHAR*)lParam;
if (_taccess(ptszFileName, 4) != 0)
return errno;
@@ -96,14 +95,21 @@ INT_PTR WhatsAppProto::SetMyAvatar(WPARAM wParam, LPARAM lParam) resize.size = sizeof(resize);
resize.fit = RESIZEBITMAP_KEEP_PROPORTIONS;
resize.max_height = resize.max_width = 96;
-
+
HBITMAP hbmpPreview = (HBITMAP)CallService(MS_IMG_RESIZE, (LPARAM)&resize, 0);
if (hbmpPreview == NULL)
return 3;
TCHAR tszTempFile[MAX_PATH], tszMyFile[MAX_PATH];
- mir_sntprintf(tszMyFile, SIZEOF(tszMyFile), _T("%s\\myavatar.jpg"), m_tszAvatarFolder.c_str());
- mir_sntprintf(tszTempFile, SIZEOF(tszTempFile), _T("%s\\myavatar.preview.jpg"), m_tszAvatarFolder.c_str());
+ if (hContact == NULL) {
+ mir_sntprintf(tszMyFile, SIZEOF(tszMyFile), _T("%s\\myavatar.jpg"), m_tszAvatarFolder.c_str());
+ mir_sntprintf(tszTempFile, SIZEOF(tszTempFile), _T("%s\\myavatar.preview.jpg"), m_tszAvatarFolder.c_str());
+ }
+ else {
+ std::tstring tszContactAva = GetAvatarFileName(hContact);
+ _tcsncpy_s(tszMyFile, tszContactAva.c_str(), _TRUNCATE);
+ _tcsncpy_s(tszTempFile, (tszContactAva + _T(".preview")).c_str(), _TRUNCATE);
+ }
IMGSRVC_INFO saveInfo = { sizeof(saveInfo), 0 };
saveInfo.hbm = hbmpPreview;
@@ -118,6 +124,11 @@ INT_PTR WhatsAppProto::SetMyAvatar(WPARAM wParam, LPARAM lParam) CopyFile(ptszFileName, tszMyFile, FALSE);
- m_pConnection->sendSetPicture(m_szJid, sttFileToMem(ptszFileName), sttFileToMem(tszTempFile));
+ m_pConnection->sendSetPicture(szJid, sttFileToMem(ptszFileName), sttFileToMem(tszTempFile));
return 0;
}
+
+INT_PTR WhatsAppProto::SetMyAvatar(WPARAM wParam, LPARAM lParam)
+{
+ return InternalSetAvatar(NULL, m_szJid.c_str(), (const TCHAR*)lParam);
+}
diff --git a/protocols/WhatsApp/src/chat.cpp b/protocols/WhatsApp/src/chat.cpp index f5d1545c04..7c78a1d5c4 100644 --- a/protocols/WhatsApp/src/chat.cpp +++ b/protocols/WhatsApp/src/chat.cpp @@ -8,7 +8,7 @@ enum IDM_INVITE, IDM_LEAVE, IDM_TOPIC,
- IDM_MESSAGE, IDM_KICK,
+ IDM_AVATAR, IDM_KICK,
IDM_CPY_NICK, IDM_CPY_TOPIC,
IDM_ADD_RJID, IDM_CPY_RJID
};
@@ -105,6 +105,9 @@ static gc_item sttLogListItems[] = { LPGENT("&Room options"), 0, MENU_NEWPOPUP },
{ LPGENT("View/change &topic"), IDM_TOPIC, MENU_POPUPITEM },
{ LPGENT("&Leave chat session"), IDM_LEAVE, MENU_POPUPITEM },
+#ifdef _DEBUG
+ { LPGENT("Set &avatar"), IDM_AVATAR, MENU_POPUPITEM }, // doesn't work, therefore commented out
+#endif
{ NULL, 0, MENU_SEPARATOR },
{ LPGENT("Copy room &JID"), IDM_CPY_RJID, MENU_ITEM },
{ LPGENT("Copy room topic"), IDM_CPY_TOPIC, MENU_ITEM },
@@ -133,6 +136,10 @@ void WhatsAppProto::ChatLogMenuHook(WAChatInfo *pInfo, struct GCHOOK *gch) if (isOnline())
m_pConnection->sendJoinLeaveGroup(_T2A(pInfo->tszJid), false);
break;
+
+ case IDM_AVATAR:
+ SetChatAvatar(pInfo);
+ break;
}
}
@@ -167,6 +174,27 @@ void WhatsAppProto::InviteChatUser(WAChatInfo *pInfo) }
}
+void WhatsAppProto::SetChatAvatar(WAChatInfo *pInfo)
+{
+ TCHAR tszFileName[MAX_PATH]; tszFileName[0] = '\0'; + + TCHAR filter[256]; filter[0] = '\0'; + CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter); + + OPENFILENAME ofn = { 0 }; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.lpstrFilter = filter; + ofn.hwndOwner = 0; + ofn.lpstrFile = tszFileName; + ofn.nMaxFile = ofn.nMaxFileTitle = SIZEOF(tszFileName); + ofn.Flags = OFN_HIDEREADONLY; + ofn.lpstrInitialDir = _T("."); + ofn.lpstrDefExt = _T(""); + if (GetOpenFileName(&ofn)) + if (_taccess(tszFileName, 4) != -1) + InternalSetAvatar(pInfo->hContact, _T2A(pInfo->tszJid), tszFileName);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// nicklist menu event handler
@@ -393,7 +421,7 @@ void WhatsAppProto::onGroupNewSubject(const std::string &gjid, const std::string void WhatsAppProto::onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts)
{
WAChatInfo *pInfo = SafeGetChat(gjid);
- if (pInfo == NULL)
+ if (pInfo == NULL || !pInfo->bActive)
return;
ptrT tszUID(str2t(ujid));
@@ -452,6 +480,7 @@ void WhatsAppProto::onGetParticipants(const std::string &gjid, const std::vector if (pInfo == NULL)
return;
+ pInfo->bActive = true;
for (size_t i = 0; i < participants.size(); i++) {
std::string curr = participants[i];
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp index d1146a5ca6..8a091af1fa 100644 --- a/protocols/WhatsApp/src/contacts.cpp +++ b/protocols/WhatsApp/src/contacts.cpp @@ -168,7 +168,7 @@ void WhatsAppProto::onContactChanged(const std::string &jid, bool added) void WhatsAppProto::onPictureChanged(const std::string &jid, const std::string &id, bool set)
{
if (isOnline())
- m_pConnection->sendGetPicture(jid, "image");
+ m_pConnection->sendGetPicture(jid.c_str(), "preview");
}
void WhatsAppProto::onSendGetPicture(const std::string &jid, const std::vector<unsigned char>& data, const std::string &id)
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 8702f2c060..4585d9e48f 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -127,6 +127,7 @@ public: void InviteChatUser(WAChatInfo *pInfo);
void KickChatUser(WAChatInfo *pInfo, const TCHAR *ptszJid);
TCHAR* GetChatUserNick(const std::string &jid);
+ void SetChatAvatar(WAChatInfo *pInfo);
void onGroupMessageReceived(const FMessage &fmsg);
@@ -161,6 +162,8 @@ private: INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM);
+ int InternalSetAvatar(MCONTACT hContact, const char *szJid, const TCHAR *ptszFileName);
+
// Private data //////////////////////////////////////////////////////////////////////
HGENMENU m_hMenuRoot;
|