about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-03-27 19:09:29 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-04-06 10:50:20 +0200
commit9278ba775b91eedef1b5ce1662681377205ff7b8 (patch)
tree5d59e9ea1bfbaf538099279b960dbcf18dcf3c39 /src
parentfe67102e716f4b1c7208c2b149a0b7be5a6d5a36 (diff)
downloadprofani-tty-9278ba775b91eedef1b5ce1662681377205ff7b8.tar.gz
db: add more needed fields
DB fields should be complete now.
Diffstat (limited to 'src')
-rw-r--r--src/database.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/database.c b/src/database.c
index a2be7f40..2f363baf 100644
--- a/src/database.c
+++ b/src/database.c
@@ -81,10 +81,10 @@ gboolean
 log_database_init(ProfAccount *account)
 {
     int ret = sqlite3_initialize();
-	if (ret != SQLITE_OK) {
+    if (ret != SQLITE_OK) {
         log_error("Error initializing SQLite database: %d", ret);
         return FALSE;
-	}
+    }
 
     char *filename = _get_db_filename(account);
     if (!filename) {
@@ -100,17 +100,30 @@ log_database_init(ProfAccount *account)
     }
 
     char *err_msg;
-	char *query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `jid` TEXT NOT NULL, `resource` TEXT, `message` TEXT, `timestamp` TEXT, `is_muc` INTEGER, `stanza_id` TEXT, `replace_id` TEXT)";
+    // id is the ID of DB the entry
+    // from_jid is the senders jid
+    // to_jid is the receivers jid
+    // from_resource is the senders resource
+    // to_jid is the receivers resource
+    // message is the message text
+    // timestamp the timestamp like "2020/03/24 11:12:14"
+    // type is there to distinguish: message, MUC message, muc pm
+    // stanza_id is the ID from XEP-0359: Unique and Stable Stanza IDs
+    // archive_id is the ID from XEP-0313: Message Archive Management
+    // replace_id is the ID from XEP-0308: Last Message Correction
+    // encryption is to distinguish: none, omemo, otr, pgp
+    // marked_read is 0/1 whether a message has been marked as read via XEP-0333: Chat Markers
+    char *query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `from_jid` TEXT NOT NULL, `to_jid` TEXT NOT NULL, `from_resource` TEXT, `to_resource` TEXT, `message` TEXT, `timestamp` TEXT, `type` TEXT, `stanza_id` TEXT, `archive_id` TEXT, `replace_id` TEXT, `encryption` TEXT, `marked_read` INTEGER)";
     if( SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
         goto out;
     }
 
-	query = "CREATE TABLE IF NOT EXISTS `DbVersion` ( `dv_id` INTEGER PRIMARY KEY, `version` INTEGER UNIQUE)";
+    query = "CREATE TABLE IF NOT EXISTS `DbVersion` ( `dv_id` INTEGER PRIMARY KEY, `version` INTEGER UNIQUE)";
     if( SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
         goto out;
     }
 
-	query = "INSERT OR IGNORE INTO `DbVersion` (`version`) VALUES('1')";
+    query = "INSERT OR IGNORE INTO `DbVersion` (`version`) VALUES('1')";
     if( SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
         goto out;
     }
@@ -148,11 +161,11 @@ log_database_add(ProfMessage *message, gboolean is_muc) {
     }
 
     char *err_msg;
-	char *query;
+    char *query;
 
     //gchar *date_fmt = g_date_time_format_iso8601(message->timestamp);
     gchar *date_fmt = g_date_time_format(message->timestamp, "%Y/%m/%d %H:%M:%S");
-    if (asprintf(&query, "INSERT INTO `ChatLogs` (`jid`, `resource`, `message`, `timestamp`, `is_muc`, `stanza_id`, `replace_id`) VALUES ('%s', '%s', '%s', '%s', '%d', '%s', '%s')",
+    if (asprintf(&query, "INSERT INTO `ChatLogs` (`jid`, `resource`, `message`, `timestamp`, `stanza_id`, `replace_id`) VALUES ('%s', '%s', '%s', '%d', '%s', '%s')",
                 message->jid->barejid, message->jid->resourcepart, message->plain, date_fmt, is_muc, message->id ? message->id : "", message->replace_id ? message->replace_id : "") == -1) {
         log_error("log_database_add(): could not allocate memory");
         return;
5' href='#n245'>245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403