@@ -441,7 +441,7 @@ Json::Value sql_find_my_msg(std::string me, std::string connect_type)
441
441
// =================== find begin
442
442
// SELECT * FROM chat WHERE (sender = 'lglglglgy' OR receiver = 'lglglglgy') AND isread = 0
443
443
std::string sqlFind_new_connect = " SELECT * FROM chat WHERE sender = ? OR receiver = ?" ;
444
- std::string sqlFind_isread_is_zero = " SELECT * FROM chat WHERE (sender = ? OR receiver = ? ) AND isread = 0" ;
444
+ std::string sqlFind_isread_is_zero = " SELECT * FROM chat WHERE (sender = ? AND sender_isread = 0 ) OR ( receiver = ? AND receiver_isread = 0 ) " ;
445
445
if (connect_type == " all" )
446
446
{
447
447
prepStmt = con->prepareStatement (sqlFind_new_connect);
@@ -461,9 +461,9 @@ Json::Value sql_find_my_msg(std::string me, std::string connect_type)
461
461
sql::ResultSet *res = prepStmt->executeQuery ();
462
462
463
463
// =================== find end and update begin
464
-
465
- std::string sql0To1 = " UPDATE chat SET isread = 1 WHERE id = ?" ;
466
- int id;
464
+ std::string sql0To1_sender = " UPDATE chat SET sender_isread = 1 WHERE id = ? " ;
465
+ std::string sql0To1_rec = " UPDATE chat SET receiver_isread = 1 WHERE id = ?" ;
466
+
467
467
468
468
// =================== update end
469
469
Json::Value result;
@@ -476,11 +476,21 @@ Json::Value sql_find_my_msg(std::string me, std::string connect_type)
476
476
// update isread to 1
477
477
if (connect_type == " new" )
478
478
{
479
- id = res->getInt (" id" );
480
- sql::PreparedStatement *updateStmt = con->prepareStatement (sql0To1);
481
- updateStmt->setInt (1 , id);
482
- updateStmt->executeUpdate ();
483
- delete updateStmt;
479
+ int id = res->getInt (" id" );
480
+ if (res->getString (" sender" )==me)
481
+ {
482
+ sql::PreparedStatement *updateStmt = con->prepareStatement (sql0To1_sender);
483
+ updateStmt->setInt (1 , id);
484
+ updateStmt->executeUpdate ();
485
+ delete updateStmt;
486
+ }
487
+ else
488
+ {
489
+ sql::PreparedStatement *updateStmt = con->prepareStatement (sql0To1_rec);
490
+ updateStmt->setInt (1 , id);
491
+ updateStmt->executeUpdate ();
492
+ delete updateStmt;
493
+ }
484
494
// std::cout <<"change"<<std::endl;
485
495
}
486
496
0 commit comments