void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str) { switch (event_type) { case RS_CHAT_LOBBY_EVENT_PEER_LEFT: ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); emit peerLeft(id()) ; break; case RS_CHAT_LOBBY_EVENT_PEER_JOINED: ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); emit peerJoined(id()) ; break; case RS_CHAT_LOBBY_EVENT_PEER_STATUS: ui.chatWidget->updateStatusString(RsHtml::plainText(nickname) + " %1", RsHtml::plainText(str)); if (!isParticipantMuted(nickname)) { emit typingEventReceived(id()) ; } break; case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 changed his name to: %2").arg(RsHtml::plainText(nickname), RsHtml::plainText(str)), ChatWidget::TYPE_SYSTEM); // TODO if a user was muted and changed his name, update mute list, but only, when the muted peer, dont change his name to a other peer in your chat lobby if (isParticipantMuted(nickname) && !isNicknameInLobby(str)) { muteParticipant(str); } break; case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE: //std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl; break; default: std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl; } updateParticipantsList() ; }
/** * We get a new Message from a chat participant * * - Ignore Messages from muted chat participants */ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info) { QDateTime sendTime = QDateTime::fromTime_t(info.sendTime); QDateTime recvTime = QDateTime::fromTime_t(info.recvTime); QString message = QString::fromStdWString(info.msg); QString name = QString::fromUtf8(info.peer_nickname.c_str()); QString rsid = QString::fromUtf8(info.rsid.c_str()); std::cerr << "message from rsid " << info.rsid.c_str() << std::endl; if(!isParticipantMuted(name)) { ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); emit messageReceived(id()) ; } // This is a trick to translate HTML into text. QTextEdit editor; editor.setHtml(message); QString notifyMsg = name + ": " + editor.toPlainText(); if(notifyMsg.length() > 30) MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg.left(30) + QString("...")); else MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg); // also update peer list. time_t now = time(NULL); if (now > lastUpdateListTime) { lastUpdateListTime = now; updateParticipantsList(); } }
/** * We get a new Message from a chat participant * * - Ignore Messages from muted chat participants */ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info) { QDateTime sendTime = QDateTime::fromTime_t(info.sendTime); QDateTime recvTime = QDateTime::fromTime_t(info.recvTime); QString message = QString::fromStdWString(info.msg); QString name = QString::fromUtf8(info.peer_nickname.c_str()); QString rsid = QString::fromUtf8(info.rsid.c_str()); std::cerr << "message from rsid " << info.rsid.c_str() << std::endl; if (!isParticipantMuted(name)) { // ui.chatWidget->addChatMsg(true, name.append(" ").append(rsid), sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); } else { // ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message.append(" (BLOCKED)"), ChatWidget::TYPE_NORMAL); } // also update peer list. time_t now = time(NULL); if (now > lastUpdateListTime) { lastUpdateListTime = now; updateParticipantsList(); } }
/** * Called when a Participant in QList get Clicked / Changed * * Check if the Checkbox altered and Mute User * * @todo auf rsid * * @param QListWidgetItem Participant to check */ void ChatLobbyDialog::changePartipationState(QListWidgetItem *item) { QString nickname = item->text(); std::cerr << "check Partipation status for '" << nickname.toStdString() << std::endl; if (item->checkState() == Qt::Unchecked) { muteParticipant(nickname); } else { unMuteParticipant(nickname); } mutedParticipants->removeDuplicates(); updateParticipantsList(); }
/** * We get a new Message from a chat participant * * - Ignore Messages from muted chat participants */ void ChatLobbyDialog::addChatMsg(const ChatMessage& msg) { QDateTime sendTime = QDateTime::fromTime_t(msg.sendTime); QDateTime recvTime = QDateTime::fromTime_t(msg.recvTime); QString message = QString::fromUtf8(msg.msg.c_str()); RsGxsId gxs_id = msg.lobby_peer_gxs_id ; if(!isParticipantMuted(gxs_id)) { // We could change addChatMsg to display the peers icon, passing a ChatId RsIdentityDetails details ; QString name ; if(rsIdentity->getIdDetails(gxs_id,details)) name = QString::fromUtf8(details.mNickname.c_str()) ; else name = QString::fromUtf8(msg.peer_alternate_nickname.c_str()) + " (" + QString::fromStdString(gxs_id.toStdString()) + ")" ; ui.chatWidget->addChatMsg(msg.incoming, name, gxs_id, sendTime, recvTime, message, ChatWidget::MSGTYPE_NORMAL); emit messageReceived(msg.incoming, id(), sendTime, name, message) ; SoundManager::play(SOUND_NEW_LOBBY_MESSAGE); // This is a trick to translate HTML into text. QTextEdit editor; editor.setHtml(message); QString notifyMsg = name + ": " + editor.toPlainText(); if(notifyMsg.length() > 30) MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg.left(30) + QString("...")); else MainWindow::displayLobbySystrayMsg(tr("Lobby chat") + ": " + _lobby_name, notifyMsg); } // also update peer list. time_t now = time(NULL); QList<QTreeWidgetItem*> qlFoundParticipants=ui.participantsList->findItems(QString::fromStdString(gxs_id.toStdString()),Qt::MatchExactly,COLUMN_ID); if (qlFoundParticipants.count()!=0) qlFoundParticipants.at(0)->setText(COLUMN_ACTIVITY,QString::number(now)); if (now > lastUpdateListTime) { lastUpdateListTime = now; updateParticipantsList(); } }
void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info) { QDateTime sendTime = QDateTime::fromTime_t(info.sendTime); QDateTime recvTime = QDateTime::fromTime_t(info.recvTime); QString message = QString::fromStdWString(info.msg); QString name = QString::fromUtf8(info.peer_nickname.c_str()); ui.chatWidget->addChatMsg(true, name, sendTime, recvTime, message, ChatWidget::TYPE_NORMAL); // also update peer list. time_t now = time(NULL); if (now > lastUpdateListTime) { lastUpdateListTime = now; updateParticipantsList(); } }
void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str) { switch (event_type) { case RS_CHAT_LOBBY_EVENT_PEER_LEFT: ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); break; case RS_CHAT_LOBBY_EVENT_PEER_JOINED: ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); break; case RS_CHAT_LOBBY_EVENT_PEER_STATUS: ui.chatWidget->updateStatusString(nickname + " %1", str); break; case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE: //std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in lobby " << getPeerId() << std::endl; break; default: std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl; } updateParticipantsList() ; }
/** * Called when a Participant in QTree get Clicked / Changed * * Check if the Checkbox altered and Mute User * * @todo auf rsid * * @param QTreeWidgetItem Participant to check */ void ChatLobbyDialog::changePartipationState() { QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems(); if (selectedItems.size() == 0) { return; } QList<QTreeWidgetItem*>::iterator item; for (item = selectedItems.begin(); item != selectedItems.end(); ++item) { QString nickname = (*item)->text(COLUMN_NAME); std::cerr << "check Partipation status for '" << nickname.toUtf8().constData() << std::endl; if (muteAct->isChecked()) { muteParticipant(nickname); } else { unMuteParticipant(nickname); } } mutedParticipants->removeDuplicates(); updateParticipantsList(); }