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
/**
* Useful shortcut to get access to the userId
*/
val myUserId: String
get() = sessionParams.credentials.userId

View file

@ -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
}
}

View file

@ -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() {

View file

@ -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()
}

View file

@ -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)
}
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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

View file

@ -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),

View file

@ -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)) {

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.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)
}
}

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))
}
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))
}

View file

@ -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,

View file

@ -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,

View file

@ -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) {

View file

@ -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)
}

View file

@ -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 {

View file

@ -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)

View file

@ -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

View file

@ -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()
}