Skip to content

Commit cee4b59

Browse files
authored
fix(profile): ordering user profile posts
* fix(profile): fix profile posts ordering * fix(profile): add reply context to liked and media posts
1 parent e1f5c54 commit cee4b59

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/tweets/tweets.repository.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ export class TweetsRepository {
485485
'tweet.num_quotes AS num_quotes',
486486
'tweet.num_replies AS num_replies',
487487
'tweet.created_at AS created_at',
488+
'tweet.post_date AS post_date',
488489
'tweet.updated_at AS updated_at',
489490
`json_build_object(
490491
'id', tweet.tweet_author_id,
@@ -500,7 +501,7 @@ export class TweetsRepository {
500501
])
501502
.where('tweet.profile_user_id = :user_id', { user_id })
502503
.andWhere('tweet.type != :type', { type: 'reply' })
503-
.orderBy('tweet.created_at', 'DESC')
504+
.orderBy('tweet.post_date', 'DESC')
504505
.addOrderBy('tweet.tweet_id', 'DESC')
505506
.limit(limit);
506507

@@ -517,7 +518,7 @@ export class TweetsRepository {
517518
query,
518519
cursor,
519520
'tweet',
520-
'created_at',
521+
'post_date',
521522
'tweet_id'
522523
);
523524

@@ -532,7 +533,7 @@ export class TweetsRepository {
532533

533534
const next_cursor = this.paginate_service.generateNextCursor(
534535
tweets,
535-
'created_at',
536+
'post_date',
536537
'tweet_id'
537538
);
538539

@@ -597,7 +598,7 @@ export class TweetsRepository {
597598
])
598599
.where('tweet.profile_user_id = :user_id', { user_id })
599600
.andWhere('tweet.type = :type', { type: 'reply' })
600-
.orderBy('tweet.created_at', 'DESC')
601+
.orderBy('tweet.post_date', 'DESC')
601602
.addOrderBy('tweet.tweet_id', 'DESC')
602603
.limit(limit);
603604

@@ -614,7 +615,7 @@ export class TweetsRepository {
614615
query,
615616
cursor,
616617
'tweet',
617-
'created_at',
618+
'post_date',
618619
'tweet_id'
619620
);
620621

@@ -629,7 +630,7 @@ export class TweetsRepository {
629630

630631
const next_cursor = this.paginate_service.generateNextCursor(
631632
tweets,
632-
'created_at',
633+
'post_date',
633634
'tweet_id'
634635
);
635636

@@ -696,7 +697,8 @@ export class TweetsRepository {
696697
.andWhere(
697698
'(array_length(tweet.images, 1) > 0 OR array_length(tweet.videos, 1) > 0)'
698699
)
699-
.orderBy('tweet.created_at', 'DESC')
700+
.andWhere('tweet.type != :type', { type: 'repost' })
701+
.orderBy('tweet.post_date', 'DESC')
700702
.addOrderBy('tweet.tweet_id', 'DESC')
701703
.limit(limit);
702704

@@ -707,11 +709,13 @@ export class TweetsRepository {
707709
'tweet.tweet_id'
708710
);
709711

712+
query = this.attachRepliedTweetQuery(query, current_user_id);
713+
710714
query = this.paginate_service.applyCursorPagination(
711715
query,
712716
cursor,
713717
'tweet',
714-
'created_at',
718+
'post_date',
715719
'tweet_id'
716720
);
717721

@@ -726,7 +730,7 @@ export class TweetsRepository {
726730

727731
const next_cursor = this.paginate_service.generateNextCursor(
728732
tweets,
729-
'created_at',
733+
'post_date',
730734
'tweet_id'
731735
);
732736

@@ -809,6 +813,8 @@ export class TweetsRepository {
809813
'tweet.tweet_id'
810814
);
811815

816+
query = this.attachRepliedTweetQuery(query, user_id);
817+
812818
query = this.paginate_service.applyCursorPagination(
813819
query,
814820
cursor,
@@ -942,7 +948,6 @@ export class TweetsRepository {
942948
query: SelectQueryBuilder<UserPostsView>,
943949
user_id?: string
944950
): SelectQueryBuilder<any> {
945-
// Helper function to generate interaction SQL
946951
const get_interactions = (alias: string) => {
947952
if (!user_id) return '';
948953

@@ -1041,7 +1046,6 @@ export class TweetsRepository {
10411046
.where('tr2.reply_tweet_id = tweet.tweet_id')
10421047
.limit(1);
10431048

1044-
// Attach subqueries to main query
10451049
query
10461050
.addSelect(`(${parent_sub_query.getQuery()})`, 'parent_tweet')
10471051
.addSelect(`(${conversation_sub_query.getQuery()})`, 'conversation_tweet');

0 commit comments

Comments
 (0)