Keep 1:1 replies after expiry and fix queries.
This commit is contained in:
parent
057231b9c3
commit
63a4d20ea9
2 changed files with 25 additions and 6 deletions
|
@ -741,13 +741,21 @@ public class MmsDatabase extends MessageDatabase {
|
||||||
String storiesBeforeTimestampWhere = IS_STORY_CLAUSE + " AND " + DATE_SENT + " < ?";
|
String storiesBeforeTimestampWhere = IS_STORY_CLAUSE + " AND " + DATE_SENT + " < ?";
|
||||||
String[] sharedArgs = SqlUtil.buildArgs(timestamp);
|
String[] sharedArgs = SqlUtil.buildArgs(timestamp);
|
||||||
String deleteStoryRepliesQuery = "DELETE FROM " + TABLE_NAME + " " +
|
String deleteStoryRepliesQuery = "DELETE FROM " + TABLE_NAME + " " +
|
||||||
"WHERE " + PARENT_STORY_ID + " IN (" +
|
"WHERE " + PARENT_STORY_ID + " > 0 AND " + PARENT_STORY_ID + " IN (" +
|
||||||
|
"SELECT " + ID + " " +
|
||||||
|
"FROM " + TABLE_NAME + " " +
|
||||||
|
"WHERE " + storiesBeforeTimestampWhere +
|
||||||
|
")";
|
||||||
|
String disassociateQuoteQuery = "UPDATE " + TABLE_NAME + " " +
|
||||||
|
"SET " + QUOTE_MISSING + " = 1, " + QUOTE_BODY + " = '' " +
|
||||||
|
"WHERE " + PARENT_STORY_ID + " < 0 AND ABS(" + PARENT_STORY_ID + ") IN (" +
|
||||||
"SELECT " + ID + " " +
|
"SELECT " + ID + " " +
|
||||||
"FROM " + TABLE_NAME + " " +
|
"FROM " + TABLE_NAME + " " +
|
||||||
"WHERE " + storiesBeforeTimestampWhere +
|
"WHERE " + storiesBeforeTimestampWhere +
|
||||||
")";
|
")";
|
||||||
|
|
||||||
db.rawQuery(deleteStoryRepliesQuery, sharedArgs);
|
db.execSQL(deleteStoryRepliesQuery, sharedArgs);
|
||||||
|
db.execSQL(disassociateQuoteQuery, sharedArgs);
|
||||||
|
|
||||||
try (Cursor cursor = db.query(TABLE_NAME, new String[]{RECIPIENT_ID}, storiesBeforeTimestampWhere, sharedArgs, null, null, null)) {
|
try (Cursor cursor = db.query(TABLE_NAME, new String[]{RECIPIENT_ID}, storiesBeforeTimestampWhere, sharedArgs, null, null, null)) {
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
|
@ -756,10 +764,18 @@ public class MmsDatabase extends MessageDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int deletedStories = db.delete(TABLE_NAME, storiesBeforeTimestampWhere, sharedArgs);
|
int deletedStoryCount;
|
||||||
|
try (Cursor cursor = db.query(TABLE_NAME, new String[]{ID}, storiesBeforeTimestampWhere, sharedArgs, null, null, null)) {
|
||||||
|
deletedStoryCount = cursor.getCount();
|
||||||
|
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
||||||
|
deleteMessage(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
return deletedStories;
|
return deletedStoryCount;
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,9 @@ public class MmsSmsDatabase extends Database {
|
||||||
|
|
||||||
public int getMessagePositionOnOrAfterTimestamp(long threadId, long timestamp) {
|
public int getMessagePositionOnOrAfterTimestamp(long threadId, long timestamp) {
|
||||||
String[] projection = new String[] { "COUNT(*)" };
|
String[] projection = new String[] { "COUNT(*)" };
|
||||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " >= " + timestamp;
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " +
|
||||||
|
MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " >= " + timestamp + " AND " +
|
||||||
|
MmsDatabase.STORY_TYPE + " = 0 AND " + MmsDatabase.PARENT_STORY_ID + " <= 0";
|
||||||
|
|
||||||
try (Cursor cursor = queryTables(projection, selection, null, null)) {
|
try (Cursor cursor = queryTables(projection, selection, null, null)) {
|
||||||
if (cursor != null && cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
|
@ -595,7 +597,8 @@ public class MmsSmsDatabase extends Database {
|
||||||
public int getMessagePositionInConversation(long threadId, long receivedTimestamp) {
|
public int getMessagePositionInConversation(long threadId, long receivedTimestamp) {
|
||||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
||||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " +
|
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId + " AND " +
|
||||||
MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " > " + receivedTimestamp;
|
MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " > " + receivedTimestamp + " AND " +
|
||||||
|
MmsDatabase.STORY_TYPE + " = 0 AND " + MmsDatabase.PARENT_STORY_ID + " <= 0";
|
||||||
|
|
||||||
try (Cursor cursor = queryTables(new String[]{ "COUNT(*)" }, selection, order, null)) {
|
try (Cursor cursor = queryTables(new String[]{ "COUNT(*)" }, selection, order, null)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue