Skip to content

Commit

Permalink
Merge pull request #119 from snuhcs-course/fix/sort-my-posts-emojis
Browse files Browse the repository at this point in the history
Fix: sort saved emojis by descending order of saved time
  • Loading branch information
dawitfamanu authored Dec 7, 2023
2 parents abc0f74 + 315505e commit 0d42047
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,18 @@ class EmojiService(
} else {
user.saved_emojis
}
var emojiList = mutableListOf<EmojiDto>()
val emojiArrayDeque = ArrayDeque<EmojiDto>()
var emojiList = listOf<EmojiDto>()
if (emojiIdList != null && emojiIdList.size != 0) {
for (emojiId in emojiIdList) {
val emoji = emojiDao.getEmoji(emojiId) ?: continue
emojiList.add(emoji)
}
// sort
if (emojiList.size != 0) {
emojiList.sortByDescending { it.created_at }
// pagination
emojiList = emojiList.subList(
min((index - 1) * count, emojiList.size - 1),
min(index * count, emojiList.size)
)
emojiArrayDeque.addFirst(emoji)
}
// pagination
// FIXME: remind - CreatedEmojiList should already be sorted by created_at
val start = min((index - 1) * count, emojiArrayDeque.size - 1)
val end = min(index * count, emojiArrayDeque.size)
emojiList = emojiArrayDeque.toList().subList(start, end)
}
return emojiList
}
Expand Down

0 comments on commit 0d42047

Please sign in to comment.