summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/contacts.cpp8
-rw-r--r--protocols/FacebookRM/src/db.h1
-rw-r--r--protocols/FacebookRM/src/dialogs.cpp102
-rw-r--r--protocols/FacebookRM/src/entities.h15
-rw-r--r--protocols/FacebookRM/src/json.cpp2
-rw-r--r--protocols/FacebookRM/src/proto.cpp45
-rw-r--r--protocols/FacebookRM/src/theme.cpp10
-rw-r--r--protocols/FacebookRM/src/theme.h3
8 files changed, 132 insertions, 54 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 794455f6c2..cdb71054ac 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -39,7 +39,7 @@ HANDLE FacebookProto::ChatIDToHContact(std::string chat_id)
if (!IsMyContact(hContact, true))
continue;
- ptrA id( getStringA(hContact, "ChatRoomID"));
+ ptrA id(getStringA(hContact, "ChatRoomID"));
if (id && !strcmp(id, chat_id.c_str()))
return hContact;
}
@@ -53,7 +53,7 @@ HANDLE FacebookProto::ContactIDToHContact(std::string user_id)
if (!IsMyContact(hContact))
continue;
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (id && !strcmp(id, user_id.c_str()))
return hContact;
}
@@ -244,7 +244,7 @@ void FacebookProto::ApproveContactToServer(void *data)
std::string get_data = "id=";
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
get_data += id;
http::response resp = facy.flap(REQUEST_APPROVE_FRIEND, &post_data, &get_data);
@@ -269,7 +269,7 @@ void FacebookProto::CancelFriendsRequest(void *data)
query += "&fb_dtsg=" + facy.dtsg_;
query += "&__user=" + facy.self_.user_id;
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
query += "&friend=" + std::string(id);
// Get unread inbox threads
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h
index 5ce0a4751f..595dc8b395 100644
--- a/protocols/FacebookRM/src/db.h
+++ b/protocols/FacebookRM/src/db.h
@@ -51,6 +51,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_KEY_LOCAL_TIMESTAMP "UseLocalTimestamp"
#define FACEBOOK_KEY_PRIVACY_TYPE "PrivacyType"
#define FACEBOOK_KEY_PLACE "Place"
+#define FACEBOOK_KEY_LAST_WALL "LastWall"
#define FACEBOOK_KEY_POLL_RATE "PollRate" // [HIDDEN]
#define FACEBOOK_KEY_TIMEOUTS_LIMIT "TimeoutsLimit" // [HIDDEN]
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp
index a9b3ad6097..555d1cc62f 100644
--- a/protocols/FacebookRM/src/dialogs.cpp
+++ b/protocols/FacebookRM/src/dialogs.cpp
@@ -109,9 +109,22 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
return FALSE;
}
+void RefreshPrivacy(HWND hwnd, post_status_data *data)
+{
+ SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_RESETCONTENT, 0, 0);
+ int wall_id = SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0);
+ if (data->walls[wall_id]->user_id == data->proto->facy.self_.user_id) {
+ for (size_t i = 0; i < SIZEOF(privacy_types); i++)
+ SendDlgItemMessageA(hwnd, IDC_PRIVACY, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(Translate(privacy_types[i].name)));
+ } else {
+ SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>(TranslateT("Default")));
+ }
+ SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_SETCURSEL, data->proto->getByte(FACEBOOK_KEY_PRIVACY_TYPE, 0), 0);
+}
+
INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
- FacebookProto *proto;
+ post_status_data *data;
switch(message)
{
@@ -122,19 +135,21 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(GetIconHandle("mind")));
- proto = reinterpret_cast<FacebookProto*>(lparam);
- SetWindowLongPtr(hwnd,GWLP_USERDATA,lparam);
- SendDlgItemMessage(hwnd,IDC_MINDMSG,EM_LIMITTEXT,FACEBOOK_MIND_LIMIT,0);
- SendDlgItemMessage(hwnd,IDC_URL,EM_LIMITTEXT,1024,0);
+ data = reinterpret_cast<post_status_data*>(lparam);
+
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
+ SendDlgItemMessage(hwnd, IDC_MINDMSG, EM_LIMITTEXT, FACEBOOK_MIND_LIMIT, 0);
+ SendDlgItemMessage(hwnd, IDC_URL, EM_LIMITTEXT, 1024, 0);
- ptrT place = proto->getTStringA(FACEBOOK_KEY_PLACE);
+ ptrT place = data->proto->getTStringA(FACEBOOK_KEY_PLACE);
SetDlgItemText(hwnd, IDC_PLACE, place != NULL ? place : _T("Miranda NG"));
- for(size_t i=0; i<SIZEOF(privacy_types); i++)
- SendDlgItemMessageA(hwnd, IDC_PRIVACY, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(Translate(privacy_types[i].name)));
- SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_SETCURSEL, proto->getByte(FACEBOOK_KEY_PRIVACY_TYPE, 0), 0);
+ for (std::vector<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
+ SendDlgItemMessageA(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(data->walls[i]->title.c_str()));
+ SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, data->proto->getByte(FACEBOOK_KEY_LAST_WALL, 0), 0);
+ RefreshPrivacy(hwnd, data);
- ptrA name( proto->getStringA(FACEBOOK_KEY_NAME));
+ ptrA name(data->proto->getStringA(FACEBOOK_KEY_NAME));
if (name != NULL) {
std::string firstname = name;
std::string::size_type pos = firstname.find(" ");
@@ -151,7 +166,23 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
return TRUE;
case WM_COMMAND:
- if (LOWORD(wparam) == IDC_MINDMSG && HIWORD(wparam) == EN_CHANGE)
+ if (LOWORD(wparam) == IDC_WALL && HIWORD(wparam) == CBN_SELCHANGE)
+ {
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+ RefreshPrivacy(hwnd, data);
+
+ // remember last choice, only when there are more options
+ if (SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCOUNT, 0, 0) > 1)
+ data->proto->setByte(FACEBOOK_KEY_LAST_WALL, SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0));
+ }
+ if (LOWORD(wparam) == IDC_PRIVACY && HIWORD(wparam) == CBN_SELCHANGE) {
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+
+ // remember last choice, only when there are more options
+ if (SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCOUNT, 0, 0) > 1)
+ data->proto->setByte(FACEBOOK_KEY_PRIVACY_TYPE, SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0));
+ }
+ else if (LOWORD(wparam) == IDC_MINDMSG && HIWORD(wparam) == EN_CHANGE)
{
size_t len = SendDlgItemMessage(hwnd,IDC_MINDMSG,WM_GETTEXTLENGTH,0,0);
EnableWindow(GetDlgItem(hwnd, IDOK), len > 0);
@@ -160,36 +191,35 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
}
else if (LOWORD(wparam) == IDOK)
{
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+
TCHAR mindMessageT[FACEBOOK_MIND_LIMIT+1];
TCHAR urlT[1024];
- TCHAR placeT[100];
- proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+ TCHAR placeT[100];
- GetDlgItemText(hwnd,IDC_MINDMSG, mindMessageT, SIZEOF(mindMessageT));
- GetDlgItemText(hwnd,IDC_PLACE, placeT, SIZEOF(placeT));
- GetDlgItemText(hwnd,IDC_URL, urlT, SIZEOF(urlT));
- ShowWindow(hwnd,SW_HIDE);
+ GetDlgItemText(hwnd, IDC_MINDMSG, mindMessageT, SIZEOF(mindMessageT));
+ GetDlgItemText(hwnd, IDC_PLACE, placeT, SIZEOF(placeT));
+ GetDlgItemText(hwnd, IDC_URL, urlT, SIZEOF(urlT));
+ ShowWindow(hwnd, SW_HIDE);
- ptrA place( mir_utf8encodeT(placeT));
- proto->setString(FACEBOOK_KEY_PLACE, place);
+ ptrA place(mir_utf8encodeT(placeT));
+ data->proto->setString(FACEBOOK_KEY_PLACE, place);
- int privacy_type = SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0);
- proto->setByte(FACEBOOK_KEY_PRIVACY_TYPE, privacy_type);
+ status_data *status = new status_data();
+ status->user_id = data->walls[SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0)]->user_id;
+ status->privacy = privacy_types[SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0)].id;
+ status->place = place;
+ status->url = _T2A(urlT);
- char *narrow = mir_utf8encodeT(mindMessageT);
- if (proto->last_status_msg_ != narrow)
- proto->last_status_msg_ = narrow;
- utils::mem::detract(narrow);
+ char *narrow = mir_utf8encodeT(mindMessageT);
+ status->text = narrow;
+
+ if (status->user_id == data->proto->facy.self_.user_id && data->proto->last_status_msg_ != narrow)
+ data->proto->last_status_msg_ = narrow;
- status_data *data = new status_data();
- data->place = place;
- data->text = proto->last_status_msg_;
- data->url = _T2A(urlT);
- data->privacy = privacy_types[privacy_type].id;
-// data->user_id = user_id;
+ utils::mem::detract(narrow);
- //char *narrow = mir_t2a_cp(mindMessage,CP_UTF8);
- proto->ForkThread(&FacebookProto::SetAwayMsgWorker, data);
+ data->proto->ForkThread(&FacebookProto::SetAwayMsgWorker, status);
EndDialog(hwnd, wparam);
return TRUE;
@@ -200,7 +230,13 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
return TRUE;
}
break;
+ case WM_DESTROY:
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+
+ for(std::vector<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
+ delete data->walls[i];
+ delete data;
}
return FALSE;
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 11f7d262a3..93eef6ea70 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -147,4 +147,17 @@ struct status_data
std::string url;
std::string place;
std::string privacy;
-}; \ No newline at end of file
+};
+
+struct wall_data
+{
+ std::string user_id;
+ std::string title;
+};
+
+struct post_status_data {
+ post_status_data(FacebookProto *proto) : proto(proto) {}
+ post_status_data(FacebookProto *proto, wall_data *wall) : proto(proto) { walls.push_back(wall); }
+ FacebookProto *proto;
+ std::vector<wall_data*> walls;
+};
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index bb5e3ada78..9ce8d6c302 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -271,6 +271,8 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
if (t == "msg" || t == "offline_msg") {
// we use this only for outgoing messages
+ // TODO: load recipient id here, but use data from "messaging" section, problem is that "messaging" is usually before this
+
JSONNODE *msg = json_get(it, "msg");
if (msg == NULL)
continue;
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index c4cebb6629..6ab1526553 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -57,7 +57,7 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) :
HOTKEYDESC hkd = { sizeof(hkd) };
hkd.dwFlags = HKD_TCHAR;
- hkd.ptszDescription = LPGENT("Show Mind Window");
+ hkd.ptszDescription = LPGENT("Show 'Share status' window");
hkd.pszName = "ShowMindWnd";
hkd.ptszSection = m_tszUserName;
hkd.pszService = module;
@@ -194,7 +194,8 @@ int FacebookProto::SetAwayMsg(int status, const PROTOCHAR *msg)
}
char *narrow = mir_utf8encodeT(msg);
- if (last_status_msg_ != narrow) last_status_msg_ = narrow;
+ if (last_status_msg_ != narrow)
+ last_status_msg_ = narrow;
utils::mem::detract(narrow);
if (isOnline() && getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS))
@@ -447,19 +448,35 @@ int FacebookProto::OnToolbarInit(WPARAM, LPARAM)
mir_snprintf(service, sizeof(service), "%s%s", m_szModuleName, "/Mind");
ttb.pszService = service;
- ttb.pszTooltipUp = ttb.name = LPGEN("What's on your mind?");
+ ttb.pszTooltipUp = ttb.name = LPGEN("Share status...");
ttb.hIconHandleUp = Skin_GetIconByHandle(GetIconHandle("mind"));
TopToolbar_AddButton(&ttb);
return 0;
}
-INT_PTR FacebookProto::OnMind(WPARAM, LPARAM)
+INT_PTR FacebookProto::OnMind(WPARAM wParam, LPARAM lParam)
{
- if (isOnline()) {
- HWND hDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MIND), (HWND)0, FBMindProc, reinterpret_cast<LPARAM>(this));
- ShowWindow(hDlg, SW_SHOW);
- }
+ if (!isOnline())
+ return 1;
+
+ HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
+
+ // TODO: why isn't wParam == 0 when is status menu moved to main menu?
+ if (wParam != 0 && !IsMyContact(hContact))
+ return 1;
+
+ wall_data *wall = new wall_data();
+ wall->user_id = ptrA(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (wall->user_id == facy.self_.user_id)
+ wall->title = Translate("Own wall");
+ else
+ wall->title = ptrA(getStringA(hContact, FACEBOOK_KEY_NAME));
+
+ post_status_data *data = new post_status_data(this, wall);
+
+ HWND hDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MIND), (HWND)0, FBMindProc, reinterpret_cast<LPARAM>(data));
+ ShowWindow(hDlg, SW_SHOW);
return 0;
}
@@ -502,7 +519,7 @@ INT_PTR FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam)
std::string url = FACEBOOK_URL_PROFILE;
- ptrA val( getStringA(hContact, "Homepage"));
+ ptrA val(getStringA(hContact, "Homepage"));
if (val != NULL) {
// Homepage link already present, get it
url = val;
@@ -524,7 +541,7 @@ INT_PTR FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam)
if (wParam == 0 || !IsMyContact(hContact))
return 1;
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
std::string url = FACEBOOK_URL_PROFILE;
url += facy.self_.user_id;
@@ -559,10 +576,10 @@ INT_PTR FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
// Ignore groupchats and, if deleting, also not-friends
- if ( isChatRoom(hContact) || (deleting && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND))
+ if (isChatRoom(hContact) || (deleting && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND))
return 0;
- ptrT tname( getTStringA(hContact, FACEBOOK_KEY_NAME));
+ ptrT tname(getTStringA(hContact, FACEBOOK_KEY_NAME));
if (tname == NULL)
tname = getTStringA(hContact, FACEBOOK_KEY_ID);
@@ -570,7 +587,7 @@ INT_PTR FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam)
mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), tname);
if (MessageBox(0, tstr, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) {
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (id == NULL)
return 1;
@@ -595,7 +612,7 @@ INT_PTR FacebookProto::RequestFriendship(WPARAM wParam,LPARAM lParam)
HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
- ptrA id( getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (id == NULL)
return 1;
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index ffed611d22..ce3fc657d3 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -101,6 +101,13 @@ void InitContactMenus()
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::VisitFriendship>);
g_hContactMenuItems[CMI_VISIT_FRIENDSHIP] = Menu_AddContactMenuItem(&mi);
+ mi.position=-2000006001;
+ mi.icolibItem = GetIconHandle("mind");
+ mi.pszName = LPGEN("Share status...");
+ mi.pszService = "FacebookProto/Mind";
+ CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::OnMind>);
+ g_hContactMenuItems[CMI_POST_STATUS] = Menu_AddContactMenuItem(&mi);
+
mi.position=-2000006002;
mi.icolibItem = GetIconHandle("poke");
mi.pszName = LPGEN("Poke");
@@ -150,6 +157,7 @@ int FacebookProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_PROFILE], true);
Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_FRIENDSHIP], !bIsChatroom);
+ Menu_ShowItem(g_hContactMenuItems[CMI_POST_STATUS], !bIsChatroom);
if (!isOffline() && !bIsChatroom)
{
@@ -196,7 +204,7 @@ int FacebookProto::OnBuildStatusMenu(WPARAM wParam,LPARAM lParam)
//CreateProtoService(m_szModuleName,"/Mind",&FacebookProto::OnMind,this);
strcpy(tDest,"/Mind");
mi.hParentMenu = hRoot;
- mi.pszName = LPGEN("Mind...");
+ mi.pszName = LPGEN("Share status...");
mi.icolibItem = GetIconHandle("mind");
m_hStatusMind = Menu_AddProtoMenuItem(&mi);
diff --git a/protocols/FacebookRM/src/theme.h b/protocols/FacebookRM/src/theme.h
index 12984682f4..0bb0fdc129 100644
--- a/protocols/FacebookRM/src/theme.h
+++ b/protocols/FacebookRM/src/theme.h
@@ -36,5 +36,6 @@ void UninitContactMenus(void);
#define CMI_AUTH_GRANT 4
#define CMI_AUTH_CANCEL 5
#define CMI_POKE 6
+#define CMI_POST_STATUS 7
-#define CMITEMS_COUNT 7 \ No newline at end of file
+#define CMITEMS_COUNT 8 \ No newline at end of file