Skip to content

Commit

Permalink
expose complete chat interface
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jul 7, 2022
1 parent 15b7477 commit 5f8cded
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions Sources/Chat/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Chat {
private let invitationHandlingService: InvitationHandlingService
private let inviteService: InviteService
let kms: KeyManagementService
let threadStore: CodableStore<Thread>

let socketConnectionStatusPublisher: AnyPublisher<SocketConnectionStatus, Never>

Expand Down Expand Up @@ -47,13 +48,14 @@ class Chat {
jsonRpcHistory: jsonRpcHistory)
let invitePayloadStore = CodableStore<RequestSubscriptionPayload>(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.invite.rawValue)
self.registryService = RegistryService(registry: registry, networkingInteractor: networkingInteractor, kms: kms, logger: logger, topicToInvitationPubKeyStore: topicToInvitationPubKeyStore)
threadStore = CodableStore<Thread>(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.threads.rawValue)
self.invitationHandlingService = InvitationHandlingService(registry: registry,
networkingInteractor: networkingInteractor,
kms: kms,
logger: logger,
topicToInvitationPubKeyStore: topicToInvitationPubKeyStore,
invitePayloadStore: invitePayloadStore,
threadsStore: CodableStore<Thread>(defaults: keyValueStorage, identifier: StorageDomainIdentifiers.threads.rawValue))
threadsStore: threadStore)
self.inviteService = InviteService(networkingInteractor: networkingInteractor, kms: kms, logger: logger)
self.messagingService = MessagingService(networkingInteractor: networkingInteractor, logger: logger)
socketConnectionStatusPublisher = relayClient.socketConnectionStatusPublisher
Expand All @@ -64,44 +66,64 @@ class Chat {
/// record is a blockchain account with a client generated public key
/// - Parameter account: CAIP10 blockchain account
/// - Returns: public key
func register(account: Account) async throws -> String {
public func register(account: Account) async throws -> String {
try await registryService.register(account: account)
}

/// Queries the default keyserver with a blockchain account
/// - Parameter account: CAIP10 blockachain account
/// - Returns: public key associated with an account in chat's keyserver
func resolve(account: Account) async throws -> String {
public func resolve(account: Account) async throws -> String {
try await registry.resolve(account: account)
}

/// Sends a chat invite with opening message
/// - Parameters:
/// - publicKey: publicKey associated with a peer
/// - openingMessage: oppening message for a chat invite
func invite(publicKey: String, openingMessage: String) async throws {
public func invite(publicKey: String, openingMessage: String) async throws {
// TODO - how to provide account?
// in init or in invite method's params
let tempAccount = Account("eip155:1:33e32e32")!
try await inviteService.invite(peerPubKey: publicKey, openingMessage: openingMessage, account: tempAccount)
}

func accept(inviteId: String) async throws {
public func accept(inviteId: String) async throws {
try await invitationHandlingService.accept(inviteId: inviteId)
}

public func reject(inviteId: String) async throws {

}

/// Sends a chat message to an active chat thread
/// - Parameters:
/// - topic: thread topic
/// - message: chat message
func message(topic: String, message: String) async throws {
public func message(topic: String, message: String) async throws {
try await messagingService.send(topic: topic, messageString: message)
}

/// To Ping peer client
/// - Parameter topic: chat thread topic
func ping(topic: String) {
public func ping(topic: String) {
fatalError("not implemented")
}

public func leave(topic: String) async throws {
fatalError("not implemented")
}

public func getInvites(account: Account) -> [Invite] {
fatalError("not implemented")
}

public func getThreads(account: Account) -> [Thread] {
fatalError("not implemented")
}

public func getMessages(topic: String) -> [Message] {
fatalError("not implemented")
}

private func setUpEnginesCallbacks() {
Expand All @@ -119,3 +141,4 @@ class Chat {
}
}
}

2 changes: 1 addition & 1 deletion Sources/Chat/Types/InviteParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct InviteResponse: Codable {
let pubKey: String
}

struct Invite: Codable, Equatable {
public struct Invite: Codable, Equatable {
let message: String
let account: Account
let pubKey: String
Expand Down

0 comments on commit 5f8cded

Please sign in to comment.