mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:08:36 +00:00
Display group actions and correctly handle group delivery.
This commit is contained in:
@@ -647,6 +647,10 @@ public class DatabaseFactory {
|
||||
db.execSQL("ALTER TABLE push ADD COLUMN device_id INTEGER DEFAULT 1;");
|
||||
db.execSQL("ALTER TABLE sms ADD COLUMN address_device_id INTEGER DEFAULT 1;");
|
||||
db.execSQL("ALTER TABLE mms ADD COLUMN address_device_id INTEGER DEFAULT 1;");
|
||||
db.execSQL("ALTER TABLE sms ADD COLUMN group_action INTEGER DEFAULT -1;");
|
||||
db.execSQL("ALTER TABLE mms ADD COLUMN group_action_arguments TEXT;");
|
||||
db.execSQL("ALTER TABLE thread ADD COLUMN group_action INTEGER DEFAULT -1;");
|
||||
db.execSQL("ALTER TABLE thread ADD COLUMN group_action_arguments TEXT;");
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.util.Hex;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
@@ -90,11 +91,20 @@ public class GroupDatabase extends Database {
|
||||
List<String> members, AttachmentPointer avatar,
|
||||
String relay)
|
||||
{
|
||||
List<String> filteredMembers = new LinkedList<String>();
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
|
||||
for (String member : members) {
|
||||
if (!member.equals(localNumber)) {
|
||||
filteredMembers.add(member);
|
||||
}
|
||||
}
|
||||
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(GROUP_ID, GroupUtil.getEncodedId(groupId));
|
||||
contentValues.put(OWNER, owner);
|
||||
contentValues.put(TITLE, title);
|
||||
contentValues.put(MEMBERS, Util.join(members, ","));
|
||||
contentValues.put(MEMBERS, Util.join(filteredMembers, ","));
|
||||
|
||||
if (avatar != null) {
|
||||
contentValues.put(AVATAR_ID, avatar.getId());
|
||||
@@ -147,7 +157,7 @@ public class GroupDatabase extends Database {
|
||||
contents.put(MEMBERS, Util.join(concatenatedMembers, ","));
|
||||
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?",
|
||||
new String[] {Hex.toString(id)});
|
||||
new String[] {GroupUtil.getEncodedId(id)});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +170,7 @@ public class GroupDatabase extends Database {
|
||||
contents.put(MEMBERS, Util.join(currentMembers, ","));
|
||||
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?",
|
||||
new String[]{Hex.toString(id)});
|
||||
new String[]{GroupUtil.getEncodedId(id)});
|
||||
}
|
||||
|
||||
private List<String> getCurrentMembers(byte[] id) {
|
||||
@@ -168,7 +178,8 @@ public class GroupDatabase extends Database {
|
||||
|
||||
try {
|
||||
cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[] {MEMBERS},
|
||||
GROUP_ID + " = ?", new String[] {Hex.toString(id)},
|
||||
GROUP_ID + " = ?",
|
||||
new String[] {GroupUtil.getEncodedId(id)},
|
||||
null, null, null);
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
|
||||
@@ -116,7 +116,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
STATUS + " INTEGER, " + TRANSACTION_ID + " TEXT, " + RETRIEVE_STATUS + " INTEGER, " +
|
||||
RETRIEVE_TEXT + " TEXT, " + RETRIEVE_TEXT_CS + " INTEGER, " + READ_STATUS + " INTEGER, " +
|
||||
CONTENT_CLASS + " INTEGER, " + RESPONSE_TEXT + " TEXT, " + DELIVERY_TIME + " INTEGER, " +
|
||||
DELIVERY_REPORT + " INTEGER);";
|
||||
DELIVERY_REPORT + " INTEGER, " + GROUP_ACTION + " INTEGER DEFAULT -1, " + GROUP_ACTION_ARGUMENTS + " TEXT);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"CREATE INDEX IF NOT EXISTS mms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
|
||||
@@ -181,7 +181,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
|
||||
private long getThreadIdFor(IncomingMediaMessage retrieved) throws RecipientFormattingException {
|
||||
if (retrieved.getGroupId() != null) {
|
||||
return DatabaseFactory.getThreadDatabase(context).getThreadIdForGroup(retrieved.getGroupId());
|
||||
Recipients groupRecipients = RecipientFactory.getRecipientsFromString(context, retrieved.getGroupId(), true);
|
||||
return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -399,6 +400,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
||||
contentValues.put(DATE_RECEIVED, System.currentTimeMillis() / 1000);
|
||||
contentValues.put(READ, unread ? 0 : 1);
|
||||
contentValues.put(GROUP_ACTION, retrieved.getGroupAction());
|
||||
contentValues.put(GROUP_ACTION_ARGUMENTS, retrieved.getGroupActionArguments());
|
||||
|
||||
if (!contentValues.containsKey(DATE_SENT)) {
|
||||
contentValues.put(DATE_SENT, contentValues.getAsLong(DATE_RECEIVED));
|
||||
@@ -797,6 +800,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
long messageSize = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_SIZE));
|
||||
long expiry = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.EXPIRY));
|
||||
int status = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.STATUS));
|
||||
int groupAction = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.GROUP_ACTION));
|
||||
String groupActionArgs = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.GROUP_ACTION_ARGUMENTS));
|
||||
|
||||
byte[]contentLocationBytes = null;
|
||||
byte[]transactionIdBytes = null;
|
||||
@@ -811,7 +816,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
return new NotificationMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(),
|
||||
addressDeviceId, dateSent, dateReceived, threadId,
|
||||
contentLocationBytes, messageSize, expiry, status,
|
||||
transactionIdBytes, mailbox);
|
||||
transactionIdBytes, mailbox, groupAction, groupActionArgs);
|
||||
}
|
||||
|
||||
private MediaMmsMessageRecord getMediaMmsMessageRecord(Cursor cursor) {
|
||||
@@ -822,6 +827,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.THREAD_ID));
|
||||
String address = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS));
|
||||
int addressDeviceId = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.ADDRESS_DEVICE_ID));
|
||||
int groupAction = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.GROUP_ACTION));
|
||||
String groupActionArgs = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.GROUP_ACTION_ARGUMENTS));
|
||||
DisplayRecord.Body body = getBody(cursor);
|
||||
int partCount = cursor.getInt(cursor.getColumnIndexOrThrow(MmsDatabase.PART_COUNT));
|
||||
Recipients recipients = getRecipientsFor(address);
|
||||
@@ -830,7 +837,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
|
||||
return new MediaMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(),
|
||||
addressDeviceId, dateSent, dateReceived, threadId, body,
|
||||
slideDeck, partCount, box);
|
||||
slideDeck, partCount, box, groupAction, groupActionArgs);
|
||||
}
|
||||
|
||||
private Recipients getRecipientsFor(String address) {
|
||||
|
||||
@@ -10,7 +10,8 @@ public interface MmsSmsColumns {
|
||||
public static final String BODY = "body";
|
||||
public static final String ADDRESS = "address";
|
||||
public static final String ADDRESS_DEVICE_ID = "address_device_id";
|
||||
|
||||
public static final String GROUP_ACTION = "group_action";
|
||||
public static final String GROUP_ACTION_ARGUMENTS = "group_action_arguments";
|
||||
|
||||
public static class Types {
|
||||
protected static final long TOTAL_MASK = 0xFFFFFFFF;
|
||||
|
||||
@@ -49,7 +49,8 @@ public class MmsSmsDatabase extends Database {
|
||||
SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
||||
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
||||
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY,
|
||||
MmsDatabase.STATUS, TRANSPORT};
|
||||
MmsDatabase.STATUS, MmsSmsColumns.GROUP_ACTION,
|
||||
MmsSmsColumns.GROUP_ACTION_ARGUMENTS, TRANSPORT};
|
||||
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
|
||||
|
||||
@@ -71,7 +72,8 @@ public class MmsSmsDatabase extends Database {
|
||||
SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
||||
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
||||
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY,
|
||||
MmsDatabase.STATUS, TRANSPORT};
|
||||
MmsDatabase.STATUS, MmsSmsColumns.GROUP_ACTION,
|
||||
MmsSmsColumns.GROUP_ACTION_ARGUMENTS, TRANSPORT};
|
||||
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
||||
@@ -89,7 +91,8 @@ public class MmsSmsDatabase extends Database {
|
||||
MmsDatabase.PART_COUNT,
|
||||
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
||||
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY,
|
||||
MmsDatabase.STATUS, TRANSPORT};
|
||||
MmsDatabase.STATUS, MmsSmsColumns.GROUP_ACTION,
|
||||
MmsSmsColumns.GROUP_ACTION_ARGUMENTS, TRANSPORT};
|
||||
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " ASC";
|
||||
String selection = MmsSmsColumns.READ + " = 0";
|
||||
@@ -112,6 +115,7 @@ public class MmsSmsDatabase extends Database {
|
||||
MmsDatabase.MESSAGE_BOX, SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
||||
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
||||
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
|
||||
MmsSmsColumns.GROUP_ACTION, MmsSmsColumns.GROUP_ACTION_ARGUMENTS,
|
||||
TRANSPORT};
|
||||
|
||||
String[] smsProjection = {SmsDatabase.DATE_SENT + " * 1 AS " + MmsSmsColumns.NORMALIZED_DATE_SENT,
|
||||
@@ -121,6 +125,7 @@ public class MmsSmsDatabase extends Database {
|
||||
MmsDatabase.MESSAGE_BOX, SmsDatabase.STATUS, MmsDatabase.PART_COUNT,
|
||||
MmsDatabase.CONTENT_LOCATION, MmsDatabase.TRANSACTION_ID,
|
||||
MmsDatabase.MESSAGE_SIZE, MmsDatabase.EXPIRY, MmsDatabase.STATUS,
|
||||
MmsSmsColumns.GROUP_ACTION, MmsSmsColumns.GROUP_ACTION_ARGUMENTS,
|
||||
TRANSPORT};
|
||||
|
||||
|
||||
@@ -149,6 +154,8 @@ public class MmsSmsDatabase extends Database {
|
||||
mmsColumnsPresent.add(MmsDatabase.TRANSACTION_ID);
|
||||
mmsColumnsPresent.add(MmsDatabase.MESSAGE_SIZE);
|
||||
mmsColumnsPresent.add(MmsDatabase.EXPIRY);
|
||||
mmsColumnsPresent.add(MmsSmsColumns.GROUP_ACTION);
|
||||
mmsColumnsPresent.add(MmsSmsColumns.GROUP_ACTION_ARGUMENTS);
|
||||
mmsColumnsPresent.add(MmsDatabase.STATUS);
|
||||
|
||||
Set<String> smsColumnsPresent = new HashSet<String>();
|
||||
@@ -162,6 +169,8 @@ public class MmsSmsDatabase extends Database {
|
||||
smsColumnsPresent.add(SmsDatabase.SUBJECT);
|
||||
smsColumnsPresent.add(SmsDatabase.DATE_SENT);
|
||||
smsColumnsPresent.add(SmsDatabase.DATE_RECEIVED);
|
||||
smsColumnsPresent.add(MmsSmsColumns.GROUP_ACTION);
|
||||
smsColumnsPresent.add(MmsSmsColumns.GROUP_ACTION_ARGUMENTS);
|
||||
smsColumnsPresent.add(SmsDatabase.STATUS);
|
||||
|
||||
String mmsSubQuery = mmsQueryBuilder.buildUnionSubQuery(TRANSPORT, mmsProjection, mmsColumnsPresent, 2, MMS_TRANSPORT, selection, null, null, null);
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.telephony.PhoneNumberUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.database.model.DisplayRecord;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
@@ -66,7 +65,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + ADDRESS_DEVICE_ID + " INTEGER DEFAULT 1, " + PERSON + " INTEGER, " +
|
||||
DATE_RECEIVED + " INTEGER, " + DATE_SENT + " INTEGER, " + PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " +
|
||||
STATUS + " INTEGER DEFAULT -1," + TYPE + " INTEGER, " + REPLY_PATH_PRESENT + " INTEGER, " +
|
||||
SUBJECT + " TEXT, " + BODY + " TEXT, " + SERVICE_CENTER + " TEXT);";
|
||||
SUBJECT + " TEXT, " + BODY + " TEXT, " + SERVICE_CENTER + " TEXT, " +
|
||||
GROUP_ACTION + " INTEGER DEFAULT -1, " + GROUP_ACTION_ARGUMENTS + " TEXT);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
|
||||
@@ -80,7 +80,7 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
DATE_RECEIVED + " AS " + NORMALIZED_DATE_RECEIVED,
|
||||
DATE_SENT + " AS " + NORMALIZED_DATE_SENT,
|
||||
PROTOCOL, READ, STATUS, TYPE,
|
||||
REPLY_PATH_PRESENT, SUBJECT, BODY, SERVICE_CENTER
|
||||
REPLY_PATH_PRESENT, SUBJECT, BODY, SERVICE_CENTER, GROUP_ACTION, GROUP_ACTION_ARGUMENTS
|
||||
};
|
||||
|
||||
public SmsDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||
@@ -303,6 +303,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
values.put(BODY, message.getMessageBody());
|
||||
values.put(TYPE, type);
|
||||
values.put(THREAD_ID, threadId);
|
||||
values.put(GROUP_ACTION, message.getGroupAction());
|
||||
values.put(GROUP_ACTION_ARGUMENTS, message.getGroupActionArgument());
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
long messageId = db.insert(TABLE_NAME, null, values);
|
||||
@@ -338,6 +340,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
contentValues.put(DATE_SENT, date);
|
||||
contentValues.put(READ, 1);
|
||||
contentValues.put(TYPE, type);
|
||||
contentValues.put(GROUP_ACTION, message.getGroupAction());
|
||||
contentValues.put(GROUP_ACTION_ARGUMENTS, message.getGroupActionArguments());
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
messageIds.add(db.insert(TABLE_NAME, ADDRESS, contentValues));
|
||||
@@ -494,6 +498,8 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
long dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.NORMALIZED_DATE_SENT));
|
||||
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.THREAD_ID));
|
||||
int status = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.STATUS));
|
||||
int groupAction = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.GROUP_ACTION));
|
||||
String groupActionArgs = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.GROUP_ACTION_ARGUMENTS));
|
||||
Recipients recipients = getRecipientsFor(address);
|
||||
DisplayRecord.Body body = getBody(cursor);
|
||||
|
||||
@@ -501,7 +507,7 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
recipients.getPrimaryRecipient(),
|
||||
addressDeviceId,
|
||||
dateSent, dateReceived, type,
|
||||
threadId, status);
|
||||
threadId, status, groupAction, groupActionArgs);
|
||||
}
|
||||
|
||||
private Recipients getRecipientsFor(String address) {
|
||||
|
||||
@@ -53,13 +53,15 @@ public class ThreadDatabase extends Database {
|
||||
private static final String ERROR = "error";
|
||||
private static final String HAS_ATTACHMENT = "has_attachment";
|
||||
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, " +
|
||||
DATE + " INTEGER DEFAULT 0, " + MESSAGE_COUNT + " 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, " +
|
||||
SNIPPET_TYPE + " INTEGER DEFAULT 0, " +
|
||||
HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
||||
SNIPPET_TYPE + " INTEGER DEFAULT 0, " + GROUP_ACTION + " INTEGER DEFAULT -1, " +
|
||||
GROUP_ACTION_ARG + " TEXT, " + HAS_ATTACHMENT + " INTEGER DEFAULT 0);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"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();
|
||||
}
|
||||
|
||||
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) {
|
||||
ContentValues contentValues = new ContentValues(4);
|
||||
long date = System.currentTimeMillis();
|
||||
@@ -126,12 +117,16 @@ public class ThreadDatabase extends Database {
|
||||
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.put(DATE, date - date % 1000);
|
||||
contentValues.put(MESSAGE_COUNT, count);
|
||||
contentValues.put(SNIPPET, body);
|
||||
contentValues.put(SNIPPET_TYPE, type);
|
||||
contentValues.put(GROUP_ACTION, groupAction);
|
||||
contentValues.put(GROUP_ACTION_ARG, groupActionArguments);
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
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) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = null;
|
||||
@@ -414,7 +389,8 @@ public class ThreadDatabase extends Database {
|
||||
MessageRecord record = 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 {
|
||||
deleteThread(threadId);
|
||||
}
|
||||
@@ -470,9 +446,12 @@ public class ThreadDatabase extends Database {
|
||||
long read = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.READ));
|
||||
long type = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_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,
|
||||
read == 1, threadId, type, distributionType);
|
||||
read == 1, threadId, type, distributionType,
|
||||
groupAction, groupActionArg);
|
||||
}
|
||||
|
||||
private DisplayRecord.Body getPlaintextBody(Cursor cursor) {
|
||||
|
||||
@@ -36,22 +36,26 @@ public abstract class DisplayRecord {
|
||||
protected final long type;
|
||||
|
||||
private final Recipients recipients;
|
||||
private final long dateSent;
|
||||
private final long dateReceived;
|
||||
private final long threadId;
|
||||
private final Body body;
|
||||
// private final String body;
|
||||
private final long dateSent;
|
||||
private final long dateReceived;
|
||||
private final long threadId;
|
||||
private final Body body;
|
||||
private final int groupAction;
|
||||
private final String groupActionArguments;
|
||||
|
||||
public DisplayRecord(Context context, Body body, Recipients recipients, long dateSent,
|
||||
long dateReceived, long threadId, long type)
|
||||
long dateReceived, long threadId, long type, int groupAction,
|
||||
String groupActionArguments)
|
||||
{
|
||||
this.context = context.getApplicationContext();
|
||||
this.threadId = threadId;
|
||||
this.recipients = recipients;
|
||||
this.dateSent = dateSent;
|
||||
this.dateReceived = dateReceived;
|
||||
this.type = type;
|
||||
this.body = body;
|
||||
this.context = context.getApplicationContext();
|
||||
this.threadId = threadId;
|
||||
this.recipients = recipients;
|
||||
this.dateSent = dateSent;
|
||||
this.dateReceived = dateReceived;
|
||||
this.type = type;
|
||||
this.body = body;
|
||||
this.groupAction = groupAction;
|
||||
this.groupActionArguments = groupActionArguments;
|
||||
}
|
||||
|
||||
public Body getBody() {
|
||||
@@ -80,6 +84,14 @@ public abstract class DisplayRecord {
|
||||
return SmsDatabase.Types.isKeyExchangeType(type);
|
||||
}
|
||||
|
||||
public int getGroupAction() {
|
||||
return groupAction;
|
||||
}
|
||||
|
||||
public String getGroupActionArguments() {
|
||||
return groupActionArguments;
|
||||
}
|
||||
|
||||
public static class Body {
|
||||
private final String body;
|
||||
private final boolean plaintext;
|
||||
|
||||
@@ -44,10 +44,12 @@ public class MediaMmsMessageRecord extends MessageRecord {
|
||||
Recipient individualRecipient, int recipientDeviceId,
|
||||
long dateSent, long dateReceived, long threadId, Body body,
|
||||
ListenableFutureTask<SlideDeck> slideDeck,
|
||||
int partCount, long mailbox)
|
||||
int partCount, long mailbox, int groupAction,
|
||||
String groupActionArguments)
|
||||
{
|
||||
super(context, id, body, recipients, individualRecipient, recipientDeviceId,
|
||||
dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox);
|
||||
dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox,
|
||||
groupAction, groupActionArguments);
|
||||
|
||||
this.context = context.getApplicationContext();
|
||||
this.partCount = partCount;
|
||||
|
||||
@@ -53,9 +53,9 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
Recipient individualRecipient, int recipientDeviceId,
|
||||
long dateSent, long dateReceived,
|
||||
long threadId, int deliveryStatus,
|
||||
long type)
|
||||
long type, int groupAction, String groupActionArguments)
|
||||
{
|
||||
super(context, body, recipients, dateSent, dateReceived, threadId, type);
|
||||
super(context, body, recipients, dateSent, dateReceived, threadId, type, groupAction, groupActionArguments);
|
||||
this.id = id;
|
||||
this.individualRecipient = individualRecipient;
|
||||
this.recipientDeviceId = recipientDeviceId;
|
||||
|
||||
@@ -44,10 +44,11 @@ public class NotificationMmsMessageRecord extends MessageRecord {
|
||||
Recipient individualRecipient, int recipientDeviceId,
|
||||
long dateSent, long dateReceived, long threadId,
|
||||
byte[] contentLocation, long messageSize, long expiry,
|
||||
int status, byte[] transactionId, long mailbox)
|
||||
int status, byte[] transactionId, long mailbox,
|
||||
int groupAction, String groupActionArguments)
|
||||
{
|
||||
super(context, id, new Body("", true), recipients, individualRecipient, recipientDeviceId,
|
||||
dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox);
|
||||
dateSent, dateReceived, threadId, DELIVERY_STATUS_NONE, mailbox, groupAction, groupActionArguments);
|
||||
|
||||
this.contentLocation = contentLocation;
|
||||
this.messageSize = messageSize;
|
||||
|
||||
@@ -41,10 +41,12 @@ public class SmsMessageRecord extends MessageRecord {
|
||||
int recipientDeviceId,
|
||||
long dateSent, long dateReceived,
|
||||
long type, long threadId,
|
||||
int status)
|
||||
int status, int groupAction,
|
||||
String groupActionArguments)
|
||||
{
|
||||
super(context, id, body, recipients, individualRecipient, recipientDeviceId,
|
||||
dateSent, dateReceived, threadId, getGenericDeliveryStatus(status), type);
|
||||
dateSent, dateReceived, threadId, getGenericDeliveryStatus(status), type,
|
||||
groupAction, groupActionArguments);
|
||||
}
|
||||
|
||||
public long getType() {
|
||||
|
||||
@@ -24,8 +24,11 @@ import android.text.style.StyleSpan;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.whispersystems.textsecure.push.PushMessageProtos;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent.GroupContext;
|
||||
|
||||
/**
|
||||
* The message record model which represents thread heading messages.
|
||||
*
|
||||
@@ -41,9 +44,9 @@ public class ThreadRecord extends DisplayRecord {
|
||||
|
||||
public ThreadRecord(Context context, Body body, Recipients recipients, long date,
|
||||
long count, boolean read, long threadId, long snippetType,
|
||||
int distributionType)
|
||||
int distributionType, int groupAction, String groupActionArg)
|
||||
{
|
||||
super(context, body, recipients, date, date, threadId, snippetType);
|
||||
super(context, body, recipients, date, date, threadId, snippetType, groupAction, groupActionArg);
|
||||
this.context = context.getApplicationContext();
|
||||
this.count = count;
|
||||
this.read = read;
|
||||
@@ -54,6 +57,14 @@ public class ThreadRecord extends DisplayRecord {
|
||||
public SpannableString getDisplayBody() {
|
||||
if (SmsDatabase.Types.isDecryptInProgressType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageDisplayHelper_decrypting_please_wait));
|
||||
} else if (getGroupAction() == GroupContext.Type.ADD_VALUE ||
|
||||
getGroupAction() == GroupContext.Type.CREATE_VALUE)
|
||||
{
|
||||
return emphasisAdded("Added " + getGroupActionArguments());
|
||||
} else if (getGroupAction() == GroupContext.Type.QUIT_VALUE) {
|
||||
return emphasisAdded(getRecipients().toShortString() + " left the group.");
|
||||
} else if (getGroupAction() == GroupContext.Type.MODIFY_VALUE) {
|
||||
return emphasisAdded(getRecipients().toShortString() + " modified the group.");
|
||||
} else if (isKeyExchange()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationListItem_key_exchange_message));
|
||||
} else if (SmsDatabase.Types.isFailedDecryptType(type)) {
|
||||
|
||||
Reference in New Issue
Block a user