diff options
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 31 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 37 |
3 files changed, 23 insertions, 57 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index 65eadd0498..c645140442 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -285,14 +285,10 @@ INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM) facy.chat_rooms.insert(std::make_pair(thread_id, fbc)); // Update loaded info about this chat - if (getBool(hContact, FACEBOOK_KEY_CHAT_CAN_REPLY, true) != fbc->can_reply) - setByte(hContact, FACEBOOK_KEY_CHAT_CAN_REPLY, fbc->can_reply); - if (getBool(hContact, FACEBOOK_KEY_CHAT_READ_ONLY, false) != fbc->read_only) - setByte(hContact, FACEBOOK_KEY_CHAT_READ_ONLY, fbc->read_only); - if (getBool(hContact, FACEBOOK_KEY_CHAT_IS_ARCHIVED, false) != fbc->is_archived) - setByte(hContact, FACEBOOK_KEY_CHAT_IS_ARCHIVED, fbc->is_archived); - if (getBool(hContact, FACEBOOK_KEY_CHAT_IS_SUBSCRIBED, true) != fbc->is_subscribed) - setByte(hContact, FACEBOOK_KEY_CHAT_IS_SUBSCRIBED, fbc->is_subscribed); + setByte(hContact, FACEBOOK_KEY_CHAT_CAN_REPLY, fbc->can_reply); + setByte(hContact, FACEBOOK_KEY_CHAT_READ_ONLY, fbc->read_only); + setByte(hContact, FACEBOOK_KEY_CHAT_IS_ARCHIVED, fbc->is_archived); + setByte(hContact, FACEBOOK_KEY_CHAT_IS_SUBSCRIBED, fbc->is_subscribed); } // RM TODO: better use check if chatroom exists/is in db/is online... no? diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index cec21e5904..60fa9c0247 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -22,27 +22,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -void updateStringUtf(FacebookProto *proto, MCONTACT hContact, const char *key, const std::string &value) { - bool update_required = true; - - DBVARIANT dbv; - if (!proto->getStringUtf(hContact, key, &dbv)) { - update_required = mir_strcmp(dbv.pszVal, value.c_str()) != 0; - db_free(&dbv); - } - - if (update_required) { - proto->setStringUtf(hContact, key, value.c_str()); - } -} - void FacebookProto::SaveName(MCONTACT hContact, const facebook_user *fbu) { if (fbu->type == CONTACT_PAGE) { // Page has only nickname and no first/last names std::string nick = m_pagePrefix + " " + fbu->real_name; - updateStringUtf(this, hContact, FACEBOOK_KEY_NICK, nick); + setStringUtf(hContact, FACEBOOK_KEY_NICK, nick.c_str()); delSetting(hContact, FACEBOOK_KEY_FIRST_NAME); delSetting(hContact, FACEBOOK_KEY_SECOND_NAME); delSetting(hContact, FACEBOOK_KEY_LAST_NAME); @@ -54,14 +40,14 @@ void FacebookProto::SaveName(MCONTACT hContact, const facebook_user *fbu) if (!getBool(FACEBOOK_KEY_NAME_AS_NICK, DEFAULT_NAME_AS_NICK) && !fbu->nick.empty()) nick = fbu->nick; - updateStringUtf(this, hContact, FACEBOOK_KEY_NICK, nick); + setStringUtf(hContact, FACEBOOK_KEY_NICK, nick.c_str()); // Explode whole name into first, second and last name std::vector<std::string> names; utils::text::explode(fbu->real_name, " ", &names); - updateStringUtf(this, hContact, FACEBOOK_KEY_FIRST_NAME, names.size() > 0 ? names.front().c_str() : ""); - updateStringUtf(this, hContact, FACEBOOK_KEY_LAST_NAME, names.size() > 1 ? names.back().c_str() : ""); + setStringUtf(hContact, FACEBOOK_KEY_FIRST_NAME, names.size() > 0 ? names.front().c_str() : ""); + setStringUtf(hContact, FACEBOOK_KEY_LAST_NAME, names.size() > 1 ? names.back().c_str() : ""); std::string middle; if (names.size() > 2) { @@ -72,7 +58,7 @@ void FacebookProto::SaveName(MCONTACT hContact, const facebook_user *fbu) middle += names.at(i); } } - updateStringUtf(this, hContact, FACEBOOK_KEY_SECOND_NAME, middle); + setStringUtf(hContact, FACEBOOK_KEY_SECOND_NAME, middle.c_str()); } bool FacebookProto::IsMyContact(MCONTACT hContact, bool include_chat) @@ -453,8 +439,7 @@ void FacebookProto::SetAllContactStatuses(int status) if (isChatRoom(hContact)) continue; - if (getWord(hContact, "Status", 0) != status) - setWord(hContact, "Status", status); + setWord(hContact, "Status", status); } } @@ -708,9 +693,7 @@ void FacebookProto::RefreshUserInfo(void *data) int oldType = getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); // From server we won't get request/approve types, only none, so we don't want to overwrite and lost it in that case if (fbu.type != CONTACT_NONE || (oldType != CONTACT_REQUEST && oldType != CONTACT_APPROVE)) { - if (oldType != fbu.type) { - setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu.type); - } + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu.type); } // If this contact is page, set it as invisible (if enabled in options) diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 213a214fbf..4bf96e0e3c 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -95,15 +95,11 @@ void FacebookProto::ProcessFriendList(void*) // TODO RM: remove, because contacts cant change it, so its only for "first run" // - but what with contacts, that was added after logon? // Update gender - if (getByte(hContact, "Gender", 0) != (int)fbu->gender) - setByte(hContact, "Gender", fbu->gender); + setByte(hContact, "Gender", (int)fbu->gender); // TODO: remove this in some future version? // Remove old useless "RealName" field - ptrA realname(getStringA(hContact, "RealName")); - if (realname != NULL) { - delSetting(hContact, "RealName"); - } + delSetting(hContact, "RealName"); // Update real name and nick if (!fbu->real_name.empty()) { @@ -111,19 +107,14 @@ void FacebookProto::ProcessFriendList(void*) } // Update username - ptrA username(getStringA(hContact, FACEBOOK_KEY_USERNAME)); - if (!username || mir_strcmp(username, fbu->username.c_str())) { - if (!fbu->username.empty()) - setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str()); - else - delSetting(hContact, FACEBOOK_KEY_USERNAME); - } + if (!fbu->username.empty()) + setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str()); + else + delSetting(hContact, FACEBOOK_KEY_USERNAME); // Update contact type - if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE) != fbu->type) { - setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type); - // TODO: remove that popup and use "Contact added you" event? - } + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type); + // TODO: remove that popup and use "Contact added you" event? // Wasn't contact removed from "server-list" someday? And is it friend now? (as we can get also non-friends from this request now)? if (fbu->type == CONTACT_FRIEND && getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { @@ -851,10 +842,8 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo // setString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, msg.message_id.c_str()); setDword(FACEBOOK_KEY_LAST_ACTION_TS, msg.time); - // Save TID if not exists already - ptrA tid(getStringA(hChatContact, FACEBOOK_KEY_TID)); - if (!tid || mir_strcmp(tid, msg.thread_id.c_str())) - setString(hChatContact, FACEBOOK_KEY_TID, msg.thread_id.c_str()); + // Save TID + setString(hChatContact, FACEBOOK_KEY_TID, msg.thread_id.c_str()); // Get name of this chat participant std::string name = msg.user_id; // fallback to numeric id @@ -942,10 +931,8 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo // Save last (this) message ID setString(hContact, FACEBOOK_KEY_MESSAGE_ID, msg.message_id.c_str()); - // Save TID if not exists already - ptrA tid(getStringA(hContact, FACEBOOK_KEY_TID)); - if ((!tid || mir_strcmp(tid, msg.thread_id.c_str())) && !msg.thread_id.empty()) - setString(hContact, FACEBOOK_KEY_TID, msg.thread_id.c_str()); + // Save TID + setString(hContact, FACEBOOK_KEY_TID, msg.thread_id.c_str()); if (msg.isIncoming && msg.isUnread && msg.type == MESSAGE) { PROTORECVEVENT recv = { 0 }; |