qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Classes | Signals | Public Member Functions | Private Slots | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
History Class Reference

Interacts with the profile database to save the chat history. More...

#include <history.h>

Inheritance diagram for History:
Inheritance graph
Collaboration diagram for History:
Collaboration graph

Classes

struct  DateIdx
 
struct  FileInfo
 
struct  HistMessage
 

Signals

void fileInserted (RowId dbId, QString fileId)
 

Public Member Functions

 History (std::shared_ptr< RawDatabase > db)
 Prepares the database to work with the history. More...
 
 ~History ()
 
bool isValid ()
 Checks if the database was opened successfully. More...
 
bool historyExists (const ToxPk &friendPk)
 Checks if a friend has chat history. More...
 
void eraseHistory ()
 Erases all the chat history from the database. More...
 
void removeFriendHistory (const ToxPk &friendPk)
 Erases the chat history with one friend. More...
 
void addNewMessage (const ToxPk &friendPk, const QString &message, const ToxPk &sender, const QDateTime &time, bool isDelivered, ExtensionSet extensions, QString dispName, const std::function< void(RowId)> &insertIdCallback={})
 Saves a chat message in the database. More...
 
void addNewFileMessage (const ToxPk &friendPk, const QString &fileId, const QString &fileName, const QString &filePath, int64_t size, const ToxPk &sender, const QDateTime &time, QString const &dispName)
 
void addNewSystemMessage (const ToxPk &friendPk, const SystemMessage &systemMessage)
 
void setFileFinished (const QString &fileId, bool success, const QString &filePath, const QByteArray &fileHash)
 
size_t getNumMessagesForFriend (const ToxPk &friendPk)
 
size_t getNumMessagesForFriendBeforeDate (const ToxPk &friendPk, const QDateTime &date)
 
QList< HistMessagegetMessagesForFriend (const ToxPk &friendPk, size_t firstIdx, size_t lastIdx)
 
QList< HistMessagegetUndeliveredMessagesForFriend (const ToxPk &friendPk)
 
QDateTime getDateWhereFindPhrase (const ToxPk &friendPk, const QDateTime &from, QString phrase, const ParameterSearch &parameter)
 Search phrase in chat messages. More...
 
QList< DateIdxgetNumMessagesForFriendBeforeDateBoundaries (const ToxPk &friendPk, const QDate &from, size_t maxNum)
 Gets date boundaries in conversation with friendPk. History doesn't model conversation indexes, but we can count messages between us and friendPk to effectively give us an index. This function returns how many messages have happened between us <-> friendPk each time the date changes. More...
 
void markAsDelivered (RowId messageId)
 Marks a message as delivered. Removing message from the faux-offline pending messages list. More...
 
void markAsBroken (RowId messageId, BrokenMessageReason reason)
 

Private Slots

void onFileInserted (RowId dbId, QString fileId)
 

Private Member Functions

QVector< RawDatabase::QuerygenerateNewFileTransferQueries (const ToxPk &friendPk, const ToxPk &sender, const QDateTime &time, const QString &dispName, const FileDbInsertionData &insertionData)
 
bool historyAccessBlocked ()
 Determines if history access should be blocked. More...
 
int64_t getPeerId (ToxPk const &pk)
 

Static Private Member Functions

static RawDatabase::Query generateFileFinished (RowId fileId, bool success, const QString &filePath, const QByteArray &fileHash)
 

Private Attributes

std::shared_ptr< RawDatabasedb
 
QHash< QString, FileInfofileInfos
 

Detailed Description

Interacts with the profile database to save the chat history.

Definition at line 135 of file history.h.

Constructor & Destructor Documentation

◆ History()

History::History ( std::shared_ptr< RawDatabase db_)
explicit

Prepares the database to work with the history.

Parameters
dbThis database will be prepared for use with the history.

Definition at line 710 of file history.cpp.

Here is the call graph for this function:

◆ ~History()

History::~History ( )

Definition at line 734 of file history.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ addNewFileMessage()

void History::addNewFileMessage ( const ToxPk friendPk,
const QString &  fileId,
const QString &  fileName,
const QString &  filePath,
int64_t  size,
const ToxPk sender,
const QDateTime &  time,
QString const &  dispName 
)

Definition at line 915 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNewMessage()

void History::addNewMessage ( const ToxPk friendPk,
const QString &  message,
const ToxPk sender,
const QDateTime &  time,
bool  isDelivered,
ExtensionSet  extensionSet,
QString  dispName,
const std::function< void(RowId)> &  insertIdCallback = {} 
)

Saves a chat message in the database.

Parameters
friendPkFriend publick key to save.
messageMessage to save.
senderSender to save.
timeTime of message sending.
isDeliveredTrue if message was already delivered.
dispNameName, which should be displayed.
insertIdCallbackFunction, called after query execution.

Definition at line 977 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNewSystemMessage()

void History::addNewSystemMessage ( const ToxPk friendPk,
const SystemMessage systemMessage 
)

Definition at line 957 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseHistory()

void History::eraseHistory ( )

Erases all the chat history from the database.

Definition at line 771 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileInserted

void History::fileInserted ( RowId  dbId,
QString  fileId 
)
signal
Here is the caller graph for this function:

◆ generateFileFinished()

RawDatabase::Query History::generateFileFinished ( RowId  fileId,
bool  success,
const QString &  filePath,
const QByteArray &  fileHash 
)
staticprivate

Definition at line 895 of file history.cpp.

Here is the caller graph for this function:

◆ generateNewFileTransferQueries()

QVector< RawDatabase::Query > History::generateNewFileTransferQueries ( const ToxPk friendPk,
const ToxPk sender,
const QDateTime &  time,
const QString &  dispName,
const FileDbInsertionData insertionData 
)
private

Definition at line 847 of file history.cpp.

Here is the caller graph for this function:

◆ getDateWhereFindPhrase()

QDateTime History::getDateWhereFindPhrase ( const ToxPk friendPk,
const QDateTime &  from,
QString  phrase,
const ParameterSearch parameter 
)

Search phrase in chat messages.

Parameters
friendPkFriend public key
froma date message where need to start a search
phrasewhat need to find
parameterfor search
Returns
date of the message where the phrase was found

Definition at line 1211 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMessagesForFriend()

QList< History::HistMessage > History::getMessagesForFriend ( const ToxPk friendPk,
size_t  firstIdx,
size_t  lastIdx 
)

Definition at line 1046 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumMessagesForFriend()

size_t History::getNumMessagesForFriend ( const ToxPk friendPk)

Definition at line 1009 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumMessagesForFriendBeforeDate()

size_t History::getNumMessagesForFriendBeforeDate ( const ToxPk friendPk,
const QDateTime &  date 
)

Definition at line 1018 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumMessagesForFriendBeforeDateBoundaries()

QList< History::DateIdx > History::getNumMessagesForFriendBeforeDateBoundaries ( const ToxPk friendPk,
const QDate &  from,
size_t  maxNum 
)

Gets date boundaries in conversation with friendPk. History doesn't model conversation indexes, but we can count messages between us and friendPk to effectively give us an index. This function returns how many messages have happened between us <-> friendPk each time the date changes.

Parameters
[in]friendPkToxPk of conversation to retrieve
[in]fromStart date to look from
[in]maxNumMaximum number of date boundaries to retrieve
Note
This API may seem a little strange, why not use QDate from and QDate to? The intent is to have an API that can be used to get the first item after a date (for search) and to get a list of date changes (for loadHistory). We could write two separate queries but the query is fairly intricate compared to our other ones so reducing duplication of it is preferable.

Definition at line 1313 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPeerId()

int64_t History::getPeerId ( ToxPk const &  pk)
private

◆ getUndeliveredMessagesForFriend()

QList< History::HistMessage > History::getUndeliveredMessagesForFriend ( const ToxPk friendPk)

Definition at line 1158 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ historyAccessBlocked()

bool History::historyAccessBlocked ( )
private

Determines if history access should be blocked.

Returns
True if history should not be accessed

Definition at line 1387 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ historyExists()

bool History::historyExists ( const ToxPk friendPk)

Checks if a friend has chat history.

Parameters
friendPk
Returns
True if has, false otherwise.

Definition at line 759 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValid()

bool History::isValid ( )

Checks if the database was opened successfully.

Returns
True if database if opened, false otherwise.

Definition at line 749 of file history.cpp.

Here is the caller graph for this function:

◆ markAsBroken()

void History::markAsBroken ( RowId  messageId,
BrokenMessageReason  reason 
)

Definition at line 1402 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markAsDelivered()

void History::markAsDelivered ( RowId  messageId)

Marks a message as delivered. Removing message from the faux-offline pending messages list.

Parameters
idMessage ID.

Definition at line 1374 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onFileInserted

void History::onFileInserted ( RowId  dbId,
QString  fileId 
)
privateslot

Definition at line 833 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeFriendHistory()

void History::removeFriendHistory ( const ToxPk friendPk)

Erases the chat history with one friend.

Parameters
friendPkFriend public key to erase.

Definition at line 792 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFileFinished()

void History::setFileFinished ( const QString &  fileId,
bool  success,
const QString &  filePath,
const QByteArray &  fileHash 
)

Definition at line 989 of file history.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ db

std::shared_ptr<RawDatabase> History::db
private

Definition at line 237 of file history.h.

◆ fileInfos

QHash<QString, FileInfo> History::fileInfos
private

Definition at line 250 of file history.h.


The documentation for this class was generated from the following files: