Skip to content

Commit 60ec890

Browse files
authored
Merge pull request #1035 from ggtylerr/master
server: Set reply sorting to 'oldest'
2 parents d9fadd2 + 400e4f7 commit 60ec890

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Bugfixes & Improvements
5757
- Python 3.12 support (`#1015`_, ix5)
5858
- Disable Postbox submit button on click, enable after response (`#993`_, pkvach)
5959
- Document title parameter and improve error handling for /new API (`#1058`_, pkvach)
60+
- Set reply sorting to always be oldest (`#1035`_, ggtylerr)
6061

6162
.. _#951: https://github.com/posativ/isso/pull/951
6263
.. _#967: https://github.com/posativ/isso/pull/967
@@ -71,6 +72,7 @@ Bugfixes & Improvements
7172
.. _#1019: https://github.com/isso-comments/isso/pull/1019
7273
.. _#1015: https://github.com/isso-comments/isso/pull/1015
7374
.. _#993: https://github.com/isso-comments/isso/pull/993
75+
.. _#1035: https://github.com/isso-comments/isso/pull/1035
7476
.. _#1058: https://github.com/isso-comments/isso/pull/1058
7577

7678
0.13.1.dev0 (2023-02-05)

docs/docs/reference/client-config.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ data-isso-sorting
267267
- ``oldest``: Bring oldest comments to the top
268268
- ``upvotes``: Bring most liked comments to the top
269269

270-
Default sorting is ``oldest``.
270+
Default sorting is ``oldest``. As of 0.13.1, replies are always sorted as
271+
``oldest``.
271272

272273
.. versionadded:: 0.13.1
273274

isso/db/comments.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ def fetchall(self, mode=5, after=0, parent='any', order_by='id',
217217

218218
# custom sanitization
219219
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'tid']:
220-
sql.append('ORDER BY ')
221-
sql.append("comments.created")
220+
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
221+
sql.append('comments.created')
222222
if not asc:
223223
sql.append(' DESC')
224224
else:
225-
sql.append('ORDER BY ')
225+
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
226226
sql.append('comments.' + order_by)
227227
if not asc:
228228
sql.append(' DESC')
229-
sql.append(", comments.created")
229+
sql.append(', comments.created')
230230

231231
if limit:
232232
sql.append('LIMIT ?,?')
@@ -257,8 +257,8 @@ def fetch(self, uri, mode=5, after=0, parent='any',
257257

258258
# custom sanitization
259259
if order_by not in ['id', 'created', 'modified', 'likes', 'dislikes', 'karma']:
260-
order_by = 'id'
261-
sql.append('ORDER BY ')
260+
order_by = 'created'
261+
sql.append('ORDER BY CASE WHEN comments.parent IS NOT NULL THEN comments.created END, ')
262262
sql.append(order_by)
263263
if not asc:
264264
sql.append(' DESC')

isso/tests/test_comments.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ def testGetSortedByNewestWithNested(self):
347347

348348
rv = loads(r.data)
349349
self.assertEqual(len(rv['replies']), 1)
350-
# assert order of nested comments is newest first
350+
# assert order of nested comments is oldest first
351351
self.assertEqual(
352352
[comment['id'] for comment in rv['replies'][0]['replies']],
353-
[6, 5, 4, 3, 2]
353+
[2, 3, 4, 5, 6]
354354
)
355355

356356
def testGetSortedByUpvotesWithNested(self):
@@ -369,10 +369,10 @@ def testGetSortedByUpvotesWithNested(self):
369369

370370
rv = loads(r.data)
371371
self.assertEqual(len(rv['replies']), 1)
372-
# assert order of nested comments is newest first
372+
# assert order of nested comments is oldest first
373373
self.assertEqual(
374374
[comment['id'] for comment in rv['replies'][0]['replies']],
375-
[6, 3, 2, 4, 5]
375+
[2, 3, 4, 5, 6]
376376
)
377377

378378
def testUpdate(self):
@@ -559,15 +559,15 @@ def testFeed(self):
559559

560560
rv = self.get('/feed?uri=%2Fpath%2F')
561561
self.assertEqual(rv.status_code, 200)
562-
self.assertEqual(rv.headers['ETag'], '"1-2"')
562+
self.assertEqual(rv.headers['ETag'], '"1-1"')
563563
data = rv.data.decode('utf-8')
564564
data = re.sub('[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]+Z',
565565
'2018-04-01T10:00:00Z', data)
566566
self.maxDiff = None
567567
# Two accepted outputs, since different versions of Python sort attributes in different order.
568568
self.assertIn(data, ["""<?xml version=\'1.0\' encoding=\'utf-8\'?>
569-
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to href="https://example.org/path/#isso-1" ref="tag:example.org,2018:/isso/1/1" /></entry><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry></feed>""", """<?xml version=\'1.0\' encoding=\'utf-8\'?>
570-
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to ref="tag:example.org,2018:/isso/1/1" href="https://example.org/path/#isso-1" /></entry><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry></feed>"""])
569+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to href="https://example.org/path/#isso-1" ref="tag:example.org,2018:/isso/1/1" /></entry></feed>""", """<?xml version=\'1.0\' encoding=\'utf-8\'?>
570+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0"><updated>2018-04-01T10:00:00Z</updated><id>tag:example.org,2018:/isso/thread/path/</id><title>Comments for example.org/path/</title><entry><id>tag:example.org,2018:/isso/1/1</id><title>Comment #1</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-1" /><content type="html">&lt;p&gt;First&lt;/p&gt;</content></entry><entry><id>tag:example.org,2018:/isso/1/2</id><title>Comment #2</title><updated>2018-04-01T10:00:00Z</updated><author><name /></author><link href="https://example.org/path/#isso-2" /><content type="html">&lt;p&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/p&gt;</content><thr:in-reply-to ref="tag:example.org,2018:/isso/1/1" href="https://example.org/path/#isso-1" /></entry></feed>"""])
571571

572572
def testCounts(self):
573573

0 commit comments

Comments
 (0)