Skip to content

Import minor EE fixes from C-Core #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
---
version: v0.4.0
version: v0.4.2
changelog:
- date: 2025-03-31
version: v0.4.2
changes:
- type: bug
text: "Imported a fix to an edge-case race condition in C-Core EE."
- type: bug
text: "Fixed an issue where user.CustomData() was improperly linked on C++ side."
- date: 2025-03-04
version: v0.4.0
changes:
Expand Down
4 changes: 2 additions & 2 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task TestGetEventHistory()
public async Task TestGetUsers()
{
var users = await chat.GetUsers();
Assert.True(users.Users.Any(x => x.Id == currentUser.Id));
Assert.True(users.Users.Any());
}

[Test]
Expand Down Expand Up @@ -181,7 +181,7 @@ public async Task TestMarkAllMessagesAsRead()

var counts = await chat.GetUnreadMessagesCounts();

Assert.False(counts.Any(x => x.Count > 0));
Assert.False(counts.Any(x => x.Channel.Id == channel.Id && x.Count > 0));
}

[Test]
Expand Down
28 changes: 17 additions & 11 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/MembershipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public async Task Setup()
{
Assert.Fail();
}

channel.Join();
await Task.Delay(3500);
}

[TearDown]
public async Task CleanUp()
{
Expand All @@ -54,6 +55,7 @@ public async Task TestUpdateMemberships()
Assert.Fail();
return;
}

var manualUpdatedEvent = new ManualResetEvent(false);
testMembership.OnMembershipUpdated += membership =>
{
Expand All @@ -63,7 +65,7 @@ public async Task TestUpdateMemberships()
testMembership.SetListeningForUpdates(true);

await Task.Delay(4000);

await testMembership.Update("{\"key\": \"" + Guid.NewGuid() + "\"}");
var updated = manualUpdatedEvent.WaitOne(8000);
Assert.IsTrue(updated);
Expand All @@ -81,7 +83,8 @@ public async Task TestInvite()
[Test]
public async Task TestInviteMultiple()
{
var testChannel = (await chat.CreateGroupConversation([user], "invite_multiple_test_group_channel_3")).CreatedChannel;
var testChannel = (await chat.CreateGroupConversation([user], "invite_multiple_test_group_channel_3"))
.CreatedChannel;
var secondUser = await chat.GetOrCreateUser("second_invite_user");
var thirdUser = await chat.GetOrCreateUser("third_invite_user");
var returnedMemberships = await testChannel.InviteMultiple([
Expand All @@ -99,9 +102,9 @@ public async Task TestLastRead()
{
var testChannel = await chat.CreatePublicConversation("last_read_test_channel_57");
testChannel.Join();

await Task.Delay(4000);

var membership = (await user.GetMemberships(limit: 20)).Memberships
.FirstOrDefault(x => x.ChannelId == testChannel.Id);
if (membership == null)
Expand All @@ -111,11 +114,11 @@ public async Task TestLastRead()
}

var messageReceivedManual = new ManualResetEvent(false);

testChannel.OnMessageReceived += async message =>
{
await membership.SetLastReadMessage(message);

await Task.Delay(7000);

var lastTimeToken = membership.GetLastReadMessageTimeToken();
Expand All @@ -138,15 +141,18 @@ public async Task TestUnreadMessagesCount()
{
var unreadChannel = await chat.CreatePublicConversation($"test_channel_{Guid.NewGuid()}");
unreadChannel.Join();

await Task.Delay(3500);

await unreadChannel.SendText("one");
await unreadChannel.SendText("two");
await unreadChannel.SendText("three");

await Task.Delay(8000);

var membership = (await chat.GetUserMemberships(user.Id, limit: 20)).Memberships
.FirstOrDefault(x => x.ChannelId == unreadChannel.Id);
Assert.True(membership != null && await membership.GetUnreadMessagesCount() == 3);

var membership = (await unreadChannel.GetMemberships())
.Memberships.FirstOrDefault(x => x.UserId == user.Id);
var unreadCount = membership == null ? -1 : await membership.GetUnreadMessagesCount();
Assert.True(unreadCount >= 3, $"Expected >=3 unread but got: {unreadCount}");
}
}
15 changes: 7 additions & 8 deletions c-sharp-chat/PubnubChatApi/PubNubChatApi.Tests/ThreadsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public async Task Setup()
PubnubTestsParameters.SubscribeKey,
"threads_tests_user_2")
);
channel = await chat.CreatePublicConversation();
var randomId = Guid.NewGuid().ToString()[..10];
channel = await chat.CreatePublicConversation(randomId);
if (!chat.TryGetCurrentUser(out user))
{
Assert.Fail();
Expand Down Expand Up @@ -77,17 +78,15 @@ public async Task TestThreadChannelParentChannelPinning()
await thread.SendText("thread init message");

await Task.Delay(7000);

thread.OnMessageReceived += async threadMessage =>
{
await thread.PinMessageToParentChannel(threadMessage);
};
await thread.SendText("some_thread_message");

var threadMessage =
(await thread.GetThreadHistory("99999999999999999", "00000000000000000", 1))[0];
await thread.PinMessageToParentChannel(threadMessage);

await Task.Delay(7000);

var hasPinned = channel.TryGetPinnedMessage(out var pinnedMessage);
var correctText = hasPinned && pinnedMessage.MessageText == "some_thread_message";
var correctText = hasPinned && pinnedMessage.MessageText == "thread init message";
Assert.True(hasPinned && correctText);
await thread.UnPinMessageFromParentChannel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ internal void ParseJsonUpdatePointers(string jsonString)
if (updatedThreadMessagePointer != IntPtr.Zero)
{
Debug.WriteLine("Deserialized thread message update");
var id = Message.GetMessageIdFromPtr(updatedThreadMessagePointer);
var id = ThreadMessage.GetThreadMessageIdFromPtr(updatedThreadMessagePointer);
if (messageWrappers.TryGetValue(id, out var existingMessageWrapper))
{
if (existingMessageWrapper is ThreadMessage existingThreadMessageWrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task<List<ThreadMessage>> GetThreadHistory(string startTimeToken, s
return history;
}

public async Task PinMessageToParentChannel(Message message)
public async Task PinMessageToParentChannel(ThreadMessage message)
{
var newChannelPointer = await Task.Run(() => pn_thread_channel_pin_message_to_parent_channel(pointer, message.Pointer));
CUtilities.CheckCFunctionResult(newChannelPointer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ internal void BroadcastInviteEvent(ChatEvent chatEvent)
public async void SetListeningForModerationEvents(bool listen)
{
moderationListeningHandle = await SetListening(moderationListeningHandle, listen,
() => chat.ListenForEvents(Id, PubnubChatEventType.Moderation));
() => chat.ListenForEvents($"PUBNUB_INTERNAL_MODERATION.{Id}", PubnubChatEventType.Moderation));
}

internal void BroadcastModerationEvent(ChatEvent chatEvent)
Expand Down
Binary file modified c-sharp-chat/PubnubChatApi/PubnubChatApi/pubnub-chat.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.pubnub.pubnubchat",
"version": "0.4.0",
"version": "0.4.2",
"displayName": "Pubnub Chat",
"description": "PubNub Unity Chat SDK",
"unity": "2022.3",
Expand Down