Fossil SCM

Try to omit unnecessary indentation on the hierarchical forum display. Include an "in reply to" mark on the hierarchical display.

drh 2019-07-14 20:32 trunk
Commit 97697b7956d3ea443e246455fd76ccc3020e52f5cc0065ab53aa695fc1189fa8
1 file changed +37 -17
+37 -17
--- src/forum.c
+++ src/forum.c
@@ -35,13 +35,14 @@
3535
struct ForumEntry {
3636
int fpid; /* rid for this entry */
3737
int fprev; /* zero if initial entry. non-zero if an edit */
3838
int firt; /* This entry replies to firt */
3939
int mfirt; /* Root in-reply-to */
40
+ int nReply; /* Number of replies to this entry */
4041
char *zUuid; /* Artifact hash */
4142
ForumEntry *pLeaf; /* Most recent edit for this entry */
42
- ForumEntry *pEdit; /* This entry is an edit of pEditee */
43
+ ForumEntry *pEdit; /* This entry is an edit of pEdit */
4344
ForumEntry *pNext; /* Next in chronological order */
4445
ForumEntry *pPrev; /* Previous in chronological order */
4546
ForumEntry *pDisplay; /* Next in display order */
4647
int nIndent; /* Number of levels of indentation for this entry */
4748
};
@@ -104,22 +105,30 @@
104105
** Extend the display list for pThread by adding all entries that
105106
** reference fpid. The first such entry will be no earlier then
106107
** entry "p".
107108
*/
108109
static void forumthread_display_order(
109
- ForumThread *pThread,
110
- ForumEntry *p,
111
- int fpid,
112
- int nIndent
110
+ ForumThread *pThread, /* The complete thread */
111
+ ForumEntry *pBase /* Add replies to this entry */
113112
){
114
- while( p ){
115
- if( p->fprev==0 && p->mfirt==fpid ){
116
- p->nIndent = nIndent;
117
- forumentry_add_to_display(pThread, p);
118
- forumthread_display_order(pThread, p->pNext, p->fpid, nIndent+1);
113
+ ForumEntry *p;
114
+ ForumEntry *pPrev = 0;
115
+ for(p=pBase->pNext; p; p=p->pNext){
116
+ if( p->fprev==0 && p->mfirt==pBase->fpid ){
117
+ if( pPrev ){
118
+ pPrev->nIndent = pBase->nIndent + 1;
119
+ forumentry_add_to_display(pThread, pPrev);
120
+ forumthread_display_order(pThread, pPrev);
121
+ }
122
+ pBase->nReply++;
123
+ pPrev = p;
119124
}
120
- p = p->pNext;
125
+ }
126
+ if( pPrev ){
127
+ pPrev->nIndent = pBase->nIndent + (pBase->nReply>1);
128
+ forumentry_add_to_display(pThread, pPrev);
129
+ forumthread_display_order(pThread, pPrev);
121130
}
122131
}
123132
124133
/*
125134
** Construct a ForumThread object given the root record id.
@@ -178,11 +187,11 @@
178187
if( computeHierarchy ){
179188
/* Compute the hierarchical display order */
180189
pEntry = pThread->pFirst;
181190
pEntry->nIndent = 1;
182191
forumentry_add_to_display(pThread, pEntry);
183
- forumthread_display_order(pThread, pEntry, pEntry->fpid, 2);
192
+ forumthread_display_order(pThread, pEntry);
184193
}
185194
186195
/* Return the result */
187196
return pThread;
188197
}
@@ -204,10 +213,13 @@
204213
db_find_and_open_repository(0,0);
205214
verify_all_options();
206215
if( g.argc!=3 ) usage("THREADID");
207216
zName = g.argv[2];
208217
fpid = symbolic_name_to_rid(zName, "f");
218
+ if( fpid<=0 ){
219
+ fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName));
220
+ }
209221
if( fpid<=0 ){
210222
fossil_fatal("Unknown or ambiguous forum id: \"%s\"", zName);
211223
}
212224
froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
213225
if( froot==0 ){
@@ -215,15 +227,16 @@
215227
}
216228
fossil_print("fpid = %d\n", fpid);
217229
fossil_print("froot = %d\n", froot);
218230
pThread = forumthread_create(froot, 1);
219231
fossil_print("Chronological:\n");
220
- /* 123456789 123456789 123456789 123456789 123456789 */
221
- fossil_print(" fpid firt fprev mfirt pLeaf\n");
232
+ /* 123456789 123456789 123456789 123456789 123456789 123456789 */
233
+ fossil_print(" fpid firt fprev mfirt pLeaf nReply\n");
222234
for(p=pThread->pFirst; p; p=p->pNext){
223
- fossil_print("%9d %9d %9d %9d %9d\n",
224
- p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0);
235
+ fossil_print("%9d %9d %9d %9d %9d %9d\n",
236
+ p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0,
237
+ p->nReply);
225238
}
226239
fossil_print("\nDisplay\n");
227240
for(p=pThread->pDisplay; p; p=p->pDisplay){
228241
fossil_print("%*s", (p->nIndent-1)*3, "");
229242
if( p->pLeaf ){
@@ -319,11 +332,11 @@
319332
}
320333
if( p->firt ){
321334
ForumEntry *pIrt = p->pPrev;
322335
while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
323336
if( pIrt ){
324
- @ reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
337
+ @ in reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
325338
}
326339
}
327340
if( p->pLeaf ){
328341
@ updated by %z(href("%R/forumpost/%S?t=c",p->pLeaf->zUuid))\
329342
@ %d(p->pLeaf->fpid)</a>
@@ -441,10 +454,17 @@
441454
}
442455
manifest_destroy(pOPost);
443456
}
444457
if( fpid!=target ){
445458
@ %z(href("%R/forumpost/%S",zUuid))[link]</a>
459
+ }
460
+ if( p->firt ){
461
+ ForumEntry *pIrt = p->pPrev;
462
+ while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
463
+ if( pIrt ){
464
+ @ in reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
465
+ }
446466
}
447467
isPrivate = content_is_private(fpid);
448468
sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
449469
if( isPrivate && !g.perm.ModForum && !sameUser ){
450470
@ <p><span class="modpending">Awaiting Moderator Approval</span></p>
451471
--- src/forum.c
+++ src/forum.c
@@ -35,13 +35,14 @@
35 struct ForumEntry {
36 int fpid; /* rid for this entry */
37 int fprev; /* zero if initial entry. non-zero if an edit */
38 int firt; /* This entry replies to firt */
39 int mfirt; /* Root in-reply-to */
 
40 char *zUuid; /* Artifact hash */
41 ForumEntry *pLeaf; /* Most recent edit for this entry */
42 ForumEntry *pEdit; /* This entry is an edit of pEditee */
43 ForumEntry *pNext; /* Next in chronological order */
44 ForumEntry *pPrev; /* Previous in chronological order */
45 ForumEntry *pDisplay; /* Next in display order */
46 int nIndent; /* Number of levels of indentation for this entry */
47 };
@@ -104,22 +105,30 @@
104 ** Extend the display list for pThread by adding all entries that
105 ** reference fpid. The first such entry will be no earlier then
106 ** entry "p".
107 */
108 static void forumthread_display_order(
109 ForumThread *pThread,
110 ForumEntry *p,
111 int fpid,
112 int nIndent
113 ){
114 while( p ){
115 if( p->fprev==0 && p->mfirt==fpid ){
116 p->nIndent = nIndent;
117 forumentry_add_to_display(pThread, p);
118 forumthread_display_order(pThread, p->pNext, p->fpid, nIndent+1);
 
 
 
 
 
 
119 }
120 p = p->pNext;
 
 
 
 
121 }
122 }
123
124 /*
125 ** Construct a ForumThread object given the root record id.
@@ -178,11 +187,11 @@
178 if( computeHierarchy ){
179 /* Compute the hierarchical display order */
180 pEntry = pThread->pFirst;
181 pEntry->nIndent = 1;
182 forumentry_add_to_display(pThread, pEntry);
183 forumthread_display_order(pThread, pEntry, pEntry->fpid, 2);
184 }
185
186 /* Return the result */
187 return pThread;
188 }
@@ -204,10 +213,13 @@
204 db_find_and_open_repository(0,0);
205 verify_all_options();
206 if( g.argc!=3 ) usage("THREADID");
207 zName = g.argv[2];
208 fpid = symbolic_name_to_rid(zName, "f");
 
 
 
209 if( fpid<=0 ){
210 fossil_fatal("Unknown or ambiguous forum id: \"%s\"", zName);
211 }
212 froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
213 if( froot==0 ){
@@ -215,15 +227,16 @@
215 }
216 fossil_print("fpid = %d\n", fpid);
217 fossil_print("froot = %d\n", froot);
218 pThread = forumthread_create(froot, 1);
219 fossil_print("Chronological:\n");
220 /* 123456789 123456789 123456789 123456789 123456789 */
221 fossil_print(" fpid firt fprev mfirt pLeaf\n");
222 for(p=pThread->pFirst; p; p=p->pNext){
223 fossil_print("%9d %9d %9d %9d %9d\n",
224 p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0);
 
225 }
226 fossil_print("\nDisplay\n");
227 for(p=pThread->pDisplay; p; p=p->pDisplay){
228 fossil_print("%*s", (p->nIndent-1)*3, "");
229 if( p->pLeaf ){
@@ -319,11 +332,11 @@
319 }
320 if( p->firt ){
321 ForumEntry *pIrt = p->pPrev;
322 while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
323 if( pIrt ){
324 @ reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
325 }
326 }
327 if( p->pLeaf ){
328 @ updated by %z(href("%R/forumpost/%S?t=c",p->pLeaf->zUuid))\
329 @ %d(p->pLeaf->fpid)</a>
@@ -441,10 +454,17 @@
441 }
442 manifest_destroy(pOPost);
443 }
444 if( fpid!=target ){
445 @ %z(href("%R/forumpost/%S",zUuid))[link]</a>
 
 
 
 
 
 
 
446 }
447 isPrivate = content_is_private(fpid);
448 sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
449 if( isPrivate && !g.perm.ModForum && !sameUser ){
450 @ <p><span class="modpending">Awaiting Moderator Approval</span></p>
451
--- src/forum.c
+++ src/forum.c
@@ -35,13 +35,14 @@
35 struct ForumEntry {
36 int fpid; /* rid for this entry */
37 int fprev; /* zero if initial entry. non-zero if an edit */
38 int firt; /* This entry replies to firt */
39 int mfirt; /* Root in-reply-to */
40 int nReply; /* Number of replies to this entry */
41 char *zUuid; /* Artifact hash */
42 ForumEntry *pLeaf; /* Most recent edit for this entry */
43 ForumEntry *pEdit; /* This entry is an edit of pEdit */
44 ForumEntry *pNext; /* Next in chronological order */
45 ForumEntry *pPrev; /* Previous in chronological order */
46 ForumEntry *pDisplay; /* Next in display order */
47 int nIndent; /* Number of levels of indentation for this entry */
48 };
@@ -104,22 +105,30 @@
105 ** Extend the display list for pThread by adding all entries that
106 ** reference fpid. The first such entry will be no earlier then
107 ** entry "p".
108 */
109 static void forumthread_display_order(
110 ForumThread *pThread, /* The complete thread */
111 ForumEntry *pBase /* Add replies to this entry */
 
 
112 ){
113 ForumEntry *p;
114 ForumEntry *pPrev = 0;
115 for(p=pBase->pNext; p; p=p->pNext){
116 if( p->fprev==0 && p->mfirt==pBase->fpid ){
117 if( pPrev ){
118 pPrev->nIndent = pBase->nIndent + 1;
119 forumentry_add_to_display(pThread, pPrev);
120 forumthread_display_order(pThread, pPrev);
121 }
122 pBase->nReply++;
123 pPrev = p;
124 }
125 }
126 if( pPrev ){
127 pPrev->nIndent = pBase->nIndent + (pBase->nReply>1);
128 forumentry_add_to_display(pThread, pPrev);
129 forumthread_display_order(pThread, pPrev);
130 }
131 }
132
133 /*
134 ** Construct a ForumThread object given the root record id.
@@ -178,11 +187,11 @@
187 if( computeHierarchy ){
188 /* Compute the hierarchical display order */
189 pEntry = pThread->pFirst;
190 pEntry->nIndent = 1;
191 forumentry_add_to_display(pThread, pEntry);
192 forumthread_display_order(pThread, pEntry);
193 }
194
195 /* Return the result */
196 return pThread;
197 }
@@ -204,10 +213,13 @@
213 db_find_and_open_repository(0,0);
214 verify_all_options();
215 if( g.argc!=3 ) usage("THREADID");
216 zName = g.argv[2];
217 fpid = symbolic_name_to_rid(zName, "f");
218 if( fpid<=0 ){
219 fpid = db_int(0, "SELECT rid FROM blob WHERE rid=%d", atoi(zName));
220 }
221 if( fpid<=0 ){
222 fossil_fatal("Unknown or ambiguous forum id: \"%s\"", zName);
223 }
224 froot = db_int(0, "SELECT froot FROM forumpost WHERE fpid=%d", fpid);
225 if( froot==0 ){
@@ -215,15 +227,16 @@
227 }
228 fossil_print("fpid = %d\n", fpid);
229 fossil_print("froot = %d\n", froot);
230 pThread = forumthread_create(froot, 1);
231 fossil_print("Chronological:\n");
232 /* 123456789 123456789 123456789 123456789 123456789 123456789 */
233 fossil_print(" fpid firt fprev mfirt pLeaf nReply\n");
234 for(p=pThread->pFirst; p; p=p->pNext){
235 fossil_print("%9d %9d %9d %9d %9d %9d\n",
236 p->fpid, p->firt, p->fprev, p->mfirt, p->pLeaf ? p->pLeaf->fpid : 0,
237 p->nReply);
238 }
239 fossil_print("\nDisplay\n");
240 for(p=pThread->pDisplay; p; p=p->pDisplay){
241 fossil_print("%*s", (p->nIndent-1)*3, "");
242 if( p->pLeaf ){
@@ -319,11 +332,11 @@
332 }
333 if( p->firt ){
334 ForumEntry *pIrt = p->pPrev;
335 while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
336 if( pIrt ){
337 @ in reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
338 }
339 }
340 if( p->pLeaf ){
341 @ updated by %z(href("%R/forumpost/%S?t=c",p->pLeaf->zUuid))\
342 @ %d(p->pLeaf->fpid)</a>
@@ -441,10 +454,17 @@
454 }
455 manifest_destroy(pOPost);
456 }
457 if( fpid!=target ){
458 @ %z(href("%R/forumpost/%S",zUuid))[link]</a>
459 }
460 if( p->firt ){
461 ForumEntry *pIrt = p->pPrev;
462 while( pIrt && pIrt->fpid!=p->firt ) pIrt = pIrt->pPrev;
463 if( pIrt ){
464 @ in reply to %z(href("%R/forumpost/%S?t=c",pIrt->zUuid))%d(p->firt)</a>
465 }
466 }
467 isPrivate = content_is_private(fpid);
468 sameUser = notAnon && fossil_strcmp(pPost->zUser, g.zLogin)==0;
469 if( isPrivate && !g.perm.ModForum && !sameUser ){
470 @ <p><span class="modpending">Awaiting Moderator Approval</span></p>
471

Keyboard Shortcuts

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