33using namespace sqlite ;
44using namespace std ;
55
6- CriptextDB::SessionRecord CriptextDB::getSessionRecord (database db, string recipientId, long int deviceId) {
6+ CriptextDB::SessionRecord CriptextDB::getSessionRecord (database db, int accountId, string recipientId, long int deviceId) {
77 string myRecord;
88 int myLen = 0 ;
9- db << " Select * from sessionrecord where recipientId == ? and deviceId == ?;"
9+ db << " Select * from sessionrecord where recipientId == ? and deviceId == ? and accountId == ? ;"
1010 << recipientId
1111 << deviceId
12- >> [&] (string recipientId, int deviceId, string record, int recordLength) {
12+ << accountId
13+ >> [&] (int id, string recipientId, int deviceId, string record, int recordLength) {
1314 myLen = recordLength;
1415 myRecord = record;
1516 };
@@ -26,13 +27,14 @@ CriptextDB::SessionRecord CriptextDB::getSessionRecord(database db, string recip
2627 return sessionRecord;
2728}
2829
29- vector<CriptextDB::SessionRecord> CriptextDB::getSessionRecords (database db, string recipientId) {
30+ vector<CriptextDB::SessionRecord> CriptextDB::getSessionRecords (database db, int accountId, string recipientId) {
3031 vector<CriptextDB::SessionRecord> sessionRecords;
3132
3233 try {
33- db << " Select * from sessionrecord where recipientId == ?;"
34+ db << " Select * from sessionrecord where recipientId == ? and accountId == ? ;"
3435 << recipientId
35- >> [&] (string recipientId, int deviceId, string record, int recordLength) {
36+ << accountId
37+ >> [&] (int id, string recipientId, int deviceId, string record, int recordLength) {
3638 SessionRecord mySessionRecord = {
3739 .recipientId = recipientId,
3840 .deviceId = deviceId,
@@ -49,28 +51,31 @@ vector<CriptextDB::SessionRecord> CriptextDB::getSessionRecords(database db, str
4951 return sessionRecords;
5052}
5153
52- bool CriptextDB::createSessionRecord (database db, string recipientId, long int deviceId, char * record, size_t len) {
54+ bool CriptextDB::createSessionRecord (database db, int accountId, string recipientId, long int deviceId, char * record, size_t len) {
5355 try {
5456 bool hasRow = false ;
5557 db << " begin;" ;
56- db << " Select * from sessionrecord where recipientId == ? and deviceId == ?;"
58+ db << " Select * from sessionrecord where recipientId == ? and deviceId == ? and accountId == ? ;"
5759 << recipientId
5860 << deviceId
61+ << accountId
5962 >> [&] (string recipientId, int deviceId, string record, int recordLength) {
6063 hasRow = true ;
6164 };
6265 if (hasRow) {
63- db << " update sessionrecord set record = ?, recordLength = ? where recipientId == ? and deviceId == ?;"
66+ db << " update sessionrecord set record = ?, recordLength = ? where recipientId == ? and deviceId == ? and accountId == ? ;"
6467 << record
6568 << static_cast <int >(len)
6669 << recipientId
67- << deviceId;
70+ << deviceId
71+ << accountId;
6872 } else {
69- db << " insert into sessionrecord (recipientId, deviceId, record, recordLength) values (?,?,?,?);"
73+ db << " insert into sessionrecord (recipientId, deviceId, record, recordLength, accountId ) values (?, ?,?,?,?);"
7074 << recipientId
7175 << deviceId
7276 << record
73- << static_cast <int >(len);
77+ << static_cast <int >(len)
78+ << accountId;
7479 }
7580 db << " commit;" ;
7681 } catch (exception& e) {
@@ -80,22 +85,24 @@ bool CriptextDB::createSessionRecord(database db, string recipientId, long int d
8085 return true ;
8186}
8287
83- bool CriptextDB::deleteSessionRecord (database db, string recipientId, long int deviceId) {
88+ bool CriptextDB::deleteSessionRecord (database db, int accountId, string recipientId, long int deviceId) {
8489 try {
85- db << " delete from sessionrecord where recipientId == ? and deviceId == ?;"
90+ db << " delete from sessionrecord where recipientId == ? and deviceId == ? and accountId ;"
8691 << recipientId
87- << deviceId;
92+ << deviceId
93+ << accountId;
8894 } catch (exception& e) {
8995 std::cout << " Error deleting session : " << e.what () << std::endl;
9096 return false ;
9197 }
9298 return true ;
9399}
94100
95- bool CriptextDB::deleteSessionRecords (database db, string recipientId) {
101+ bool CriptextDB::deleteSessionRecords (database db, int accountId, string recipientId) {
96102 try {
97- db << " delete from sessionrecord where recipientId == ?;"
98- << recipientId;
103+ db << " delete from sessionrecord where recipientId == ? and accountId == ?;"
104+ << recipientId
105+ << accountId;
99106 } catch (exception& e) {
100107 std::cout << " Error deleting sessions : " << e.what () << std::endl;
101108 return false ;
0 commit comments