@@ -1025,7 +1025,6 @@ QHash<QString, QStringList> DatabaseQueries::bagsOfMessages(const QSqlDatabase&
1025
1025
QPair<int , int > DatabaseQueries::updateMessages (QSqlDatabase db,
1026
1026
const QList<Message>& messages,
1027
1027
Feed* feed,
1028
- const QString& url,
1029
1028
bool force_update,
1030
1029
bool * ok) {
1031
1030
if (messages.isEmpty ()) {
@@ -1053,6 +1052,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1053
1052
// 2) they have same URL AND,
1054
1053
// 3) they have same AUTHOR AND,
1055
1054
// 4) they have same TITLE.
1055
+ // NOTE: This only applies to messages from standard RSS/ATOM/JSON feeds without ID/GUID.
1056
1056
query_select_with_url.setForwardOnly (true );
1057
1057
query_select_with_url.prepare (" SELECT id, date_created, is_read, is_important, contents, feed FROM Messages "
1058
1058
" WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;" );
@@ -1096,18 +1096,16 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1096
1096
for (Message message : messages) {
1097
1097
// Check if messages contain relative URLs and if they do, then replace them.
1098
1098
if (message.m_url .startsWith (QL1S (" //" ))) {
1099
- // TODO: This probably should be replace with HTTPS or taken scheme from feed's URL?
1100
- message.m_url = QString (URI_SCHEME_HTTP) + message.m_url .mid (2 );
1099
+ message.m_url = QString (URI_SCHEME_HTTPS) + message.m_url .mid (2 );
1101
1100
}
1102
- else if (message.m_url .startsWith (QL1S (" /" ))) {
1103
- QString new_message_url = QUrl (url).toString (QUrl::UrlFormattingOption::RemoveUserInfo |
1104
- QUrl::UrlFormattingOption::RemovePath |
1105
- QUrl::UrlFormattingOption::RemoveQuery |
1106
- QUrl::UrlFormattingOption::RemoveFilename |
1107
- QUrl::UrlFormattingOption::StripTrailingSlash);
1101
+ else if (QUrl (message.m_url ).isRelative ()) {
1102
+ QUrl base (feed->source ());
1108
1103
1109
- new_message_url += message.m_url ;
1110
- message.m_url = new_message_url;
1104
+ if (base.isValid ()) {
1105
+ base = QUrl (base.scheme () + QSL (" ://" ) + base.host ());
1106
+
1107
+ message.m_url = base.resolved (message.m_url ).toString ();
1108
+ }
1111
1109
}
1112
1110
1113
1111
int id_existing_message = -1 ;
@@ -1120,7 +1118,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1120
1118
1121
1119
if (message.m_id > 0 ) {
1122
1120
// We recognize directly existing message.
1123
- // NOTE: Particular for manual message filter execution.
1121
+ // NOTE: Particularly for manual message filter execution.
1124
1122
query_select_with_id.bindValue (QSL (" :id" ), message.m_id );
1125
1123
query_select_with_id.bindValue (QSL (" :account_id" ), account_id);
1126
1124
@@ -1139,15 +1137,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1139
1137
title_existing_message = query_select_with_id.value (5 ).toString ();
1140
1138
1141
1139
qDebugNN << LOGSEC_DB
1142
- << " Message with these attributes is already present in DB and has DB ID '"
1143
- << id_existing_message
1144
- << " '." ;
1140
+ << " Message with direct DB ID is already present in DB and has DB ID"
1141
+ << QUOTE_W_SPACE_DOT (id_existing_message);
1145
1142
}
1146
1143
else if (query_select_with_id.lastError ().isValid ()) {
1147
1144
qWarningNN << LOGSEC_DB
1148
- << " Failed to check for existing message in DB via primary ID: '"
1149
- << query_select_with_id.lastError ().text ()
1150
- << " '." ;
1145
+ << " Failed to check for existing message in DB via primary ID:"
1146
+ << QUOTE_W_SPACE_DOT (query_select_with_id.lastError ().text ());
1151
1147
}
1152
1148
1153
1149
query_select_with_id.finish ();
@@ -1181,15 +1177,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1181
1177
title_existing_message = unnulifyString (message.m_title );
1182
1178
1183
1179
qDebugNN << LOGSEC_DB
1184
- << " Message with these attributes is already present in DB and has DB ID '"
1185
- << id_existing_message
1186
- << " '." ;
1180
+ << " Message with these attributes is already present in DB and has DB ID"
1181
+ << QUOTE_W_SPACE_DOT (id_existing_message);
1187
1182
}
1188
1183
else if (query_select_with_url.lastError ().isValid ()) {
1189
1184
qWarningNN << LOGSEC_DB
1190
- << " Failed to check for existing message in DB via URL: '"
1191
- << query_select_with_url.lastError ().text ()
1192
- << " '." ;
1185
+ << " Failed to check for existing message in DB via URL/TITLE/AUTHOR:"
1186
+ << QUOTE_W_SPACE_DOT (query_select_with_url.lastError ().text ());
1193
1187
}
1194
1188
1195
1189
query_select_with_url.finish ();
@@ -1203,9 +1197,9 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1203
1197
query_select_with_custom_id.bindValue (QSL (" :custom_id" ), unnulifyString (message.m_customId ));
1204
1198
1205
1199
qDebugNN << LOGSEC_DB
1206
- << " Checking if message with custom ID ' "
1207
- << message.m_customId
1208
- << " ' is present in DB." ;
1200
+ << " Checking if message with service-specific custom ID"
1201
+ << QUOTE_W_SPACE ( message.m_customId )
1202
+ << " is present in DB." ;
1209
1203
1210
1204
if (query_select_with_custom_id.exec () && query_select_with_custom_id.next ()) {
1211
1205
id_existing_message = query_select_with_custom_id.value (0 ).toInt ();
@@ -1225,9 +1219,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1225
1219
}
1226
1220
else if (query_select_with_custom_id.lastError ().isValid ()) {
1227
1221
qWarningNN << LOGSEC_DB
1228
- << " Failed to check for existing message in DB via ID: '"
1229
- << query_select_with_custom_id.lastError ().text ()
1230
- << " '." ;
1222
+ << " Failed to check for existing message in DB via ID:"
1223
+ << QUOTE_W_SPACE_DOT (query_select_with_custom_id.lastError ().text ());
1231
1224
}
1232
1225
1233
1226
query_select_with_custom_id.finish ();
@@ -1240,9 +1233,9 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1240
1233
query_select_with_custom_id_for_feed.bindValue (QSL (" :custom_id" ), unnulifyString (message.m_customId ));
1241
1234
1242
1235
qDebugNN << LOGSEC_DB
1243
- << " Checking if message with custom ID ' "
1244
- << message.m_customId
1245
- << " ' is present in DB." ;
1236
+ << " Checking if message with feed-specific custom ID"
1237
+ << QUOTE_W_SPACE ( message.m_customId )
1238
+ << " is present in DB." ;
1246
1239
1247
1240
if (query_select_with_custom_id_for_feed.exec () && query_select_with_custom_id_for_feed.next ()) {
1248
1241
id_existing_message = query_select_with_custom_id_for_feed.value (0 ).toInt ();
@@ -1256,15 +1249,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1256
1249
qDebugNN << LOGSEC_DB
1257
1250
<< " Message with custom ID"
1258
1251
<< QUOTE_W_SPACE (message.m_customId )
1259
- << " is already present in DB and has DB ID '"
1260
- << id_existing_message
1261
- << " '." ;
1252
+ << " is already present in DB and has DB ID"
1253
+ << QUOTE_W_SPACE_DOT (id_existing_message);
1262
1254
}
1263
1255
else if (query_select_with_custom_id_for_feed.lastError ().isValid ()) {
1264
1256
qWarningNN << LOGSEC_DB
1265
- << " Failed to check for existing message in DB via ID: '"
1266
- << query_select_with_custom_id_for_feed.lastError ().text ()
1267
- << " '." ;
1257
+ << " Failed to check for existing message in DB via ID:"
1258
+ << QUOTE_W_SPACE_DOT (query_select_with_custom_id_for_feed.lastError ().text ());
1268
1259
}
1269
1260
1270
1261
query_select_with_custom_id_for_feed.finish ();
@@ -1282,7 +1273,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1282
1273
// 2) FOR NON-SYNCHRONIZED SERVICES (RSS/ATOM/JSON): Message has custom ID/GUID and its title or contents are changed.
1283
1274
//
1284
1275
// 3) FOR ALL SERVICES: Message has its date fetched from feed AND its date is different
1285
- // from date in DB and contents is changed.
1276
+ // from date in DB or content is changed.
1286
1277
//
1287
1278
// 4) FOR ALL SERVICES: Message update is forced, we want to overwrite message as some arbitrary atribute was changed,
1288
1279
// this particularly happens when manual message filter execution happens.
@@ -1302,7 +1293,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1302
1293
message.m_contents != contents_existing_message) ||
1303
1294
1304
1295
/* 4 */ force_update) {
1305
- // Message exists, it is changed, update it.
1296
+ // Message exists and is changed, update it.
1306
1297
query_update.bindValue (QSL (" :title" ), unnulifyString (message.m_title ));
1307
1298
query_update.bindValue (QSL (" :is_read" ), int (message.m_isRead ));
1308
1299
query_update.bindValue (QSL (" :is_important" ), int (message.m_isImportant ));
@@ -1312,13 +1303,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1312
1303
query_update.bindValue (QSL (" :date_created" ), message.m_created .toMSecsSinceEpoch ());
1313
1304
query_update.bindValue (QSL (" :contents" ), unnulifyString (message.m_contents ));
1314
1305
query_update.bindValue (QSL (" :enclosures" ), Enclosures::encodeEnclosuresToString (message.m_enclosures ));
1315
- query_update.bindValue (QSL (" :feed" ), feed_id_existing_message );
1306
+ query_update.bindValue (QSL (" :feed" ), message. m_feedId );
1316
1307
query_update.bindValue (QSL (" :score" ), message.m_score );
1317
1308
query_update.bindValue (QSL (" :id" ), id_existing_message);
1318
1309
1319
1310
if (query_update.exec ()) {
1320
1311
qDebugNN << LOGSEC_DB
1321
- << " Updating message with title"
1312
+ << " Overwriting message with title"
1322
1313
<< QUOTE_W_SPACE (message.m_title )
1323
1314
<< " URL"
1324
1315
<< QUOTE_W_SPACE (message.m_url )
@@ -1332,7 +1323,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1332
1323
}
1333
1324
else if (query_update.lastError ().isValid ()) {
1334
1325
qWarningNN << LOGSEC_DB
1335
- << " Failed to update message in DB: '" << query_update.lastError ().text () << " '." ;
1326
+ << " Failed to update message in DB:"
1327
+ << QUOTE_W_SPACE_DOT (query_update.lastError ().text ());
1336
1328
}
1337
1329
1338
1330
query_update.finish ();
@@ -1375,7 +1367,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1375
1367
}
1376
1368
else if (query_insert.lastError ().isValid ()) {
1377
1369
qWarningNN << LOGSEC_DB
1378
- << " Failed to insert message to DB:"
1370
+ << " Failed to insert new message to DB:"
1379
1371
<< QUOTE_W_SPACE (query_insert.lastError ().text ())
1380
1372
<< " - message title is"
1381
1373
<< QUOTE_W_SPACE_DOT (message.m_title );
@@ -1410,9 +1402,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
1410
1402
" SET custom_id = id "
1411
1403
" WHERE custom_id IS NULL OR custom_id = '';" ).lastError ().isValid ()) {
1412
1404
qWarningNN << LOGSEC_DB
1413
- << " Failed to set custom ID for all messages: '"
1414
- << db.lastError ().text ()
1415
- << " '." ;
1405
+ << " Failed to set custom ID for all messages:"
1406
+ << QUOTE_W_SPACE_DOT (db.lastError ().text ());
1416
1407
}
1417
1408
1418
1409
if (use_transactions && !db.commit ()) {
0 commit comments