@@ -85,6 +85,7 @@ class UserStateViewModel @Inject constructor(
8585 suspend fun loginMemosWithAccessToken (
8686 host : String ,
8787 accessToken : String ,
88+ accountLabel : String = "",
8889 allowHigherV1Version : Boolean = false,
8990 ): ApiResponse <Unit > = withContext(viewModelScope.coroutineContext) {
9091 try {
@@ -99,30 +100,38 @@ class UserStateViewModel @Inject constructor(
99100 }
100101 }
101102 when (accountCase) {
102- UserData .AccountCase .MEMOS_V1 -> loginMemosV1WithAccessToken(host, accessToken)
103- UserData .AccountCase .MEMOS_V0 -> loginMemosV0WithAccessToken(host, accessToken)
103+ UserData .AccountCase .MEMOS_V1 -> loginMemosV1WithAccessToken(host, accessToken, accountLabel )
104+ UserData .AccountCase .MEMOS_V0 -> loginMemosV0WithAccessToken(host, accessToken, accountLabel )
104105 else -> throw MoeMemosException .invalidServer
105106 }
106107 } catch (e: Throwable ) {
107108 ApiResponse .exception(e)
108109 }
109110 }
110111
111- private suspend fun loginMemosV0WithAccessToken (host : String , accessToken : String ): ApiResponse <Unit > = withContext(viewModelScope.coroutineContext) {
112+ private suspend fun loginMemosV0WithAccessToken (
113+ host : String ,
114+ accessToken : String ,
115+ accountLabel : String ,
116+ ): ApiResponse <Unit > = withContext(viewModelScope.coroutineContext) {
112117 try {
113118 val resp = accountService.createMemosV0Client(host, accessToken).second.me()
114119 if (resp !is ApiResponse .Success ) {
115120 return @withContext resp.mapSuccess {}
116121 }
117- accountService.addAccount(getAccount(host, accessToken, resp.data))
122+ accountService.addAccount(getAccount(host, accessToken, accountLabel, resp.data))
118123 currentUser = resp.data.toUser()
119124 ApiResponse .Success (Unit )
120125 } catch (e: Throwable ) {
121126 ApiResponse .exception(e)
122127 }
123128 }
124129
125- private suspend fun loginMemosV1WithAccessToken (host : String , accessToken : String ): ApiResponse <Unit > = withContext(viewModelScope.coroutineContext) {
130+ private suspend fun loginMemosV1WithAccessToken (
131+ host : String ,
132+ accessToken : String ,
133+ accountLabel : String ,
134+ ): ApiResponse <Unit > = withContext(viewModelScope.coroutineContext) {
126135 try {
127136 val resp = accountService.createMemosV1Client(host, accessToken).second.getCurrentUser()
128137 if (resp !is ApiResponse .Success ) {
@@ -132,7 +141,7 @@ class UserStateViewModel @Inject constructor(
132141 if (user == null ) {
133142 return @withContext ApiResponse .exception(MoeMemosException .notLogin)
134143 }
135- accountService.addAccount(getAccount(host, accessToken, user))
144+ accountService.addAccount(getAccount(host, accessToken, accountLabel, user))
136145 loadCurrentUser().mapSuccess {}
137146 } catch (e: Throwable ) {
138147 ApiResponse .exception(e)
@@ -164,7 +173,7 @@ class UserStateViewModel @Inject constructor(
164173 }
165174 }
166175
167- private fun getAccount (host : String , accessToken : String , user : MemosV0User ): Account = Account .MemosV0 (
176+ private fun getAccount (host : String , accessToken : String , accountLabel : String , user : MemosV0User ): Account = Account .MemosV0 (
168177 info = MemosAccount (
169178 host = host,
170179 accessToken = accessToken,
@@ -173,17 +182,19 @@ class UserStateViewModel @Inject constructor(
173182 avatarUrl = user.avatarUrl ? : " " ,
174183 startDateEpochSecond = user.createdTs,
175184 defaultVisibility = user.toUser().defaultVisibility.name,
185+ accountLabel = accountLabel.trim(),
176186 )
177187 )
178188
179- private fun getAccount (host : String , accessToken : String , user : MemosV1User ): Account = Account .MemosV1 (
189+ private fun getAccount (host : String , accessToken : String , accountLabel : String , user : MemosV1User ): Account = Account .MemosV1 (
180190 info = MemosAccount (
181191 host = host,
182192 accessToken = accessToken,
183193 id = user.name.substringAfterLast(' /' ).toLong(),
184194 name = user.username,
185195 avatarUrl = user.avatarUrl ? : " " ,
186196 startDateEpochSecond = user.createTime?.epochSecond ? : 0L ,
197+ accountLabel = accountLabel.trim(),
187198 )
188199 )
189200}
0 commit comments