Skip to content

Commit a3a493e

Browse files
committed
send message optimizations
1 parent d3d5598 commit a3a493e

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

Spixi/Pages/Chat/SingleChatPage.xaml.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -538,58 +538,58 @@ private void onLoad()
538538
webView.Focus();
539539
}
540540

541-
542-
public async void onSend(string str)
541+
public void onSend(string str)
543542
{
544543
if (str.Length < 1)
545544
{
546545
return;
547546
}
548547

549-
if(friend.bot)
548+
Task.Run(async () =>
550549
{
551-
if (friend.metaData.botInfo.cost > 0)
550+
if (friend.bot)
552551
{
553-
IxiNumber message_cost = friend.getMessagePrice(str.Length);
554-
if (message_cost > 0)
552+
if (friend.metaData.botInfo.cost > 0)
555553
{
556-
Transaction tx = new Transaction((int)Transaction.Type.Normal, message_cost, ConsensusConfig.forceTransactionPrice, friend.walletAddress, IxianHandler.getWalletStorage().getPrimaryAddress(), null, new Address(IxianHandler.getWalletStorage().getPrimaryPublicKey()), IxianHandler.getHighestKnownNetworkBlockHeight());
557-
IxiNumber balance = IxianHandler.getWalletBalance(IxianHandler.getWalletStorage().getPrimaryAddress());
558-
if (tx.amount + tx.fee > balance)
554+
IxiNumber message_cost = friend.getMessagePrice(str.Length);
555+
if (message_cost > 0)
559556
{
560-
string alert_body = String.Format(SpixiLocalization._SL("wallet-error-balance-text"), tx.amount + tx.fee, balance);
561-
await displaySpixiAlert(SpixiLocalization._SL("wallet-error-balance-title"), alert_body, SpixiLocalization._SL("global-dialog-ok"));
562-
return;
557+
Transaction tx = new Transaction((int)Transaction.Type.Normal, message_cost, ConsensusConfig.forceTransactionPrice, friend.walletAddress, IxianHandler.getWalletStorage().getPrimaryAddress(), null, new Address(IxianHandler.getWalletStorage().getPrimaryPublicKey()), IxianHandler.getHighestKnownNetworkBlockHeight());
558+
IxiNumber balance = IxianHandler.getWalletBalance(IxianHandler.getWalletStorage().getPrimaryAddress());
559+
if (tx.amount + tx.fee > balance)
560+
{
561+
string alert_body = String.Format(SpixiLocalization._SL("wallet-error-balance-text"), tx.amount + tx.fee, balance);
562+
await displaySpixiAlert(SpixiLocalization._SL("wallet-error-balance-title"), alert_body, SpixiLocalization._SL("global-dialog-ok"));
563+
return;
564+
}
563565
}
564566
}
565567
}
566-
}
567-
568-
// Send the message
569-
SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.chat, Encoding.UTF8.GetBytes(str), selectedChannel);
570-
byte[] spixi_msg_bytes = spixi_message.getBytes();
571-
572-
// store the message and display it
573-
FriendMessage friend_message = Node.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, selectedChannel, str, true, null, 0, true, spixi_msg_bytes.Length);
574568

575-
// Finally, clear the input field
576-
Utils.sendUiCommand(this, "clearInput");
569+
SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.chat, Encoding.UTF8.GetBytes(str), selectedChannel);
570+
byte[] spixi_msg_bytes = spixi_message.getBytes();
571+
572+
// store the message and display it
573+
FriendMessage friend_message = Node.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, selectedChannel, str, true, null, 0, true, spixi_msg_bytes.Length);
577574

575+
// Finally, clear the input field
576+
Utils.sendUiCommand(this, "clearInput");
578577

579-
StreamMessage message = new StreamMessage(friend.protocolVersion);
580-
message.type = StreamMessageCode.data;
581-
message.recipient = friend.walletAddress;
582-
message.sender = IxianHandler.getWalletStorage().getPrimaryAddress();
583-
message.data = spixi_msg_bytes;
584-
message.id = friend_message.id;
578+
StreamMessage message = new StreamMessage(friend.protocolVersion);
579+
message.type = StreamMessageCode.data;
580+
message.recipient = friend.walletAddress;
581+
message.sender = IxianHandler.getWalletStorage().getPrimaryAddress();
582+
message.data = spixi_msg_bytes;
583+
message.id = friend_message.id;
585584

586-
if (friend.bot)
587-
{
588-
message.encryptionType = StreamMessageEncryptionCode.none;
589-
message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());
590-
}
585+
if (friend.bot)
586+
{
587+
message.encryptionType = StreamMessageEncryptionCode.none;
588+
message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());
589+
}
591590

592-
StreamProcessor.sendMessage(friend, message);
591+
StreamProcessor.sendMessage(friend, message);
592+
});
593593
}
594594

595595
public async Task onSendFile()

Spixi/Platforms/Android/SAudioPlayer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public void onDecodedData(short[] data)
297297
}
298298
else if (1 + Random.Shared.NextDouble() < catchup.Speed)
299299
{
300-
Logging.warn($"VoIP Dropping frame, avg {playbackCatchupController.GetAverageLatency() * 1000:F0}ms");
301300
shouldDrop = true;
302301
}
303302
break;

0 commit comments

Comments
 (0)