wip
This commit is contained in:
parent
178f22a140
commit
77b9aa8d3a
|
@ -2,8 +2,8 @@ import Foundation
|
|||
import GRDB
|
||||
import Martin
|
||||
|
||||
extension Database: MartinsManager {
|
||||
// MARK: - Martin's roster manager
|
||||
extension Database: Martin.RosterManager {
|
||||
func clear(for context: Martin.Context) {
|
||||
print("Clearing roster for context: \(context)")
|
||||
do {
|
||||
|
@ -151,8 +151,10 @@ extension Database: MartinsManager {
|
|||
|
||||
func initialize(context _: Martin.Context) {}
|
||||
func deinitialize(context _: Martin.Context) {}
|
||||
}
|
||||
|
||||
// MARK: - Martin's chats manager
|
||||
extension Database: Martin.ChatManager {
|
||||
func chats(for context: Martin.Context) -> [any Martin.ChatProtocol] {
|
||||
do {
|
||||
let chats: [Chat] = try _db.read { db in
|
||||
|
@ -220,3 +222,52 @@ extension Database: MartinsManager {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Martin's rooms manager
|
||||
extension Database: Martin.RoomManager {
|
||||
func rooms(for _: Martin.Context) -> [any Martin.RoomProtocol] {
|
||||
[]
|
||||
}
|
||||
|
||||
func room(for _: Martin.Context, with _: Martin.BareJID) -> (any Martin.RoomProtocol)? {
|
||||
nil
|
||||
}
|
||||
|
||||
func createRoom(for _: Martin.Context, with _: Martin.BareJID, nickname _: String, password _: String?) -> (any Martin.RoomProtocol)? {
|
||||
nil
|
||||
}
|
||||
|
||||
func close(room _: any Martin.RoomProtocol) -> Bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Martin's channels manager
|
||||
extension Database: Martin.ChannelManager {
|
||||
func channels(for _: Martin.Context) -> [any Martin.ChannelProtocol] {
|
||||
[]
|
||||
// do {
|
||||
// let channels: [Channel] = try _db.read { db in
|
||||
// try Channel.filter(Column("account") == context.userBareJid.stringValue).fetchAll(db)
|
||||
// }
|
||||
// return channels.map { channel in
|
||||
// Martin.ChannelBase(context: context, channelJid: channel.channel, participantId: , nickname: , state: )
|
||||
// }
|
||||
// } catch {
|
||||
// logIt(.error, "Error fetching channels: \(error.localizedDescription)")
|
||||
// return []
|
||||
// }
|
||||
}
|
||||
|
||||
func createChannel(for _: Martin.Context, with _: Martin.BareJID, participantId _: String, nick _: String?, state _: Martin.ChannelState) -> Martin.ConversationCreateResult<any Martin.ChannelProtocol> {
|
||||
.none
|
||||
}
|
||||
|
||||
func channel(for _: Martin.Context, with _: Martin.BareJID) -> (any Martin.ChannelProtocol)? {
|
||||
nil
|
||||
}
|
||||
|
||||
func close(channel _: any Martin.ChannelProtocol) -> Bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,21 @@ extension Database {
|
|||
}
|
||||
}
|
||||
|
||||
// 2nd migration - channels/rooms
|
||||
migrator.registerMigration("Add channels/rooms") { db in
|
||||
// channels
|
||||
try db.create(table: "channels", options: [.ifNotExists]) { table in
|
||||
table.column("id", .text).notNull().primaryKey().unique(onConflict: .replace)
|
||||
table.column("account", .text).notNull()
|
||||
table.column("channel", .text).notNull()
|
||||
}
|
||||
|
||||
// rooms
|
||||
// try db.create(table: "rooms", options: [.ifNotExists]) { table in
|
||||
// table.column("id", .text).notNull().primaryKey().unique(onConflict: .replace)
|
||||
// }
|
||||
}
|
||||
|
||||
// return migrator
|
||||
return migrator
|
||||
}()
|
||||
|
|
15
ConversationsClassic/AppCore/Models/Channel.swift
Normal file
15
ConversationsClassic/AppCore/Models/Channel.swift
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Foundation
|
||||
import GRDB
|
||||
import Martin
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Account
|
||||
struct Channel: DBStorable {
|
||||
var id: String
|
||||
var account: String
|
||||
var channel: String
|
||||
}
|
||||
|
||||
extension Channel {
|
||||
static let channelTableName = "channels"
|
||||
}
|
13
ConversationsClassic/AppCore/Models/Room.swift
Normal file
13
ConversationsClassic/AppCore/Models/Room.swift
Normal file
|
@ -0,0 +1,13 @@
|
|||
import Foundation
|
||||
import GRDB
|
||||
import Martin
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - Account
|
||||
struct Room: DBStorable {
|
||||
var id: String
|
||||
}
|
||||
|
||||
extension Room {
|
||||
static let roomTableName = "rooms"
|
||||
}
|
|
@ -3,15 +3,18 @@ import Foundation
|
|||
import GRDB
|
||||
import Martin
|
||||
|
||||
protocol MartinsManager: Martin.RosterManager & Martin.ChatManager {}
|
||||
protocol MartinsManager: Martin.RosterManager & Martin.ChatManager & Martin.ChannelManager & Martin.RoomManager {}
|
||||
|
||||
final class XMPPService: ObservableObject {
|
||||
private let manager: MartinsManager
|
||||
|
||||
private let clientStatePublisher = PassthroughSubject<(XMPPClient, XMPPClient.State), Never>()
|
||||
private let clientMessagesPublisher = PassthroughSubject<(XMPPClient, Martin.Message), Never>()
|
||||
private let clientFeaturesPublisher = PassthroughSubject<(XMPPClient, [String]), Never>()
|
||||
private var clientStateCancellables: Set<AnyCancellable> = []
|
||||
|
||||
private let clientMessagesPublisher = PassthroughSubject<(XMPPClient, Martin.Message), Never>()
|
||||
private var clientMessagesCancellables: Set<AnyCancellable> = []
|
||||
|
||||
private let clientFeaturesPublisher = PassthroughSubject<(XMPPClient, [String]), Never>()
|
||||
private var clientFeaturesCancellables: Set<AnyCancellable> = []
|
||||
|
||||
@Published private(set) var clients: [XMPPClient] = []
|
||||
|
@ -130,6 +133,12 @@ final class XMPPService: ObservableObject {
|
|||
client.connectionConfiguration.userJid = .init(account.bareJid)
|
||||
client.connectionConfiguration.credentials = .password(password: account.pass)
|
||||
|
||||
// channels
|
||||
client.modulesManager.register(MixModule(channelManager: manager))
|
||||
|
||||
// group chats
|
||||
// client.modulesManager.register(MucModule(roomManager: manager))
|
||||
|
||||
// add client to clients
|
||||
return client
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue