mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 07:32:19 +00:00
Distinguish public chat and rss feed from regular groups
This commit is contained in:
@@ -52,17 +52,9 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
|
||||
private final String address;
|
||||
|
||||
// Loki - Special flag to indicate whether this address represents a public chat or not
|
||||
private Boolean isPublicChat;
|
||||
|
||||
private Address(@NonNull String address) {
|
||||
this(address, false);
|
||||
}
|
||||
|
||||
private Address(@NonNull String address, Boolean isPublicChat) {
|
||||
if (address == null) throw new AssertionError(address);
|
||||
this.address = address.toLowerCase();
|
||||
this.isPublicChat = isPublicChat;
|
||||
}
|
||||
|
||||
public Address(Parcel in) {
|
||||
@@ -77,10 +69,6 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
return Address.fromSerialized(external);
|
||||
}
|
||||
|
||||
public static @NonNull Address fromPublicChatGroupID(@NonNull String serialized) {
|
||||
return new Address(serialized, true);
|
||||
}
|
||||
|
||||
public static @NonNull List<Address> fromSerializedList(@NonNull String serialized, char delimiter) {
|
||||
String[] escapedAddresses = DelimiterUtil.split(serialized, delimiter);
|
||||
List<Address> addresses = new LinkedList<>();
|
||||
@@ -121,13 +109,15 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGroup() {
|
||||
return GroupUtil.isEncodedGroup(address);
|
||||
}
|
||||
public boolean isGroup() { return GroupUtil.isEncodedGroup(address); }
|
||||
|
||||
public boolean isMmsGroup() {
|
||||
return GroupUtil.isMmsGroup(address);
|
||||
}
|
||||
public boolean isSignalGroup() { return !isPublicChat() && !isRSSFeed(); }
|
||||
|
||||
public boolean isPublicChat() { return GroupUtil.isPublicChat(address); }
|
||||
|
||||
public boolean isRSSFeed() { return GroupUtil.isRssFeed(address); }
|
||||
|
||||
public boolean isMmsGroup() { return GroupUtil.isMmsGroup(address); }
|
||||
|
||||
public boolean isEmail() {
|
||||
return NumberUtil.isValidEmail(address);
|
||||
@@ -143,7 +133,7 @@ public class Address implements Parcelable, Comparable<Address> {
|
||||
}
|
||||
|
||||
public @NonNull String toPhoneString() {
|
||||
if (!isPhone() && !isPublicChat) {
|
||||
if (!isPhone() && !isPublicChat()) {
|
||||
if (isEmail()) throw new AssertionError("Not e164, is email");
|
||||
if (isGroup()) throw new AssertionError("Not e164, is group");
|
||||
throw new AssertionError("Not e164, unknown");
|
||||
|
||||
@@ -448,6 +448,10 @@ public class GroupDatabase extends Database {
|
||||
return mms;
|
||||
}
|
||||
|
||||
public boolean isPublicChat() { return Address.fromSerialized(id).isPublicChat(); }
|
||||
|
||||
public boolean isRSSFeed() { return Address.fromSerialized(id).isRSSFeed(); }
|
||||
|
||||
public String getUrl() { return url; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,14 @@ import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.*;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.loki.api.LokiPublicChat;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.acl.Group;
|
||||
|
||||
public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
|
||||
@@ -71,8 +75,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
private static final int lokiV2 = 23;
|
||||
private static final int lokiV3 = 24;
|
||||
private static final int lokiV4 = 25;
|
||||
private static final int lokiV5 = 26;
|
||||
|
||||
private static final int DATABASE_VERSION = lokiV4; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
|
||||
private static final int DATABASE_VERSION = lokiV5; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
|
||||
private static final String DATABASE_NAME = "signal.db";
|
||||
|
||||
private final Context context;
|
||||
@@ -510,6 +515,40 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiMessageDatabase.getCreateMessageToThreadMappingTableCommand());
|
||||
}
|
||||
|
||||
if (oldVersion < lokiV5) {
|
||||
// Migrate public chats from __textsecure_group__ to __loki_public_chat_group__
|
||||
try (Cursor lokiPublicChatCursor = db.rawQuery("SELECT public_chat FROM loki_public_chat_database", null)) {
|
||||
while (lokiPublicChatCursor != null && lokiPublicChatCursor.moveToNext()) {
|
||||
String chatString = lokiPublicChatCursor.getString(0);
|
||||
LokiPublicChat publicChat = LokiPublicChat.fromJSON(chatString);
|
||||
if (publicChat != null) {
|
||||
byte[] groupId = publicChat.getId().getBytes();
|
||||
String oldId = GroupUtil.getEncodedId(groupId, false);
|
||||
String newId = GroupUtil.getEncodedPublicChatId(groupId);
|
||||
ContentValues threadUpdate = new ContentValues();
|
||||
threadUpdate.put("recipient_ids", newId);
|
||||
db.update("thread", threadUpdate, "recipient_ids = ?", new String[]{ oldId });
|
||||
ContentValues groupUpdate = new ContentValues();
|
||||
groupUpdate.put("group_id", newId);
|
||||
db.update("groups", groupUpdate,"group_id = ?", new String[] { oldId });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate rss feeds from __textsecure_group__ to __loki_rss_feed_group__
|
||||
String[] rssFeedIds = new String[] { "loki.network.feed", "loki.network.messenger-updates.feed" };
|
||||
for (String groupId : rssFeedIds) {
|
||||
String oldId = GroupUtil.getEncodedId(groupId.getBytes(), false);
|
||||
String newId = GroupUtil.getEncodedRSSFeedId(groupId.getBytes());
|
||||
ContentValues threadUpdate = new ContentValues();
|
||||
threadUpdate.put("recipient_ids", newId);
|
||||
db.update("thread", threadUpdate, "recipient_ids = ?", new String[]{ oldId });
|
||||
ContentValues groupUpdate = new ContentValues();
|
||||
groupUpdate.put("group_id", newId);
|
||||
db.update("groups", groupUpdate,"group_id = ?", new String[] { oldId });
|
||||
}
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
|
||||
Reference in New Issue
Block a user