void FacebookProto::PrepareNotificationsChatRoom() { if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM)) return; // Prepare notifications chatroom if not exists MCONTACT hNotificationsChatRoom = ChatIDToHContact(FACEBOOK_NOTIFICATIONS_CHATROOM); if (hNotificationsChatRoom == NULL || getDword(hNotificationsChatRoom, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE) { TCHAR nameT[200]; mir_sntprintf(nameT, _T("%s: %s"), m_tszUserName, TranslateT("Notifications")); // Create the group chat session GCSESSION gcw = { sizeof(gcw) }; gcw.iType = GCW_PRIVMESS; gcw.ptszID = _T(FACEBOOK_NOTIFICATIONS_CHATROOM); gcw.pszModule = m_szModuleName; gcw.ptszName = nameT; CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw); // Send setting events GCDEST gcd = { m_szModuleName, _T(FACEBOOK_NOTIFICATIONS_CHATROOM), GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; gce.time = ::time(NULL); CallServiceSync(MS_GC_EVENT, WINDOW_HIDDEN, reinterpret_cast<LPARAM>(&gce)); CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce)); } }
void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old) { // replace % to %% to not interfere with chat color codes std::string smessage = message; utils::text::replace_all(&smessage, "%", "%%"); ptrT tid(mir_a2t(id)); ptrT tnick(mir_a2t_cp(name, CP_UTF8)); ptrT ttext(mir_a2t_cp(smessage.c_str(), CP_UTF8)); ptrT tchat_id(mir_a2t(chat_id)); GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.ptszText = ttext; gce.time = timestamp ? timestamp : ::time(NULL); if (id != NULL) gce.bIsMe = !mir_strcmp(id, facy.self_.user_id.c_str()); gce.dwFlags |= GCEF_ADDTOLOG; if (is_old) { gce.dwFlags |= GCEF_NOTNOTIFY; gce.dwFlags &= ~GCEF_ADDTOLOG; } gce.ptszNick = tnick; gce.ptszUID = tid; CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce)); facy.erase_reader(ChatIDToHContact(chat_id)); }
void FacebookProto::SendChatMsgWorker(void *p) { if (p == NULL) return; send_chat *data = static_cast<send_chat*>(p); std::string err_message; // replace %% back to %, because chat automatically does this to sent messages utils::text::replace_all(&data->msg, "%%", "%"); MCONTACT hContact = ChatIDToHContact(data->chat_id); if (hContact) { ptrA tid_(getStringA(hContact, FACEBOOK_KEY_TID)); std::string tid; if (tid_ != NULL && mir_strcmp(tid_, "null")) { tid = tid_; } else { std::string post_data = "client=mercury"; post_data += "&__user="******"&__dyn=" + facy.__dyn(); post_data += "&__req=" + facy.__req(); post_data += "&fb_dtsg=" + facy.dtsg_; post_data += "&ttstamp=" + facy.ttstamp_; post_data += "&__rev=" + facy.__rev(); post_data += "&threads[thread_ids][0]=" + utils::url::encode(data->chat_id); http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data); // NOTE: Request revised 1.9.2015 tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\""); if (!tid.empty() && tid.compare("null")) setString(hContact, FACEBOOK_KEY_TID, tid.c_str()); debugLogA(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str()); } if (!tid.empty()) { if (facy.send_message(0, hContact, data->msg, &err_message) == SEND_MESSAGE_OK) UpdateChat(data->chat_id.c_str(), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str()); else { ptrA text(mir_utf8encode(err_message.c_str())); UpdateChat(data->chat_id.c_str(), NULL, NULL, text); } } } delete data; }