summaryrefslogtreecommitdiffstats
path: root/pica-client/history.h
blob: ebf6dbd6b3e079491bcc44956dcc6752a27e51a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef HISTORY_H
#define HISTORY_H

#include <QString>
#include <QtSql>
#include <QSqlDatabase>
#include <QList>
#include <QMap>

class History
{
public:
    struct HistoryRecord
    {
        quint32 peer_id;
        bool is_me;
        bool is_delivered;
        quint32 timestamp;
        QString message;
    };

    History(QString storage, quint32 my_id);
    void Add(quint32 peer_id, QString message, bool is_me);//is_me - true - message from me to peer, false - from peer to me
    void SetDelivered(quint32 peer_id); //mark first undelivered message from me to peer as delivered
    QList<HistoryRecord> GetMessages(quint32 peer_id, quint32 start_timestamp, quint32 end_timestamp);
    QMap<quint32, QList<QString> > GetUndeliveredMessages();
    bool isOK();
    QString GetLastError();

private:
    QSqlDatabase dbconn;
    QSqlError lasterr;

    quint32 me_;
};

#endif // HISTORY_H