Skip to content

Commit 9f5c13c

Browse files
Merge pull request #1573 from session-foundation/release/1.28.1
Prepare for release 1.28.1
2 parents 403c5f6 + 3f11fd3 commit 9f5c13c

File tree

8 files changed

+120
-31
lines changed

8 files changed

+120
-31
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ configurations.configureEach {
2626
exclude(module = "commons-logging")
2727
}
2828

29-
val canonicalVersionCode = 421
30-
val canonicalVersionName = "1.28.0"
29+
val canonicalVersionCode = 426
30+
val canonicalVersionName = "1.28.1"
3131

3232
val postFixSize = 10
3333
val abiPostFix = mapOf(

app/src/main/java/org/session/libsession/messaging/open_groups/OpenGroup.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data class OpenGroup(
1616
val room: String,
1717
@SerialName("displayName") // This rename caters for existing data
1818
val name: String,
19-
val description: String?,
19+
val description: String? = null,
2020
val publicKey: String,
2121
val imageId: String?,
2222
val infoUpdates: Int,

app/src/main/java/org/thoughtcrime/securesms/attachments/AvatarUploadManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ class AvatarUploadManager @Inject constructor(
191191
val result = it.userProfile.getPic()
192192
val userPic = remoteFile.toUserPic()
193193
if (isReupload) {
194-
it.userProfile.setReuploadedPic(userPic)
194+
it.userProfile.setPic(userPic)
195+
196+
// TODO: We'll need to call this when the libsession re-enables the re-uploaded
197+
// avatar logic.
198+
// it.userProfile.setReuploadedPic(userPic)
195199
} else {
196200
it.userProfile.setPic(userPic)
197201
}

app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.thoughtcrime.securesms.database.MmsSmsColumns.ID;
2121
import static org.thoughtcrime.securesms.database.MmsSmsColumns.NOTIFIED;
2222
import static org.thoughtcrime.securesms.database.MmsSmsColumns.READ;
23+
import static org.thoughtcrime.securesms.database.MmsSmsColumns.THREAD_ID;
2324

2425
import android.content.ContentValues;
2526
import android.content.Context;
@@ -525,6 +526,8 @@ public int getMessagePositionInConversation(long threadId, long sentTimestamp, @
525526
return -1;
526527
}
527528

529+
// Please note this migration contain a mistake (message_id used as thread_id), it's corrected in the subsequent release,
530+
// so you shouldn't try to fix it here.
528531
private static void migrateLegacyCommunityAddresses(final SQLiteDatabase db, final String tableName) {
529532
final String query = "SELECT " + ID + ", " + MmsSmsColumns.ADDRESS + " FROM " + tableName;
530533
try (final Cursor cursor = db.rawQuery(query)) {
@@ -578,11 +581,80 @@ private static void migrateLegacyCommunityAddresses(final SQLiteDatabase db, fin
578581
}
579582
}
580583

584+
// This is an attempt to fix the issue in migrateLegacyCommunityAddresses
585+
private static void migrateLegacyCommunityAddresses2(final SQLiteDatabase db, final String tableName) {
586+
final String query = "SELECT " + ID + ", " + THREAD_ID + ", " + MmsSmsColumns.ADDRESS + " FROM " + tableName;
587+
try (final Cursor cursor = db.rawQuery(query)) {
588+
while (cursor.moveToNext()) {
589+
final long messageId = cursor.getLong(0);
590+
final long threadId = cursor.getLong(1);
591+
final String address = cursor.getString(2);
592+
final String newAddress;
593+
594+
try {
595+
if (address.startsWith(GroupUtil.COMMUNITY_PREFIX)) {
596+
// First, if a message has a sender being a community address, it suggests the message
597+
// is sent by us (this is an assumption from other part of the code).
598+
// This also means that the address will be the thread's address, if the thread address
599+
// is indeed a community address
600+
final String threadSql = "SELECT " + ThreadDatabase.ADDRESS + " FROM " +
601+
ThreadDatabase.TABLE_NAME + " WHERE " + ThreadDatabase.ID + " = ?";
602+
try (final Cursor threadCursor = db.rawQuery(threadSql, threadId)) {
603+
if (threadCursor.moveToNext()) {
604+
final Address threadAddress = Address.fromSerialized(threadCursor.getString(0));
605+
if (threadAddress instanceof Address.Community) {
606+
newAddress = threadAddress.getAddress();
607+
} else {
608+
// If this message has a sender being a community address, but the thread address
609+
// is not community(!), we'll have to fall back to unsafe group id migration
610+
final String groupId = GroupUtil.getDecodedGroupID(address);
611+
final int dotIndex = groupId.lastIndexOf('.');
612+
if (dotIndex > 0 && dotIndex < groupId.length() - 1) {
613+
newAddress = new Address.Community(
614+
groupId.substring(0, dotIndex),
615+
groupId.substring(dotIndex + 1)
616+
).getAddress();
617+
} else {
618+
Log.w(TAG, "Unable to decode group id from address: " + address);
619+
continue;
620+
}
621+
}
622+
} else {
623+
Log.w(TAG, "Thread not found for message id = " + messageId);
624+
// Thread not found? - this is strange but if we don't have threads these messages
625+
// aren't visible anyway.
626+
continue;
627+
}
628+
}
629+
} else {
630+
continue;
631+
}
632+
} catch (Throwable e) {
633+
Log.e(TAG, "Error while migrating address " + address, e);
634+
continue;
635+
}
636+
637+
if (!newAddress.equals(address)) {
638+
Log.i(TAG, "Migrating message ID=" + messageId);
639+
ContentValues contentValues = new ContentValues(1);
640+
contentValues.put(MmsSmsColumns.ADDRESS, newAddress);
641+
db.update(tableName, contentValues, ID + " = ?", new String[]{String.valueOf(messageId)});
642+
}
643+
}
644+
}
645+
646+
}
647+
581648
public static void migrateLegacyCommunityAddresses(final SQLiteDatabase db) {
582649
migrateLegacyCommunityAddresses(db, SmsDatabase.TABLE_NAME);
583650
migrateLegacyCommunityAddresses(db, MmsDatabase.TABLE_NAME);
584651
}
585652

653+
public static void migrateLegacyCommunityAddresses2(final SQLiteDatabase db) {
654+
migrateLegacyCommunityAddresses2(db, SmsDatabase.TABLE_NAME);
655+
migrateLegacyCommunityAddresses2(db, MmsDatabase.TABLE_NAME);
656+
}
657+
586658
private Cursor queryTables(String[] projection, String selection, String order, String limit) {
587659
String reactionsColumn = "json_group_array(json_object(" +
588660
"'" + ReactionDatabase.ROW_ID + "', " + ReactionDatabase.TABLE_NAME + "." + ReactionDatabase.ROW_ID + ", " +

app/src/main/java/org/thoughtcrime/securesms/database/ReactionDatabase.kt

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.database.Cursor
66
import kotlinx.coroutines.channels.BufferOverflow
77
import kotlinx.coroutines.flow.Flow
88
import kotlinx.coroutines.flow.MutableSharedFlow
9+
import net.zetetic.database.sqlcipher.SQLiteDatabase
910
import org.json.JSONArray
1011
import org.json.JSONException
1112
import org.session.libsignal.utilities.JsonUtil.SaneJSONObject
@@ -86,15 +87,15 @@ class ReactionDatabase(context: Context, helper: Provider<SQLCipherOpenHelper>)
8687
@JvmField
8788
val CREATE_MESSAGE_ID_MMS_INDEX = arrayOf("CREATE INDEX IF NOT EXISTS reaction_message_id_mms_idx ON $TABLE_NAME ($MESSAGE_ID, $IS_MMS)")
8889

89-
@JvmField
90-
val MIGRATE_REACTION_TABLE_TO_USE_RECIPIENT_SETTINGS = arrayOf(
90+
fun migrateToDropForeignConstraint(db: SQLiteDatabase) {
9191
// Create the new table with updated schema
92-
"""
92+
db.rawExecSQL(
93+
"""
9394
CREATE TABLE ${TABLE_NAME}_new (
9495
$ROW_ID INTEGER PRIMARY KEY,
9596
$MESSAGE_ID INTEGER NOT NULL,
9697
$IS_MMS INTEGER NOT NULL,
97-
$AUTHOR_ID INTEGER NOT NULL REFERENCES ${RecipientSettingsDatabase.TABLE_NAME} (${RecipientSettingsDatabase.COL_ADDRESS}) ON DELETE CASCADE,
98+
$AUTHOR_ID TEXT NOT NULL,
9899
$EMOJI TEXT NOT NULL,
99100
$SERVER_ID TEXT NOT NULL,
100101
$COUNT INTEGER NOT NULL,
@@ -103,27 +104,34 @@ class ReactionDatabase(context: Context, helper: Provider<SQLCipherOpenHelper>)
103104
$DATE_RECEIVED INTEGER NOT NULL,
104105
UNIQUE($MESSAGE_ID, $IS_MMS, $EMOJI, $AUTHOR_ID) ON CONFLICT REPLACE
105106
)
106-
""",
107+
"""
108+
)
107109

108110
// Copy data from the old table to the new table
109-
"""
110-
INSERT INTO ${TABLE_NAME}_new ($ROW_ID, $MESSAGE_ID, $IS_MMS, $AUTHOR_ID, $EMOJI, $SERVER_ID, $COUNT, $SORT_ID, $DATE_SENT, $DATE_RECEIVED)
111-
SELECT $ROW_ID, $MESSAGE_ID, $IS_MMS, ${AUTHOR_ID}, $EMOJI, $SERVER_ID, $COUNT, $SORT_ID, $DATE_SENT, $DATE_RECEIVED
111+
db.rawExecSQL(
112+
"""
113+
INSERT OR REPLACE INTO ${TABLE_NAME}_new ($ROW_ID, $MESSAGE_ID, $IS_MMS, $AUTHOR_ID, $EMOJI, $SERVER_ID, $COUNT, $SORT_ID, $DATE_SENT, $DATE_RECEIVED)
114+
SELECT $ROW_ID, $MESSAGE_ID, $IS_MMS, $AUTHOR_ID, $EMOJI, $SERVER_ID, $COUNT, $SORT_ID, $DATE_SENT, $DATE_RECEIVED
112115
FROM $TABLE_NAME
113-
""",
116+
""")
114117

115118
// Drop the old table and their triggers
116-
"DROP TABLE $TABLE_NAME",
117-
"DROP TRIGGER reactions_sms_delete",
118-
"DROP TRIGGER reactions_mms_delete",
119+
db.rawExecSQL("DROP TRIGGER IF EXISTS reactions_sms_delete")
120+
db.rawExecSQL("DROP TRIGGER IF EXISTS reactions_mms_delete")
121+
db.rawExecSQL("DROP TABLE IF EXISTS $TABLE_NAME")
119122

120123
// Rename the new table to the original table name
121-
"ALTER TABLE ${TABLE_NAME}_new RENAME TO $TABLE_NAME",
124+
db.rawExecSQL("ALTER TABLE ${TABLE_NAME}_new RENAME TO $TABLE_NAME")
122125

123126
// Add the necessary indexes and triggers to the new table
124-
*CREATE_INDEXS,
125-
*CREATE_REACTION_TRIGGERS,
126-
)
127+
for (indexCmd in CREATE_INDEXS) {
128+
db.rawExecSQL(indexCmd)
129+
}
130+
131+
for (triggerCmd in CREATE_REACTION_TRIGGERS) {
132+
db.rawExecSQL(triggerCmd)
133+
}
134+
}
127135

128136
private fun readReaction(cursor: Cursor): ReactionRecord {
129137
return ReactionRecord(

app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
9898
private static final int lokiV50 = 71;
9999
private static final int lokiV51 = 72;
100100
private static final int lokiV52 = 73;
101+
private static final int lokiV53 = 74;
101102

102103
// Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
103-
private static final int DATABASE_VERSION = lokiV52;
104+
private static final int DATABASE_VERSION = lokiV53;
104105
private static final int MIN_DATABASE_VERSION = lokiV7;
105106
public static final String DATABASE_NAME = "session.db";
106107

@@ -248,8 +249,8 @@ public void onCreate(SQLiteDatabase db) {
248249
db.execSQL(ThreadDatabase.ADD_SNIPPET_CONTENT_COLUMN);
249250

250251
executeStatements(db, RecipientSettingsDatabase.Companion.getMIGRATION_CREATE_TABLE());
252+
ReactionDatabase.Companion.migrateToDropForeignConstraint(db);
251253
db.execSQL(RecipientSettingsDatabase.MIGRATE_DROP_OLD_TABLE);
252-
executeStatements(db, ReactionDatabase.MIGRATE_REACTION_TABLE_TO_USE_RECIPIENT_SETTINGS);
253254
db.execSQL(BlindedIdMappingDatabase.DROP_TABLE_COMMAND);
254255
db.execSQL(ExpirationConfigurationDatabase.DROP_TABLE_COMMAND);
255256
db.execSQL(SessionContactDatabase.getDropTableCommand());
@@ -570,8 +571,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
570571

571572
executeStatements(db, RecipientSettingsDatabase.Companion.getMIGRATION_CREATE_TABLE());
572573
db.execSQL(RecipientSettingsDatabase.MIGRATE_MOVE_DATA_FROM_OLD_TABLE);
574+
ReactionDatabase.Companion.migrateToDropForeignConstraint(db);
573575
db.execSQL(RecipientSettingsDatabase.MIGRATE_DROP_OLD_TABLE);
574-
executeStatements(db, ReactionDatabase.MIGRATE_REACTION_TABLE_TO_USE_RECIPIENT_SETTINGS);
575576
db.execSQL(BlindedIdMappingDatabase.DROP_TABLE_COMMAND);
576577
db.execSQL(ExpirationConfigurationDatabase.DROP_TABLE_COMMAND);
577578
db.execSQL(SessionContactDatabase.getDropTableCommand());
@@ -582,6 +583,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
582583
executeStatements(db, CommunityDatabase.Companion.getMIGRATE_DROP_OLD_TABLES());
583584
}
584585

586+
if (oldVersion < lokiV53) {
587+
MmsSmsDatabase.migrateLegacyCommunityAddresses2(db);
588+
}
589+
585590
db.setTransactionSuccessful();
586591
} finally {
587592
db.endTransaction();

app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.filterNotNull
1313
import kotlinx.coroutines.flow.first
1414
import kotlinx.coroutines.flow.flatMapLatest
1515
import kotlinx.coroutines.flow.map
16-
import kotlinx.coroutines.flow.mapLatest
1716
import kotlinx.coroutines.flow.merge
1817
import kotlinx.coroutines.flow.onStart
1918
import kotlinx.coroutines.flow.stateIn
@@ -226,12 +225,13 @@ class DefaultConversationRepository @Inject constructor(
226225
it == TextSecurePreferences.SET_FORCE_POST_PRO
227226
}
228227
).debounce(500)
229-
.onStart { emit(Unit) }
230-
.mapLatest {
231-
withContext(Dispatchers.Default) {
232-
threadDb.getThreads(allAddresses)
233-
}
234-
}
228+
.onStart { emit(allAddresses) }
229+
.map { allAddresses }
230+
}
231+
.map { addresses ->
232+
withContext(Dispatchers.Default) {
233+
threadDb.getThreads(addresses)
234+
}
235235
}
236236
}
237237

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ kotlinVersion = "2.2.20"
2929
kryoVersion = "5.6.2"
3030
kspVersion = "2.2.10-2.0.2"
3131
legacySupportV13Version = "1.0.0"
32-
libsessionUtilAndroidVersion = "1.0.8"
32+
libsessionUtilAndroidVersion = "1.0.8-1-g27817b4"
3333
media3ExoplayerVersion = "1.8.0"
3434
mockitoCoreVersion = "5.20.0"
3535
navVersion = "2.9.4"

0 commit comments

Comments
 (0)