ios: menu to switch active user profile (#1758)

* ios: User chooser UI

* Change

* Changes

* update view

* fix layout/refactor

* fix preview

* wider menu, update label

* hide Your profiles button

* Clickable background that hides userChooser

* No click listener

* Better animation

* Disabled scrolling for small number of items

* Separated scrollview and buttons

* No transition

* Re-indent

* Limiting width by the longest label

* UserManagerView

* Adapted API

* Hide user chooser after selection

* Top counter,  users refactor

* Padding

* use VStack to fix layout bug

* eol

* rename: rename to getUserChatData

* update layout

* s/semibold/medium

* remove SettingsButton view

* rename

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Stanislav Dmitrenko
2023-01-17 17:47:37 +00:00
committed by GitHub
parent a668bd5736
commit 153f80fe64
11 changed files with 382 additions and 53 deletions

View File

@@ -131,6 +131,24 @@ func apiCreateActiveUser(_ p: Profile) throws -> User {
throw r
}
func listUsers() -> [UserInfo] {
let r = chatSendCmdSync(.listUsers)
if case let .usersList(users) = r { return users }
return []
}
func apiSetActiveUser(_ userId: Int64) throws -> User {
let r = chatSendCmdSync(.apiSetActiveUser(userId: userId))
if case let .activeUser(user) = r { return user }
throw r
}
func apiDeleteUser(_ userId: Int64) throws {
let r = chatSendCmdSync(.apiDeleteUser(userId: userId))
if case .cmdOk = r { return }
throw r
}
func apiStartChat() throws -> Bool {
let r = chatSendCmdSync(.startChat(subscribe: true, expire: true))
switch r {
@@ -900,11 +918,8 @@ func startChat() throws {
try setNetworkConfig(getNetCfg())
let justStarted = try apiStartChat()
if justStarted {
m.userAddress = try apiGetUserAddress()
(m.userSMPServers, m.presetSMPServers) = try getUserSMPServers()
m.chatItemTTL = try getChatItemTTL()
let chats = try apiGetChats()
m.chats = chats.map { Chat.init($0) }
try getUserChatData(m)
m.users = listUsers()
NtfManager.shared.setNtfBadgeCount(m.totalUnreadCount())
try refreshCallInvitations()
(m.savedToken, m.tokenStatus, m.notificationMode) = apiGetNtfToken()
@@ -922,6 +937,14 @@ func startChat() throws {
chatLastStartGroupDefault.set(Date.now)
}
func getUserChatData(_ m: ChatModel) throws {
m.userAddress = try apiGetUserAddress()
(m.userSMPServers, m.presetSMPServers) = try getUserSMPServers()
m.chatItemTTL = try getChatItemTTL()
let chats = try apiGetChats()
m.chats = chats.map { Chat.init($0) }
}
class ChatReceiver {
private var receiveLoop: Task<Void, Never>?
private var receiveMessages = true