Skip to content

Commit

Permalink
Temporary rollback on the SynchronizationContext removal and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-grzesiowski committed Feb 3, 2025
1 parent e329551 commit 18c5ff1
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -199,4 +199,4 @@ public void TestEmitUserMention()
var received = receivedManualEvent.WaitOne(7000);
Assert.True(received);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -55,4 +55,4 @@ public void TestModerationEvents()
var moderationEventReceived = manualModerationEvent.WaitOne(5000);
Assert.IsTrue(moderationEventReceived);
}
}
}*/
8 changes: 4 additions & 4 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ChatTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PubNubChatAPI.Entities;
/*using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
using PubnubChatApi.Enums;
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task TestGetUserSuggestions()
var suggestions = chat.GetUserSuggestions("@THE");
Assert.True(suggestions.Any(x => x.Id == suggestedUser.Id));
}*/
}#1#
[Test]
public async Task TestGetEventHistory()
Expand All @@ -99,7 +99,7 @@ public async Task TestGetChannelSuggestions()
var suggestions = chat.GetChannelSuggestions("#SUGGESTED");
Assert.True(suggestions.Any(x => x.Id == suggestedChannel.Id));
}*/
}#1#
[Test]
public void TestGetUsers()
Expand Down Expand Up @@ -258,4 +258,4 @@ public async Task TestCanI()
Assert.True(accessChat.ChatAccessManager.CanI(PubnubAccessPermission.Read, PubnubAccessResourceType.Channels,
"can_i_test_channel"));
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -147,4 +147,4 @@ public async Task TestUnreadMessagesCount()
.FirstOrDefault(x => x.ChannelId == unreadChannel.Id);
Assert.True(membership != null && membership.GetUnreadMessagesCount() == 3);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PubNubChatAPI.Entities;
/*using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
namespace PubNubChatApi.Tests;
Expand Down Expand Up @@ -166,4 +166,4 @@ public void TestSend()
var gotCallback = successReset.WaitOne(6000);
Assert.True(gotCallback);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -216,7 +216,7 @@ public void TestMessageReactions()
/*var has = message.HasUserReaction("happy");
Assert.True(has);
var reactions = message.Reactions;
Assert.True(reactions.Count == 1 && reactions.Any(x => x.Value == "happy"));*/
Assert.True(reactions.Count == 1 && reactions.Any(x => x.Value == "happy"));#1#
await Task.Delay(5000);
Expand Down Expand Up @@ -286,4 +286,4 @@ public async Task TestCreateThread()
var received = manualReceiveEvent.WaitOne(30000);
Assert.IsTrue(received);
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -80,4 +80,4 @@ public async Task TestGetRestrictionsSets()
Assert.True(a.Restrictions.Any(x => x.UserId == user.Id));
Assert.True(b.Restrictions.Any(x => x.ChannelId == channel.Id));
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -184,4 +184,4 @@ public void TestThreadMessageUpdate()
var updated = messageUpdatedReset.WaitOne(255000);
Assert.True(updated);
}
}
}*/
4 changes: 2 additions & 2 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/UserTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
/*using System.Diagnostics;
using PubNubChatAPI.Entities;
using PubnubChatApi.Entities.Data;
Expand Down Expand Up @@ -76,4 +76,4 @@ public async Task TestUserUpdate()
var updated = updatedReset.WaitOne(8000);
Assert.True(updated);
}
}
}*/
114 changes: 57 additions & 57 deletions c-sharp-chat/PubnubChatApi/PubnubChatApi/Entities/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public Chat(PubnubChatConfig config, SynchronizationContext? synchronizationCont

Config = config;
ChatAccessManager = new ChatAccessManager(chatPointer);
context = null;//synchronizationContext ?? SynchronizationContext.Current;
context = synchronizationContext ?? SynchronizationContext.Current;

fetchUpdatesThread = new Thread(FetchUpdatesLoop) { IsBackground = true };
fetchUpdatesThread.Start();
Expand All @@ -365,7 +365,7 @@ private void FetchUpdatesLoop()

internal void ParseJsonUpdatePointers(string jsonPointers)
{
/*void Post(SendOrPostCallback callback, object? state)
void Post(SendOrPostCallback callback, object? state)
{
if (context != null)
{
Expand All @@ -375,7 +375,7 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
{
callback.Invoke(state);
}
}*/
}

if (!string.IsNullOrEmpty(jsonPointers) && jsonPointers != "[]")
{
Expand Down Expand Up @@ -411,69 +411,69 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
if (TryGetChannel(chatEvent.ChannelId, out var typingChannel)
&& typingChannel.TryParseAndBroadcastTypingEvent(chatEvent))
{
//Post(delegate
//{
Post(delegate
{
OnTypingEvent?.Invoke(chatEvent);
//}, null);
}, null);
}
else
{
failedToInvoke = true;
}
break;
case PubnubChatEventType.Report:
//Post(delegate
//{
Post(delegate
{
OnReportEvent?.Invoke(chatEvent);
//}, null);
}, null);
break;
case PubnubChatEventType.Receipt:
//Post(delegate
//{
Post(delegate
{
OnReadReceiptEvent?.Invoke(chatEvent);
//}, null);
}, null);
if (TryGetChannel(chatEvent.ChannelId, out var readReceiptChannel))
{
//Post(delegate
//{
Post(delegate
{
readReceiptChannel.BroadcastReadReceipt(chatEvent);
//}, null);
}, null);
}
break;
case PubnubChatEventType.Mention:
//Post(delegate
//{
Post(delegate
{
OnMentionEvent?.Invoke(chatEvent);
//}, null);
}, null);
break;
case PubnubChatEventType.Invite:
//Post(delegate
//{
Post(delegate
{
OnInviteEvent?.Invoke(chatEvent);
//}, null);
}, null);
break;
case PubnubChatEventType.Custom:
//Post(delegate
//{
Post(delegate
{
OnCustomEvent?.Invoke(chatEvent);
//}, null);
}, null);
break;
case PubnubChatEventType.Moderation:
//Post(delegate
//{
Post(delegate
{
OnModerationEvent?.Invoke(chatEvent);
//}, null);
}, null);
break;
default:
throw new ArgumentOutOfRangeException();
}

if (!failedToInvoke)
{
//Post(delegate
//{
Post(delegate
{
OnAnyEvent?.Invoke(chatEvent);
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -492,10 +492,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
var timeToken = Message.GetMessageIdFromPtr(threadMessagePointer);
var message = new ThreadMessage(this, threadMessagePointer, timeToken);
messageWrappers[timeToken] = message;
//Post(delegate
//{
Post(delegate
{
threadChannel.BroadcastMessageReceived(message);
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -514,10 +514,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
var timeToken = Message.GetMessageIdFromPtr(messagePointer);
var message = new Message(this, messagePointer, timeToken);
messageWrappers[timeToken] = message;
//Post(delegate
//{
Post(delegate
{
channel.BroadcastMessageReceived(message);
//}, null);
}, null);
}
pn_dispose_message(pointer);
continue;
Expand All @@ -534,10 +534,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
if (existingMessageWrapper is ThreadMessage existingThreadMessageWrapper)
{
existingThreadMessageWrapper.UpdateWithPartialPtr(updatedThreadMessagePointer);
//Post(delegate
//{
Post(delegate
{
existingThreadMessageWrapper.BroadcastMessageUpdate();
//}, null);
}, null);
}
else
{
Expand All @@ -559,10 +559,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
if (messageWrappers.TryGetValue(id, out var existingMessageWrapper))
{
existingMessageWrapper.UpdateWithPartialPtr(updatedMessagePointer);
//Post(delegate
//{
Post(delegate
{
existingMessageWrapper.BroadcastMessageUpdate();
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -583,18 +583,18 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
//This has a check for "PUBNUB_INTERNAL_THREAD" and will correctly update the pointer
TryGetChannel(id, out var existingThreadChannel);
//TODO: broadcast thread channel update (very low priority because I don't think they have that in JS chat)
//Post(delegate
//{
Post(delegate
{
existingThreadChannel.BroadcastChannelUpdate();
//}, null);
}, null);
}
else if (channelWrappers.TryGetValue(id, out var existingChannelWrapper))
{
existingChannelWrapper.UpdateWithPartialPtr(channelPointer);
//Post(delegate
//{
Post(delegate
{
existingChannelWrapper.BroadcastChannelUpdate();
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -611,10 +611,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
if (userWrappers.TryGetValue(id, out var existingUserWrapper))
{
existingUserWrapper.UpdateWithPartialPtr(userPointer);
//Post(delegate
//{
Post(delegate
{
existingUserWrapper.BroadcastUserUpdate();
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -631,10 +631,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)
if (membershipWrappers.TryGetValue(id, out var existingMembershipWrapper))
{
existingMembershipWrapper.UpdateWithPartialPtr(membershipPointer);
//Post(delegate
//{
Post(delegate
{
existingMembershipWrapper.BroadcastMembershipUpdate();
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand All @@ -656,10 +656,10 @@ internal void ParseJsonUpdatePointers(string jsonPointers)

if (TryGetChannel(channelId, out var channel))
{
//Post(delegate
//{
Post(delegate
{
channel.BroadcastPresenceUpdate();
//}, null);
}, null);
}

pn_dispose_message(pointer);
Expand Down

0 comments on commit 18c5ff1

Please sign in to comment.