Skip to content

Commit 55e93c8

Browse files
Updated to use libsession's lastProfileUpdated (#1520)
1 parent abd2083 commit 55e93c8

File tree

10 files changed

+31
-45
lines changed

10 files changed

+31
-45
lines changed

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/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/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()

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class AvatarUploadManager @Inject constructor(
9797
Log.d(TAG, "Avatar expired, re-uploading")
9898
uploadAvatar(
9999
pictureData = localEncryptedFileInputStreamFactory.create(localFile)
100-
.use { it.readBytes() }
100+
.use { it.readBytes() },
101+
isReupload = true,
101102
)
102103
}
103104
} else {
@@ -137,7 +138,8 @@ class AvatarUploadManager @Inject constructor(
137138

138139

139140
suspend fun uploadAvatar(
140-
pictureData: ByteArray
141+
pictureData: ByteArray,
142+
isReupload: Boolean, // Whether this is a re-upload of an existing avatar
141143
) = withContext(Dispatchers.IO) {
142144
check(pictureData.isNotEmpty()) {
143145
"Should not upload an empty avatar"
@@ -187,7 +189,13 @@ class AvatarUploadManager @Inject constructor(
187189
// Now that we have the file both locally and remotely, we can update the user profile
188190
val oldPic = configFactory.withMutableUserConfigs {
189191
val result = it.userProfile.getPic()
190-
it.userProfile.setPic(remoteFile.toUserPic())
192+
val userPic = remoteFile.toUserPic()
193+
if (isReupload) {
194+
it.userProfile.setReuploadedPic(userPic)
195+
} else {
196+
it.userProfile.setPic(userPic)
197+
}
198+
191199
result.toRemoteFile()
192200
}
193201

@@ -199,8 +207,6 @@ class AvatarUploadManager @Inject constructor(
199207
oldFile.delete()
200208
}
201209
}
202-
203-
prefs.lastProfileUpdated = Instant.now()
204210
}
205211

206212
companion object {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ import org.thoughtcrime.securesms.database.model.ReactionRecord
7070
import org.thoughtcrime.securesms.dependencies.ConfigFactory
7171
import org.thoughtcrime.securesms.groups.OpenGroupManager
7272
import org.thoughtcrime.securesms.mms.PartAuthority
73+
import org.thoughtcrime.securesms.util.DateUtils.Companion.secondsToInstant
7374
import org.thoughtcrime.securesms.util.FilenameUtils
7475
import org.thoughtcrime.securesms.util.SessionMetaProtocol
76+
import java.time.Instant
7577
import javax.inject.Inject
7678
import javax.inject.Provider
7779
import javax.inject.Singleton
@@ -122,7 +124,7 @@ open class Storage @Inject constructor(
122124
displayName = configs.userProfile.getName(),
123125
profilePictureURL = pic.url.takeIf { it.isNotBlank() },
124126
profileKey = pic.key.data.takeIf { pic.url.isNotBlank() },
125-
profileUpdated = preferences.lastProfileUpdated,
127+
profileUpdated = configs.userProfile.getProfileUpdatedSeconds().secondsToInstant(),
126128
)
127129
}
128130
}

app/src/main/java/org/thoughtcrime/securesms/preferences/PrivacySettingsPreferenceFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class PrivacySettingsPreferenceFragment : CorrectedPreferenceFragment() {
6969
it.userProfile.setCommunityMessageRequests(value)
7070
}
7171

72-
textSecurePreferences.lastProfileUpdated = Instant.now()
7372
return
7473
}
7574
super.putBoolean(key, value)

app/src/main/java/org/thoughtcrime/securesms/preferences/SettingsViewModel.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import org.thoughtcrime.securesms.util.NetworkConnectivity
5656
import org.thoughtcrime.securesms.util.mapToStateFlow
5757
import java.io.File
5858
import java.io.IOException
59-
import java.time.Instant
6059
import javax.inject.Inject
6160

6261
@OptIn(ExperimentalCoroutinesApi::class)
@@ -312,12 +311,10 @@ class SettingsViewModel @Inject constructor(
312311
it.userProfile.setPic(UserPic.DEFAULT)
313312
}
314313

315-
prefs.lastProfileUpdated = Instant.now()
316-
317314
// update dialog state
318315
_uiState.update { it.copy(avatarDialogState = AvatarDialogState.NoAvatar) }
319316
} else {
320-
avatarUploadManager.uploadAvatar(profilePicture)
317+
avatarUploadManager.uploadAvatar(profilePicture, isReupload = false)
321318

322319
// We'll have to refetch the recipient to get the new avatar
323320
val selfRecipient = recipientRepository.getSelf()
@@ -444,8 +441,6 @@ class SettingsViewModel @Inject constructor(
444441
configFactory.withMutableUserConfigs {
445442
it.userProfile.setName(name)
446443
}
447-
448-
prefs.lastProfileUpdated = Instant.now()
449444
}
450445

451446
fun onCommand(command: Commands) {

app/src/main/proto/SignalService.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ message DataMessage {
122122
message LokiProfile {
123123
optional string displayName = 1;
124124
optional string profilePicture = 2;
125-
optional uint64 lastProfileUpdateMs = 3;
125+
optional uint64 lastProfileUpdateSeconds = 3;
126126
}
127127

128128
message OpenGroupInvitation {

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.10"
2929
kryoVersion = "5.6.2"
3030
kspVersion = "2.2.10-2.0.2"
3131
legacySupportV13Version = "1.0.0"
32-
libsessionUtilAndroidVersion = "1.0.7"
32+
libsessionUtilAndroidVersion = "1.0.7-1-g5481c06"
3333
media3ExoplayerVersion = "1.8.0"
3434
mockitoCoreVersion = "5.19.0"
3535
navVersion = "2.9.3"

0 commit comments

Comments
 (0)