summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/vk_wallpost.cpp
blob: 5a7b76fc7ea81606cc4a8de13b65ff4f4822945f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright (c) 2013-24 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/>.
*/

#include "stdafx.h"

INT_PTR __cdecl CVkProto::SvcWallPost(WPARAM hContact, LPARAM)
{
	debugLogA("CVkProto::SvcWallPost");

	WALLPOST_FORM_PARAMS param(db_get_wsa(hContact, m_szModuleName, "Nick"));
	CVkWallPostForm dlg(this, &param);
	if (!dlg.DoModal())
		return 1;

	WallPost((MCONTACT)hContact, param.pwszMsg, param.pwszUrl, param.bFriendsOnly);
	return 0;
}

void CVkProto::WallPost(MCONTACT hContact, wchar_t *pwszMsg, wchar_t *pwszUrl, bool bFriendsOnly)
{
	debugLogA("CVkProto::WallPost");
	if (!IsOnline() || (IsEmpty(pwszMsg) && IsEmpty(pwszUrl)))
		return;

	VKUserID_t iUserId = hContact ? m_iMyUserId : ReadVKUserID(hContact);
	if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
		return;

	AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/wall.post.json", true, &CVkProto::OnReceiveSmth);
	pReq << INT_PARAM("owner_id", iUserId) << INT_PARAM("friends_only", bFriendsOnly ? 1 : 0);

	if (!IsEmpty(pwszMsg))
		pReq << WCHAR_PARAM("message", pwszMsg);

	if (!IsEmpty(pwszUrl))
		pReq << WCHAR_PARAM("attachments", pwszUrl);

	Push(pReq);
}