|
|
@ -53,13 +53,15 @@ public class ThreadDatabase extends Database {
|
|
|
|
private static final String ERROR = "error";
|
|
|
|
private static final String ERROR = "error";
|
|
|
|
private static final String HAS_ATTACHMENT = "has_attachment";
|
|
|
|
private static final String HAS_ATTACHMENT = "has_attachment";
|
|
|
|
public static final String SNIPPET_TYPE = "snippet_type";
|
|
|
|
public static final String SNIPPET_TYPE = "snippet_type";
|
|
|
|
|
|
|
|
private static final String GROUP_ACTION = "group_action";
|
|
|
|
|
|
|
|
private static final String GROUP_ACTION_ARG = "group_action_arguments";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
|
|
|
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
|
|
|
|
DATE + " INTEGER DEFAULT 0, " + MESSAGE_COUNT + " INTEGER DEFAULT 0, " +
|
|
|
|
DATE + " INTEGER DEFAULT 0, " + MESSAGE_COUNT + " INTEGER DEFAULT 0, " +
|
|
|
|
RECIPIENT_IDS + " TEXT, " + SNIPPET + " TEXT, " + SNIPPET_CHARSET + " INTEGER DEFAULT 0, " +
|
|
|
|
RECIPIENT_IDS + " TEXT, " + SNIPPET + " TEXT, " + SNIPPET_CHARSET + " INTEGER DEFAULT 0, " +
|
|
|
|
READ + " INTEGER DEFAULT 1, " + TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
|
|
|
|
READ + " INTEGER DEFAULT 1, " + TYPE + " INTEGER DEFAULT 0, " + ERROR + " INTEGER DEFAULT 0, " +
|
|
|
|
SNIPPET_TYPE + " INTEGER DEFAULT 0, " +
|
|
|
|
SNIPPET_TYPE + " INTEGER DEFAULT 0, " + GROUP_ACTION + " INTEGER DEFAULT -1, " +
|
|
|
|
HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
|
|
|
GROUP_ACTION_ARG + " TEXT, " + HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String[] CREATE_INDEXS = {
|
|
|
|
public static final String[] CREATE_INDEXS = {
|
|
|
|
"CREATE INDEX IF NOT EXISTS thread_recipient_ids_index ON " + TABLE_NAME + " (" + RECIPIENT_IDS + ");",
|
|
|
|
"CREATE INDEX IF NOT EXISTS thread_recipient_ids_index ON " + TABLE_NAME + " (" + RECIPIENT_IDS + ");",
|
|
|
@ -99,17 +101,6 @@ public class ThreadDatabase extends Database {
|
|
|
|
return sb.toString();
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private long createThreadForGroup(String group) {
|
|
|
|
|
|
|
|
long date = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
|
|
|
values.put(DATE, date - date % 1000);
|
|
|
|
|
|
|
|
values.put(RECIPIENT_IDS, group);
|
|
|
|
|
|
|
|
values.put(MESSAGE_COUNT, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return databaseHelper.getWritableDatabase().insert(TABLE_NAME, null, values);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long createThreadForRecipients(String recipients, int recipientCount, int distributionType) {
|
|
|
|
private long createThreadForRecipients(String recipients, int recipientCount, int distributionType) {
|
|
|
|
ContentValues contentValues = new ContentValues(4);
|
|
|
|
ContentValues contentValues = new ContentValues(4);
|
|
|
|
long date = System.currentTimeMillis();
|
|
|
|
long date = System.currentTimeMillis();
|
|
|
@ -126,12 +117,16 @@ public class ThreadDatabase extends Database {
|
|
|
|
return db.insert(TABLE_NAME, null, contentValues);
|
|
|
|
return db.insert(TABLE_NAME, null, contentValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateThread(long threadId, long count, String body, long date, long type) {
|
|
|
|
private void updateThread(long threadId, long count, String body, long date, long type,
|
|
|
|
|
|
|
|
int groupAction, String groupActionArguments)
|
|
|
|
|
|
|
|
{
|
|
|
|
ContentValues contentValues = new ContentValues(3);
|
|
|
|
ContentValues contentValues = new ContentValues(3);
|
|
|
|
contentValues.put(DATE, date - date % 1000);
|
|
|
|
contentValues.put(DATE, date - date % 1000);
|
|
|
|
contentValues.put(MESSAGE_COUNT, count);
|
|
|
|
contentValues.put(MESSAGE_COUNT, count);
|
|
|
|
contentValues.put(SNIPPET, body);
|
|
|
|
contentValues.put(SNIPPET, body);
|
|
|
|
contentValues.put(SNIPPET_TYPE, type);
|
|
|
|
contentValues.put(SNIPPET_TYPE, type);
|
|
|
|
|
|
|
|
contentValues.put(GROUP_ACTION, groupAction);
|
|
|
|
|
|
|
|
contentValues.put(GROUP_ACTION_ARG, groupActionArguments);
|
|
|
|
|
|
|
|
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
|
|
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId + ""});
|
|
|
|
db.update(TABLE_NAME, contentValues, ID + " = ?", new String[] {threadId + ""});
|
|
|
@ -358,26 +353,6 @@ public class ThreadDatabase extends Database {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long getThreadIdForGroup(String groupId) {
|
|
|
|
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
|
|
|
|
String where = RECIPIENT_IDS + " = ?";
|
|
|
|
|
|
|
|
String[] recipientsArg = new String[] {groupId};
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
|
|
|
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return createThreadForGroup(groupId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
|
|
|
cursor.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Recipients getRecipientsForThreadId(long threadId) {
|
|
|
|
public Recipients getRecipientsForThreadId(long threadId) {
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
|
|
|
Cursor cursor = null;
|
|
|
|
Cursor cursor = null;
|
|
|
@ -414,7 +389,8 @@ public class ThreadDatabase extends Database {
|
|
|
|
MessageRecord record = null;
|
|
|
|
MessageRecord record = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (reader != null && (record = reader.getNext()) != null) {
|
|
|
|
if (reader != null && (record = reader.getNext()) != null) {
|
|
|
|
updateThread(threadId, count, record.getBody().getBody(), record.getDateReceived(), record.getType());
|
|
|
|
updateThread(threadId, count, record.getBody().getBody(), record.getDateReceived(),
|
|
|
|
|
|
|
|
record.getType(), record.getGroupAction(), record.getGroupActionArguments());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
deleteThread(threadId);
|
|
|
|
deleteThread(threadId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -470,9 +446,12 @@ public class ThreadDatabase extends Database {
|
|
|
|
long read = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.READ));
|
|
|
|
long read = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.READ));
|
|
|
|
long type = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_TYPE));
|
|
|
|
long type = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_TYPE));
|
|
|
|
int distributionType = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.TYPE));
|
|
|
|
int distributionType = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.TYPE));
|
|
|
|
|
|
|
|
int groupAction = cursor.getInt(cursor.getColumnIndexOrThrow(ThreadDatabase.GROUP_ACTION));
|
|
|
|
|
|
|
|
String groupActionArg = cursor.getString(cursor.getColumnIndexOrThrow(ThreadDatabase.GROUP_ACTION_ARG));
|
|
|
|
|
|
|
|
|
|
|
|
return new ThreadRecord(context, body, recipients, date, count,
|
|
|
|
return new ThreadRecord(context, body, recipients, date, count,
|
|
|
|
read == 1, threadId, type, distributionType);
|
|
|
|
read == 1, threadId, type, distributionType,
|
|
|
|
|
|
|
|
groupAction, groupActionArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private DisplayRecord.Body getPlaintextBody(Cursor cursor) {
|
|
|
|
private DisplayRecord.Body getPlaintextBody(Cursor cursor) {
|
|
|
|