Skip to content

Commit

Permalink
Keep pinned chats at the top of the 'recent' chat section.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Aug 17, 2020
1 parent e96faf3 commit 29b8fa5
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public Cursor getRecentConversationList(int limit, boolean includeInactiveGroups
query += " AND " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.GROUP_ID + " NOT NULL";
}

return db.rawQuery(createQuery(query, limit), null);
return db.rawQuery(createQuery(query, 0, limit, true), null);
}

public Cursor getRecentPushConversationList(int limit, boolean includeInactiveGroups) {
Expand All @@ -505,7 +505,7 @@ public Cursor getRecentPushConversationList(int limit, boolean includeInactiveGr
activeGroupQuery +
")" +
")";
String query = createQuery(where, limit);
String query = createQuery(where, 0, limit, true);

return db.rawQuery(query, null);
}
Expand Down Expand Up @@ -601,7 +601,7 @@ private Cursor getConversationList(String archived) {

public Cursor getUnarchivedConversationList(boolean pinned, long offset, long limit) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String query = createQuery(ARCHIVED + " = 0 AND " + MESSAGE_COUNT + " != 0 AND " + PINNED + " = ?", offset, limit);
String query = createQuery(ARCHIVED + " = 0 AND " + MESSAGE_COUNT + " != 0 AND " + PINNED + " = ?", offset, limit, false);
Cursor cursor = db.rawQuery(query, new String[]{pinned ? "1" : "0"});

setNotifyConversationListListeners(cursor);
Expand All @@ -611,7 +611,7 @@ public Cursor getUnarchivedConversationList(boolean pinned, long offset, long li

private Cursor getConversationList(@NonNull String archived, long offset, long limit) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", offset, limit);
String query = createQuery(ARCHIVED + " = ? AND " + MESSAGE_COUNT + " != 0", offset, limit, false);
Cursor cursor = db.rawQuery(query, new String[]{archived});

setNotifyConversationListListeners(cursor);
Expand Down Expand Up @@ -1074,19 +1074,21 @@ public boolean update(long threadId, boolean unarchive, boolean allowDeletion) {
}

private @NonNull String createQuery(@NonNull String where, long limit) {
return createQuery(where, 0, limit);
return createQuery(where, 0, limit, false);
}

private @NonNull String createQuery(@NonNull String where, long offset, long limit) {
private @NonNull String createQuery(@NonNull String where, long offset, long limit, boolean preferPinned) {
String orderBy = (preferPinned ? TABLE_NAME + "." + PINNED + " DESC, " : "") + TABLE_NAME + "." + DATE + " DESC";
String projection = Util.join(COMBINED_THREAD_RECIPIENT_GROUP_PROJECTION, ",");

String query =
"SELECT " + projection + " FROM " + TABLE_NAME +
" LEFT OUTER JOIN " + RecipientDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + RecipientDatabase.TABLE_NAME + "." + RecipientDatabase.ID +
" LEFT OUTER JOIN " + GroupDatabase.TABLE_NAME +
" ON " + TABLE_NAME + "." + RECIPIENT_ID + " = " + GroupDatabase.TABLE_NAME + "." + GroupDatabase.RECIPIENT_ID +
" WHERE " + where +
" ORDER BY " + TABLE_NAME + "." + DATE + " DESC";
" ORDER BY " + orderBy;

if (limit > 0) {
query += " LIMIT " + limit;
Expand Down

0 comments on commit 29b8fa5

Please sign in to comment.