diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt index 08e706c3e4..54ae24c77a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt @@ -57,6 +57,9 @@ interface Session : */ val sessionParams: SessionParams + /** + * Useful shortcut to get access to the userId + */ val myUserId: String get() = sessionParams.credentials.userId diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt index 7cc73ceb37..0a87a7cef4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/SessionManager.kt @@ -58,7 +58,7 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M .factory() .create(matrixComponent, sessionParams) .also { - sessionComponents[sessionParams.credentials.userId] = it + sessionComponents[userId] = it } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 6a1cda534a..a84e0193bb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -94,11 +94,11 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se } override fun requireBackgroundSync() { - SyncWorker.requireBackgroundSync(context, sessionParams.credentials.userId) + SyncWorker.requireBackgroundSync(context, myUserId) } override fun startAutomaticBackgroundSync(repeatDelay: Long) { - SyncWorker.automaticallyBackgroundSync(context, sessionParams.credentials.userId, 0, repeatDelay) + SyncWorker.automaticallyBackgroundSync(context, myUserId, 0, repeatDelay) } override fun stopAnyBackgroundSync() { diff --git a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt index 6c9f16c67e..5a4aa36c74 100755 --- a/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotx/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -199,7 +199,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { if (eventType == null) { //Just add a generic unknown event val simpleNotifiableEvent = SimpleNotifiableEvent( - session.sessionParams.credentials.userId, + session.myUserId, eventId, true, //It's an issue in this case, all event will bing even if expected to be silent. title = getString(R.string.notification_unknown_new_event), @@ -238,7 +238,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { } notifiableEvent.isPushGatewayEvent = true - notifiableEvent.matrixID = session.sessionParams.credentials.userId + notifiableEvent.matrixID = session.myUserId notificationDrawerManager.onNotifiableEventReceived(notifiableEvent) notificationDrawerManager.refreshNotificationDrawer() } diff --git a/vector/src/main/java/im/vector/riotx/core/preference/UserAvatarPreference.kt b/vector/src/main/java/im/vector/riotx/core/preference/UserAvatarPreference.kt index e5e8451450..b0747e7e86 100755 --- a/vector/src/main/java/im/vector/riotx/core/preference/UserAvatarPreference.kt +++ b/vector/src/main/java/im/vector/riotx/core/preference/UserAvatarPreference.kt @@ -58,10 +58,10 @@ open class UserAvatarPreference : Preference { open fun refreshAvatar() { val session = mSession ?: return val view = mAvatarView ?: return - session.getUser(session.sessionParams.credentials.userId)?.let { + session.getUser(session.myUserId)?.let { avatarRenderer.render(it, view) } ?: run { - avatarRenderer.render(null, session.sessionParams.credentials.userId, null, view) + avatarRenderer.render(null, session.myUserId, null, view) } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyViewModel.kt index c4da3038e0..1d7a6a3515 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyViewModel.kt @@ -21,8 +21,8 @@ import androidx.lifecycle.ViewModel import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.listeners.StepProgressListener import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService -import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult +import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.riotx.R import im.vector.riotx.core.platform.WaitingViewData import im.vector.riotx.core.ui.views.KeysBackupBanner @@ -57,7 +57,7 @@ class KeysBackupRestoreFromKeyViewModel @Inject constructor() : ViewModel() { keysBackup.restoreKeysWithRecoveryKey(keysVersionResult, recoveryKey, null, - session.sessionParams.credentials.userId, + session.myUserId, object : StepProgressListener { override fun onStepProgress(step: StepProgressListener.Step) { when (step) { diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt index 3a4a952892..45995434ea 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt @@ -21,8 +21,8 @@ import androidx.lifecycle.ViewModel import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.listeners.StepProgressListener import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService -import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.matrix.android.internal.crypto.keysbackup.model.rest.KeysVersionResult +import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult import im.vector.riotx.R import im.vector.riotx.core.platform.WaitingViewData import im.vector.riotx.core.ui.views.KeysBackupBanner @@ -58,7 +58,7 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor() : ViewModel keysBackup.restoreKeyBackupWithPassword(keysVersionResult, passphrase.value!!, null, - sharedViewModel.session.sessionParams.credentials.userId, + sharedViewModel.session.myUserId, object : StepProgressListener { override fun onStepProgress(step: StepProgressListener.Step) { when (step) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt index 832e8a5e4f..ac4cc08dfc 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDrawerFragment.kt @@ -52,7 +52,7 @@ class HomeDrawerFragment : VectorBaseFragment() { replaceChildFragment(groupListFragment, R.id.homeDrawerGroupListContainer) } - session.observeUser(session.sessionParams.credentials.userId).observeK(this) { user -> + session.observeUser(session.myUserId).observeK(this) { user -> if (user != null) { avatarRenderer.render(user.avatarUrl, user.userId, user.displayName, homeDrawerHeaderAvatarView) homeDrawerUsernameView.text = user.displayName diff --git a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt index 229652b0a5..513379bdcf 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/group/GroupListViewModel.kt @@ -93,7 +93,7 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro .rx() .liveGroupSummaries() .map { - val myUser = session.getUser(session.sessionParams.credentials.userId) + val myUser = session.getUser(session.myUserId) val allCommunityGroup = GroupSummary( groupId = ALL_COMMUNITIES_GROUP_ID, displayName = stringProvider.getString(R.string.group_all_communities), diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 943b6165e0..23ff7a3124 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -486,7 +486,7 @@ class RoomDetailFragment : timelineEventController.setTimeline(state.timeline, state.eventId) inviteView.visibility = View.GONE - val uid = session.sessionParams.credentials.userId + val uid = session.myUserId val meMember = session.getRoom(state.roomId)?.getRoomMember(uid) avatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composerLayout.composerAvatarImageView) @@ -780,7 +780,7 @@ class RoomDetailFragment : if (null != text) { // var vibrate = false - val myDisplayName = session.getUser(session.sessionParams.credentials.userId)?.displayName + val myDisplayName = session.getUser(session.myUserId)?.displayName if (TextUtils.equals(myDisplayName, text)) { // current user if (TextUtils.isEmpty(composerLayout.composerEditText.text)) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 36b989fe31..fe83002f12 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -39,7 +39,6 @@ import im.vector.matrix.android.api.session.room.model.message.getFileUrl import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt import im.vector.matrix.rx.rx -import im.vector.riotx.R import im.vector.riotx.core.intent.getFilenameFromUri import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.resources.UserPreferencesProvider @@ -52,8 +51,6 @@ import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer import timber.log.Timber import java.io.File -import java.text.SimpleDateFormat -import java.util.* import java.util.concurrent.TimeUnit @@ -347,7 +344,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleUndoReact(action: RoomDetailActions.UndoReaction) { - room.undoReaction(action.key, action.targetEventId, session.sessionParams.credentials.userId) + room.undoReaction(action.key, action.targetEventId, session.myUserId) } @@ -355,7 +352,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro if (action.add) { room.sendReaction(action.selectedReaction, action.targetEventId) } else { - room.undoReaction(action.selectedReaction, action.targetEventId, session.sessionParams.credentials.userId) + room.undoReaction(action.selectedReaction, action.targetEventId, session.myUserId) } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index b49731d9d4..dc7c926d08 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -139,11 +139,11 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M this.add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) } - if (canEdit(event, session.sessionParams.credentials.userId)) { + if (canEdit(event, session.myUserId)) { this.add(SimpleAction(ACTION_EDIT, R.string.edit, R.drawable.ic_edit, eventId)) } - if (canRedact(event, session.sessionParams.credentials.userId)) { + if (canRedact(event, session.myUserId)) { this.add(SimpleAction(ACTION_DELETE, R.string.delete, R.drawable.ic_delete, eventId)) } @@ -183,7 +183,7 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M } this.add(SimpleAction(ACTION_COPY_PERMALINK, R.string.permalink, R.drawable.ic_permalink, event.root.eventId)) - if (session.sessionParams.credentials.userId != event.root.senderId && event.root.getClearType() == EventType.MESSAGE) { + if (session.myUserId != event.root.senderId && event.root.getClearType() == EventType.MESSAGE) { //not sent by me this.add(SimpleAction(ACTION_FLAG, R.string.report_content, R.drawable.ic_flag, event.root.eventId)) } diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt index a98c7535fc..6650bf0d0d 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotifiableEventResolver.kt @@ -70,7 +70,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St val bodyPreview = event.type return SimpleNotifiableEvent( - session.sessionParams.credentials.userId, + session.myUserId, eventId = event.eventId!!, noisy = false,//will be updated timestamp = event.originServerTs ?: System.currentTimeMillis(), @@ -109,7 +109,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St roomId = event.root.roomId!!, roomName = roomName) - notifiableEvent.matrixID = session.sessionParams.credentials.userId + notifiableEvent.matrixID = session.myUserId return notifiableEvent } else { if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) { @@ -145,7 +145,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St roomName = roomName, roomIsDirect = room.roomSummary()?.isDirect ?: false) - notifiableEvent.matrixID = session.sessionParams.credentials.userId + notifiableEvent.matrixID = session.myUserId notifiableEvent.soundName = null // Get the avatars URL @@ -175,7 +175,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St val body = noticeEventFormatter.format(event, dName) ?: stringProvider.getString(R.string.notification_new_invitation) return InviteNotifiableEvent( - session.sessionParams.credentials.userId, + session.myUserId, eventId = event.eventId!!, roomId = roomId, timestamp = event.originServerTs ?: 0, diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt index 17a1b222a7..ac6068b08d 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationBroadcastReceiver.kt @@ -121,9 +121,9 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { UUID.randomUUID().toString(), false, System.currentTimeMillis(), - session.getUser(session.sessionParams.credentials.userId)?.displayName + session.getUser(session.myUserId)?.displayName ?: context?.getString(R.string.notification_sender_me), - session.sessionParams.credentials.userId, + session.myUserId, message, room.roomId, room.roomSummary()?.displayName ?: room.roomId, diff --git a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt index 67eef393dc..45317da570 100644 --- a/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/riotx/features/notifications/NotificationDrawerManager.kt @@ -181,9 +181,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context val session = activeSessionHolder.getSafeActiveSession() ?: return - val user = session.getUser(session.sessionParams.credentials.userId) + val user = session.getUser(session.myUserId) // myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash - val myUserDisplayName = user?.displayName?.takeIf { it.isNotBlank() } ?: session.sessionParams.credentials.userId + val myUserDisplayName = user?.displayName?.takeIf { it.isNotBlank() } ?: session.myUserId val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(user?.avatarUrl, avatarSize, avatarSize, ContentUrlResolver.ThumbnailMethod.SCALE) synchronized(eventList) { diff --git a/vector/src/main/java/im/vector/riotx/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/riotx/features/rageshake/BugReporter.kt index 774bdfb9d9..d34d2be493 100755 --- a/vector/src/main/java/im/vector/riotx/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/riotx/features/rageshake/BugReporter.kt @@ -204,7 +204,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes var olmVersion = "undefined" activeSessionHolder.getSafeActiveSession()?.let { session -> - userId = session.sessionParams.credentials.userId + userId = session.myUserId deviceId = session.sessionParams.credentials.deviceId ?: "undefined" olmVersion = session.getCryptoVersion(context, true) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt index 7fd605629b..5db218c3e4 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsActivity.kt @@ -79,9 +79,9 @@ class VectorSettingsActivity : VectorBaseActivity(), var oFragment: Fragment? = null if (VectorPreferences.SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY == pref?.key) { - oFragment = VectorSettingsNotificationsTroubleshootFragment.newInstance(session.sessionParams.credentials.userId) + oFragment = VectorSettingsNotificationsTroubleshootFragment.newInstance(session.myUserId) } else if (VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY == pref?.key) { - oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.sessionParams.credentials.userId) + oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.myUserId) } else { try { pref?.fragment?.let { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt index 63246b2560..2bec8cf103 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt @@ -95,7 +95,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { // Display name mDisplayNamePreference.let { - it.summary = session.getUser(session.sessionParams.credentials.userId)?.displayName ?: "" + it.summary = session.getUser(session.myUserId)?.displayName ?: "" it.text = it.summary.toString() it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> onDisplayNameClick(newValue?.let { (it as String).trim() }) @@ -148,7 +148,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { // user account findPreference(VectorPreferences.SETTINGS_LOGGED_IN_PREFERENCE_KEY) - .summary = session.sessionParams.credentials.userId + .summary = session.myUserId // home server findPreference(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY) diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt index 10a4fcce6f..06a3343486 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -367,7 +367,7 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() { * @param aMyDeviceInfo the device info */ private fun refreshCryptographyPreference(aMyDeviceInfo: DeviceInfo?) { - val userId = session.sessionParams.credentials.userId + val userId = session.myUserId val deviceId = session.sessionParams.credentials.deviceId // device name diff --git a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt index e3e7fb3003..fd0af94f80 100644 --- a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt +++ b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt @@ -35,7 +35,7 @@ class SignOutUiWorker(private val activity: FragmentActivity) { activeSessionHolder = context.vectorComponent().activeSessionHolder() val session = activeSessionHolder.getActiveSession() if (SignOutViewModel.doYouNeedToBeDisplayed(session)) { - val signOutDialog = SignOutBottomSheetDialogFragment.newInstance(session.sessionParams.credentials.userId) + val signOutDialog = SignOutBottomSheetDialogFragment.newInstance(session.myUserId) signOutDialog.onSignOut = Runnable { doSignOut() }