mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:08:36 +00:00
Add 'leave group' functionality. Includes other bug fixes.
This commit is contained in:
@@ -642,7 +642,7 @@ public class DatabaseFactory {
|
||||
}
|
||||
|
||||
if (oldVersion < INTRODUCED_GROUP_DATABASE_VERSION) {
|
||||
db.execSQL("CREATE TABLE groups (_id INTEGER PRIMARY KEY, group_id TEXT, owner TEXT, title TEXT, members TEXT, avatar BLOB, avatar_id INTEGER, avatar_key BLOB, avatar_content_type TEXT, avatar_relay TEXT, timestamp INTEGER);");
|
||||
db.execSQL("CREATE TABLE groups (_id INTEGER PRIMARY KEY, group_id TEXT, owner TEXT, title TEXT, members TEXT, avatar BLOB, avatar_id INTEGER, avatar_key BLOB, avatar_content_type TEXT, avatar_relay TEXT, timestamp INTEGER, active INTEGER DEFAULT 1);");
|
||||
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS group_id_index ON groups (GROUP_ID);");
|
||||
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;");
|
||||
|
||||
@@ -16,14 +16,11 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,6 +40,7 @@ public class GroupDatabase extends Database {
|
||||
private static final String AVATAR_CONTENT_TYPE = "avatar_content_type";
|
||||
private static final String AVATAR_RELAY = "avatar_relay";
|
||||
private static final String TIMESTAMP = "timestamp";
|
||||
private static final String ACTIVE = "active";
|
||||
|
||||
public static final String CREATE_TABLE =
|
||||
"CREATE TABLE " + TABLE_NAME +
|
||||
@@ -56,7 +54,8 @@ public class GroupDatabase extends Database {
|
||||
AVATAR_KEY + " BLOB, " +
|
||||
AVATAR_CONTENT_TYPE + " TEXT, " +
|
||||
AVATAR_RELAY + " TEXT, " +
|
||||
TIMESTAMP + " INTEGER);";
|
||||
TIMESTAMP + " INTEGER, " +
|
||||
ACTIVE + " INTEGER DEFAULT 1);";
|
||||
|
||||
public static final String[] CREATE_INDEXS = {
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS group_id_index ON " + TABLE_NAME + " (" + GROUP_ID + ");",
|
||||
@@ -125,6 +124,7 @@ public class GroupDatabase extends Database {
|
||||
|
||||
contentValues.put(AVATAR_RELAY, relay);
|
||||
contentValues.put(TIMESTAMP, System.currentTimeMillis());
|
||||
contentValues.put(ACTIVE, 1);
|
||||
|
||||
databaseHelper.getWritableDatabase().insert(TABLE_NAME, null, contentValues);
|
||||
}
|
||||
@@ -173,6 +173,7 @@ public class GroupDatabase extends Database {
|
||||
|
||||
ContentValues contents = new ContentValues();
|
||||
contents.put(MEMBERS, Util.join(concatenatedMembers, ","));
|
||||
contents.put(ACTIVE, 1);
|
||||
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?",
|
||||
new String[] {GroupUtil.getEncodedId(id)});
|
||||
@@ -211,6 +212,18 @@ public class GroupDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActive(byte[] id) {
|
||||
GroupRecord record = getGroup(id);
|
||||
return record != null && record.isActive();
|
||||
}
|
||||
|
||||
public void setActive(byte[] id, boolean active) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ACTIVE, active ? 1 : 0);
|
||||
database.update(TABLE_NAME, values, GROUP_ID + " = ?", new String[] {GroupUtil.getEncodedId(id)});
|
||||
}
|
||||
|
||||
public String getOwner(byte[] id) {
|
||||
Cursor cursor = null;
|
||||
|
||||
@@ -265,7 +278,8 @@ public class GroupDatabase extends Database {
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow(AVATAR_ID)),
|
||||
cursor.getBlob(cursor.getColumnIndexOrThrow(AVATAR_KEY)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR_CONTENT_TYPE)),
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR_RELAY)));
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR_RELAY)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(ACTIVE)) == 1);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
@@ -285,10 +299,11 @@ public class GroupDatabase extends Database {
|
||||
private final byte[] avatarKey;
|
||||
private final String avatarContentType;
|
||||
private final String relay;
|
||||
private final boolean active;
|
||||
|
||||
public GroupRecord(String id, String title, String owner, String members, byte[] avatar,
|
||||
long avatarId, byte[] avatarKey, String avatarContentType,
|
||||
String relay)
|
||||
String relay, boolean active)
|
||||
{
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
@@ -299,6 +314,7 @@ public class GroupDatabase extends Database {
|
||||
this.avatarKey = avatarKey;
|
||||
this.avatarContentType = avatarContentType;
|
||||
this.relay = relay;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public byte[] getId() {
|
||||
@@ -340,5 +356,9 @@ public class GroupDatabase extends Database {
|
||||
public String getRelay() {
|
||||
return relay;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class PushDatabase extends Database {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TYPE, message.getType());
|
||||
values.put(SOURCE, message.getSource());
|
||||
values.put(DEVICE_ID, message.getSourceDevice());
|
||||
values.put(BODY, Base64.encodeBytes(message.getBody()));
|
||||
values.put(TIMESTAMP, message.getTimestampMillis());
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
public SpannableString getDisplayBody() {
|
||||
if (isGroupUpdate()) {
|
||||
return emphasisAdded(GroupUtil.getDescription(getBody().getBody()));
|
||||
} else if (isGroupQuit() && isOutgoing()) {
|
||||
return emphasisAdded("You have left the group.");
|
||||
} else if (isGroupQuit()) {
|
||||
return emphasisAdded(context.getString(R.string.ConversationItem_group_action_left, getIndividualRecipient().toShortString()));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ThreadRecord extends DisplayRecord {
|
||||
} else if (isGroupUpdate()) {
|
||||
return emphasisAdded(GroupUtil.getDescription(getBody().getBody()));
|
||||
} else if (isGroupQuit()) {
|
||||
return emphasisAdded(getRecipients().toShortString() + " left the group.");
|
||||
return emphasisAdded("Someone left 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