mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
feat: add chatting by ID
This commit is contained in:
@@ -43,19 +43,19 @@ QByteArray ClientAnswerParser::deAuthorization(bool result, QString login)
|
||||
return dataParser->xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray ClientAnswerParser::message(QString text, QString login)
|
||||
QByteArray ClientAnswerParser::message(QString loginFrom,QString loginTo,QString text)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
SAttribute attribute2;
|
||||
QList<SAttribute> listAttr;
|
||||
SAttribute attribute1;
|
||||
attribute1 = {"From",loginFrom};
|
||||
listAttr.append(attribute1);
|
||||
attribute1 = {"To",loginTo};
|
||||
listAttr.append(attribute1);
|
||||
attribute1 = {"Text",text};
|
||||
listAttr.append(attribute1);
|
||||
|
||||
SAttribute attribute1 = {"Text", text};
|
||||
QList<SAttribute> listAttr = {attribute1};
|
||||
if(login != "")
|
||||
{
|
||||
attribute2 = {"Login", login};
|
||||
listAttr.append(attribute2);
|
||||
}
|
||||
SXmlAnswerTag tag = {"ServerMessage", listAttr};
|
||||
SXmlAnswerTag tag = {"ClientMessage", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
QByteArray authorization(bool result, QString instructorName, QString clientName, QString accessType, QString login, int id);
|
||||
QByteArray deAuthorization(bool result, QString login);
|
||||
QByteArray message(QString text, QString login = "");
|
||||
QByteArray message(QString loginFrom,QString loginTo,QString text);
|
||||
QByteArray task(QString text);
|
||||
QByteArray notify(QString code);
|
||||
QByteArray tasks(QStringList listTasks);
|
||||
|
||||
@@ -34,11 +34,6 @@ void ProcessParser::read(ClientHandler *client, QByteArray array)
|
||||
|
||||
clientDeAuth(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "ToClientMessage")
|
||||
{//Отправка сообщения Клиенту
|
||||
|
||||
toClientMessage(xmlReader,client);
|
||||
}
|
||||
else if(xmlReader.name() == "QueryToDB")
|
||||
{//Запрос к базе данных от клиента
|
||||
|
||||
@@ -339,28 +334,6 @@ void ProcessParser::clientDeAuth(QXmlStreamReader &xmlReader,ClientHandler *clie
|
||||
processingSystem->processingClientDeAutorization(client, clientDeAutorization);
|
||||
}
|
||||
|
||||
void ProcessParser::toClientMessage(QXmlStreamReader &xmlReader,ClientHandler *client)
|
||||
{
|
||||
ToClientMessage toClientMessage;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "id")
|
||||
toClientMessage.id = value.toInt();
|
||||
else if(name == "Text")
|
||||
toClientMessage.Text = value;
|
||||
else if(name == "Login")
|
||||
toClientMessage.Login = value;
|
||||
}
|
||||
|
||||
processingSystem->processingToClientMessage(client, toClientMessage);
|
||||
}
|
||||
|
||||
void ProcessParser::queryToDb(QXmlStreamReader &xmlReader,ClientHandler *client, QByteArray array)
|
||||
{
|
||||
ClientQueryToDB queryToDB;
|
||||
@@ -519,11 +492,15 @@ void ProcessParser::clientMessage(QXmlStreamReader &xmlReader,ClientHandler *cli
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "Text")
|
||||
if (name == "Text")
|
||||
clientMessage.Text = value;
|
||||
if (name == "From")
|
||||
clientMessage.From = value;
|
||||
if (name == "To")
|
||||
clientMessage.To = value;
|
||||
}
|
||||
|
||||
processingSystem->processingFromClientMessage(client, clientMessage);
|
||||
processingSystem->processingSendMessage(client, clientMessage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -120,55 +120,23 @@ void CommonClientHandler::slot_sendPacketToAllClients(PacketType packetType)
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_msgToClientFromGUI(QString login, QString text)
|
||||
void CommonClientHandler::slotSendMessage(QString idFrom, QString idTo, QString text)
|
||||
{
|
||||
QString textMsg = text;
|
||||
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg);
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(idFrom,idTo,text);
|
||||
|
||||
//Проходим все открытые сокеты, ищем нужный
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
if(handler->getClient()->getLogin() == login)
|
||||
{//Отправляем ему
|
||||
|
||||
handler->sendXmlAnswer(byteArrayMsg);
|
||||
|
||||
QString peerAddress = handler->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(handler->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg To Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
|
||||
|
||||
emit sigSendToLogger(str);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_msgToGUIfromClient(QString login, QString text)
|
||||
{
|
||||
QString textMsg = text;
|
||||
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg, login);
|
||||
|
||||
//Проходим все открытые сокеты, ищем нужный
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);;
|
||||
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
|
||||
{//Отправляем GUI-клиенту для отображения в Мессенджере
|
||||
|
||||
if(handler->getClient()->getId() == idTo)
|
||||
{
|
||||
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
|
||||
|
||||
QString peerAddress = handler->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(handler->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg From Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
|
||||
QString str = "Msg From Client [" + idFrom + " to " + idTo + "] : " + textMsg;
|
||||
|
||||
emit sigSendToLogger(str);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ public:
|
||||
void slot_StatusTasksAMMofTraineeChanged(int trainee_id);
|
||||
void slot_StatusTasksFIMofTraineeChanged(int trainee_id);
|
||||
void slot_sendPacketToAllClients(PacketType packetType);
|
||||
//слот обработки сигнала о готовности нового сообщения на отправку клиенту от мессенджера
|
||||
void slot_msgToClientFromGUI(QString login, QString text);
|
||||
void slot_msgToGUIfromClient(QString login, QString text);
|
||||
void slotSendMessage(QString loginFrom, QString loginTo, QString text);
|
||||
void slot_sendTaskToClient(QString fullNameClient, QString textTask);
|
||||
signals:
|
||||
void sigSendToLogger(QString text);
|
||||
|
||||
@@ -29,8 +29,7 @@ void ProcessingSystem::initialize(ServerLMSWidget *server,
|
||||
|
||||
connect(this,&ProcessingSystem::sigUpdateListClients,server, &ServerLMSWidget::slotUpdateListClients,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigSetData,updateController,&UpdateController::setDataInfo,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::signal_msgToClientReady,commonClientHandler, &CommonClientHandler::slot_msgToClientFromGUI);
|
||||
connect(this,&ProcessingSystem::signal_msgFromClientReady,commonClientHandler, &CommonClientHandler::slot_msgToGUIfromClient);
|
||||
connect(this,&ProcessingSystem::sigSendMessage,commonClientHandler, &CommonClientHandler::slotSendMessage,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger,Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@@ -59,11 +58,12 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
|
||||
|
||||
client->getClient()->setLogin(clientAutorization.Login);
|
||||
client->getClient()->setTypeClient(clientAutorization.TypeClient);
|
||||
|
||||
emit sigUpdateListClients();
|
||||
|
||||
instructorName = providerDBLMS->getNameInstructorByLogin(clientAutorization.Login);
|
||||
clientID = providerDBLMS->getIdInstructorByLogin(clientAutorization.Login);
|
||||
|
||||
client->getClient()->setId(QString::number(clientID));
|
||||
arrayAnswer = dataParser->ClientAnswer()->authorization(true, instructorName, instructorName, "instructor", clientAutorization.Login, clientID);
|
||||
}
|
||||
else if(clientAutorization.TypeClient != TypeClientAutorization::TYPE_GUI)
|
||||
@@ -78,7 +78,7 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
|
||||
instructorName = providerDBLMS->getMainInstructorName();
|
||||
traineeName = providerDBLMS->getNameTraineeByLogin(clientAutorization.Login);
|
||||
clientID = providerDBLMS->getIdTraineeByLogin(clientAutorization.Login);
|
||||
|
||||
client->getClient()->setId(QString::number(clientID));
|
||||
arrayAnswer = dataParser->ClientAnswer()->authorization(true, instructorName, traineeName, "trainee", clientAutorization.Login, clientID);
|
||||
}
|
||||
else
|
||||
@@ -474,23 +474,9 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingToClientMessage(ClientHandler *client, ToClientMessage toClientMessage)
|
||||
void ProcessingSystem::processingSendMessage(ClientHandler *client, ClientMessage clientMessage)
|
||||
{
|
||||
signal_msgToClientReady(toClientMessage.Login, toClientMessage.Text);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingFromClientMessage(ClientHandler *client, ClientMessage clientMessage)
|
||||
{
|
||||
/*
|
||||
QString peerAddress = client->getSocket()->peerAddress().toString();
|
||||
QString peerPort = QString::number(client->getSocket()->peerPort());
|
||||
|
||||
QString str = "Msg From Client [" + peerAddress + ":" + peerPort + "] : " + clientMessage.Text;
|
||||
|
||||
emit sigLogMessage(str);
|
||||
*/
|
||||
|
||||
signal_msgFromClientReady(client->getClient()->getLogin(), clientMessage.Text);
|
||||
emit sigSendMessage(clientMessage.From, clientMessage.To, clientMessage.Text);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotify clientNotify)
|
||||
|
||||
@@ -33,9 +33,8 @@ public:
|
||||
void processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization);
|
||||
void processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id = 0, void* data = nullptr);
|
||||
void processingClientQueryTasksXML(ClientHandler *client, ClientQueryTasksXML clientQueryTasksXML);
|
||||
void processingToClientMessage(ClientHandler *client, ToClientMessage toClientMessage);
|
||||
|
||||
void processingFromClientMessage(ClientHandler *client, ClientMessage clientMessage);
|
||||
void processingSendMessage(ClientHandler *client, ClientMessage clientMessage);
|
||||
void processingClientNotify(ClientHandler *client, ClientNotify clientNotify);
|
||||
|
||||
void setCurrentDataInfo(DataInfo *dataInfo);
|
||||
@@ -58,8 +57,7 @@ signals:
|
||||
void sigStatusTasksFIMofTraineeChanged(int trainee_id);
|
||||
void sigLogMessage(QString log);
|
||||
void sigAddToMessanger(QString login,QString text);
|
||||
void signal_msgToClientReady(QString login, QString text);
|
||||
void signal_msgFromClientReady(QString login, QString text);
|
||||
void sigSendMessage(QString loginFrom, QString loginTo, QString text);
|
||||
void sigSetData(DataInfo *dataInfo);
|
||||
|
||||
private:
|
||||
|
||||
@@ -29,7 +29,7 @@ void SendSystem::setClient(Client *client,QTcpSocket *socket)
|
||||
|
||||
void SendSystem::sendMessageBlock(QString message)
|
||||
{
|
||||
auto messageBlock = emit sigSendXMLmessage(message);
|
||||
auto messageBlock = emit sigSendNotify(message);
|
||||
sendXmlAnswer(messageBlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public slots:
|
||||
signals:
|
||||
void sigLoadHash();
|
||||
void sigSendToLogger(QString message);
|
||||
QByteArray sigSendXMLmessage(QString message, QString login = "");
|
||||
QByteArray sigSendXMLmessage(QString loginFrom, QString loginTo, QString text);
|
||||
QByteArray sigSendNotify(QString message);
|
||||
QByteArray sigSendVersion();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user