|
|
@ -28,7 +28,6 @@ import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer
|
|
|
|
import org.session.libsignal.service.loki.database.LokiOpenGroupDatabaseProtocol;
|
|
|
|
import org.session.libsignal.service.loki.database.LokiOpenGroupDatabaseProtocol;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.Closeable;
|
|
|
|
import java.io.Closeable;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
@ -44,6 +43,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
static final String GROUP_ID = "group_id";
|
|
|
|
static final String GROUP_ID = "group_id";
|
|
|
|
private static final String TITLE = "title";
|
|
|
|
private static final String TITLE = "title";
|
|
|
|
private static final String MEMBERS = "members";
|
|
|
|
private static final String MEMBERS = "members";
|
|
|
|
|
|
|
|
private static final String ZOMBIE_MEMBERS = "zombie_members";
|
|
|
|
private static final String AVATAR = "avatar";
|
|
|
|
private static final String AVATAR = "avatar";
|
|
|
|
private static final String AVATAR_ID = "avatar_id";
|
|
|
|
private static final String AVATAR_ID = "avatar_id";
|
|
|
|
private static final String AVATAR_KEY = "avatar_key";
|
|
|
|
private static final String AVATAR_KEY = "avatar_key";
|
|
|
@ -64,6 +64,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
GROUP_ID + " TEXT, " +
|
|
|
|
GROUP_ID + " TEXT, " +
|
|
|
|
TITLE + " TEXT, " +
|
|
|
|
TITLE + " TEXT, " +
|
|
|
|
MEMBERS + " TEXT, " +
|
|
|
|
MEMBERS + " TEXT, " +
|
|
|
|
|
|
|
|
ZOMBIE_MEMBERS + " TEXT, " +
|
|
|
|
AVATAR + " BLOB, " +
|
|
|
|
AVATAR + " BLOB, " +
|
|
|
|
AVATAR_ID + " INTEGER, " +
|
|
|
|
AVATAR_ID + " INTEGER, " +
|
|
|
|
AVATAR_KEY + " BLOB, " +
|
|
|
|
AVATAR_KEY + " BLOB, " +
|
|
|
@ -81,7 +82,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
private static final String[] GROUP_PROJECTION = {
|
|
|
|
private static final String[] GROUP_PROJECTION = {
|
|
|
|
GROUP_ID, TITLE, MEMBERS, AVATAR, AVATAR_ID, AVATAR_KEY, AVATAR_CONTENT_TYPE, AVATAR_RELAY, AVATAR_DIGEST,
|
|
|
|
GROUP_ID, TITLE, MEMBERS, ZOMBIE_MEMBERS, AVATAR, AVATAR_ID, AVATAR_KEY, AVATAR_CONTENT_TYPE, AVATAR_RELAY, AVATAR_DIGEST,
|
|
|
|
TIMESTAMP, ACTIVE, MMS, AVATAR_URL, ADMINS
|
|
|
|
TIMESTAMP, ACTIVE, MMS, AVATAR_URL, ADMINS
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -162,7 +163,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public @NonNull List<Recipient> getGroupMembers(String groupId, boolean includeSelf) {
|
|
|
|
public @NonNull List<Recipient> getGroupMembers(String groupId, boolean includeSelf) {
|
|
|
|
List<Address> members = getCurrentMembers(groupId);
|
|
|
|
List<Address> members = getCurrentMembers(groupId, false);
|
|
|
|
List<Recipient> recipients = new LinkedList<>();
|
|
|
|
List<Recipient> recipients = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
|
|
for (Address member : members) {
|
|
|
|
for (Address member : members) {
|
|
|
@ -177,6 +178,19 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
return recipients;
|
|
|
|
return recipients;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public @NonNull List<Recipient> getGroupZombieMembers(String groupId) {
|
|
|
|
|
|
|
|
List<Address> members = getCurrentZombieMembers(groupId);
|
|
|
|
|
|
|
|
List<Recipient> recipients = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Address member : members) {
|
|
|
|
|
|
|
|
if (member.isContact()) {
|
|
|
|
|
|
|
|
recipients.add(Recipient.from(context, member, false));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return recipients;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long create(@NonNull String groupId, @Nullable String title, @NonNull List<Address> members,
|
|
|
|
public long create(@NonNull String groupId, @Nullable String title, @NonNull List<Address> members,
|
|
|
|
@Nullable SignalServiceAttachmentPointer avatar, @Nullable String relay, @Nullable List<Address> admins, @NonNull Long formationTimestamp)
|
|
|
|
@Nullable SignalServiceAttachmentPointer avatar, @Nullable String relay, @Nullable List<Address> admins, @NonNull Long formationTimestamp)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -300,6 +314,16 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateZombieMembers(String groupId, List<Address> members) {
|
|
|
|
|
|
|
|
Collections.sort(members);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContentValues contents = new ContentValues();
|
|
|
|
|
|
|
|
contents.put(ZOMBIE_MEMBERS, Address.toSerializedList(members, ','));
|
|
|
|
|
|
|
|
contents.put(ACTIVE, 1);
|
|
|
|
|
|
|
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contents, GROUP_ID + " = ?",
|
|
|
|
|
|
|
|
new String[] {groupId});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void updateAdmins(String groupId, List<Address> admins) {
|
|
|
|
public void updateAdmins(String groupId, List<Address> admins) {
|
|
|
|
Collections.sort(admins);
|
|
|
|
Collections.sort(admins);
|
|
|
|
|
|
|
|
|
|
|
@ -311,7 +335,7 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeMember(String groupId, Address source) {
|
|
|
|
public void removeMember(String groupId, Address source) {
|
|
|
|
List<Address> currentMembers = getCurrentMembers(groupId);
|
|
|
|
List<Address> currentMembers = getCurrentMembers(groupId, false);
|
|
|
|
currentMembers.remove(source);
|
|
|
|
currentMembers.remove(source);
|
|
|
|
|
|
|
|
|
|
|
|
ContentValues contents = new ContentValues();
|
|
|
|
ContentValues contents = new ContentValues();
|
|
|
@ -329,17 +353,21 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Address> getCurrentMembers(String groupId) {
|
|
|
|
private List<Address> getCurrentMembers(String groupId, boolean zombieMembers) {
|
|
|
|
Cursor cursor = null;
|
|
|
|
Cursor cursor = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String membersColumn = MEMBERS;
|
|
|
|
|
|
|
|
if (zombieMembers) membersColumn = ZOMBIE_MEMBERS;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[] {MEMBERS},
|
|
|
|
cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, new String[] {membersColumn},
|
|
|
|
GROUP_ID + " = ?",
|
|
|
|
GROUP_ID + " = ?",
|
|
|
|
new String[] {groupId},
|
|
|
|
new String[] {groupId},
|
|
|
|
null, null, null);
|
|
|
|
null, null, null);
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
String serializedMembers = cursor.getString(cursor.getColumnIndexOrThrow(MEMBERS));
|
|
|
|
String serializedMembers = cursor.getString(cursor.getColumnIndexOrThrow(membersColumn));
|
|
|
|
|
|
|
|
if (serializedMembers != null && !serializedMembers.isEmpty())
|
|
|
|
return Address.fromSerializedList(serializedMembers, ',');
|
|
|
|
return Address.fromSerializedList(serializedMembers, ',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -350,6 +378,10 @@ public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Address> getCurrentZombieMembers(String groupId) {
|
|
|
|
|
|
|
|
return getCurrentMembers(groupId, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isActive(String groupId) {
|
|
|
|
public boolean isActive(String groupId) {
|
|
|
|
Optional<GroupRecord> record = getGroup(groupId);
|
|
|
|
Optional<GroupRecord> record = getGroup(groupId);
|
|
|
|
return record.isPresent() && record.get().isActive();
|
|
|
|
return record.isPresent() && record.get().isActive();
|
|
|
|