mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Expose chat-log reads on the database interface (#7830)
getMessageLogHistory, getPrivateChatHistory, and getUserIdInDB were reachable only through Servatrice_DatabaseInterface, so the two log-history commands in the socket handler needed the concrete class. Declare the two readers on Server_DatabaseInterface with empty/false defaults, mark the Servatrice implementations as overrides, and resolve the private-chat peer through the already-promoted getUserId.
This commit is contained in:
parent
2ca3117765
commit
28f92ac5f5
3 changed files with 36 additions and 7 deletions
|
|
@ -2,7 +2,9 @@
|
||||||
#define SERVER_DATABASE_INTERFACE_H
|
#define SERVER_DATABASE_INTERFACE_H
|
||||||
|
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_ban.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_ban.pb.h"
|
||||||
|
#include "libcockatrice/protocol/pb/serverinfo_chat_message.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_moderator_login.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_moderator_login.pb.h"
|
||||||
|
#include "libcockatrice/protocol/pb/serverinfo_private_chat_message.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user_alt.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user_alt.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user_session.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user_session.pb.h"
|
||||||
|
|
@ -128,6 +130,33 @@ public:
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
virtual QList<ServerInfo_ChatMessage> getMessageLogHistory(const QString & /* user */,
|
||||||
|
const QString & /* ipaddress */,
|
||||||
|
const QString & /* gamename */,
|
||||||
|
const QString & /* gameid */,
|
||||||
|
const QString & /* message */,
|
||||||
|
bool & /* chat */,
|
||||||
|
bool & /* game */,
|
||||||
|
bool & /* room */,
|
||||||
|
int & /* range */,
|
||||||
|
int & /* maxresults */,
|
||||||
|
int /* offset */ = 0,
|
||||||
|
const QString & /* beforeTime */ = QString(),
|
||||||
|
bool * /* hasMore */ = nullptr)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual bool getPrivateChatHistory(int /* callerId */,
|
||||||
|
const QString & /* callerName */,
|
||||||
|
int /* peerId */,
|
||||||
|
const QString & /* peerName */,
|
||||||
|
quint64 /* before */,
|
||||||
|
int /* limit */,
|
||||||
|
QList<ServerInfo_PrivateChatMessage> & /* messages */,
|
||||||
|
bool & /* hasMore */)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Whether the backing store is reachable, reconnecting when it is not.
|
* @brief Whether the backing store is reachable, reconnecting when it is not.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -230,7 +230,7 @@ public:
|
||||||
int &maxresults,
|
int &maxresults,
|
||||||
int offset = 0,
|
int offset = 0,
|
||||||
const QString &beforeTime = QString(),
|
const QString &beforeTime = QString(),
|
||||||
bool *hasMore = nullptr);
|
bool *hasMore = nullptr) override;
|
||||||
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit) override;
|
QList<ServerInfo_UserSession> getUserSessions(const QString &userName, int limit) override;
|
||||||
bool getPrivateChatHistory(int callerId,
|
bool getPrivateChatHistory(int callerId,
|
||||||
const QString &callerName,
|
const QString &callerName,
|
||||||
|
|
@ -239,7 +239,7 @@ public:
|
||||||
quint64 before,
|
quint64 before,
|
||||||
int limit,
|
int limit,
|
||||||
QList<ServerInfo_PrivateChatMessage> &messages,
|
QList<ServerInfo_PrivateChatMessage> &messages,
|
||||||
bool &hasMore);
|
bool &hasMore) override;
|
||||||
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName,
|
QList<ServerInfo_UserAlt> getUserAlts(const QString &userName,
|
||||||
int depth = 1,
|
int depth = 1,
|
||||||
bool useEmail = true,
|
bool useEmail = true,
|
||||||
|
|
|
||||||
|
|
@ -1722,7 +1722,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetPrivateChatHistory(c
|
||||||
|
|
||||||
// Resolve the peer to an account id. Matching by name alone would merge the
|
// Resolve the peer to an account id. Matching by name alone would merge the
|
||||||
// conversations of everyone who has ever used that name.
|
// conversations of everyone who has ever used that name.
|
||||||
const int peerId = sqlInterface->getUserIdInDB(peer);
|
const int peerId = databaseInterface->getUserId(peer);
|
||||||
if (peerId < 1) {
|
if (peerId < 1) {
|
||||||
return Response::RespNameNotFound;
|
return Response::RespNameNotFound;
|
||||||
}
|
}
|
||||||
|
|
@ -1730,8 +1730,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetPrivateChatHistory(c
|
||||||
const int limit = qBound<quint32>(1, cmd.limit(), 200);
|
const int limit = qBound<quint32>(1, cmd.limit(), 200);
|
||||||
QList<ServerInfo_PrivateChatMessage> messages;
|
QList<ServerInfo_PrivateChatMessage> messages;
|
||||||
bool hasMore = false;
|
bool hasMore = false;
|
||||||
if (!sqlInterface->getPrivateChatHistory(userInfo->id(), QString::fromStdString(userInfo->name()), peerId, peer,
|
if (!databaseInterface->getPrivateChatHistory(userInfo->id(), QString::fromStdString(userInfo->name()), peerId,
|
||||||
cmd.before(), limit, messages, hasMore)) {
|
peer, cmd.before(), limit, messages, hasMore)) {
|
||||||
return Response::RespInternalError;
|
return Response::RespInternalError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1793,8 +1793,8 @@ Response::ResponseCode AbstractServerSocketInterface::cmdGetLogHistory(const Com
|
||||||
if (servatrice->getEnableLogQuery()) {
|
if (servatrice->getEnableLogQuery()) {
|
||||||
bool hasMore = false;
|
bool hasMore = false;
|
||||||
QList<ServerInfo_ChatMessage> history =
|
QList<ServerInfo_ChatMessage> history =
|
||||||
sqlInterface->getMessageLogHistory(userName, ipAddress, gameName, gameID, message, chatType, gameType,
|
databaseInterface->getMessageLogHistory(userName, ipAddress, gameName, gameID, message, chatType, gameType,
|
||||||
roomType, dateRange, maximumResults, offset, beforeTime, &hasMore);
|
roomType, dateRange, maximumResults, offset, beforeTime, &hasMore);
|
||||||
QListIterator<ServerInfo_ChatMessage> messageIterator(history);
|
QListIterator<ServerInfo_ChatMessage> messageIterator(history);
|
||||||
while (messageIterator.hasNext()) {
|
while (messageIterator.hasNext()) {
|
||||||
ServerInfo_ChatMessage chatMessage = messageIterator.next();
|
ServerInfo_ChatMessage chatMessage = messageIterator.next();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue