Skip to content

Commit ec12878

Browse files
committed
Merge branch 'dev' into feature/pro-settings-non-originating
2 parents f1e2ccb + f3414f1 commit ec12878

File tree

122 files changed

+1911
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1911
-464
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 = 417
30-
val canonicalVersionName = "1.27.0"
29+
val canonicalVersionCode = 419
30+
val canonicalVersionName = "1.27.1"
3131

3232
val postFixSize = 10
3333
val abiPostFix = mapOf(

app/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.session.libsession.messaging
22

33
import android.content.Context
44
import dagger.hilt.android.qualifiers.ApplicationContext
5+
import kotlinx.serialization.json.Json
56
import org.session.libsession.database.MessageDataProvider
67
import org.session.libsession.database.StorageProtocol
78
import org.session.libsession.messaging.groups.GroupManagerV2
@@ -34,6 +35,7 @@ class MessagingModuleConfiguration @Inject constructor(
3435
val avatarUtils: AvatarUtils,
3536
val proStatusManager: ProStatusManager,
3637
val messageSendJobFactory: MessageSendJob.Factory,
38+
val json: Json,
3739
) {
3840

3941
companion object {

app/src/main/java/org/session/libsession/messaging/messages/ProfileUpdateHandler.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ProfileUpdateHandler @Inject constructor(
5454
// If the sender has standard address (either as unblinded, or as is), we will check if
5555
// they are a contact and update their contact information accordingly.
5656
val standardSender = unblinded ?: (senderAddress as? Address.Standard)
57-
if (standardSender != null && (updates.name != null || updates.pic != null || updates.profileUpdateTime != null)) {
57+
if (standardSender != null && (!updates.name.isNullOrBlank() || updates.pic != null)) {
5858
configFactory.withMutableUserConfigs { configs ->
5959
configs.contacts.updateContact(standardSender) {
6060
if (shouldUpdateProfile(
@@ -96,6 +96,10 @@ class ProfileUpdateHandler @Inject constructor(
9696
c.name = updates.name
9797
}
9898

99+
if (updates.profileUpdateTime != null) {
100+
c.profileUpdatedEpochSeconds = updates.profileUpdateTime.toEpochSeconds()
101+
}
102+
99103
configs.contacts.setBlinded(c)
100104
}
101105
}
@@ -136,7 +140,8 @@ class ProfileUpdateHandler @Inject constructor(
136140
lastUpdated: Instant?,
137141
newUpdateTime: Instant?
138142
): Boolean {
139-
return (lastUpdated == null || newUpdateTime == null) || (newUpdateTime > lastUpdated)
143+
return (lastUpdated == null && newUpdateTime == null) ||
144+
(newUpdateTime != null && lastUpdated != null && newUpdateTime > lastUpdated)
140145
}
141146

142147
class Updates private constructor(

app/src/main/java/org/session/libsession/messaging/messages/visible/Profile.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.session.libsignal.protos.SignalServiceProtos.DataMessage.LokiProfile
77
import org.thoughtcrime.securesms.util.DateUtils.Companion.asEpochMillis
88
import org.thoughtcrime.securesms.util.DateUtils.Companion.asEpochSeconds
99
import org.thoughtcrime.securesms.util.DateUtils.Companion.millsToInstant
10+
import org.thoughtcrime.securesms.util.DateUtils.Companion.secondsToInstant
11+
import org.thoughtcrime.securesms.util.DateUtils.Companion.toEpochSeconds
1012
import java.time.Instant
1113
import java.time.ZonedDateTime
1214

@@ -25,9 +27,9 @@ class Profile(
2527
val displayName = profileProto.displayName ?: return null
2628
val profileKey = proto.profileKey
2729
val profilePictureURL = profileProto.profilePicture
28-
val profileUpdated = profileProto.lastProfileUpdateMs.takeIf {
29-
profileProto.hasLastProfileUpdateMs()
30-
}?.millsToInstant()
30+
val profileUpdated = profileProto.lastProfileUpdateSeconds
31+
.takeIf { profileProto.hasLastProfileUpdateSeconds() }
32+
?.secondsToInstant()
3133

3234
if (profileKey != null && profilePictureURL != null) {
3335
return Profile(displayName, profileKey.toByteArray(), profilePictureURL, profileUpdated = profileUpdated)
@@ -48,7 +50,7 @@ class Profile(
4850
profileProto.displayName = displayName
4951
profileKey?.let { dataMessageProto.profileKey = ByteString.copyFrom(it) }
5052
profilePictureURL?.let { profileProto.profilePicture = it }
51-
profileUpdated?.let { profileProto.lastProfileUpdateMs = it.toEpochMilli() }
53+
profileUpdated?.let { profileProto.lastProfileUpdateSeconds = it.toEpochSeconds() }
5254
// Build
5355
try {
5456
dataMessageProto.profile = profileProto.build()

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

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import kotlinx.coroutines.GlobalScope
1010
import kotlinx.coroutines.flow.MutableSharedFlow
1111
import kotlinx.serialization.SerialName
1212
import kotlinx.serialization.Serializable
13+
import kotlinx.serialization.json.decodeFromStream
1314
import network.loki.messenger.libsession_util.ED25519
1415
import network.loki.messenger.libsession_util.Hash
1516
import network.loki.messenger.libsession_util.util.BlindKeyAPI
@@ -25,7 +26,6 @@ import org.session.libsession.snode.OnionResponse
2526
import org.session.libsession.snode.SnodeAPI
2627
import org.session.libsession.snode.utilities.asyncPromise
2728
import org.session.libsession.snode.utilities.await
28-
import org.session.libsession.utilities.TextSecurePreferences
2929
import org.session.libsignal.utilities.AccountId
3030
import org.session.libsignal.utilities.Base64.encodeBytes
3131
import org.session.libsignal.utilities.ByteArraySlice
@@ -46,15 +46,6 @@ import kotlin.collections.set
4646

4747
object OpenGroupApi {
4848
val defaultRooms = MutableSharedFlow<List<DefaultGroup>>(replay = 1)
49-
private val hasPerformedInitialPoll = mutableMapOf<String, Boolean>()
50-
private var hasUpdatedLastOpenDate = false
51-
private val timeSinceLastOpen by lazy {
52-
val context = MessagingModuleConfiguration.shared.context
53-
val lastOpenDate = TextSecurePreferences.getLastOpenTimeDate(context)
54-
val now = System.currentTimeMillis()
55-
now - lastOpenDate
56-
}
57-
5849
const val defaultServerPublicKey = "a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238"
5950
const val legacyServerIP = "116.203.70.33"
6051
const val legacyDefaultServer = "http://116.203.70.33" // TODO: migrate all references to use new value
@@ -302,8 +293,12 @@ object OpenGroupApi {
302293
}
303294
}
304295

305-
private fun getResponseBodyJson(request: Request, signRequest: Boolean = true): Promise<Map<*, *>, Exception> {
306-
return send(request, signRequest = signRequest).map {
296+
private fun getResponseBodyJson(
297+
request: Request,
298+
signRequest: Boolean = true,
299+
serverPubKeyHex: String? = null
300+
): Promise<Map<*, *>, Exception> {
301+
return send(request, signRequest = signRequest, serverPubKeyHex = serverPubKeyHex).map {
307302
JsonUtil.fromJson(it.body, Map::class.java)
308303
}
309304
}
@@ -316,7 +311,10 @@ object OpenGroupApi {
316311
return caps
317312
}
318313

319-
val fetched = getCapabilities(server).await()
314+
val fetched = getCapabilities(server,
315+
serverPubKeyHex = defaultServerPublicKey.takeIf { server == defaultServer }
316+
).await()
317+
320318
storage.setServerCapabilities(server, fetched.capabilities)
321319
return fetched.capabilities
322320
}
@@ -436,14 +434,15 @@ object OpenGroupApi {
436434
roomID: String,
437435
imageId: String,
438436
signRequest: Boolean = true,
437+
serverPubKeyHex: String? = null,
439438
): Promise<ByteArraySlice, Exception> {
440439
val request = Request(
441440
verb = GET,
442441
room = roomID,
443442
server = server,
444443
endpoint = Endpoint.RoomFileIndividual(roomID, imageId)
445444
)
446-
return getResponseBody(request, signRequest = signRequest)
445+
return getResponseBody(request, signRequest = signRequest, serverPubKeyHex = serverPubKeyHex)
447446
}
448447

449448
// region Upload/Download
@@ -722,7 +721,13 @@ object OpenGroupApi {
722721
}
723722
}
724723
val images = groups.associate { group ->
725-
group.token to group.imageId?.let { downloadOpenGroupProfilePicture(defaultServer, group.token, it, signRequest = false) }
724+
group.token to group.imageId?.let { downloadOpenGroupProfilePicture(
725+
server = defaultServer,
726+
roomID = group.token,
727+
imageId = it,
728+
signRequest = false,
729+
serverPubKeyHex = defaultServerPublicKey,
730+
) }
726731
}
727732
groups.map { group ->
728733
val image = try {
@@ -736,30 +741,21 @@ object OpenGroupApi {
736741
}
737742
}
738743

739-
fun getRoomInfo(roomToken: String, server: String): Promise<RoomInfoDetails, Exception> {
740-
val request = Request(
741-
verb = GET,
742-
room = null,
743-
server = server,
744-
endpoint = Endpoint.Room(roomToken)
745-
)
746-
return getResponseBody(request).map { response ->
747-
JsonUtil.fromJson(response, RoomInfoDetails::class.java)
748-
}
749-
}
750-
751744
private fun getAllRooms(): Promise<List<RoomInfoDetails>, Exception> {
752745
val request = Request(
753746
verb = GET,
754747
room = null,
755748
server = defaultServer,
756749
endpoint = Endpoint.Rooms
757750
)
758-
return getResponseBody(request, signRequest = false).map { response ->
759-
val rawRooms = JsonUtil.fromJson(response, List::class.java) ?: throw Error.ParsingFailed
760-
rawRooms.mapNotNull {
761-
JsonUtil.fromJson(JsonUtil.toJson(it), RoomInfoDetails::class.java)
762-
}
751+
return getResponseBody(
752+
request = request,
753+
signRequest = false,
754+
serverPubKeyHex = defaultServerPublicKey
755+
).map { response ->
756+
MessagingModuleConfiguration.shared.json
757+
.decodeFromStream<Array<RoomInfoDetails>>(response.inputStream())
758+
.toList()
763759
}
764760
}
765761

@@ -770,35 +766,6 @@ object OpenGroupApi {
770766
}
771767
}
772768

773-
fun getCapabilitiesAndRoomInfo(
774-
room: String,
775-
server: String
776-
): Promise<Pair<Capabilities, RoomInfoDetails>, Exception> {
777-
val requests = mutableListOf<BatchRequestInfo<*>>(
778-
BatchRequestInfo(
779-
request = BatchRequest(
780-
method = GET,
781-
path = "/capabilities"
782-
),
783-
endpoint = Endpoint.Capabilities,
784-
responseType = object : TypeReference<Capabilities>(){}
785-
),
786-
BatchRequestInfo(
787-
request = BatchRequest(
788-
method = GET,
789-
path = "/room/$room"
790-
),
791-
endpoint = Endpoint.Room(room),
792-
responseType = object : TypeReference<RoomInfoDetails>(){}
793-
)
794-
)
795-
return sequentialBatch(server, requests).map {
796-
val capabilities = it.firstOrNull()?.body as? Capabilities ?: throw Error.ParsingFailed
797-
val roomInfo = it.lastOrNull()?.body as? RoomInfoDetails ?: throw Error.ParsingFailed
798-
capabilities to roomInfo
799-
}
800-
}
801-
802769
fun sendDirectMessage(message: String, blindedAccountId: String, server: String): Promise<DirectMessage, Exception> {
803770
val request = Request(
804771
verb = POST,

app/src/main/java/org/session/libsession/messaging/sending_receiving/MessageReceiver.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ object MessageReceiver {
165165
CallMessage.fromProto(proto) ?:
166166
GroupUpdated.fromProto(proto) ?:
167167
VisibleMessage.fromProto(proto) ?: throw Error.UnknownMessage
168-
// Don't process the envelope any further if the sender is blocked
169-
if (isBlocked(sender!!) && message.shouldDiscardIfBlocked()) {
168+
169+
// Don't process the envelope any further if the sender is blocked (still visible in community chats)
170+
if (!isOpenGroupMessage && isBlocked(sender!!) && message.shouldDiscardIfBlocked()) {
170171
throw Error.SenderBlocked
171172
}
172173
val isUserBlindedSender = sender == openGroupPublicKey?.let {

app/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class ReceivedMessageHandler @Inject constructor(
444444
picKey = message.profile?.profileKey,
445445
blocksCommunityMessageRequests = message.blocksMessageRequests,
446446
proStatus = null,
447-
profileUpdateTime = null,
447+
profileUpdateTime = message.profile?.profileUpdated,
448448
)
449449

450450
if (updates != null) {

app/src/main/java/org/session/libsession/utilities/StringSubKeys.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ object StringSubstitutionConstants {
5050
const val APP_PRO_KEY: StringSubKey = "app_pro"
5151
const val PRO_KEY: StringSubKey = "pro"
5252
const val CURRENT_PLAN_KEY: StringSubKey = "current_plan"
53-
const val SELECTED_PLAN_KEY: StringSubKey = "selected_plan"
53+
const val SELECTED_PLAN_KEY: StringSubKey = "selected_plan"
5454
const val PLATFORM_STORE_KEY: StringSubKey = "platform_store"
5555
const val PLATFORM_ACCOUNT_KEY: StringSubKey = "platform_account"
5656
const val MONTHLY_PRICE_KEY: StringSubKey = "monthly_price"
5757
const val PRICE_KEY: StringSubKey = "price"
5858
const val PERCENT_KEY: StringSubKey = "percent"
59-
const val DEVICE_TYPE_KEY: StringSubKey = "device_type"
59+
const val DEVICE_TYPE_KEY: StringSubKey = "device_type"
60+
const val SESSION_FOUNDATION_KEY: StringSubKey = "session_foundation"
6061
}

app/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion._events
4747
import org.session.libsignal.utilities.Log
4848
import org.thoughtcrime.securesms.debugmenu.DebugMenuViewModel
4949
import org.thoughtcrime.securesms.pro.ProStatusManager
50-
import org.thoughtcrime.securesms.util.DateUtils.Companion.secondsToInstant
51-
import org.thoughtcrime.securesms.util.DateUtils.Companion.toEpochSeconds
5250
import java.io.IOException
53-
import java.time.Instant
5451
import java.time.ZonedDateTime
5552
import java.util.Arrays
5653
import java.util.Date
@@ -231,7 +228,6 @@ interface TextSecurePreferences {
231228

232229
var inAppReviewState: String?
233230

234-
var lastProfileUpdated: Instant?
235231

236232
companion object {
237233
val TAG = TextSecurePreferences::class.simpleName
@@ -304,7 +300,6 @@ interface TextSecurePreferences {
304300
const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
305301
val IS_PUSH_ENABLED get() = "pref_is_using_fcm$pushSuffix"
306302
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
307-
const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
308303
const val PROFILE_PIC_EXPIRY = "profile_pic_expiry"
309304
const val LAST_OPEN_DATE = "pref_last_open_date"
310305
const val HAS_HIDDEN_MESSAGE_REQUESTS = "pref_message_requests_hidden"
@@ -873,17 +868,6 @@ interface TextSecurePreferences {
873868
fun setLastSnodePoolRefreshDate(context: Context?, date: Date) {
874869
setLongPreference(context!!, "last_snode_pool_refresh_date", date.time)
875870
}
876-
877-
@JvmStatic
878-
fun shouldUpdateProfile(context: Context, profileUpdateTime: Long): Boolean {
879-
return profileUpdateTime > getLongPreference(context, LAST_PROFILE_UPDATE_TIME, 0)
880-
}
881-
882-
@JvmStatic
883-
fun setLastProfileUpdateTime(context: Context, profileUpdateTime: Long) {
884-
setLongPreference(context, LAST_PROFILE_UPDATE_TIME, profileUpdateTime)
885-
}
886-
887871
fun getLastOpenTimeDate(context: Context): Long {
888872
return getLongPreference(context, LAST_OPEN_DATE, 0)
889873
}
@@ -1740,13 +1724,6 @@ class AppTextSecurePreferences @Inject constructor(
17401724
setStringPreference(TextSecurePreferences.DEPRECATING_START_TIME_OVERRIDE, value.toString())
17411725
}
17421726
}
1743-
1744-
override var lastProfileUpdated: Instant?
1745-
get() = getLongPreference(TextSecurePreferences.LAST_PROFILE_UPDATE_TIME, 0).secondsToInstant()
1746-
set(value) {
1747-
setLongPreference(TextSecurePreferences.LAST_PROFILE_UPDATE_TIME, value?.toEpochSeconds() ?: 0L)
1748-
}
1749-
17501727
override fun getDebugMessageFeatures(): Set<ProStatusManager.MessageProFeature> {
17511728
return getStringSetPreference( TextSecurePreferences.DEBUG_MESSAGE_FEATURES, emptySet())
17521729
?.map { ProStatusManager.MessageProFeature.valueOf(it) }?.toSet() ?: emptySet()

0 commit comments

Comments
 (0)