Exemplo n.º 1
0
int WhatsAppProto::onGroupChatEvent(WPARAM wParam, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK*)lParam;
	if (mir_strcmp(gch->pDest->pszModule, m_szModuleName))
		return 0;

	std::string chat_id(T2Utf(gch->pDest->ptszID));
	WAChatInfo *pInfo = SafeGetChat(chat_id);
	if (pInfo == NULL)
		return 0;

	switch (gch->pDest->iType) {
	case GC_USER_LOGMENU:
		ChatLogMenuHook(pInfo, gch);
		break;

	case GC_USER_NICKLISTMENU:
		NickListMenuHook(pInfo, gch);
		break;

	case GC_USER_MESSAGE:
		if (isOnline()) {
			std::string msg(T2Utf(gch->ptszText));
			
			try {
				int msgId = GetSerial();
				time_t now = time(NULL);
				std::string id = Utilities::intToStr(now) + "-" + Utilities::intToStr(msgId);

				FMessage fmsg(chat_id, true, id);
				fmsg.timestamp = now;
				fmsg.data = msg;
				m_pConnection->sendMessage(&fmsg);

				pInfo->m_unsentMsgs[id] = gch->ptszText;
			}
			CODE_BLOCK_CATCH_ALL
		}
		break;

	case GC_USER_PRIVMESS:
		string jid = string(_T2A(gch->ptszUID)) + "@s.whatsapp.net";
		MCONTACT hContact = ContactIDToHContact(jid);
		if (hContact == 0) {
			hContact = AddToContactList(jid, (char*)_T2A(gch->ptszUID));
			setWord(hContact, "Status", ID_STATUS_ONLINE);

			db_set_b(hContact, "CList", "Hidden", 1);
			setTString(hContact, "Nick", gch->ptszUID);
			db_set_dw(hContact, "Ignore", "Mask1", 0);
		}
		CallService(MS_MSG_SENDMESSAGE, hContact, 0);
		break;
	}

	return 0;
}
Exemplo n.º 2
0
void ChatHandler::handleLobbies(Request &/*req*/, Response &resp)
{
    tick();

    RS_STACK_MUTEX(mMtx); /********** LOCKED **********/
    resp.mDataStream.getStreamToMember();
    for(std::vector<Lobby>::iterator vit = mLobbies.begin(); vit != mLobbies.end(); ++vit)
    {
        uint32_t unread_msgs = 0;
        ChatId chat_id(vit->id);
        std::map<ChatId, std::list<Msg> >::iterator mit = mMsgs.find(chat_id);
        if(mit != mMsgs.end())
        {
            std::list<Msg>& msgs = mit->second;
            for(std::list<Msg>::iterator lit = msgs.begin(); lit != msgs.end(); ++lit)
                if(!lit->read)
                    unread_msgs++;
        }
        resp.mDataStream.getStreamToMember() << *vit << makeKeyValueReference("unread_msg_count", unread_msgs);
    }
    resp.mStateToken = mLobbiesStateToken;
    resp.setOk();
}
Exemplo n.º 3
0
int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK*)lParam;
	if (!gch)
	{
		return 1;
	}
	else if (mir_strcmp(gch->pDest->pszModule, m_szModuleName) != 0)
	{
		return 0;
	}

	ptrA chat_id(mir_t2a(gch->pDest->ptszID));

	switch (gch->pDest->iType)
	{
	case GC_USER_MESSAGE:
	{
		OnSendChatMessage(gch->pDest->ptszID, gch->ptszText);
		break;
	}

	case GC_USER_PRIVMESS:
	{
		MCONTACT hContact = FindContact(_T2A(gch->ptszUID));
		if (hContact == NULL)
		{
			hContact = AddContact(_T2A(gch->ptszUID), true);
			setWord(hContact, "Status", ID_STATUS_ONLINE);
			db_set_b(hContact, "CList", "Hidden", 1);
			setTString(hContact, "Nick", gch->ptszUID);
			db_set_dw(hContact, "Ignore", "Mask1", 0);
		}
		CallService(MS_MSG_SENDMESSAGET, hContact, 0);
		break;
	}

	case GC_USER_LOGMENU:
	{
		switch (gch->dwData)
		{
		case 10: {
			CSkypeInviteDlg dlg(this);
			if(!dlg.DoModal())
			{
				break;
			}
			MCONTACT hContact = dlg.m_hContact;
			if (hContact != NULL)
			{
				ptrA username(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID));
				SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, username, "User", m_szServer));
			}
			break;
		}
		case 20:
			OnLeaveChatRoom(FindChatRoom(chat_id), NULL);
			break;
		case 30:
			CMString newTopic = ChangeTopicForm();
			if (!newTopic.IsEmpty())
				SendRequest(new SetChatPropertiesRequest(m_szRegToken, chat_id, "topic", ptrA(mir_utf8encodeT(newTopic.GetBuffer())), m_szServer));
			break;
		}
		break;
	}

	case GC_USER_NICKLISTMENU:
	{
		ptrA user_id;
		if (gch->dwData == 10 || gch->dwData == 30 || gch->dwData == 40)
		{
			user_id = mir_t2a_cp(gch->ptszUID, CP_UTF8);
		}

		switch (gch->dwData)
		{
		case 10:
			SendRequest(new KickUserRequest(m_szRegToken, chat_id, user_id, m_szServer));
			break;
		case 30:
			SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "Admin", m_szServer));
			break;
		case 40:
			SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "User", m_szServer));
			break;
		}

		break;

	}
	}
	return 0;
}
Exemplo n.º 4
0
void NotifyQt::UpdateGUI()
{
	if(RsAutoUpdatePage::eventsLocked())
		return ;

	{
		QMutexLocker m(&_mutex) ;
		if(!_enabled)
			return ;
	}

	static bool already_updated = false ;	// these only update once at start because they may already have been set before 
														// the gui is running, then they get updated by callbacks.
	if(!already_updated)
	{
		emit messagesChanged() ;
		emit neighboursChanged();
		emit configChanged();

		already_updated = true ;
	}
	
	/* Finally Check for PopupMessages / System Error Messages */

	if (rsNotify)
	{
		uint32_t sysid;
		uint32_t type;
        std::string title, id, msg;

		/* You can set timeToShow, timeToLive and timeToHide or can leave the standard */
		ToasterItem *toaster = NULL;
		if (rsNotify->NotifyPopupMessage(type, id, title, msg))
		{
			uint popupflags = Settings->getNotifyFlags();

			switch(type)
			{
				case RS_POPUP_ENCRYPTED_MSG:
					SoundManager::play(SOUND_MESSAGE_ARRIVED);

					if ((popupflags & RS_POPUP_MSG) && !_disableAllToaster)
					{
						toaster = new ToasterItem(new MessageToaster("", tr("Encrypted message"), QString("[%1]").arg(tr("Encrypted message"))));
					}
					break;
				case RS_POPUP_MSG:
					SoundManager::play(SOUND_MESSAGE_ARRIVED);

					if ((popupflags & RS_POPUP_MSG) && !_disableAllToaster)
					{
						toaster = new ToasterItem(new MessageToaster(id, QString::fromUtf8(title.c_str()), QString::fromUtf8(msg.c_str())));
					}
					break;
				case RS_POPUP_CONNECT:
					SoundManager::play(SOUND_USER_ONLINE);

					if ((popupflags & RS_POPUP_CONNECT) && !_disableAllToaster)
					{
						toaster = new ToasterItem(new OnlineToaster(RsPeerId(id)));
					}
					break;
				case RS_POPUP_DOWNLOAD:
					SoundManager::play(SOUND_DOWNLOAD_COMPLETE);

					if ((popupflags & RS_POPUP_DOWNLOAD) && !_disableAllToaster)
					{
						/* id = file hash */
						toaster = new ToasterItem(new DownloadToaster(RsFileHash(id), QString::fromUtf8(title.c_str())));
					}
					break;
				case RS_POPUP_CHAT:
					if ((popupflags & RS_POPUP_CHAT) && !_disableAllToaster)
					{
                        // TODO: fix for distant chat, look up if dstant chat uses RS_POPUP_CHAT
                        ChatDialog *chatDialog = ChatDialog::getChat(ChatId(RsPeerId(id)));
						ChatWidget *chatWidget;
						if (chatDialog && (chatWidget = chatDialog->getChatWidget()) && chatWidget->isActive()) {
							// do not show when active
							break;
						}
                        toaster = new ToasterItem(new ChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str())));
					}
					break;
				case RS_POPUP_GROUPCHAT:
					if ((popupflags & RS_POPUP_GROUPCHAT) && !_disableAllToaster)
					{
						MainWindow *mainWindow = MainWindow::getInstance();
						if (mainWindow && mainWindow->isActiveWindow() && !mainWindow->isMinimized()) {
							if (MainWindow::getActivatePage() == MainWindow::Friends) {
								if (FriendsDialog::isGroupChatActive()) {
									// do not show when active
									break;
								}
							}
						}
						toaster = new ToasterItem(new GroupChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str())));
					}
					break;
				case RS_POPUP_CHATLOBBY:
					if ((popupflags & RS_POPUP_CHATLOBBY) && !_disableAllToaster)
					{
                        ChatId chat_id(id);

                        ChatDialog *chatDialog = ChatDialog::getChat(chat_id);
						ChatWidget *chatWidget;
                        if (chatDialog && (chatWidget = chatDialog->getChatWidget()) && chatWidget->isActive()) {
                            // do not show when active
                            break;
                        }
                        ChatLobbyDialog *chatLobbyDialog = dynamic_cast<ChatLobbyDialog*>(chatDialog);

						RsGxsId sender(title);
						if (!chatLobbyDialog || chatLobbyDialog->isParticipantMuted(sender))
                            break; // participant is muted

                        toaster = new ToasterItem(new ChatLobbyToaster(chat_id.toLobbyId(), sender, QString::fromUtf8(msg.c_str())));
					}
					break;
				case RS_POPUP_CONNECT_ATTEMPT:
					if ((popupflags & RS_POPUP_CONNECT_ATTEMPT) && !_disableAllToaster)
					{
						// id = gpgid
						// title = ssl name
						// msg = peer id
						toaster = new ToasterItem(new FriendRequestToaster(RsPgpId(id), QString::fromUtf8(title.c_str()), RsPeerId(msg)));
					}
					break;
			}
		}

		/*Now check Plugins*/
		if (!toaster) {
			int pluginCount = rsPlugins->nbPlugins();
			for (int i = 0; i < pluginCount; ++i) {
				RsPlugin *rsPlugin = rsPlugins->plugin(i);
				if (rsPlugin) {
					ToasterNotify *toasterNotify = rsPlugin->qt_toasterNotify();
					if (toasterNotify) {
						toaster = toasterNotify->toasterItem();
						continue;
					}
				}
			}
		}

		if (toaster) {
			/* init attributes */
			toaster->widget->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);

			/* add toaster to waiting list */
			//QMutexLocker lock(&waitingToasterMutex);
			waitingToasterList.push_back(toaster);
		}

		if (rsNotify->NotifySysMessage(sysid, type, title, msg))
		{
			/* make a warning message */
			switch(type)
			{
				case RS_SYS_ERROR:
					QMessageBox::critical(MainWindow::getInstance(),
							QString::fromUtf8(title.c_str()),
							QString::fromUtf8(msg.c_str()));
					break;
				case RS_SYS_WARNING:
					QMessageBox::warning(MainWindow::getInstance(),
							QString::fromUtf8(title.c_str()),
							QString::fromUtf8(msg.c_str()));
					break;
				default:
				case RS_SYS_INFO:
					QMessageBox::information(MainWindow::getInstance(),
							QString::fromUtf8(title.c_str()),
							QString::fromUtf8(msg.c_str()));
					break;
			}
		}

		if (rsNotify->NotifyLogMessage(sysid, type, title, msg))
		{
			/* make a log message */
			std::string logMesString = title + " " + msg;
			switch(type)
			{
				case RS_SYS_ERROR:
				case RS_SYS_WARNING:
				case RS_SYS_INFO:
					emit logInfoChanged(QString::fromUtf8(logMesString.c_str()));
			}
		}
	}

	/* Now start the waiting toasters */
	startWaitingToasters();
}