Skip to content

Commit

Permalink
Merge pull request #528 from Adamant-im/dev/trello.com/c/Qa3Dx6EI
Browse files Browse the repository at this point in the history
[trello.com/c/Qa3Dx6EI] Release 3.8.0
  • Loading branch information
StanislavDevIOS authored Aug 26, 2024
2 parents f6d0b76 + 2fecd44 commit ec4b606
Show file tree
Hide file tree
Showing 162 changed files with 9,161 additions and 168 deletions.
238 changes: 232 additions & 6 deletions Adamant.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Adamant.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Adamant/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Swinject
import CryptoSwift
import CoreData
import CommonKit
import FilesStorageKit

// MARK: - Constants
extension String.adamant {
Expand Down
44 changes: 44 additions & 0 deletions Adamant/App/DI/AppAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
import Swinject
import BitcoinKit
import CommonKit
import FilesStorageKit
import FilesPickerKit

struct AppAssembly: Assembly {
func assemble(container: Container) {
// MARK: - Standalone services
// MARK: AdamantCore
container.register(AdamantCore.self) { _ in NativeAdamantCore() }.inObjectScope(.container)

// MARK: FilesStorageProtocol
container.register(FilesStorageProtocol.self) { _ in FilesStorageKit() }.inObjectScope(.container)

container.register(FilesPickerProtocol.self) { r in
FilesPickerKit(storageKit: r.resolve(FilesStorageProtocol.self)!)
}

// MARK: CellFactory
container.register(CellFactory.self) { _ in AdamantCellFactory() }.inObjectScope(.container)

Expand Down Expand Up @@ -120,6 +129,23 @@ struct AppAssembly: Assembly {
)
}.inObjectScope(.container)

// MARK: IPFSApiService
container.register(IPFSApiService.self) { r in
IPFSApiService(
healthCheckWrapper: .init(
service: .init(apiCore: r.resolve(APICoreProtocol.self)!),
nodesStorage: r.resolve(NodesStorageProtocol.self)!,
nodesAdditionalParamsStorage: r.resolve(NodesAdditionalParamsStorageProtocol.self)!,
nodeGroup: .ipfs
)
)
}.inObjectScope(.container)

// MARK: FilesNetworkManagerProtocol
container.register(FilesNetworkManagerProtocol.self) { r in
FilesNetworkManager(ipfsService: r.resolve(IPFSApiService.self)!)
}.inObjectScope(.container)

// MARK: BtcApiService
container.register(BtcApiService.self) { r in
BtcApiService(api: .init(
Expand Down Expand Up @@ -264,6 +290,24 @@ struct AppAssembly: Assembly {
)
}.inObjectScope(.container)

// MARK: ChatFileService
container.register(ChatFileProtocol.self) { r in
ChatFileService(
accountService: r.resolve(AccountService.self)!,
filesStorage: r.resolve(FilesStorageProtocol.self)!,
chatsProvider: r.resolve(ChatsProvider.self)!,
filesNetworkManager: r.resolve(FilesNetworkManagerProtocol.self)!,
adamantCore: r.resolve(AdamantCore.self)!
)
}.inObjectScope(.container)

// MARK: FilesStorageProprietiesService
container.register(FilesStorageProprietiesProtocol.self) { r in
FilesStorageProprietiesService(
securedStore: r.resolve(SecuredStore.self)!
)
}.inObjectScope(.container)

// MARK: Chats
container.register(ChatsProvider.self) { r in
AdamantChatsProvider(
Expand Down
10 changes: 10 additions & 0 deletions Adamant/Debug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
<array>
<string>applinks:msg.adamant.im</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array/>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array/>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.camera</key>
Expand Down
34 changes: 34 additions & 0 deletions Adamant/Helpers/EdgeInsetLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// EdgeInsetLabel.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 16.07.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation
import UIKit

final class EdgeInsetLabel: UILabel {
var textInsets = UIEdgeInsets.zero {
didSet { invalidateIntrinsicContentSize() }
}

override func textRect(
forBounds bounds: CGRect,
limitedToNumberOfLines numberOfLines: Int
) -> CGRect {
let textRect = super.textRect(forBounds: bounds, limitedToNumberOfLines: numberOfLines)
let invertedInsets = UIEdgeInsets(
top: -textInsets.top,
left: -textInsets.left,
bottom: -textInsets.bottom,
right: -textInsets.right
)
return textRect.inset(by: invertedInsets)
}

override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: textInsets))
}
}
48 changes: 48 additions & 0 deletions Adamant/Helpers/Markdown+Adamant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,51 @@ final class MarkdownCodeAdamant: MarkdownCommonElement {
addAttributes(attributedString, range: match.range)
}
}

// MARK: Detect file emoji & count
// - ex: 📄2
final class MarkdownFileRaw: MarkdownElement {
private let emoji: String
private let matchFont: UIFont

init(
emoji: String,
font: UIFont
) {
self.emoji = emoji
self.matchFont = font
}

var regex: String {
return "\(emoji)\\d{0,2}"
}

func regularExpression() throws -> NSRegularExpression {
try NSRegularExpression(pattern: regex, options: .dotMatchesLineSeparators)
}

func match(_ match: NSTextCheckingResult, attributedString: NSMutableAttributedString) {
let attributesColor: [NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.lightGray,
.font: matchFont,
.baselineOffset: -3.0
]

let nsString = (attributedString.string as NSString)
let matchText = nsString.substring(with: match.range)

let textWithoutEmoji = matchText.replacingOccurrences(of: emoji, with: "")
let countRange = (matchText as NSString).range(of: textWithoutEmoji)
let emojiRange = (matchText as NSString).range(of: emoji)

let range = NSRange(
location: match.range.location + emojiRange.length,
length: countRange.length
)

attributedString.addAttributes(
attributesColor,
range: range
)
}
}
10 changes: 10 additions & 0 deletions Adamant/Helpers/NodeGroup+Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public extension NodeGroup {
return DogeWalletService.healthCheckParameters.onScreenUpdateInterval
case .dash:
return DashWalletService.healthCheckParameters.onScreenUpdateInterval
case .ipfs:
return IPFSApiService.healthCheckParameters.onScreenUpdateInterval
}
}

Expand All @@ -44,6 +46,8 @@ public extension NodeGroup {
return DogeWalletService.healthCheckParameters.crucialUpdateInterval
case .dash:
return DashWalletService.healthCheckParameters.crucialUpdateInterval
case .ipfs:
return IPFSApiService.healthCheckParameters.crucialUpdateInterval
}
}

Expand All @@ -63,6 +67,8 @@ public extension NodeGroup {
return DogeWalletService.healthCheckParameters.threshold
case .dash:
return DashWalletService.healthCheckParameters.threshold
case .ipfs:
return IPFSApiService.healthCheckParameters.threshold
}
}

Expand All @@ -82,6 +88,8 @@ public extension NodeGroup {
return DogeWalletService.healthCheckParameters.normalUpdateInterval
case .dash:
return DashWalletService.healthCheckParameters.normalUpdateInterval
case .ipfs:
return IPFSApiService.healthCheckParameters.normalUpdateInterval
}
}

Expand All @@ -102,6 +110,8 @@ public extension NodeGroup {
minNodeVersion = DogeWalletService.minNodeVersion
case .dash:
minNodeVersion = DashWalletService.minNodeVersion
case .ipfs:
minNodeVersion = nil
}

guard let versionNumber = Node.stringToDouble(minNodeVersion) else {
Expand Down
1 change: 1 addition & 0 deletions Adamant/Helpers/UIFont+adamant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extension UIFont {
return UIFont(name: name, size: size) ?? .systemFont(ofSize: size, weight: weight)
}

static var adamantChatFileRawDefault = UIFont.systemFont(ofSize: 8)
static var adamantChatDefault = UIFont.systemFont(ofSize: 17)
static var adamantCodeDefault = UIFont.adamantMono(ofSize: 15, weight: .regular)
static var adamantChatReplyDefault = UIFont.systemFont(ofSize: 14)
Expand Down
1 change: 1 addition & 0 deletions Adamant/Helpers/UITextField+adamant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import CommonKit

extension UITextField {

Expand Down
4 changes: 2 additions & 2 deletions Adamant/Models/ApiServiceError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ enum ApiServiceError: LocalizedError, Error {
let message = error?.localizedDescription ?? msg
return String.adamant.sharedErrors.internalError(message: message)

case .networkError(error: _):
return String.adamant.sharedErrors.networkError
case let .networkError(error):
return error.localizedDescription

case .requestCancelled:
return String.adamant.sharedErrors.requestCancelled
Expand Down
1 change: 1 addition & 0 deletions Adamant/Models/ApiServiceResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
//

typealias ApiServiceResult<Success> = Result<Success, ApiServiceError>
typealias FileApiServiceResult<Success> = Result<Success, FileManagerError>
8 changes: 8 additions & 0 deletions Adamant/Models/CoreData/Chatroom+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public class Chatroom: NSManagedObject {
return result?.checkAndReplaceSystemWallets()
}

@MainActor func hasPartnerName(addressBookService: AddressBookService) -> Bool {
guard let partner = partner else { return false }

return partner.address.flatMap { addressBookService.getName(for: $0) } != nil
|| title != nil
|| partner.name != nil
}

private let semaphore = DispatchSemaphore(value: 1)

func updateLastTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,36 @@ extension RichMessageTransaction {
return richContent?[RichContentKeys.reply.replyMessage] is [String: String]
}

func isFileReply() -> Bool {
let replyMessage = richContent?[RichContentKeys.reply.replyMessage] as? [String: Any]
return replyMessage?[RichContentKeys.file.files] is [[String: Any]]
}

func getRichValue(for key: String) -> String? {
if let value = richContent?[key] as? String {
return value
}

if let content = richContent?[RichContentKeys.reply.replyMessage] as? [String: String],
let value = content[key] {
if let content = richContent?[RichContentKeys.reply.replyMessage] as? [String: Any],
let value = content[key] as? String {
return value
}

return nil
}

func getRichValue<T>(for key: String) -> T? {
if let value = richContent?[key] as? T {
return value
}

if let content = richContent?[RichContentKeys.file.files] as? [String: Any],
let value = content[key] as? T {
return value
}

if let content = richContent?[RichContentKeys.reply.replyMessage] as? [String: Any],
let value = content[key] as? T {
return value
}

Expand Down
34 changes: 34 additions & 0 deletions Adamant/Models/DownloadPolicy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DownloadPolicy.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 13.08.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation
import CommonKit

extension Notification.Name {
struct Storage {
public static let storageClear = Notification.Name("adamant.storage.clear")
public static let storageProprietiesUpdated = Notification.Name("adamant.storage.ProprietiesUpdated")
}
}

enum DownloadPolicy: String {
case everybody
case nobody
case contacts

var title: String {
switch self {
case .everybody:
return .localized("Storage.DownloadPolicy.Everybody.Title")
case .nobody:
return .localized("Storage.DownloadPolicy.Nobody.Title")
case .contacts:
return .localized("Storage.DownloadPolicy.Contacts.Title")
}
}
}
31 changes: 31 additions & 0 deletions Adamant/Models/IPFSNodeStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// IPFSNodeStatus.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 19.08.2024.
// Copyright © 2024 Adamant. All rights reserved.
//

import Foundation

struct IPFSNodeStatus: Codable {
let version: String
}

/* JSON
{
"version":"0.0.1",
"timestamp":1724085764840,
"heliaStatus":"started",
"peerId":"12D3KooWGMp6SaKon2UKwJsDEf3chLAGRzsjdAfDGN9zcwt6ydqJ",
"multiAddresses":[
"/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWGMp6SaKon2UKwJsDEf3chLAGRzsjdAfDGN9zcwt6ydqJ",
"/ip4/95.216.45.88/tcp/4001/p2p/12D3KooWGMp6SaKon2UKwJsDEf3chLAGRzsjdAfDGN9zcwt6ydqJ"
],
"blockstoreSizeMb":5053.823321342468,
"datastoreSizeMb":0.135406494140625,
"availableSizeInMb":943942
}
*/
Loading

0 comments on commit ec4b606

Please sign in to comment.