Fossil SCM

Improved timeline messages for forum events.

drh 2018-07-25 19:00 forum-v2
Commit e9b13d68a7c9411a8e1fb81db3ff9797f06c605e0bfc1a6f33207d8ee06baf64
2 files changed +19 -10 +48 -19
+19 -10
--- src/forum.c
+++ src/forum.c
@@ -27,19 +27,27 @@
2727
void forum_render(
2828
const char *zTitle,
2929
const char *zMimetype,
3030
const char *zContent
3131
){
32
- Blob x;
3332
@ <div style='border: 1px solid black;padding: 1ex;'>
3433
if( zTitle ){
35
- @ <h1>%h(zTitle)</h1>
34
+ if( zTitle[0] ){
35
+ @ <h1>%h(zTitle)</h1>
36
+ }else{
37
+ @ <h1><i>Deleted</i></h1>
38
+ }
3639
}
37
- blob_init(&x, 0, 0);
38
- blob_append(&x, zContent, -1);
39
- wiki_render_by_mimetype(&x, zMimetype);
40
- blob_reset(&x);
40
+ if( zContent && zContent[0] ){
41
+ Blob x;
42
+ blob_init(&x, 0, 0);
43
+ blob_append(&x, zContent, -1);
44
+ wiki_render_by_mimetype(&x, zMimetype);
45
+ blob_reset(&x);
46
+ }else{
47
+ @ <i>Deleted</i>
48
+ }
4149
@ </div>
4250
}
4351
4452
/*
4553
** Display all posts in a forum thread in chronological order
@@ -368,12 +376,13 @@
368376
}
369377
if( done ) return;
370378
}
371379
if( isDelete ){
372380
zMimetype = "text/x-fossil-wiki";
373
- zContent = "<i>Deleted</i>";
374
- if( pPost->zThreadTitle ) zTitle = "<i>Deleted</i>";
381
+ zContent = "";
382
+ if( pPost->zThreadTitle ) zTitle = "";
383
+ style_header("Delete %s", zTitle ? "Post" : "Reply");
375384
@ <h1>Original Post:</h1>
376385
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
377386
@ <h1>Change Into:</h1>
378387
forum_render(zTitle, zMimetype, zContent);
379388
@ <form action="%R/forumedit" method="POST">
@@ -392,11 +401,11 @@
392401
if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki);
393402
if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype);
394403
if( zTitle==0 && pPost->zThreadTitle!=0 ){
395404
zTitle = fossil_strdup(pPost->zThreadTitle);
396405
}
397
- style_header("Edit Forum Post");
406
+ style_header("Edit %s", zTitle ? "Post" : "Reply");
398407
@ <h1>Original Post:</h1>
399408
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
400409
if( P("preview") ){
401410
@ <h1>Preview Of Editted Post:</h1>
402411
forum_render(zTitle, zMimetype, zContent);
@@ -408,11 +417,11 @@
408417
forum_entry_widget(zTitle, zMimetype, zContent);
409418
}else{
410419
/* Reply */
411420
zMimetype = PD("mimetype","text/x-fossil-wiki");
412421
zContent = PDT("content","");
413
- style_header("Forum Reply");
422
+ style_header("Reply");
414423
@ <h1>Replying To:</h1>
415424
forum_render(0, pPost->zMimetype, pPost->zWiki);
416425
if( P("preview") ){
417426
@ <h1>Preview:</h1>
418427
forum_render(0, zMimetype,zContent);
419428
--- src/forum.c
+++ src/forum.c
@@ -27,19 +27,27 @@
27 void forum_render(
28 const char *zTitle,
29 const char *zMimetype,
30 const char *zContent
31 ){
32 Blob x;
33 @ <div style='border: 1px solid black;padding: 1ex;'>
34 if( zTitle ){
35 @ <h1>%h(zTitle)</h1>
 
 
 
 
36 }
37 blob_init(&x, 0, 0);
38 blob_append(&x, zContent, -1);
39 wiki_render_by_mimetype(&x, zMimetype);
40 blob_reset(&x);
 
 
 
 
 
41 @ </div>
42 }
43
44 /*
45 ** Display all posts in a forum thread in chronological order
@@ -368,12 +376,13 @@
368 }
369 if( done ) return;
370 }
371 if( isDelete ){
372 zMimetype = "text/x-fossil-wiki";
373 zContent = "<i>Deleted</i>";
374 if( pPost->zThreadTitle ) zTitle = "<i>Deleted</i>";
 
375 @ <h1>Original Post:</h1>
376 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
377 @ <h1>Change Into:</h1>
378 forum_render(zTitle, zMimetype, zContent);
379 @ <form action="%R/forumedit" method="POST">
@@ -392,11 +401,11 @@
392 if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki);
393 if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype);
394 if( zTitle==0 && pPost->zThreadTitle!=0 ){
395 zTitle = fossil_strdup(pPost->zThreadTitle);
396 }
397 style_header("Edit Forum Post");
398 @ <h1>Original Post:</h1>
399 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
400 if( P("preview") ){
401 @ <h1>Preview Of Editted Post:</h1>
402 forum_render(zTitle, zMimetype, zContent);
@@ -408,11 +417,11 @@
408 forum_entry_widget(zTitle, zMimetype, zContent);
409 }else{
410 /* Reply */
411 zMimetype = PD("mimetype","text/x-fossil-wiki");
412 zContent = PDT("content","");
413 style_header("Forum Reply");
414 @ <h1>Replying To:</h1>
415 forum_render(0, pPost->zMimetype, pPost->zWiki);
416 if( P("preview") ){
417 @ <h1>Preview:</h1>
418 forum_render(0, zMimetype,zContent);
419
--- src/forum.c
+++ src/forum.c
@@ -27,19 +27,27 @@
27 void forum_render(
28 const char *zTitle,
29 const char *zMimetype,
30 const char *zContent
31 ){
 
32 @ <div style='border: 1px solid black;padding: 1ex;'>
33 if( zTitle ){
34 if( zTitle[0] ){
35 @ <h1>%h(zTitle)</h1>
36 }else{
37 @ <h1><i>Deleted</i></h1>
38 }
39 }
40 if( zContent && zContent[0] ){
41 Blob x;
42 blob_init(&x, 0, 0);
43 blob_append(&x, zContent, -1);
44 wiki_render_by_mimetype(&x, zMimetype);
45 blob_reset(&x);
46 }else{
47 @ <i>Deleted</i>
48 }
49 @ </div>
50 }
51
52 /*
53 ** Display all posts in a forum thread in chronological order
@@ -368,12 +376,13 @@
376 }
377 if( done ) return;
378 }
379 if( isDelete ){
380 zMimetype = "text/x-fossil-wiki";
381 zContent = "";
382 if( pPost->zThreadTitle ) zTitle = "";
383 style_header("Delete %s", zTitle ? "Post" : "Reply");
384 @ <h1>Original Post:</h1>
385 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
386 @ <h1>Change Into:</h1>
387 forum_render(zTitle, zMimetype, zContent);
388 @ <form action="%R/forumedit" method="POST">
@@ -392,11 +401,11 @@
401 if( zContent==0 ) zContent = fossil_strdup(pPost->zWiki);
402 if( zMimetype==0 ) zMimetype = fossil_strdup(pPost->zMimetype);
403 if( zTitle==0 && pPost->zThreadTitle!=0 ){
404 zTitle = fossil_strdup(pPost->zThreadTitle);
405 }
406 style_header("Edit %s", zTitle ? "Post" : "Reply");
407 @ <h1>Original Post:</h1>
408 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki);
409 if( P("preview") ){
410 @ <h1>Preview Of Editted Post:</h1>
411 forum_render(zTitle, zMimetype, zContent);
@@ -408,11 +417,11 @@
417 forum_entry_widget(zTitle, zMimetype, zContent);
418 }else{
419 /* Reply */
420 zMimetype = PD("mimetype","text/x-fossil-wiki");
421 zContent = PDT("content","");
422 style_header("Reply");
423 @ <h1>Replying To:</h1>
424 forum_render(0, pPost->zMimetype, pPost->zWiki);
425 if( P("preview") ){
426 @ <h1>Preview:</h1>
427 forum_render(0, zMimetype,zContent);
428
+48 -19
--- src/manifest.c
+++ src/manifest.c
@@ -2465,38 +2465,67 @@
24652465
);
24662466
blob_reset(&comment);
24672467
}
24682468
if( p->type==CFTYPE_FORUM ){
24692469
int froot, fprev, firt;
2470
+ char *zFType;
2471
+ const char *zTitle;
24702472
schema_forum();
24712473
froot = p->zThreadRoot ? uuid_to_rid(p->zThreadRoot, 1) : rid;
24722474
fprev = p->nParent ? uuid_to_rid(p->azParent[0],1) : 0;
24732475
firt = p->zInReplyTo ? uuid_to_rid(p->zInReplyTo,1) : 0;
24742476
db_multi_exec(
24752477
"INSERT INTO forumpost(fpid,froot,fprev,firt,fmtime)"
24762478
"VALUES(%d,%d,nullif(%d,0),nullif(%d,0),%.17g)",
24772479
p->rid, froot, fprev, firt, p->rDate
24782480
);
2479
- if( froot!=p->rid ){
2480
- db_multi_exec(
2481
- "REPLACE INTO event(type,mtime,objid,user,comment)"
2482
- "VALUES('f',%.17g,%d,%Q,'Reply to:'||"
2483
- "coalesce(substr((SELECT comment FROM event"
2484
- " WHERE objid=%d),12),' post '||substr(%Q,1,14)))",
2485
- p->rDate, rid, p->zUser, froot, zUuid
2486
- );
2487
- }else{
2488
- db_multi_exec(
2489
- "REPLACE INTO event(type,mtime,objid,user,comment)"
2490
- "VALUES('f',%.17g,%d,%Q,'Forum post: %q')",
2491
- p->rDate, rid, p->zUser, p->zThreadTitle
2492
- );
2493
- db_multi_exec(
2494
- "UPDATE event SET comment='Reply to: %q' WHERE objid IN"
2495
- " (SELECT fpid FROM forumpost WHERE froot=%d AND fpid!=froot)",
2496
- p->zThreadTitle, rid
2497
- );
2481
+ if( firt==0 ){
2482
+ /* This is the start of a new thread, either the initial entry
2483
+ ** or an edit of the initial entry. */
2484
+ zTitle = p->zThreadTitle;
2485
+ if( zTitle==0 || zTitle[0]==0 ){
2486
+ zTitle = "<i>Deleted</i>";
2487
+ }
2488
+ zFType = fprev ? "Edit" : "Post";
2489
+ db_multi_exec(
2490
+ "REPLACE INTO event(type,mtime,objid,user,comment)"
2491
+ "VALUES('f',%.17g,%d,%Q,'%q: %q')",
2492
+ p->rDate, rid, p->zUser, zFType, zTitle
2493
+ );
2494
+ /*
2495
+ ** If this edit is the most recent, then make it the title for
2496
+ ** all other entries for the same thread
2497
+ */
2498
+ if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt=0"
2499
+ " AND fpid!=%d AND fmtime>%.17g", froot, rid, p->rDate)
2500
+ ){
2501
+ /* This entry establishes a new title for all entries on the thread */
2502
+ db_multi_exec(
2503
+ "UPDATE event"
2504
+ " SET comment=substr(comment,1,instr(comment,':')) || ' %q'"
2505
+ " WHERE objid IN (SELECT fpid FROM forumpost WHERE froot=%d)",
2506
+ zTitle, froot
2507
+ );
2508
+ }
2509
+ }else{
2510
+ /* This is a reply to a prior post. Take the title from the root. */
2511
+ zTitle = db_text(0, "SELECT substr(comment,instr(comment,':')+2)"
2512
+ " FROM event WHERE objid=%d", froot);
2513
+ if( zTitle==0 ) zTitle = fossil_strdup("<i>Unknown</i>");
2514
+ if( p->zWiki[0]==0 ){
2515
+ zFType = "Delete reply";
2516
+ }else if( fprev ){
2517
+ zFType = "Edit reply";
2518
+ }else{
2519
+ zFType = "Reply";
2520
+ }
2521
+ db_multi_exec(
2522
+ "REPLACE INTO event(type,mtime,objid,user,comment)"
2523
+ "VALUES('f',%.17g,%d,%Q,'%q: %q')",
2524
+ p->rDate, rid, p->zUser, zFType, zTitle
2525
+ );
2526
+ fossil_free(zTitle);
24982527
}
24992528
}
25002529
db_end_transaction(0);
25012530
if( permitHooks ){
25022531
rc = xfer_run_common_script();
25032532
--- src/manifest.c
+++ src/manifest.c
@@ -2465,38 +2465,67 @@
2465 );
2466 blob_reset(&comment);
2467 }
2468 if( p->type==CFTYPE_FORUM ){
2469 int froot, fprev, firt;
 
 
2470 schema_forum();
2471 froot = p->zThreadRoot ? uuid_to_rid(p->zThreadRoot, 1) : rid;
2472 fprev = p->nParent ? uuid_to_rid(p->azParent[0],1) : 0;
2473 firt = p->zInReplyTo ? uuid_to_rid(p->zInReplyTo,1) : 0;
2474 db_multi_exec(
2475 "INSERT INTO forumpost(fpid,froot,fprev,firt,fmtime)"
2476 "VALUES(%d,%d,nullif(%d,0),nullif(%d,0),%.17g)",
2477 p->rid, froot, fprev, firt, p->rDate
2478 );
2479 if( froot!=p->rid ){
2480 db_multi_exec(
2481 "REPLACE INTO event(type,mtime,objid,user,comment)"
2482 "VALUES('f',%.17g,%d,%Q,'Reply to:'||"
2483 "coalesce(substr((SELECT comment FROM event"
2484 " WHERE objid=%d),12),' post '||substr(%Q,1,14)))",
2485 p->rDate, rid, p->zUser, froot, zUuid
2486 );
2487 }else{
2488 db_multi_exec(
2489 "REPLACE INTO event(type,mtime,objid,user,comment)"
2490 "VALUES('f',%.17g,%d,%Q,'Forum post: %q')",
2491 p->rDate, rid, p->zUser, p->zThreadTitle
2492 );
2493 db_multi_exec(
2494 "UPDATE event SET comment='Reply to: %q' WHERE objid IN"
2495 " (SELECT fpid FROM forumpost WHERE froot=%d AND fpid!=froot)",
2496 p->zThreadTitle, rid
2497 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2498 }
2499 }
2500 db_end_transaction(0);
2501 if( permitHooks ){
2502 rc = xfer_run_common_script();
2503
--- src/manifest.c
+++ src/manifest.c
@@ -2465,38 +2465,67 @@
2465 );
2466 blob_reset(&comment);
2467 }
2468 if( p->type==CFTYPE_FORUM ){
2469 int froot, fprev, firt;
2470 char *zFType;
2471 const char *zTitle;
2472 schema_forum();
2473 froot = p->zThreadRoot ? uuid_to_rid(p->zThreadRoot, 1) : rid;
2474 fprev = p->nParent ? uuid_to_rid(p->azParent[0],1) : 0;
2475 firt = p->zInReplyTo ? uuid_to_rid(p->zInReplyTo,1) : 0;
2476 db_multi_exec(
2477 "INSERT INTO forumpost(fpid,froot,fprev,firt,fmtime)"
2478 "VALUES(%d,%d,nullif(%d,0),nullif(%d,0),%.17g)",
2479 p->rid, froot, fprev, firt, p->rDate
2480 );
2481 if( firt==0 ){
2482 /* This is the start of a new thread, either the initial entry
2483 ** or an edit of the initial entry. */
2484 zTitle = p->zThreadTitle;
2485 if( zTitle==0 || zTitle[0]==0 ){
2486 zTitle = "<i>Deleted</i>";
2487 }
2488 zFType = fprev ? "Edit" : "Post";
2489 db_multi_exec(
2490 "REPLACE INTO event(type,mtime,objid,user,comment)"
2491 "VALUES('f',%.17g,%d,%Q,'%q: %q')",
2492 p->rDate, rid, p->zUser, zFType, zTitle
2493 );
2494 /*
2495 ** If this edit is the most recent, then make it the title for
2496 ** all other entries for the same thread
2497 */
2498 if( !db_exists("SELECT 1 FROM forumpost WHERE froot=%d AND firt=0"
2499 " AND fpid!=%d AND fmtime>%.17g", froot, rid, p->rDate)
2500 ){
2501 /* This entry establishes a new title for all entries on the thread */
2502 db_multi_exec(
2503 "UPDATE event"
2504 " SET comment=substr(comment,1,instr(comment,':')) || ' %q'"
2505 " WHERE objid IN (SELECT fpid FROM forumpost WHERE froot=%d)",
2506 zTitle, froot
2507 );
2508 }
2509 }else{
2510 /* This is a reply to a prior post. Take the title from the root. */
2511 zTitle = db_text(0, "SELECT substr(comment,instr(comment,':')+2)"
2512 " FROM event WHERE objid=%d", froot);
2513 if( zTitle==0 ) zTitle = fossil_strdup("<i>Unknown</i>");
2514 if( p->zWiki[0]==0 ){
2515 zFType = "Delete reply";
2516 }else if( fprev ){
2517 zFType = "Edit reply";
2518 }else{
2519 zFType = "Reply";
2520 }
2521 db_multi_exec(
2522 "REPLACE INTO event(type,mtime,objid,user,comment)"
2523 "VALUES('f',%.17g,%d,%Q,'%q: %q')",
2524 p->rDate, rid, p->zUser, zFType, zTitle
2525 );
2526 fossil_free(zTitle);
2527 }
2528 }
2529 db_end_transaction(0);
2530 if( permitHooks ){
2531 rc = xfer_run_common_script();
2532

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button