wip
This commit is contained in:
parent
c4d70ef77d
commit
57793daf3d
|
@ -176,6 +176,8 @@
|
||||||
7E995F2B2CEAC9A0005B30EE /* monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; };
|
7E995F2B2CEAC9A0005B30EE /* monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; };
|
||||||
7E995F2C2CEAC9A0005B30EE /* monalxmpp.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
7E995F2C2CEAC9A0005B30EE /* monalxmpp.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 26CC579223A0867400ABB92A /* monalxmpp.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
7E995F302CEAC9F6005B30EE /* Pods_monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B9C86E0A568734587FE9BA2 /* Pods_monalxmpp.framework */; };
|
7E995F302CEAC9F6005B30EE /* Pods_monalxmpp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B9C86E0A568734587FE9BA2 /* Pods_monalxmpp.framework */; };
|
||||||
|
7EA6B8EC2CF208FB00196B10 /* ChatsCreateScreenMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EA6B8E92CF208FB00196B10 /* ChatsCreateScreenMain.swift */; };
|
||||||
|
7EA6B8ED2CF208FB00196B10 /* ChatsListScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EA6B8EA2CF208FB00196B10 /* ChatsListScreen.swift */; };
|
||||||
7ED6F0172CECC3AB0035B3B7 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7ED6F0162CECC3AB0035B3B7 /* Colors.xcassets */; };
|
7ED6F0172CECC3AB0035B3B7 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7ED6F0162CECC3AB0035B3B7 /* Colors.xcassets */; };
|
||||||
7ED6F0192CECC3BF0035B3B7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7ED6F0182CECC3BF0035B3B7 /* Images.xcassets */; };
|
7ED6F0192CECC3BF0035B3B7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7ED6F0182CECC3BF0035B3B7 /* Images.xcassets */; };
|
||||||
840E23CA28ADA56900A7FAC9 /* MLUploadQueueCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 840E23C828ADA56900A7FAC9 /* MLUploadQueueCell.m */; };
|
840E23CA28ADA56900A7FAC9 /* MLUploadQueueCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 840E23C828ADA56900A7FAC9 /* MLUploadQueueCell.m */; };
|
||||||
|
@ -680,6 +682,8 @@
|
||||||
7E995F202CEAC5D2005B30EE /* AnotherIMApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnotherIMApp.swift; sourceTree = "<group>"; };
|
7E995F202CEAC5D2005B30EE /* AnotherIMApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnotherIMApp.swift; sourceTree = "<group>"; };
|
||||||
7E995F222CEAC5D2005B30EE /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; };
|
7E995F222CEAC5D2005B30EE /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; };
|
||||||
7E995F282CEAC672005B30EE /* ASN1Decoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ASN1Decoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
7E995F282CEAC672005B30EE /* ASN1Decoder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ASN1Decoder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
7EA6B8E92CF208FB00196B10 /* ChatsCreateScreenMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatsCreateScreenMain.swift; sourceTree = "<group>"; };
|
||||||
|
7EA6B8EA2CF208FB00196B10 /* ChatsListScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatsListScreen.swift; sourceTree = "<group>"; };
|
||||||
7ED6F0162CECC3AB0035B3B7 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
|
7ED6F0162CECC3AB0035B3B7 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
|
||||||
7ED6F0182CECC3BF0035B3B7 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
7ED6F0182CECC3BF0035B3B7 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||||
7FA9582E4CC566FE5466C557 /* Pods-Monal.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Monal.debug.xcconfig"; path = "Target Support Files/Pods-Monal/Pods-Monal.debug.xcconfig"; sourceTree = "<group>"; };
|
7FA9582E4CC566FE5466C557 /* Pods-Monal.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Monal.debug.xcconfig"; path = "Target Support Files/Pods-Monal/Pods-Monal.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
|
@ -1558,6 +1562,15 @@
|
||||||
path = another.im;
|
path = another.im;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
7EA6B8EB2CF208FB00196B10 /* ChatList */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
7EA6B8E92CF208FB00196B10 /* ChatsCreateScreenMain.swift */,
|
||||||
|
7EA6B8EA2CF208FB00196B10 /* ChatsListScreen.swift */,
|
||||||
|
);
|
||||||
|
path = ChatList;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
7ED6F0152CECC37E0035B3B7 /* Assets */ = {
|
7ED6F0152CECC37E0035B3B7 /* Assets */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
@ -1730,6 +1743,7 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
7E1C0AC62CEF68C000B8FEC0 /* MainTabScreen.swift */,
|
7E1C0AC62CEF68C000B8FEC0 /* MainTabScreen.swift */,
|
||||||
|
7EA6B8EB2CF208FB00196B10 /* ChatList */,
|
||||||
7E1C0ACA2CEF6C7800B8FEC0 /* Contacts */,
|
7E1C0ACA2CEF6C7800B8FEC0 /* Contacts */,
|
||||||
);
|
);
|
||||||
path = Main;
|
path = Main;
|
||||||
|
@ -2630,6 +2644,8 @@
|
||||||
7E8D7B182CECEE79009AD3DF /* ButtonStyles.swift in Sources */,
|
7E8D7B182CECEE79009AD3DF /* ButtonStyles.swift in Sources */,
|
||||||
7E8D7B192CECEE79009AD3DF /* AVAsset+Thumbnail.swift in Sources */,
|
7E8D7B192CECEE79009AD3DF /* AVAsset+Thumbnail.swift in Sources */,
|
||||||
7E8D7B1A2CECEE79009AD3DF /* Const.swift in Sources */,
|
7E8D7B1A2CECEE79009AD3DF /* Const.swift in Sources */,
|
||||||
|
7EA6B8EC2CF208FB00196B10 /* ChatsCreateScreenMain.swift in Sources */,
|
||||||
|
7EA6B8ED2CF208FB00196B10 /* ChatsListScreen.swift in Sources */,
|
||||||
7E8D7B1B2CECEE79009AD3DF /* Typography.swift in Sources */,
|
7E8D7B1B2CECEE79009AD3DF /* Typography.swift in Sources */,
|
||||||
7E8D7B1C2CECEE79009AD3DF /* TimeInterval+Extensions.swift in Sources */,
|
7E8D7B1C2CECEE79009AD3DF /* TimeInterval+Extensions.swift in Sources */,
|
||||||
7E8D7B1D2CECEE79009AD3DF /* EdgeInsets+Extensions.swift in Sources */,
|
7E8D7B1D2CECEE79009AD3DF /* EdgeInsets+Extensions.swift in Sources */,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ChatsListScreen: View {
|
struct ChatsListScreen: View {
|
||||||
|
@EnvironmentObject var wrapper: MonalXmppWrapper
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
@EnvironmentObject var clientsStore: ClientsStore
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
|
@ -26,15 +26,10 @@ struct ChatsListScreen: View {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chats list
|
// Chats list
|
||||||
if !clientsStore.actualChats.isEmpty {
|
if !wrapper.activeChats.isEmpty {
|
||||||
List {
|
List {
|
||||||
ForEach(elements.indices, id: \.self) { index in
|
ForEach(wrapper.activeChats) {
|
||||||
let element = elements[index]
|
ChatsRow(chat: $0)
|
||||||
if let chat = element as? Chat {
|
|
||||||
ChatsRow(chat: chat)
|
|
||||||
} else if let account = element as? String {
|
|
||||||
SharedSectionTitle(text: account)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
|
@ -45,33 +40,17 @@ struct ChatsListScreen: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var elements: [Any] {
|
|
||||||
if clientsStore.clients.filter({ $0.credentials.isActive }).count == 1 {
|
|
||||||
return clientsStore.actualChats
|
|
||||||
} else {
|
|
||||||
var result: [Any] = []
|
|
||||||
for chat in clientsStore.actualChats {
|
|
||||||
if result.isEmpty {
|
|
||||||
result.append(chat.account)
|
|
||||||
} else if let last = result.last as? Chat, last.account != chat.account {
|
|
||||||
result.append(chat.account)
|
|
||||||
}
|
|
||||||
result.append(chat)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct ChatsRow: View {
|
private struct ChatsRow: View {
|
||||||
|
@EnvironmentObject var wrapper: MonalXmppWrapper
|
||||||
@Environment(\.router) var router
|
@Environment(\.router) var router
|
||||||
@EnvironmentObject var clientsStore: ClientsStore
|
|
||||||
|
|
||||||
var chat: Chat
|
var chat: Chat
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant, controlType: .none)
|
Text("dump")
|
||||||
|
SharedListRow(iconType: .charCircle(chat.name), text: chat.name, controlType: .none)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
Task {
|
Task {
|
||||||
router.showModal {
|
router.showModal {
|
||||||
|
@ -82,12 +61,12 @@ private struct ChatsRow: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try? await clientsStore.addRosterForNewChatIfNeeded(chat)
|
// try? await clientsStore.addRosterForNewChatIfNeeded(chat)
|
||||||
let (messages, attachments, settings) = try await clientsStore.conversationStores(for: chat)
|
// let (messages, attachments, settings) = try await clientsStore.conversationStores(for: chat)
|
||||||
router.showScreen(.push) { _ in
|
// router.showScreen(.push) { _ in
|
||||||
ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings)
|
// ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings)
|
||||||
.navigationBarHidden(true)
|
// .navigationBarHidden(true)
|
||||||
}
|
// }
|
||||||
} catch {
|
} catch {
|
||||||
router.showAlert(
|
router.showAlert(
|
||||||
.alert,
|
.alert,
|
||||||
|
|
|
@ -23,9 +23,7 @@ struct MainTabScreen: View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
switch selectedTab {
|
switch selectedTab {
|
||||||
case .chats:
|
case .chats:
|
||||||
Text("chats")
|
ChatsListScreen()
|
||||||
Spacer()
|
|
||||||
// ChatsListScreen()
|
|
||||||
|
|
||||||
case .contacts:
|
case .contacts:
|
||||||
ContactsScreen()
|
ContactsScreen()
|
||||||
|
|
|
@ -54,3 +54,29 @@ struct Contact: Identifiable {
|
||||||
name = obj.nickName.isEmpty ? nil : obj.nickName
|
name = obj.nickName.isEmpty ? nil : obj.nickName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Chat
|
||||||
|
struct Chat: Identifiable {
|
||||||
|
let accountId: Int
|
||||||
|
let participantJid: String
|
||||||
|
let participantName: String?
|
||||||
|
|
||||||
|
var id: String {
|
||||||
|
"\(accountId)_\(participantJid)"
|
||||||
|
}
|
||||||
|
|
||||||
|
var name: String {
|
||||||
|
if let participantName, !participantName.isEmpty {
|
||||||
|
return participantName
|
||||||
|
} else {
|
||||||
|
return participantJid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init?(_ obj: MLContact) {
|
||||||
|
guard let accId = obj.accountID as? Int else { return nil }
|
||||||
|
accountId = accId
|
||||||
|
participantJid = obj.contactJid
|
||||||
|
participantName = obj.nickName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class MonalXmppWrapper: ObservableObject {
|
||||||
@Published private(set) var accountsAvailability: AccountsAvailability = .noAccounts
|
@Published private(set) var accountsAvailability: AccountsAvailability = .noAccounts
|
||||||
@Published private(set) var accounts: [Account] = []
|
@Published private(set) var accounts: [Account] = []
|
||||||
@Published private(set) var contacts: [Contact] = []
|
@Published private(set) var contacts: [Contact] = []
|
||||||
|
@Published private(set) var activeChats: [Chat] = []
|
||||||
|
|
||||||
private let xmpp: MLXMPPManager
|
private let xmpp: MLXMPPManager
|
||||||
private let db: DataLayer
|
private let db: DataLayer
|
||||||
|
@ -106,17 +107,23 @@ private extension MonalXmppWrapper {
|
||||||
let generalRefresh = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalRefresh), object: nil, queue: .main) { [weak self] _ in
|
let generalRefresh = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalRefresh), object: nil, queue: .main) { [weak self] _ in
|
||||||
self?.refreshAccounts()
|
self?.refreshAccounts()
|
||||||
self?.refreshContacts()
|
self?.refreshContacts()
|
||||||
|
self?.refreshChats()
|
||||||
}
|
}
|
||||||
notificationObservers.append(generalRefresh)
|
notificationObservers.append(generalRefresh)
|
||||||
|
|
||||||
// For contacts
|
// For contacts
|
||||||
let contactRefresh = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRefresh), object: nil, queue: .main) { [weak self] _ in
|
let contactRefresh = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRefresh), object: nil, queue: .main) { [weak self] _ in
|
||||||
self?.refreshContacts()
|
self?.refreshContacts()
|
||||||
|
self?.refreshChats()
|
||||||
}
|
}
|
||||||
let contactRemove = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRemoved), object: nil, queue: .main) { [weak self] _ in
|
let contactRemove = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRemoved), object: nil, queue: .main) { [weak self] _ in
|
||||||
self?.refreshContacts()
|
self?.refreshContacts()
|
||||||
|
self?.refreshChats()
|
||||||
}
|
}
|
||||||
notificationObservers.append(contentsOf: [contactRefresh, contactRemove])
|
notificationObservers.append(contentsOf: [contactRefresh, contactRemove])
|
||||||
|
|
||||||
|
// For chats
|
||||||
|
// ???
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshAccounts() {
|
func refreshAccounts() {
|
||||||
|
@ -144,4 +151,12 @@ private extension MonalXmppWrapper {
|
||||||
.filter { !$0.isSelfChat } // removed for now
|
.filter { !$0.isSelfChat } // removed for now
|
||||||
.compactMap { Contact($0) }
|
.compactMap { Contact($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshChats() {
|
||||||
|
activeChats = db.activeContacts(withPinned: false)
|
||||||
|
.compactMap {
|
||||||
|
guard let contact = $0 as? MLContact else { return nil }
|
||||||
|
return Chat(contact)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue