Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ShakibHabibi/019f58ed73186a9156fc1587b46a30ae to your computer and use it in GitHub Desktop.
Save ShakibHabibi/019f58ed73186a9156fc1587b46a30ae to your computer and use it in GitHub Desktop.
message
public List<PrivateMessage> getChatMessages(int chatId) {
List<PrivateMessage> privateMessages = new ArrayList<>();
SQLiteDatabase db = dbHelper.getReadableDatabase();
String query = SELECT_ALL + CHAT_MESSAGES_TABLE_NAME
+ WHERE + CHAT_MESSAGES_COLUMN_CHAT_ID + EQUAL + chatId + ORDER_BY
+ CHAT_MESSAGES_COLUMN_MESSAGE_ID + ASC;
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
// if (privateMessages.size() != 0 && privateMessages.get(privateMessages.size() - 1)
// .isHasParent()) {
// privateMessages.get(privateMessages.size() - 1).setParentMessage(new PrivateMessage(
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_CREATE_DATE)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_CHAT_ID)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_ID)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_TEXT)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_CREATE_USER_ID)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SEND_USER_ID)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_STATUS)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_IDENTIFIER)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SENDER_PICTURE)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_TYPE)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_TYPE)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_DOWNLOAD_LINK)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SENDER_NAME)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_LAST_EDIT_DATE)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_EXTENSION)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_NAME)),
// cursor.getLong(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_SIZE)),
// cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_THN_LINK)),
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_HAS_PARENT)) == 1));
// } else {
privateMessages.add(new PrivateMessage(
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_CREATE_DATE)),
cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_CHAT_ID)),
cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_ID)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_TEXT)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_CREATE_USER_ID)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SEND_USER_ID)),
cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_STATUS)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_IDENTIFIER)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SENDER_PICTURE)),
cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_MESSAGE_TYPE)),
cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_TYPE)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_DOWNLOAD_LINK)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_SENDER_NAME)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_LAST_EDIT_DATE)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_EXTENSION)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_NAME)),
cursor.getLong(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_FILE_SIZE)),
cursor.getString(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_THN_LINK)),
//TODO
// cursor.getInt(cursor.getColumnIndex(CHAT_MESSAGES_COLUMN_HAS_PARENT)) == 1));
false));
// }
cursor.moveToNext();
}
return privateMessages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment