[mastodon-client] Fix ordering of conversations
This commit is contained in:
parent
bbc0f0278a
commit
a515b6b4d4
1 changed files with 12 additions and 8 deletions
|
|
@ -161,13 +161,9 @@ export class TimelineHelpers {
|
||||||
|
|
||||||
public static async getConversations(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20): Promise<LinkPaginationObject<MastodonEntity.Conversation[]>> {
|
public static async getConversations(user: ILocalUser, maxId: string | undefined, sinceId: string | undefined, minId: string | undefined, limit: number = 20): Promise<LinkPaginationObject<MastodonEntity.Conversation[]>> {
|
||||||
if (limit > 40) limit = 40;
|
if (limit > 40) limit = 40;
|
||||||
const query = PaginationHelpers.makePaginationQuery(
|
const sq = Notes.createQueryBuilder("note")
|
||||||
Notes.createQueryBuilder("note"),
|
.select("COALESCE(note.threadId, note.id)", "conversationId")
|
||||||
sinceId,
|
.addSelect("note.id", "latest")
|
||||||
maxId,
|
|
||||||
minId,
|
|
||||||
"COALESCE(note.threadId, note.id)",
|
|
||||||
)
|
|
||||||
.distinctOn(["COALESCE(note.threadId, note.id)"])
|
.distinctOn(["COALESCE(note.threadId, note.id)"])
|
||||||
.orderBy({"COALESCE(note.threadId, note.id)": minId ? "ASC" : "DESC", "note.id": "DESC"})
|
.orderBy({"COALESCE(note.threadId, note.id)": minId ? "ASC" : "DESC", "note.id": "DESC"})
|
||||||
.andWhere("note.visibility = 'specified'")
|
.andWhere("note.visibility = 'specified'")
|
||||||
|
|
@ -175,7 +171,15 @@ export class TimelineHelpers {
|
||||||
new Brackets(qb => {
|
new Brackets(qb => {
|
||||||
qb.where("note.userId = :userId");
|
qb.where("note.userId = :userId");
|
||||||
qb.orWhere("note.visibleUserIds @> array[:userId]::varchar[]");
|
qb.orWhere("note.visibleUserIds @> array[:userId]::varchar[]");
|
||||||
}))
|
}));
|
||||||
|
|
||||||
|
const query = PaginationHelpers.makePaginationQuery(
|
||||||
|
Notes.createQueryBuilder("note"),
|
||||||
|
sinceId,
|
||||||
|
maxId,
|
||||||
|
minId
|
||||||
|
)
|
||||||
|
.innerJoin(`(${sq.getQuery()})`, "sq", "note.id = sq.latest")
|
||||||
.setParameters({userId: user.id})
|
.setParameters({userId: user.id})
|
||||||
|
|
||||||
return query.take(limit).getMany().then(p => {
|
return query.take(limit).getMany().then(p => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue