From 7db673bc319c9dd51798adc591b036dfbe348c83 Mon Sep 17 00:00:00 2001 From: Piotr Suwala Date: Fri, 7 Jun 2024 14:03:14 +0200 Subject: [PATCH 1/3] feat(lib): respect eTag and updated fields in the Membership object --- lib/package.json | 2 +- lib/src/entities/membership.ts | 12 ++++++- lib/tests/channel.test.ts | 61 +++++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/lib/package.json b/lib/package.json index 5279a77..7030941 100644 --- a/lib/package.json +++ b/lib/package.json @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/pubnub/js-chat#readme", "dependencies": { - "pubnub": "8.2.0" + "pubnub": "8.2.3" }, "devDependencies": { "@babel/core": "7.22.15", diff --git a/lib/src/entities/membership.ts b/lib/src/entities/membership.ts index 6a2bba3..fce07e0 100644 --- a/lib/src/entities/membership.ts +++ b/lib/src/entities/membership.ts @@ -5,13 +5,15 @@ import { Message } from "./message" import { User } from "./user" import { getErrorProxiedEntity } from "../error-logging" -export type MembershipFields = Pick +export type MembershipFields = Pick export class Membership { private chat: Chat readonly channel: Channel readonly user: User readonly custom: ObjectCustom | null | undefined + readonly updated: string + readonly eTag: string /** @internal */ constructor(chat: Chat, params: MembershipFields) { @@ -19,6 +21,8 @@ export class Membership { this.channel = params.channel this.user = params.user this.custom = params.custom + this.updated = params.updated + this.eTag = params.eTag } /** @internal */ @@ -31,6 +35,8 @@ export class Membership { channel: Channel.fromDTO(chat, channelMembershipObject.channel), user, custom: channelMembershipObject.custom, + updated: channelMembershipObject.updated, + eTag: channelMembershipObject.eTag, } return getErrorProxiedEntity(new Membership(chat, data), chat.errorLogger) @@ -46,6 +52,8 @@ export class Membership { user: User.fromDTO(chat, userMembershipObject.uuid), channel, custom: userMembershipObject.custom, + updated: userMembershipObject.updated, + eTag: userMembershipObject.eTag, } return getErrorProxiedEntity(new Membership(chat, data), chat.errorLogger) @@ -104,6 +112,8 @@ export class Membership { user: membership.user, channel: membership.channel, custom: event.message.data.custom, + updated: event.message.data.updated, + eTag: event.message.data.eTag, }) const newMemberships = memberships.map((membership) => membership.channel.id === newMembership.channel.id && diff --git a/lib/tests/channel.test.ts b/lib/tests/channel.test.ts index 8033126..e926f9f 100644 --- a/lib/tests/channel.test.ts +++ b/lib/tests/channel.test.ts @@ -1,4 +1,11 @@ -import { Channel, Message, Chat, MessageDraft, INTERNAL_MODERATION_PREFIX } from "../src" +import { + Channel, + Message, + Chat, + MessageDraft, + INTERNAL_MODERATION_PREFIX, + Membership, +} from "../src" import { sleep, extractMentionedUserIds, @@ -336,9 +343,6 @@ describe("Channel test", () => { await channel.createThread() } catch (error) { errorOccurred = true - - //Should to be clarified - // expect(error.message).toBe("Cannot create an empty thread") } expect(errorOccurred).toBe(true) @@ -1162,4 +1166,53 @@ describe("Channel test", () => { filter: `!(channel.id LIKE '${INTERNAL_MODERATION_PREFIX}*')`, }) }) + + test("should set 'eTag' and 'updated' on the Membership object", async () => { + const membershipsDTOMock = { + status: 200, + data: [ + { + channel: { + id: "0053d903-62d5-4f14-91cc-50aa90b1ab30", + name: "0053d903-62d5-4f14-91cc-50aa90b1ab30", + description: null, + type: "group", + status: null, + custom: null, + updated: "2024-02-28T13:04:28.210319Z", + eTag: "41ba0b6a52df2cc52775a83674ad4ba1", + }, + status: null, + custom: null, + updated: "2024-02-28T13:04:28.645304Z", + eTag: "AZO/t53al7m8fw", + }, + ], + totalCount: 309, + next: "MTAw", + } + + jest.spyOn(chat.sdk.objects, "getMemberships").mockImplementation(() => membershipsDTOMock) + + const memberships = await chat.currentUser.getMemberships() + expect(memberships.memberships[0].updated).toBe(membershipsDTOMock.data[0].updated) + expect(memberships.memberships[0].eTag).toBe(membershipsDTOMock.data[0].eTag) + }) + + test("should set 'eTag' and 'updated' on the Membership object in real time", async () => { + const groupConversation = await chat.createGroupConversation({ users: [chat.currentUser] }) + const hostMembership = groupConversation.hostMembership + let updatedMembership: Membership | undefined + + const removeListener = hostMembership.streamUpdates((updatedMembershipData) => { + updatedMembership = updatedMembershipData + }) + + await hostMembership.update({ custom: { hello: "world" } }) + await sleep(2000) + expect(updatedMembership?.custom?.hello).toBe("world") + expect(updatedMembership?.updated).toBeDefined() + expect(updatedMembership?.eTag).toBeDefined() + removeListener() + }) }) From 7c5378cd9d8728bb6e18e42b135a91d6b1e93ffa Mon Sep 17 00:00:00 2001 From: Piotr Suwala Date: Fri, 7 Jun 2024 14:05:06 +0200 Subject: [PATCH 2/3] feat(lib): update js sdk --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 5ace7d0..ee3542b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11152,10 +11152,10 @@ proxy-from-env@^1.1.0: resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz" integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== -pubnub@8.2.0: - version "8.2.0" - resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.2.0.tgz#6de8ee52be0c03d48c66667397f1e84a08d54268" - integrity sha512-gXck3w/9es+w3/tdzipIjIpzKEl2CAcWnKSyMhBP/Q43Rbk0eAeS0JV6uzcTsJdi6v8nZ6TAqghjy/0Y73zqoQ== +pubnub@8.2.3: + version "8.2.3" + resolved "https://registry.yarnpkg.com/pubnub/-/pubnub-8.2.3.tgz#ad47e1636e5301cb3d55aa55ac166e8955fa9245" + integrity sha512-VqAyildzNmkTJCSCFzAiMTeNFTO10On6Ah2AX59LkKCrNDPcqS4jw+xnyyakwmB/R9gLZuCieeTxHqsSWrZD2g== dependencies: agentkeepalive "^3.5.2" buffer "^6.0.3" From 1443bb0320553c393d26a426e6daa6e8b66ab396 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:02:09 +0000 Subject: [PATCH 3/3] PubNub SDK v0.7.2 release. --- .pubnub.yml | 7 ++++++- lib/package.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 17b2758..efe5d2c 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,11 +1,16 @@ --- name: pubnub-js-chat -version: v0.7.1 +version: v0.7.2 scm: github.com/pubnub/js-chat schema: 1 files: - lib/dist/index.js changelog: + - date: 2024-06-10 + version: v0.7.2 + changes: + - type: feature + text: "Respect eTag and updated fields in the Membership object." - date: 2024-06-05 version: v0.7.1 changes: diff --git a/lib/package.json b/lib/package.json index 7030941..add7425 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "@pubnub/chat", - "version": "0.7.1", + "version": "0.7.2", "description": "PubNub JavaScript Chat SDK", "author": "PubNub ", "license": "SEE LICENSE IN LICENSE",