Skip to content

Commit dbf5632

Browse files
socket work improvements
1 parent b0e9a05 commit dbf5632

File tree

9 files changed

+70
-30
lines changed

9 files changed

+70
-30
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@
28972897
CODE_SIGN_ENTITLEMENTS = MessageNotificationContentExtension/Debug.entitlements;
28982898
CODE_SIGN_IDENTITY = "iPhone Developer";
28992899
CODE_SIGN_STYLE = Manual;
2900-
CURRENT_PROJECT_VERSION = 174;
2900+
CURRENT_PROJECT_VERSION = 175;
29012901
DEVELOPMENT_TEAM = J2L77FMN46;
29022902
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
29032903
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -2906,7 +2906,7 @@
29062906
"@executable_path/Frameworks",
29072907
"@executable_path/../../Frameworks",
29082908
);
2909-
MARKETING_VERSION = 2.3.1;
2909+
MARKETING_VERSION = 2.3.2;
29102910
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
29112911
MTL_FAST_MATH = YES;
29122912
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.MessageNotificationContentExtension";
@@ -2926,7 +2926,7 @@
29262926
CODE_SIGN_IDENTITY = "Apple Development";
29272927
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
29282928
CODE_SIGN_STYLE = Manual;
2929-
CURRENT_PROJECT_VERSION = 174;
2929+
CURRENT_PROJECT_VERSION = 175;
29302930
DEVELOPMENT_TEAM = J2L77FMN46;
29312931
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
29322932
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -2935,7 +2935,7 @@
29352935
"@executable_path/Frameworks",
29362936
"@executable_path/../../Frameworks",
29372937
);
2938-
MARKETING_VERSION = 2.3.1;
2938+
MARKETING_VERSION = 2.3.2;
29392939
MTL_FAST_MATH = YES;
29402940
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.MessageNotificationContentExtension";
29412941
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -3073,7 +3073,7 @@
30733073
CODE_SIGN_ENTITLEMENTS = Adamant/Debug.entitlements;
30743074
CODE_SIGN_IDENTITY = "iPhone Developer";
30753075
CODE_SIGN_STYLE = Manual;
3076-
CURRENT_PROJECT_VERSION = 174;
3076+
CURRENT_PROJECT_VERSION = 175;
30773077
DEVELOPMENT_TEAM = J2L77FMN46;
30783078
DISPLAY_NAME = ADM.Dev;
30793079
EXCLUDED_SOURCE_FILE_NAMES = "";
@@ -3083,7 +3083,7 @@
30833083
"$(inherited)",
30843084
"@executable_path/Frameworks",
30853085
);
3086-
MARKETING_VERSION = 2.3.1;
3086+
MARKETING_VERSION = 2.3.2;
30873087
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev";
30883088
PRODUCT_NAME = "$(TARGET_NAME)";
30893089
PROVISIONING_PROFILE = "e4233bbf-3705-44fe-95b0-e77475672c60";
@@ -3102,7 +3102,7 @@
31023102
CODE_SIGN_IDENTITY = "Apple Development";
31033103
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
31043104
CODE_SIGN_STYLE = Manual;
3105-
CURRENT_PROJECT_VERSION = 174;
3105+
CURRENT_PROJECT_VERSION = 175;
31063106
DEVELOPMENT_TEAM = J2L77FMN46;
31073107
DISPLAY_NAME = Adamant;
31083108
EXCLUDED_SOURCE_FILE_NAMES = Debug.xcassets;
@@ -3112,7 +3112,7 @@
31123112
"$(inherited)",
31133113
"@executable_path/Frameworks",
31143114
);
3115-
MARKETING_VERSION = 2.3.1;
3115+
MARKETING_VERSION = 2.3.2;
31163116
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger";
31173117
PRODUCT_NAME = "$(TARGET_NAME)";
31183118
PROVISIONING_PROFILE = "bedd1b75-2f23-4a85-a0b2-14c424fcff42";
@@ -3130,7 +3130,7 @@
31303130
CODE_SIGN_ENTITLEMENTS = TransferNotificationContentExtension/Debug.entitlements;
31313131
CODE_SIGN_IDENTITY = "iPhone Developer";
31323132
CODE_SIGN_STYLE = Manual;
3133-
CURRENT_PROJECT_VERSION = 174;
3133+
CURRENT_PROJECT_VERSION = 175;
31343134
DEVELOPMENT_TEAM = J2L77FMN46;
31353135
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
31363136
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3139,7 +3139,7 @@
31393139
"@executable_path/Frameworks",
31403140
"@executable_path/../../Frameworks",
31413141
);
3142-
MARKETING_VERSION = 2.3.1;
3142+
MARKETING_VERSION = 2.3.2;
31433143
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
31443144
MTL_FAST_MATH = YES;
31453145
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.TransferNotificationContentExtension";
@@ -3159,7 +3159,7 @@
31593159
CODE_SIGN_IDENTITY = "Apple Development";
31603160
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
31613161
CODE_SIGN_STYLE = Manual;
3162-
CURRENT_PROJECT_VERSION = 174;
3162+
CURRENT_PROJECT_VERSION = 175;
31633163
DEVELOPMENT_TEAM = J2L77FMN46;
31643164
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
31653165
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3168,7 +3168,7 @@
31683168
"@executable_path/Frameworks",
31693169
"@executable_path/../../Frameworks",
31703170
);
3171-
MARKETING_VERSION = 2.3.1;
3171+
MARKETING_VERSION = 2.3.2;
31723172
MTL_FAST_MATH = YES;
31733173
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.TransferNotificationContentExtension";
31743174
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -3188,7 +3188,7 @@
31883188
CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/Debug.entitlements;
31893189
CODE_SIGN_IDENTITY = "iPhone Developer";
31903190
CODE_SIGN_STYLE = Manual;
3191-
CURRENT_PROJECT_VERSION = 174;
3191+
CURRENT_PROJECT_VERSION = 175;
31923192
DEVELOPMENT_TEAM = J2L77FMN46;
31933193
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
31943194
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3197,7 +3197,7 @@
31973197
"@executable_path/Frameworks",
31983198
"@executable_path/../../Frameworks",
31993199
);
3200-
MARKETING_VERSION = 2.3.1;
3200+
MARKETING_VERSION = 2.3.2;
32013201
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
32023202
MTL_FAST_MATH = YES;
32033203
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.NotificationServiceExtension";
@@ -3217,7 +3217,7 @@
32173217
CODE_SIGN_IDENTITY = "Apple Development";
32183218
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
32193219
CODE_SIGN_STYLE = Manual;
3220-
CURRENT_PROJECT_VERSION = 174;
3220+
CURRENT_PROJECT_VERSION = 175;
32213221
DEVELOPMENT_TEAM = J2L77FMN46;
32223222
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
32233223
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3226,7 +3226,7 @@
32263226
"@executable_path/Frameworks",
32273227
"@executable_path/../../Frameworks",
32283228
);
3229-
MARKETING_VERSION = 2.3.1;
3229+
MARKETING_VERSION = 2.3.2;
32303230
MTL_FAST_MATH = YES;
32313231
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.NotificationServiceExtension";
32323232
PRODUCT_NAME = "$(TARGET_NAME)";

Adamant/ServiceProtocols/NodesSource.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ protocol NodesSource {
4343
func getNewNode() -> Node
4444
func getValidNode(completion: @escaping ((Node?) -> Void))
4545

46+
func getSocketNewNode() -> Node
47+
4648
func saveNodes()
4749
func reloadNodes()
4850

Adamant/Services/AdamantNodesSource.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class AdamantNodesSource: NodesSource {
7171
}
7272
}
7373

74+
func getSocketNewNode() -> Node {
75+
return nodes[0]
76+
}
77+
7478
// MARK: - Tools
7579
func saveNodes() {
7680
do {

Adamant/Services/DataProviders/AdamantChatsProvider.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ extension AdamantChatsProvider {
199199
switch result {
200200
case .success(let trans):
201201
self.processingQueue.async {
202-
203202
self.process(messageTransactions: [trans],
204203
senderId: address,
205204
privateKey: privateKey,
@@ -551,6 +550,7 @@ extension AdamantChatsProvider {
551550
switch result {
552551
case .success(let transaction):
553552
do {
553+
transaction.statusEnum = MessageStatus.delivered
554554
try context.save()
555555
completion(.success(transaction: transaction))
556556
} catch {
@@ -941,7 +941,6 @@ extension AdamantChatsProvider {
941941
if height < h {
942942
height = h
943943
}
944-
945944
unconfirmedsSemaphore.signal()
946945
continue
947946
} else {
@@ -993,11 +992,15 @@ extension AdamantChatsProvider {
993992
}
994993

995994
if trans == nil {
995+
if (chatTransaction.blockId?.isEmpty ?? true) && (chatTransaction.amountValue ?? 0.0 > 0.0) {
996+
chatTransaction.statusEnum = .pending
997+
}
996998
messages.insert(chatTransaction)
997999
} else {
9981000
trans?.height = chatTransaction.height
9991001
trans?.blockId = chatTransaction.blockId
10001002
trans?.confirmations = chatTransaction.confirmations
1003+
trans?.statusEnum = .delivered
10011004
}
10021005
}
10031006
}
@@ -1013,7 +1016,10 @@ extension AdamantChatsProvider {
10131016

10141017
// MARK: 4. Unread messagess
10151018
if let readedLastHeight = readedLastHeight {
1016-
let unreadTransactions = newMessageTransactions.filter { $0.height > readedLastHeight }
1019+
var unreadTransactions = newMessageTransactions.filter { $0.height > readedLastHeight }
1020+
if unreadTransactions.count == 0 {
1021+
unreadTransactions = newMessageTransactions.filter { $0.height == 0 }
1022+
}
10171023
let chatrooms = Dictionary(grouping: unreadTransactions, by: ({ (t: ChatTransaction) -> Chatroom in t.chatroom! }))
10181024
for (chatroom, trs) in chatrooms {
10191025
if let address = chatroom.partner?.address {
@@ -1217,11 +1223,9 @@ extension AdamantChatsProvider {
12171223
return
12181224
}
12191225

1220-
transaction.isConfirmed = true
12211226
transaction.height = height
12221227
transaction.blockId = blockId
12231228
transaction.confirmations = confirmations
1224-
transaction.statusEnum = .delivered
12251229
self.unconfirmedTransactions.removeValue(forKey: id)
12261230

12271231
if let lastHeight = receivedLastHeight, lastHeight < height {

Adamant/Services/SocketService/AdamantSocketService.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,34 @@ class AdamantSocketService: SocketService {
1616
var adamantCore: AdamantCore!
1717
var nodesSource: NodesSource! {
1818
didSet {
19-
//nodesSource.migrate()
20-
// refreshNode()
19+
refreshNode()
2120
}
2221
}
2322

24-
private let manager = SocketManager(socketURL: URL(string: "https://endless.adamant.im")!, config: [.log(true), .compress])
25-
private var socket:SocketIOClient?
23+
// MARK: - Properties
24+
25+
private(set) var node: Node? {
26+
didSet {
27+
currentUrl = node?.asSocketURL()
28+
}
29+
}
30+
31+
private var currentUrl: URL?
32+
33+
private var manager: SocketManager!
34+
private var socket: SocketIOClient?
2635

2736
let defaultResponseDispatchQueue = DispatchQueue(label: "com.adamant.response-queue", qos: .utility, attributes: [.concurrent])
2837

38+
// MARK: - Tools
39+
40+
func refreshNode() {
41+
node = nodesSource?.getSocketNewNode()
42+
}
43+
2944
func connect(address: String) {
45+
guard let currentUrl = currentUrl else { return }
46+
manager = SocketManager(socketURL: currentUrl, config: [.log(false), .compress])
3047
socket = manager.defaultSocket
3148
socket?.on(clientEvent: .connect, callback: {[weak self] _, _ in
3249
self?.socket?.emit("address", with: [address])

Adamant/Stories/Chats/ChatViewController+MessageKit.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ extension ChatViewController: MessagesDataSource {
111111
}
112112
}
113113

114-
return NSAttributedString(string: humanizedTime.string, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2), NSAttributedString.Key.foregroundColor: UIColor.adamant.secondary])
114+
var dop = ""
115+
if let message = message as? MessageTransaction,
116+
let blockId = message.blockId,
117+
!blockId.isEmpty {
118+
dop = ""
119+
}
120+
121+
return NSAttributedString(string: dop + humanizedTime.string, attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption2), NSAttributedString.Key.foregroundColor: UIColor.adamant.secondary])
115122
}
116123

117124
func customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell {

Adamant/Wallets/Adamant/AdmWalletService+RichMessageProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ extension AdmWalletService: RichMessageProvider {
126126
extension MessageStatus {
127127
func toTransactionStatus() -> TransactionStatus {
128128
switch self {
129-
case .pending: return TransactionStatus.updating
129+
case .pending: return TransactionStatus.pending
130130
case .delivered: return TransactionStatus.success
131131
case .failed: return TransactionStatus.failed
132132
}

Adamant/Wallets/TransactionDetailsViewControllerBase.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ class TransactionDetailsViewControllerBase: FormViewController {
411411
$0.tag = Rows.block.tag
412412
$0.title = Rows.block.localized
413413

414-
if let value = transaction?.blockValue {
414+
if let value = transaction?.blockValue,
415+
!value.isEmpty {
415416
$0.value = value
416417
} else {
417418
$0.value = TransactionDetailsViewControllerBase.awaitingValueString
@@ -425,7 +426,8 @@ class TransactionDetailsViewControllerBase: FormViewController {
425426
}.cellUpdate { [weak self] (cell, row) in
426427
cell.textLabel?.textColor = .black
427428

428-
if let value = self?.transaction?.blockValue {
429+
if let value = self?.transaction?.blockValue,
430+
!value.isEmpty {
429431
row.value = value
430432
} else {
431433
row.value = TransactionDetailsViewControllerBase.awaitingValueString

AdamantShared/Models/Node.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ class Node: Equatable, Codable {
4444
}
4545
}
4646

47-
4847
/// Builds URL, using specified port, or default scheme's port, if nil
4948
///
5049
/// - Returns: URL, if no errors were thrown
50+
51+
func asSocketURL() -> URL? {
52+
return asURL(forcePort: false)
53+
}
54+
5155
func asURL() -> URL? {
5256
return asURL(forcePort: true)
5357
}

0 commit comments

Comments
 (0)