Fossil

Check-in [9757488a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixes to the forum hierarchical display algorithm.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | forum-v2
Files: files | file ages | folders
SHA3-256: 9757488a5dc0edc899cc5fca0c78b73dc43a5f808cb6b5189edf722fe771a1ca
User & Date: drh 2018-07-26 01:02:58.777
Context
2018-07-26
01:33
Automatic scroll to the specific message of the thread when calling /info on a forum message. ... (check-in: 8f0e18f4 user: drh tags: forum-v2)
01:02
Fixes to the forum hierarchical display algorithm. ... (check-in: 9757488a user: drh tags: forum-v2)
2018-07-25
22:34
Begin adding style to the forum display. ... (check-in: 8eccd9a2 user: drh tags: forum-v2)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/default_css.txt.
685
686
687
688
689
690
691



}
div.forumHier, div.forumTime {
  border: 1px solid black;
  padding-left: 1ex;
  padding-right: 1ex;
  margin-top: 1ex;
}










>
>
>
685
686
687
688
689
690
691
692
693
694
}
div.forumHier, div.forumTime {
  border: 1px solid black;
  padding-left: 1ex;
  padding-right: 1ex;
  margin-top: 1ex;
}
div.forumSel {
  background-color: #cef;
}
Changes to src/forum.c.
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
static void forumthread_display_order(
  ForumThread *pThread,
  ForumEntry *p,
  int fpid,
  int nIndent
){
  while( p ){
    if( p->pEdit==0 && p->mfirt==fpid ){
      p->nIndent = nIndent;
      forumentry_add_to_display(pThread, p);
      forumthread_display_order(pThread, p->pNext, p->fpid, nIndent+1);
    }
    p = p->pNext;
  }
}







|







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
static void forumthread_display_order(
  ForumThread *pThread,
  ForumEntry *p,
  int fpid,
  int nIndent
){
  while( p ){
    if( p->fprev==0 && p->mfirt==fpid ){
      p->nIndent = nIndent;
      forumentry_add_to_display(pThread, p);
      forumthread_display_order(pThread, p->pNext, p->fpid, nIndent+1);
    }
    p = p->pNext;
  }
}
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  /* Establish which entries are the latest edit.  After this loop
  ** completes, entries that have non-NULL pLeaf should not be
  ** displayed.
  */
  for(pEntry=pThread->pFirst; pEntry; pEntry=pEntry->pNext){
    if( pEntry->fprev ){
      ForumEntry *pBase, *p;
      pBase = p = forumentry_backward(pEntry->pPrev, pEntry->fprev);
      pEntry->pEdit = p;
      while( p ){
        pBase = p;
        p->pLeaf = pEntry;
        p = pBase->pEdit;
      }
      for(p=pEntry->pNext; p; p=p->pNext){
        if( p->mfirt==pEntry->fpid ) p->mfirt = pBase->mfirt;
      }
    }
  }

  /* Compute the display order */
  pEntry = pThread->pFirst;
  pEntry->nIndent = 1;







|







|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  /* Establish which entries are the latest edit.  After this loop
  ** completes, entries that have non-NULL pLeaf should not be
  ** displayed.
  */
  for(pEntry=pThread->pFirst; pEntry; pEntry=pEntry->pNext){
    if( pEntry->fprev ){
      ForumEntry *pBase, *p;
      p = forumentry_backward(pEntry->pPrev, pEntry->fprev);
      pEntry->pEdit = p;
      while( p ){
        pBase = p;
        p->pLeaf = pEntry;
        p = pBase->pEdit;
      }
      for(p=pEntry->pNext; p; p=p->pNext){
        if( p->mfirt==pEntry->fpid ) p->mfirt = pBase->fpid;
      }
    }
  }

  /* Compute the display order */
  pEntry = pThread->pFirst;
  pEntry->nIndent = 1;
268
269
270
271
272
273
274



275

276
277
278
279
280
281
282
    int fpid = db_column_int(&q, 0);
    int fprev = db_column_int(&q, 1);
    int firt = db_column_int(&q, 2);
    const char *zUuid = db_column_text(&q, 3);
    const char *zDate = db_column_text(&q, 4);
    Manifest *pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
    if( pPost==0 ) continue;



    @ <div id="forum%d(fpid)" class="forumTime">

    if( pPost->zThreadTitle ){
      @ <h1>%h(pPost->zThreadTitle)</h1>
    }
    @ <p>By %h(pPost->zUser) on %h(zDate) (%d(fpid))
    if( fprev ){
      @ edit of %d(fprev)
    }







>
>
>
|
>







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
    int fpid = db_column_int(&q, 0);
    int fprev = db_column_int(&q, 1);
    int firt = db_column_int(&q, 2);
    const char *zUuid = db_column_text(&q, 3);
    const char *zDate = db_column_text(&q, 4);
    Manifest *pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
    if( pPost==0 ) continue;
    if( fpid==target ){
      @ <div id="forum%d(fpid)" class="forumTime forumSel">
    }else{
      @ <div id="forum%d(fpid)" class="forumTime">
    }
    if( pPost->zThreadTitle ){
      @ <h1>%h(pPost->zThreadTitle)</h1>
    }
    @ <p>By %h(pPost->zUser) on %h(zDate) (%d(fpid))
    if( fprev ){
      @ edit of %d(fprev)
    }
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

/*
** Display all messages in a forumthread with indentation.
*/
static int forum_display_hierarchical(int froot, int target){
  ForumThread *pThread;
  ForumEntry *p;
  Manifest *pPost;
  int fpid;
  char *zDate;
  char *zUuid;


  pThread = forumthread_create(froot);







  for(p=pThread->pDisplay; p; p=p->pDisplay){


    fpid = p->pLeaf ? p->pLeaf->fpid : p->fpid;






    if( p->nIndent==1 ){
      @ <div id='forum(%d(fpid)' class='forumHierRoot'>
    }else{
      @ <div id='forum%d(fpid)' class='forumHier' \
      @ style='margin-left: %d((p->nIndent-1)*3)ex;'>
    }
    pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
    if( pPost==0 ) continue;
    if( pPost->zThreadTitle ){
      @ <h1>%h(pPost->zThreadTitle)</h1>
    }









    zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);



    @ <p>By %h(pPost->zUser) on %h(zDate) (%d(fpid))

    fossil_free(zDate);

    zUuid = rid_to_uuid(fpid);
    if( g.perm.Debug ){
      @ <span class="debug">\
      @ <a href="%R/artifact/%h(zUuid)">artifact</a></span>


    }
    forum_render(0, pPost->zMimetype, pPost->zWiki, 0);
    if( g.perm.WrForum ){
      int sameUser = login_is_individual()
                     && fossil_strcmp(pPost->zUser, g.zLogin)==0;
      int isPrivate = content_is_private(fpid);
      @ <p><form action="%R/forumedit" method="POST">







|



>


>
>
>
>
>
>
>

>
>
|
>
>
>
>
>
>

|

|







>
>
>
>
>
>
>
>
>
|
>
>
>
|
>
|
>
|
|
|
|
>
>







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

/*
** Display all messages in a forumthread with indentation.
*/
static int forum_display_hierarchical(int froot, int target){
  ForumThread *pThread;
  ForumEntry *p;
  Manifest *pPost, *pOPost;
  int fpid;
  char *zDate;
  char *zUuid;
  const char *zSel;

  pThread = forumthread_create(froot);
  for(p=pThread->pFirst; p; p=p->pNext){
    if( p->fpid==target ){
      while( p->pEdit ) p = p->pEdit;
      target = p->fpid;
      break;
    }
  }
  for(p=pThread->pDisplay; p; p=p->pDisplay){
    pOPost = manifest_get(p->fpid, CFTYPE_FORUM, 0);
    if( p->pLeaf ){
      fpid = p->pLeaf->fpid;
      pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
    }else{
      fpid = p->fpid;
      pPost = pOPost;
    }
    zSel = p->fpid==target ? " forumSel" : "";
    if( p->nIndent==1 ){
      @ <div id='forum(%d(fpid)' class='forumHierRoot%s(zSel)'>
    }else{
      @ <div id='forum%d(fpid)' class='forumHier%s(zSel)' \
      @ style='margin-left: %d((p->nIndent-1)*3)ex;'>
    }
    pPost = manifest_get(fpid, CFTYPE_FORUM, 0);
    if( pPost==0 ) continue;
    if( pPost->zThreadTitle ){
      @ <h1>%h(pPost->zThreadTitle)</h1>
    }
    zDate = db_text(0, "SELECT datetime(%.17g)", pOPost->rDate);
    @ <p>By %h(pOPost->zUser) on %h(zDate)
    fossil_free(zDate);
    zUuid = rid_to_uuid(p->fpid);
    if( g.perm.Debug ){
      @ <span class="debug">\
      @ <a href="%R/artifact/%h(zUuid)">(%d(p->fpid))</a></span>
    }
    if( p->pLeaf ){
      zDate = db_text(0, "SELECT datetime(%.17g)", pPost->rDate);
      if( fossil_strcmp(pOPost->zUser,pPost->zUser)==0 ){
        @ and edited on %h(zDate)
      }else{
        @ as edited by %h(pPost->zUser) on %h(zDate)
      }
      fossil_free(zDate);
      fossil_free(zUuid);
      zUuid = rid_to_uuid(fpid);
      if( g.perm.Debug ){
        @ <span class="debug">\
        @ <a href="%R/artifact/%h(zUuid)">(%d(fpid))</a></span>
      }
      manifest_destroy(pOPost);
    }
    forum_render(0, pPost->zMimetype, pPost->zWiki, 0);
    if( g.perm.WrForum ){
      int sameUser = login_is_individual()
                     && fossil_strcmp(pPost->zUser, g.zLogin)==0;
      int isPrivate = content_is_private(fpid);
      @ <p><form action="%R/forumedit" method="POST">
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
      }
      @ </form></p>
    }
    manifest_destroy(pPost);
    fossil_free(zUuid);
    @ </div>
  }
  for(p=pThread->pFirst; p; p=p->pNext){
    if( p->fpid==target ){
      if( p->pLeaf ) target = p->pLeaf->fpid;
      break;
    }
  }
  forumthread_delete(pThread);
  return target;
}

/*
** WEBPAGE: forumthread
**







<
<
<
<
<
<







416
417
418
419
420
421
422






423
424
425
426
427
428
429
      }
      @ </form></p>
    }
    manifest_destroy(pPost);
    fossil_free(zUuid);
    @ </div>
  }






  forumthread_delete(pThread);
  return target;
}

/*
** WEBPAGE: forumthread
**