diff options
-rw-r--r-- | protocols/Teams/Teams.vcxproj | 1 | ||||
-rw-r--r-- | protocols/Teams/Teams.vcxproj.filters | 8 | ||||
-rw-r--r-- | protocols/Teams/src/requests/chatrooms.h | 66 | ||||
-rw-r--r-- | protocols/Teams/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/Teams/src/teams_chatrooms.cpp | 51 | ||||
-rw-r--r-- | protocols/Teams/src/teams_proto.h | 3 |
6 files changed, 46 insertions, 85 deletions
diff --git a/protocols/Teams/Teams.vcxproj b/protocols/Teams/Teams.vcxproj index 201576d268..b689769f6d 100644 --- a/protocols/Teams/Teams.vcxproj +++ b/protocols/Teams/Teams.vcxproj @@ -47,7 +47,6 @@ <ClCompile Include="src\teams_server.cpp" /> <ClCompile Include="src\teams_trouter.cpp" /> <ClCompile Include="src\teams_utils.cpp" /> - <ClInclude Include="src\requests\chatrooms.h" /> <ClInclude Include="src\resource.h" /> <ClInclude Include="src\stdafx.h" /> <ClInclude Include="src\teams_menus.h" /> diff --git a/protocols/Teams/Teams.vcxproj.filters b/protocols/Teams/Teams.vcxproj.filters index 2e6b7466b3..45db7abfb8 100644 --- a/protocols/Teams/Teams.vcxproj.filters +++ b/protocols/Teams/Teams.vcxproj.filters @@ -78,9 +78,6 @@ <ClInclude Include="src\teams_proto.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="src\requests\chatrooms.h"> - <Filter>Header Files\Requests</Filter> - </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="res\Resource.rc"> @@ -95,10 +92,5 @@ <Filter>Resource Files</Filter> </Image> </ItemGroup> - <ItemGroup> - <Filter Include="Header Files\Requests"> - <UniqueIdentifier>{8564ba51-686a-4e09-bfe0-b1926a5a640d}</UniqueIdentifier> - </Filter> - </ItemGroup> <Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" /> </Project>
\ No newline at end of file diff --git a/protocols/Teams/src/requests/chatrooms.h b/protocols/Teams/src/requests/chatrooms.h deleted file mode 100644 index e691b533f1..0000000000 --- a/protocols/Teams/src/requests/chatrooms.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright (c) 2015-25 Miranda NG team (https://miranda-ng.org) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 -of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SKYPE_REQUEST_CHATS_H_ -#define _SKYPE_REQUEST_CHATS_H_ - -struct CreateChatroomRequest : public AsyncHttpRequest -{ - CreateChatroomRequest(const LIST<char> &skypenames, CTeamsProto *ppro) : - AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/threads") - { - //{"members":[{"id":"8:user3","role":"User"},{"id":"8:user2","role":"User"},{"id":"8:user1","role":"Admin"}]} - JSONNode node; - JSONNode members(JSON_ARRAY); members.set_name("members"); - - for (auto &it : skypenames) { - JSONNode member; - member << CHAR_PARAM("id", it) << CHAR_PARAM("role", !mir_strcmpi(it, ppro->m_szSkypename) ? "Admin" : "User"); - members << member; - } - node << members; - m_szParam = node.write().c_str(); - } -}; - -struct InviteUserToChatRequest : public AsyncHttpRequest -{ - InviteUserToChatRequest(const char *chatId, const char *skypename, const char *role) : - AsyncHttpRequest(REQUEST_PUT, HOST_DEFAULT) - { - m_szUrl.AppendFormat("/threads/%s/members/%s", chatId, skypename); - - JSONNode node; - node << CHAR_PARAM("role", role); - m_szParam = node.write().c_str(); - } -}; - -struct SetChatPropertiesRequest : public AsyncHttpRequest -{ - SetChatPropertiesRequest(const char *chatId, const char *propname, const char *value) : - AsyncHttpRequest(REQUEST_PUT, HOST_DEFAULT) - { - m_szUrl.AppendFormat("/threads/%s/properties?name=%s", chatId, propname); - - JSONNode node; - node << CHAR_PARAM(propname, value); - m_szParam = node.write().c_str(); - } -}; - -#endif //_SKYPE_REQUEST_CHATS_H_
\ No newline at end of file diff --git a/protocols/Teams/src/stdafx.h b/protocols/Teams/src/stdafx.h index 773a42ef50..656e4d15ea 100644 --- a/protocols/Teams/src/stdafx.h +++ b/protocols/Teams/src/stdafx.h @@ -89,6 +89,4 @@ struct AsyncHttpRequest : public MTHttpRequest<CTeamsProto> #include "teams_proto.h" -#include "requests/chatrooms.h" - #endif //_COMMON_H_ diff --git a/protocols/Teams/src/teams_chatrooms.cpp b/protocols/Teams/src/teams_chatrooms.cpp index 3f8593c5e0..7a35d00562 100644 --- a/protocols/Teams/src/teams_chatrooms.cpp +++ b/protocols/Teams/src/teams_chatrooms.cpp @@ -127,7 +127,7 @@ int CTeamsProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) CSkypeInviteDlg dlg(this); if (dlg.DoModal()) if (dlg.m_hContact != NULL) - PushRequest(new InviteUserToChatRequest(chat_id, getId(dlg.m_hContact), "User")); + InviteUserToChat(chat_id, getId(dlg.m_hContact), "User"); } break; @@ -138,7 +138,7 @@ int CTeamsProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) case 30: CMStringW newTopic = ChangeTopicForm(); if (!newTopic.IsEmpty()) - PushRequest(new SetChatPropertiesRequest(chat_id, "topic", T2Utf(newTopic.GetBuffer()))); + SetChatProperty(chat_id, "topic", T2Utf(newTopic.GetBuffer())); break; } break; @@ -149,10 +149,10 @@ int CTeamsProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) KickChatUser(chat_id, user_id); break; case 30: - PushRequest(new InviteUserToChatRequest(chat_id, user_id, "Admin")); + InviteUserToChat(chat_id, user_id, "Admin"); break; case 40: - PushRequest(new InviteUserToChatRequest(chat_id, user_id, "User")); + InviteUserToChat(chat_id, user_id, "User"); break; case 50: ptrW tnick_old(GetChatContactNick(si, gch->ptszUID, gch->ptszText)); @@ -424,12 +424,13 @@ void CTeamsProto::OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest*) void CTeamsProto::GetChatInfo(const wchar_t *chatId) { - auto *pReq = new AsyncHttpRequest(REQUEST_GET, HOST_DEFAULT, 0, &CTeamsProto::OnGetChatInfo); + auto *pReq = new AsyncHttpRequest(REQUEST_GET, HOST_CHATS, 0, &CTeamsProto::OnGetChatInfo); pReq->m_szUrl.AppendFormat("/threads/%S", chatId); pReq << CHAR_PARAM("view", "msnp24Equivalent"); PushRequest(pReq); } +///////////////////////////////////////////////////////////////////////////////////////// wchar_t* CTeamsProto::GetChatContactNick(SESSION_INFO *si, const wchar_t *id, const wchar_t *name, bool *isQualified) { @@ -472,6 +473,30 @@ wchar_t* CTeamsProto::GetChatContactNick(SESSION_INFO *si, const wchar_t *id, co return mir_wstrdup(GetSkypeNick(id)); } +void CTeamsProto::InviteUserToChat(const char *chatId, const char *skypename, const char *role) +{ + JSONNode node; + node << CHAR_PARAM("role", role); + + auto *pReq = new AsyncHttpRequest(REQUEST_PUT, HOST_CHATS); + pReq->m_szUrl.AppendFormat("/threads/%s/members/%s", chatId, skypename); + pReq->m_szParam = node.write().c_str(); + PushRequest(pReq); +} + +void CTeamsProto::SetChatProperty(const char *chatId, const char *propname, const char *value) +{ + JSONNode node; + node << CHAR_PARAM(propname, value); + + auto *pReq = new AsyncHttpRequest(REQUEST_PUT, HOST_CHATS); + pReq->m_szUrl.AppendFormat("/threads/%s/properties?name=%s", chatId, propname); + pReq->m_szParam = node.write().c_str(); + PushRequest(pReq); +} + +///////////////////////////////////////////////////////////////////////////////////////// + bool CTeamsProto::AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange) { bool isQualified; @@ -509,7 +534,7 @@ void CTeamsProto::RemoveChatContact(SESSION_INFO *si, const wchar_t *id, const w void CTeamsProto::KickChatUser(const char *chatId, const char *userId) { - PushRequest(new AsyncHttpRequest(REQUEST_DELETE, HOST_DEFAULT, "/threads/" + mir_urlEncode(chatId) + "/members/" + mir_urlEncode(userId))); + PushRequest(new AsyncHttpRequest(REQUEST_DELETE, HOST_CHATS, "/threads/" + mir_urlEncode(chatId) + "/members/" + mir_urlEncode(userId))); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -578,7 +603,19 @@ INT_PTR CTeamsProto::SvcCreateChat(WPARAM, LPARAM) if (IsOnline()) { CSkypeGCCreateDlg dlg(this); if (dlg.DoModal()) { - PushRequest(new CreateChatroomRequest(dlg.m_ContactsList, this)); + JSONNode node; + JSONNode members(JSON_ARRAY); members.set_name("members"); + + for (auto &it : dlg.m_ContactsList) { + JSONNode member; + member << CHAR_PARAM("id", it) << CHAR_PARAM("role", !mir_strcmpi(it, m_szSkypename) ? "Admin" : "User"); + members << member; + } + node << members; + + auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_CHATS, "/threads"); + pReq->m_szParam = node.write().c_str(); + PushRequest(pReq); return 0; } } diff --git a/protocols/Teams/src/teams_proto.h b/protocols/Teams/src/teams_proto.h index f6a9ea7e58..775152e973 100644 --- a/protocols/Teams/src/teams_proto.h +++ b/protocols/Teams/src/teams_proto.h @@ -183,8 +183,9 @@ private: void RemoveChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *initiator = L""); void SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage); + void InviteUserToChat(const char *chatId, const char *skypename, const char *role); void KickChatUser(const char *chatId, const char *userId); - + void SetChatProperty(const char *chatId, const char *propname, const char *value); void SetChatStatus(MCONTACT hContact, int iStatus); bool ParseMessage(const JSONNode &node, DB::EventInfo &dbei); |