Skip to content

Commit 888f424

Browse files
committed
- client discovery optimizations
- push/local notifications improvements - received indicator fixes - other improvements
1 parent ae56bb4 commit 888f424

File tree

16 files changed

+243
-94
lines changed

16 files changed

+243
-94
lines changed

Spixi-PushService/Spixi-PushService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
</PropertyGroup>
3838

3939
<ItemGroup>
40-
<PackageReference Include="OneSignalSDK.DotNet" Version="5.2.1" />
40+
<PackageReference Include="OneSignalSDK.DotNet" Version="5.2.2" />
4141
</ItemGroup>
4242
</Project>

Spixi/Interfaces/IPushService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ public interface IPushService
55
{
66
void initialize();
77
void setTag(string tag);
8-
void clearNotifications();
9-
void showLocalNotification(string title, string message, string data);
8+
void clearNotifications(int unreadCount);
9+
void clearRemoteNotifications(int unreadCount);
10+
void showLocalNotification(int messageId, string title, string message, string data, bool alert, int unreadCount);
1011
}
1112
}

Spixi/Meta/Node.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IXICore;
1+
using Force.Crc32;
2+
using IXICore;
23
using IXICore.Inventory;
34
using IXICore.Meta;
45
using IXICore.Network;
@@ -278,14 +279,18 @@ static public void mainLoop()
278279

279280
try
280281
{
282+
bool fireLocalNotification = OperatingSystem.IsAndroid();
281283
while (running)
282284
{
283285
try
284286
{
285287
PeerStorage.savePeersFile();
286288

287289
if (Config.enablePushNotifications)
288-
OfflinePushMessages.fetchPushMessages();
290+
{
291+
OfflinePushMessages.fetchPushMessages(false, fireLocalNotification, false);
292+
fireLocalNotification = false;
293+
}
289294

290295
// Update the friendlist
291296
updateFriendStatuses();
@@ -357,7 +362,8 @@ static public void updateFriendStatuses()
357362

358363
if (presence != null)
359364
{
360-
if (friend.online == false)
365+
if (friend.online == false
366+
&& friend.relayNode != null)
361367
{
362368
friend.online = true;
363369
UIHelpers.setContactStatus(friend.walletAddress, friend.online, friend.getUnreadMessageCount(), "", 0);
@@ -656,7 +662,7 @@ public override byte[] getBlockHash(ulong blockNum)
656662
return b.blockChecksum;
657663
}
658664

659-
public static FriendMessage addMessageWithType(byte[] id, FriendMessageType type, Address wallet_address, int channel, string message, bool local_sender = false, Address sender_address = null, long timestamp = 0, bool fire_local_notification = true, int payable_data_len = 0)
665+
public static FriendMessage addMessageWithType(byte[] id, FriendMessageType type, Address wallet_address, int channel, string message, bool local_sender = false, Address sender_address = null, long timestamp = 0, bool fire_local_notification = true, bool alert = true, int payable_data_len = 0)
660666
{
661667
FriendMessage friend_message = FriendList.addMessageWithType(id, type, wallet_address, channel, message, local_sender, sender_address, timestamp, fire_local_notification, payable_data_len);
662668
if (friend_message != null)
@@ -706,7 +712,9 @@ public static FriendMessage addMessageWithType(byte[] id, FriendMessageType type
706712
if (friend.bot == false
707713
|| (friend.metaData.botInfo != null && friend.metaData.botInfo.sendNotification))
708714
{
709-
SPushService.showLocalNotification("Spixi", "New Message", friend.walletAddress.ToString());
715+
int unreadCount = FriendList.getUnreadMessageCount();
716+
SPushService.showLocalNotification((int)Crc32Algorithm.Compute(friend_message.id), "Spixi", "New Message", friend.walletAddress.ToString(), alert, unreadCount);
717+
SPushService.clearRemoteNotifications(unreadCount);
710718
}
711719
}
712720
}

Spixi/Network/NetworkProtocol.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,16 @@ private static void handleUpdatePresence(byte[] data, RemoteEndpoint endpoint)
413413
if (f != null)
414414
{
415415
var pa = p.addresses[0];
416-
// TODO use actual wallet address once Presence hostname contains such address
417-
f.relayNode = new Peer(pa.address, null, pa.lastSeenTime, 0, 0, 0);
418-
f.updatedStreamingNodes = pa.lastSeenTime;
419-
if (UIHelpers.isChatScreenDisplayed(f))
416+
if (f.lastSeenTime < pa.lastSeenTime)
420417
{
421-
StreamClientManager.connectTo(f.relayNode.hostname, f.relayNode.walletAddress);
418+
// TODO use actual wallet address once Presence hostname contains such address
419+
f.relayNode = new Peer(pa.address, null, pa.lastSeenTime, 0, 0, 0);
420+
f.updatedStreamingNodes = pa.lastSeenTime;
421+
f.lastSeenTime = pa.lastSeenTime;
422+
if (UIHelpers.isChatScreenDisplayed(f))
423+
{
424+
StreamClientManager.connectTo(f.relayNode.hostname, f.relayNode.walletAddress);
425+
}
422426
}
423427
}
424428
}
@@ -444,12 +448,16 @@ private static void handleKeepAlivePresence(byte[] data, RemoteEndpoint endpoint
444448
if (f != null)
445449
{
446450
var pa = p.addresses[0];
447-
// TODO use actual wallet address once Presence hostname contains such address
448-
f.relayNode = new Peer(pa.address, null, pa.lastSeenTime, 0, 0, 0);
449-
f.updatedStreamingNodes = pa.lastSeenTime;
450-
if (UIHelpers.isChatScreenDisplayed(f))
451+
if (f.lastSeenTime < pa.lastSeenTime)
451452
{
452-
StreamClientManager.connectTo(f.relayNode.hostname, f.relayNode.walletAddress);
453+
// TODO use actual wallet address once Presence hostname contains such address
454+
f.relayNode = new Peer(pa.address, null, pa.lastSeenTime, 0, 0, 0);
455+
f.updatedStreamingNodes = pa.lastSeenTime;
456+
f.lastSeenTime = pa.lastSeenTime;
457+
if (UIHelpers.isChatScreenDisplayed(f))
458+
{
459+
StreamClientManager.connectTo(f.relayNode.hostname, f.relayNode.walletAddress);
460+
}
453461
}
454462
}
455463
}
@@ -522,7 +530,7 @@ static void handleSectorNodes(byte[] data, RemoteEndpoint endpoint)
522530
var friends = FriendList.getFriendsBySectorPrefix(prefix);
523531
foreach(var friend in friends)
524532
{
525-
friend.updatedSectorNodes = Clock.getNetworkTimestamp();
533+
friend.updatedSectorNodes = Clock.getTimestamp();
526534
friend.sectorNodes = peers;
527535
}
528536
}

Spixi/Network/StreamProcessor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public static void handleFileFullyReceived(Address sender, SpixiMessage data)
177177
}*/
178178

179179
// Called when receiving S2 data from clients
180-
public override ReceiveDataResponse receiveData(byte[] bytes, RemoteEndpoint endpoint, bool fireLocalNotification = true)
180+
public override ReceiveDataResponse receiveData(byte[] bytes, RemoteEndpoint endpoint, bool fireLocalNotification = true, bool alert = true)
181181
{
182-
ReceiveDataResponse rdr = base.receiveData(bytes, endpoint, fireLocalNotification);
182+
ReceiveDataResponse rdr = base.receiveData(bytes, endpoint);
183183
if (rdr == null)
184184
{
185185
return rdr;
@@ -377,7 +377,7 @@ public override ReceiveDataResponse receiveData(byte[] bytes, RemoteEndpoint end
377377
break;
378378

379379
case SpixiMessageCode.chat:
380-
Node.addMessageWithType(message.id, FriendMessageType.standard, sender_address, spixi_message.channel, Encoding.UTF8.GetString(spixi_message.data), false, real_sender_address, message.timestamp, fireLocalNotification);
380+
Node.addMessageWithType(message.id, FriendMessageType.standard, sender_address, spixi_message.channel, Encoding.UTF8.GetString(spixi_message.data), false, real_sender_address, message.timestamp, fireLocalNotification, alert, 0);
381381
break;
382382

383383
case SpixiMessageCode.msgReceived:
@@ -580,7 +580,7 @@ private static void handleAppRequest(byte[] messageId, Address sender_address, A
580580
{
581581
if (VoIPManager.onReceivedCall(friend, app_data.sessionId, app_data.data))
582582
{
583-
Node.addMessageWithType(app_data.sessionId, FriendMessageType.voiceCall, sender_address, 0, "");
583+
Node.addMessageWithType(messageId, FriendMessageType.voiceCall, sender_address, 0, "");
584584
}
585585
UIHelpers.refreshAppRequests = true;
586586
}

Spixi/Pages/Chat/SingleChatPage.xaml.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,17 @@ private void onLoad()
538538
Preferences.Default.Set("rating_action", "show");
539539
}
540540

541-
if (FriendList.getUnreadMessageCount() == 0)
541+
int unreadCount = FriendList.getUnreadMessageCount();
542+
if (unreadCount == 0)
542543
{
543-
SPushService.clearNotifications();
544+
SPushService.clearNotifications(unreadCount);
544545
}
545546
});
546547
}
547548

548549
public void onSend(string str)
549550
{
551+
str = str.Trim(new char[] { ' ', '\t', '\r', '\n' });
550552
if (str.Length < 1)
551553
{
552554
return;
@@ -575,7 +577,7 @@ public void onSend(string str)
575577
byte[] spixi_msg_bytes = spixi_message.getBytes();
576578

577579
// store the message and display it
578-
FriendMessage friend_message = Node.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, selectedChannel, str, true, null, 0, true, spixi_msg_bytes.Length);
580+
FriendMessage friend_message = Node.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, selectedChannel, str, true, null, 0, true, true, spixi_msg_bytes.Length);
579581

580582
// Finally, clear the input field
581583
Utils.sendUiCommand(this, "clearInput");
@@ -1647,9 +1649,10 @@ public override void onResume()
16471649

16481650
updateMessagesReadStatus();
16491651

1650-
if (FriendList.getUnreadMessageCount() == 0)
1652+
int unreadCount = FriendList.getUnreadMessageCount();
1653+
if (unreadCount == 0)
16511654
{
1652-
SPushService.clearNotifications();
1655+
SPushService.clearNotifications(unreadCount);
16531656
}
16541657
}
16551658
}

Spixi/Pages/Home/HomePage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ public override void updateScreen()
11771177
Node.changedSettings = false;
11781178
}
11791179

1180-
SPushService.clearNotifications();
1180+
SPushService.clearNotifications(FriendList.getUnreadMessageCount());
11811181
}
11821182

11831183
private void onUpdateUI(/*object source, ElapsedEventArgs e*/)

Spixi/Platforms/Android/MainActivity.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class MainActivity : MauiAppCompatActivity
3737

3838
public TaskCompletionSource<SpixiImageData> PickImageTaskCompletionSource { set; get; }
3939
internal static MainActivity Instance { get; private set; }
40-
protected override void OnCreate(Bundle bundle)
40+
protected override void OnCreate(Bundle? bundle)
4141
{
4242
Instance = this;
4343

@@ -68,7 +68,7 @@ protected override void OnCreate(Bundle bundle)
6868
handleNotificationIntent(Intent);
6969
}
7070

71-
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
71+
protected override void OnActivityResult(int requestCode, Result resultCode, Intent? intent)
7272
{
7373
base.OnActivityResult(requestCode, resultCode, intent);
7474

@@ -113,7 +113,7 @@ private void SaveFileToUri(Android.Net.Uri uri, string filePath)
113113
}
114114
}
115115

116-
protected override void OnNewIntent(Intent intent)
116+
protected override void OnNewIntent(Intent? intent)
117117
{
118118
base.OnNewIntent(intent);
119119

@@ -124,11 +124,11 @@ protected override void OnNewIntent(Intent intent)
124124
});
125125
}
126126

127-
void handleNotificationIntent(Intent intent)
127+
void handleNotificationIntent(Intent? intent)
128128
{
129129
if (intent?.Extras != null && intent.Extras.ContainsKey("fa"))
130130
{
131-
string chatId = intent.Extras.GetString("fa");
131+
string? chatId = intent.Extras.GetString("fa");
132132
if (!string.IsNullOrEmpty(chatId))
133133
{
134134
App.startingScreen = chatId;
@@ -140,7 +140,7 @@ void handleNotificationIntent(Intent intent)
140140
// Fix Edge to Edge
141141
private class InsetsListener : Java.Lang.Object, AndroidX.Core.View.IOnApplyWindowInsetsListener
142142
{
143-
public WindowInsetsCompat OnApplyWindowInsets(View v, WindowInsetsCompat insets)
143+
public WindowInsetsCompat? OnApplyWindowInsets(View? v, WindowInsetsCompat? insets)
144144
{
145145
// Get system bars (status + navigation) and IME (keyboard) insets
146146
var sysInsets = insets.GetInsets(WindowInsetsCompat.Type.SystemBars());
@@ -156,9 +156,9 @@ public WindowInsetsCompat OnApplyWindowInsets(View v, WindowInsetsCompat insets)
156156
}
157157

158158
// Optional override for older Android versions
159-
public WindowInsets OnApplyWindowInsets(View v, WindowInsets insets)
159+
public WindowInsets? OnApplyWindowInsets(View? v, WindowInsets? insets)
160160
{
161-
return v.OnApplyWindowInsets(insets);
161+
return v?.OnApplyWindowInsets(insets);
162162
}
163163
}
164164

0 commit comments

Comments
 (0)