summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2016-07-16 13:38:08 +0000
committerRobert Pösel <robyer@seznam.cz>2016-07-16 13:38:08 +0000
commit3a30fdfc6c545ba51cf1587b58b22316f2622e8f (patch)
tree06daf3b099663cba01f6e2432ca8f2b8f020bbee /protocols
parent5dc9ff65b453efdcbe2218720307fae52b5d6e90 (diff)
Facebook: Improve working with different user types (friend, user, page)
Also simplify arguments of AddToContactList method. And don't show auth items in contact menu for page contacts. git-svn-id: http://svn.miranda-ng.org/main/trunk@17099 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/chat.cpp4
-rw-r--r--protocols/FacebookRM/src/constants.h3
-rw-r--r--protocols/FacebookRM/src/contacts.cpp4
-rw-r--r--protocols/FacebookRM/src/entities.h2
-rw-r--r--protocols/FacebookRM/src/json.cpp16
-rw-r--r--protocols/FacebookRM/src/process.cpp7
-rw-r--r--protocols/FacebookRM/src/proto.cpp2
-rw-r--r--protocols/FacebookRM/src/proto.h2
-rw-r--r--protocols/FacebookRM/src/theme.cpp8
9 files changed, 32 insertions, 16 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index bcdad74310..9ec90536a7 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -96,7 +96,7 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
fbu.user_id = _T2A(hook->ptszUID, CP_UTF8);
// Find this contact in list or add new temporary contact
- MCONTACT hContact = AddToContactList(&fbu, CONTACT_NONE, false, true);
+ MCONTACT hContact = AddToContactList(&fbu, false, true);
if (!hContact)
break;
@@ -131,7 +131,7 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
fbu.user_id = _T2A(hook->ptszUID, CP_UTF8);
// Find this contact in list or add new temporary contact
- hContact = AddToContactList(&fbu, CONTACT_NONE, false, true);
+ hContact = AddToContactList(&fbu, false, true);
if (!hContact)
break;
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h
index 42f581c755..8868d6a99a 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -167,7 +167,8 @@ enum ContactType {
CONTACT_FRIEND = 1, // contact that IS on our server list
CONTACT_NONE = 2, // contact that ISN'T on our server list
CONTACT_REQUEST = 3, // contact that we asked for friendship
- CONTACT_APPROVE = 4 // contact that is asking us for approval of friendship
+ CONTACT_APPROVE = 4, // contact that is asking us for approval of friendship
+ CONTACT_PAGE = 5 // contact is Facebook page
};
enum ClientType {
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 70bb6aca5a..6ecc9ba5f4 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -391,7 +391,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
facy.handle_success("LoadChatInfo");
}
-MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, bool force_add, bool add_temporarily)
+MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, bool force_add, bool add_temporarily)
{
// Ignore self user completely
if (fbu->user_id == facy.self_.user_id)
@@ -432,7 +432,7 @@ MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, b
if (m_tszDefaultGroup)
db_set_ts(hContact, "CList", "Group", m_tszDefaultGroup);
- setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, type);
+ setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type);
if (getByte(FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, 0))
CallService(MS_IGNORE_IGNORE, hContact, (LPARAM)IGNOREEVENT_USERONLINE);
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index a12404de74..e289a176eb 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -43,6 +43,7 @@ struct facebook_user
bool updated;
ClientType client;
+ ContactType type;
facebook_user()
{
@@ -51,6 +52,7 @@ struct facebook_user
this->gender = this->last_active = 0;
this->deleted = this->idle = this->updated = false;
this->client = CLIENT_WEB;
+ this->type = CONTACT_NONE;
}
TCHAR *getMirVer()
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index bc79b6b8b6..4786213919 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -42,6 +42,13 @@ void parseUser(const JSONNode &it, facebook_user *fbu)
return;
}
+ if (type == "friend")
+ fbu->type = CONTACT_FRIEND;
+ else if (type == "user")
+ fbu->type = CONTACT_NONE;
+ else if (type == "page")
+ fbu->type = CONTACT_PAGE;
+
if (!name.empty())
fbu->real_name = utils::text::slashu_to_utf8(name);
if (!thumbSrc.empty())
@@ -608,8 +615,9 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo
facebook_user fbu;
fbu.user_id = from.as_string();
+ fbu.type = CONTACT_FRIEND; // only friends are able to send typing notifications
- MCONTACT hContact = proto->AddToContactList(&fbu, CONTACT_FRIEND); // only friends are able to send typing notifications
+ MCONTACT hContact = proto->AddToContactList(&fbu);
const JSONNode &st = (*it)["st"];
if (st.as_int() == 1)
@@ -694,7 +702,8 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo
MCONTACT hContact = proto->ContactIDToHContact(id);
if (!hContact) {
// FIXME: What to do, when we don't have this contact? What does it mean?
- // fbu->handle = AddToContactList(fbu, CONTACT_FRIEND); // add this contact as friend?
+ // fbu->type = CONTACT_FRIEND; // add this contact as a friend?
+ // fbu->handle = AddToContactList(fbu);
continue;
}
@@ -768,7 +777,8 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector<faceboo
MCONTACT hContact = proto->ContactIDToHContact(id);
if (!hContact) {
// FIXME: What to do, when we don't have this contact? What does it mean?
- // fbu->handle = AddToContactList(fbu, CONTACT_FRIEND); // add this contact as friend?
+ // fbu->type = CONTACT_FRIEND; // add this contact as a friend?
+ // fbu->handle = AddToContactList(fbu);
continue;
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index ee12864581..aba751c8b9 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -169,7 +169,7 @@ void FacebookProto::ProcessFriendList(void*)
// Check remaining contacts in map and add them to contact list
for (std::map< std::string, facebook_user* >::iterator it = friends.begin(); it != friends.end();) {
if (!it->second->deleted)
- AddToContactList(it->second, CONTACT_FRIEND, true); // we know this contact doesn't exists, so we force add it
+ AddToContactList(it->second, true); // we know this contact doesn't exists, so we force add it
delete it->second;
it = friends.erase(it);
@@ -828,7 +828,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
// We don't have this contact, lets load info about him
LoadContactInfo(&fbu);
- hContact = AddToContactList(&fbu, CONTACT_NONE);
+ hContact = AddToContactList(&fbu);
}
if (!hContact) {
@@ -1033,9 +1033,10 @@ void FacebookProto::ProcessFriendRequests(void*)
facebook_user fbu;
fbu.real_name = utils::text::remove_html(utils::text::source_get_value(&req, 3, "<a", ">", "</a>"));
fbu.user_id = utils::text::source_get_value2(&get, "confirm=", "&\"");
+ fbu.type = CONTACT_APPROVE;
if (!fbu.user_id.empty() && !fbu.real_name.empty()) {
- MCONTACT hContact = AddToContactList(&fbu, CONTACT_APPROVE);
+ MCONTACT hContact = AddToContactList(&fbu);
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_APPROVE);
bool isNew = false;
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 90e8024f78..109388bd8b 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -295,7 +295,7 @@ MCONTACT FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
}
bool add_temporarily = (flags & PALF_TEMPORARY);
- MCONTACT hContact = AddToContactList(&fbu, CONTACT_NONE, false, add_temporarily);
+ MCONTACT hContact = AddToContactList(&fbu, false, add_temporarily);
// Reset NotOnList flag if present and we're adding this contact not temporarily
if (hContact && !add_temporarily && db_get_b(hContact, "CList", "NotOnList", 0)) {
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index f243c00d24..3ddbdb44e9 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -200,7 +200,7 @@ public:
MCONTACT ChatIDToHContact(const std::string&);
std::string ThreadIDToContactID(const std::string&);
void LoadContactInfo(facebook_user* fbu);
- MCONTACT AddToContactList(facebook_user*, ContactType type, bool force_add = false, bool add_temporarily = false);
+ MCONTACT AddToContactList(facebook_user*, bool force_add = false, bool add_temporarily = false);
void SetAllContactStatuses(int status);
MCONTACT HContactFromAuthEvent(MEVENT hEvent);
void StartTyping(MCONTACT hContact);
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index d0304b0a47..b6f6481a14 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -199,17 +199,19 @@ void InitContactMenus()
int FacebookProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
{
MCONTACT hContact = MCONTACT(wParam);
+
+ BYTE type = getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0);
bool bIsChatroom = isChatRoom(hContact);
+ bool bIsPage = (type == CONTACT_PAGE);
Menu_ShowItem(g_hContactMenuVisitProfile, !bIsChatroom);
- Menu_ShowItem(g_hContactMenuVisitFriendship, !bIsChatroom);
+ Menu_ShowItem(g_hContactMenuVisitFriendship, !bIsChatroom && !bIsPage);
Menu_ShowItem(g_hContactMenuVisitConversation, true);
Menu_ShowItem(g_hContactMenuPostStatus, !bIsChatroom);
- if (!isOffline() && !bIsChatroom)
+ if (!isOffline() && !bIsChatroom && !bIsPage)
{
bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
- BYTE type = getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0);
Menu_ShowItem(g_hContactMenuAuthAsk, ctrlPressed || type == CONTACT_NONE || !type);
Menu_ShowItem(g_hContactMenuAuthGrant, ctrlPressed || type == CONTACT_APPROVE);