Use Session.myUserId whereas it's possible

This commit is contained in:
Benoit Marty 2019-07-16 15:50:07 +02:00
parent 6bbc784c29
commit 0f7a56d005
20 changed files with 38 additions and 38 deletions

View File

@ -57,6 +57,9 @@ interface Session :
*/ */
val sessionParams: SessionParams val sessionParams: SessionParams


/**
* Useful shortcut to get access to the userId
*/
val myUserId: String val myUserId: String
get() = sessionParams.credentials.userId get() = sessionParams.credentials.userId



View File

@ -58,7 +58,7 @@ internal class SessionManager @Inject constructor(private val matrixComponent: M
.factory() .factory()
.create(matrixComponent, sessionParams) .create(matrixComponent, sessionParams)
.also { .also {
sessionComponents[sessionParams.credentials.userId] = it sessionComponents[userId] = it
} }
} }



View File

@ -94,11 +94,11 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
} }


override fun requireBackgroundSync() { override fun requireBackgroundSync() {
SyncWorker.requireBackgroundSync(context, sessionParams.credentials.userId) SyncWorker.requireBackgroundSync(context, myUserId)
} }


override fun startAutomaticBackgroundSync(repeatDelay: Long) { override fun startAutomaticBackgroundSync(repeatDelay: Long) {
SyncWorker.automaticallyBackgroundSync(context, sessionParams.credentials.userId, 0, repeatDelay) SyncWorker.automaticallyBackgroundSync(context, myUserId, 0, repeatDelay)
} }


override fun stopAnyBackgroundSync() { override fun stopAnyBackgroundSync() {

View File

@ -199,7 +199,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
if (eventType == null) { if (eventType == null) {
//Just add a generic unknown event //Just add a generic unknown event
val simpleNotifiableEvent = SimpleNotifiableEvent( val simpleNotifiableEvent = SimpleNotifiableEvent(
session.sessionParams.credentials.userId, session.myUserId,
eventId, eventId,
true, //It's an issue in this case, all event will bing even if expected to be silent. 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), title = getString(R.string.notification_unknown_new_event),
@ -238,7 +238,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
} }


notifiableEvent.isPushGatewayEvent = true notifiableEvent.isPushGatewayEvent = true
notifiableEvent.matrixID = session.sessionParams.credentials.userId notifiableEvent.matrixID = session.myUserId
notificationDrawerManager.onNotifiableEventReceived(notifiableEvent) notificationDrawerManager.onNotifiableEventReceived(notifiableEvent)
notificationDrawerManager.refreshNotificationDrawer() notificationDrawerManager.refreshNotificationDrawer()
} }

View File

@ -58,10 +58,10 @@ open class UserAvatarPreference : Preference {
open fun refreshAvatar() { open fun refreshAvatar() {
val session = mSession ?: return val session = mSession ?: return
val view = mAvatarView ?: return val view = mAvatarView ?: return
session.getUser(session.sessionParams.credentials.userId)?.let { session.getUser(session.myUserId)?.let {
avatarRenderer.render(it, view) avatarRenderer.render(it, view)
} ?: run { } ?: run {
avatarRenderer.render(null, session.sessionParams.credentials.userId, null, view) avatarRenderer.render(null, session.myUserId, null, view)
} }


} }

View File

@ -21,8 +21,8 @@ import androidx.lifecycle.ViewModel
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.listeners.StepProgressListener import im.vector.matrix.android.api.listeners.StepProgressListener
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService 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.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.platform.WaitingViewData import im.vector.riotx.core.platform.WaitingViewData
import im.vector.riotx.core.ui.views.KeysBackupBanner import im.vector.riotx.core.ui.views.KeysBackupBanner
@ -57,7 +57,7 @@ class KeysBackupRestoreFromKeyViewModel @Inject constructor() : ViewModel() {
keysBackup.restoreKeysWithRecoveryKey(keysVersionResult, keysBackup.restoreKeysWithRecoveryKey(keysVersionResult,
recoveryKey, recoveryKey,
null, null,
session.sessionParams.credentials.userId, session.myUserId,
object : StepProgressListener { object : StepProgressListener {
override fun onStepProgress(step: StepProgressListener.Step) { override fun onStepProgress(step: StepProgressListener.Step) {
when (step) { when (step) {

View File

@ -21,8 +21,8 @@ import androidx.lifecycle.ViewModel
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.listeners.StepProgressListener import im.vector.matrix.android.api.listeners.StepProgressListener
import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupService 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.keysbackup.model.rest.KeysVersionResult
import im.vector.matrix.android.internal.crypto.model.ImportRoomKeysResult
import im.vector.riotx.R import im.vector.riotx.R
import im.vector.riotx.core.platform.WaitingViewData import im.vector.riotx.core.platform.WaitingViewData
import im.vector.riotx.core.ui.views.KeysBackupBanner import im.vector.riotx.core.ui.views.KeysBackupBanner
@ -58,7 +58,7 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor() : ViewModel
keysBackup.restoreKeyBackupWithPassword(keysVersionResult, keysBackup.restoreKeyBackupWithPassword(keysVersionResult,
passphrase.value!!, passphrase.value!!,
null, null,
sharedViewModel.session.sessionParams.credentials.userId, sharedViewModel.session.myUserId,
object : StepProgressListener { object : StepProgressListener {
override fun onStepProgress(step: StepProgressListener.Step) { override fun onStepProgress(step: StepProgressListener.Step) {
when (step) { when (step) {

View File

@ -52,7 +52,7 @@ class HomeDrawerFragment : VectorBaseFragment() {
replaceChildFragment(groupListFragment, R.id.homeDrawerGroupListContainer) replaceChildFragment(groupListFragment, R.id.homeDrawerGroupListContainer)
} }


session.observeUser(session.sessionParams.credentials.userId).observeK(this) { user -> session.observeUser(session.myUserId).observeK(this) { user ->
if (user != null) { if (user != null) {
avatarRenderer.render(user.avatarUrl, user.userId, user.displayName, homeDrawerHeaderAvatarView) avatarRenderer.render(user.avatarUrl, user.userId, user.displayName, homeDrawerHeaderAvatarView)
homeDrawerUsernameView.text = user.displayName homeDrawerUsernameView.text = user.displayName

View File

@ -93,7 +93,7 @@ class GroupListViewModel @AssistedInject constructor(@Assisted initialState: Gro
.rx() .rx()
.liveGroupSummaries() .liveGroupSummaries()
.map { .map {
val myUser = session.getUser(session.sessionParams.credentials.userId) val myUser = session.getUser(session.myUserId)
val allCommunityGroup = GroupSummary( val allCommunityGroup = GroupSummary(
groupId = ALL_COMMUNITIES_GROUP_ID, groupId = ALL_COMMUNITIES_GROUP_ID,
displayName = stringProvider.getString(R.string.group_all_communities), displayName = stringProvider.getString(R.string.group_all_communities),

View File

@ -486,7 +486,7 @@ class RoomDetailFragment :
timelineEventController.setTimeline(state.timeline, state.eventId) timelineEventController.setTimeline(state.timeline, state.eventId)
inviteView.visibility = View.GONE inviteView.visibility = View.GONE


val uid = session.sessionParams.credentials.userId val uid = session.myUserId
val meMember = session.getRoom(state.roomId)?.getRoomMember(uid) val meMember = session.getRoom(state.roomId)?.getRoomMember(uid)
avatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composerLayout.composerAvatarImageView) avatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composerLayout.composerAvatarImageView)


@ -780,7 +780,7 @@ class RoomDetailFragment :
if (null != text) { if (null != text) {
// var vibrate = false // var vibrate = false


val myDisplayName = session.getUser(session.sessionParams.credentials.userId)?.displayName val myDisplayName = session.getUser(session.myUserId)?.displayName
if (TextUtils.equals(myDisplayName, text)) { if (TextUtils.equals(myDisplayName, text)) {
// current user // current user
if (TextUtils.isEmpty(composerLayout.composerEditText.text)) { if (TextUtils.isEmpty(composerLayout.composerEditText.text)) {

View File

@ -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.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotx.R
import im.vector.riotx.core.intent.getFilenameFromUri import im.vector.riotx.core.intent.getFilenameFromUri
import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.core.platform.VectorViewModel
import im.vector.riotx.core.resources.UserPreferencesProvider import im.vector.riotx.core.resources.UserPreferencesProvider
@ -52,8 +51,6 @@ import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer import org.commonmark.renderer.html.HtmlRenderer
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit




@ -347,7 +344,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
} }


private fun handleUndoReact(action: RoomDetailActions.UndoReaction) { 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) { if (action.add) {
room.sendReaction(action.selectedReaction, action.targetEventId) room.sendReaction(action.selectedReaction, action.targetEventId)
} else { } else {
room.undoReaction(action.selectedReaction, action.targetEventId, session.sessionParams.credentials.userId) room.undoReaction(action.selectedReaction, action.targetEventId, session.myUserId)
} }
} }



View File

@ -139,11 +139,11 @@ class MessageMenuViewModel @AssistedInject constructor(@Assisted initialState: M
this.add(SimpleAction(ACTION_REPLY, R.string.reply, R.drawable.ic_reply, eventId)) 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)) 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)) 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)) 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 //not sent by me
this.add(SimpleAction(ACTION_FLAG, R.string.report_content, R.drawable.ic_flag, event.root.eventId)) this.add(SimpleAction(ACTION_FLAG, R.string.report_content, R.drawable.ic_flag, event.root.eventId))
} }

View File

@ -70,7 +70,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
val bodyPreview = event.type val bodyPreview = event.type


return SimpleNotifiableEvent( return SimpleNotifiableEvent(
session.sessionParams.credentials.userId, session.myUserId,
eventId = event.eventId!!, eventId = event.eventId!!,
noisy = false,//will be updated noisy = false,//will be updated
timestamp = event.originServerTs ?: System.currentTimeMillis(), timestamp = event.originServerTs ?: System.currentTimeMillis(),
@ -109,7 +109,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
roomId = event.root.roomId!!, roomId = event.root.roomId!!,
roomName = roomName) roomName = roomName)


notifiableEvent.matrixID = session.sessionParams.credentials.userId notifiableEvent.matrixID = session.myUserId
return notifiableEvent return notifiableEvent
} else { } else {
if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) { if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) {
@ -145,7 +145,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
roomName = roomName, roomName = roomName,
roomIsDirect = room.roomSummary()?.isDirect ?: false) roomIsDirect = room.roomSummary()?.isDirect ?: false)


notifiableEvent.matrixID = session.sessionParams.credentials.userId notifiableEvent.matrixID = session.myUserId
notifiableEvent.soundName = null notifiableEvent.soundName = null


// Get the avatars URL // Get the avatars URL
@ -175,7 +175,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
val body = noticeEventFormatter.format(event, dName) val body = noticeEventFormatter.format(event, dName)
?: stringProvider.getString(R.string.notification_new_invitation) ?: stringProvider.getString(R.string.notification_new_invitation)
return InviteNotifiableEvent( return InviteNotifiableEvent(
session.sessionParams.credentials.userId, session.myUserId,
eventId = event.eventId!!, eventId = event.eventId!!,
roomId = roomId, roomId = roomId,
timestamp = event.originServerTs ?: 0, timestamp = event.originServerTs ?: 0,

View File

@ -121,9 +121,9 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
false, false,
System.currentTimeMillis(), System.currentTimeMillis(),
session.getUser(session.sessionParams.credentials.userId)?.displayName session.getUser(session.myUserId)?.displayName
?: context?.getString(R.string.notification_sender_me), ?: context?.getString(R.string.notification_sender_me),
session.sessionParams.credentials.userId, session.myUserId,
message, message,
room.roomId, room.roomId,
room.roomSummary()?.displayName ?: room.roomId, room.roomSummary()?.displayName ?: room.roomId,

View File

@ -181,9 +181,9 @@ class NotificationDrawerManager @Inject constructor(private val context: Context


val session = activeSessionHolder.getSafeActiveSession() ?: return 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 // 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) val myUserAvatarUrl = session.contentUrlResolver().resolveThumbnail(user?.avatarUrl, avatarSize, avatarSize, ContentUrlResolver.ThumbnailMethod.SCALE)
synchronized(eventList) { synchronized(eventList) {



View File

@ -204,7 +204,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes
var olmVersion = "undefined" var olmVersion = "undefined"


activeSessionHolder.getSafeActiveSession()?.let { session -> activeSessionHolder.getSafeActiveSession()?.let { session ->
userId = session.sessionParams.credentials.userId userId = session.myUserId
deviceId = session.sessionParams.credentials.deviceId ?: "undefined" deviceId = session.sessionParams.credentials.deviceId ?: "undefined"
olmVersion = session.getCryptoVersion(context, true) olmVersion = session.getCryptoVersion(context, true)
} }

View File

@ -79,9 +79,9 @@ class VectorSettingsActivity : VectorBaseActivity(),
var oFragment: Fragment? = null var oFragment: Fragment? = null


if (VectorPreferences.SETTINGS_NOTIFICATION_TROUBLESHOOT_PREFERENCE_KEY == pref?.key) { 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) { } else if (VectorPreferences.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY == pref?.key) {
oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.sessionParams.credentials.userId) oFragment = VectorSettingsAdvancedNotificationPreferenceFragment.newInstance(session.myUserId)
} else { } else {
try { try {
pref?.fragment?.let { pref?.fragment?.let {

View File

@ -95,7 +95,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {


// Display name // Display name
mDisplayNamePreference.let { mDisplayNamePreference.let {
it.summary = session.getUser(session.sessionParams.credentials.userId)?.displayName ?: "" it.summary = session.getUser(session.myUserId)?.displayName ?: ""
it.text = it.summary.toString() it.text = it.summary.toString()
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
onDisplayNameClick(newValue?.let { (it as String).trim() }) onDisplayNameClick(newValue?.let { (it as String).trim() })
@ -148,7 +148,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {


// user account // user account
findPreference(VectorPreferences.SETTINGS_LOGGED_IN_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_LOGGED_IN_PREFERENCE_KEY)
.summary = session.sessionParams.credentials.userId .summary = session.myUserId


// home server // home server
findPreference(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY) findPreference(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY)

View File

@ -367,7 +367,7 @@ class VectorSettingsSecurityPrivacyFragment : VectorSettingsBaseFragment() {
* @param aMyDeviceInfo the device info * @param aMyDeviceInfo the device info
*/ */
private fun refreshCryptographyPreference(aMyDeviceInfo: DeviceInfo?) { private fun refreshCryptographyPreference(aMyDeviceInfo: DeviceInfo?) {
val userId = session.sessionParams.credentials.userId val userId = session.myUserId
val deviceId = session.sessionParams.credentials.deviceId val deviceId = session.sessionParams.credentials.deviceId


// device name // device name

View File

@ -35,7 +35,7 @@ class SignOutUiWorker(private val activity: FragmentActivity) {
activeSessionHolder = context.vectorComponent().activeSessionHolder() activeSessionHolder = context.vectorComponent().activeSessionHolder()
val session = activeSessionHolder.getActiveSession() val session = activeSessionHolder.getActiveSession()
if (SignOutViewModel.doYouNeedToBeDisplayed(session)) { if (SignOutViewModel.doYouNeedToBeDisplayed(session)) {
val signOutDialog = SignOutBottomSheetDialogFragment.newInstance(session.sessionParams.credentials.userId) val signOutDialog = SignOutBottomSheetDialogFragment.newInstance(session.myUserId)
signOutDialog.onSignOut = Runnable { signOutDialog.onSignOut = Runnable {
doSignOut() doSignOut()
} }