-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JS] MessageDraftV2 + remove
crypto
usage (#144)
* [JS] MessageDraftV2 * Remove crypto dependency by replacing JS UUIDv4 implementation * Bump pubnub SDK version * Bump Pubnub Swift version * PubNub kotlin v0.9.2 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
- Loading branch information
1 parent
f2848d9
commit ed7648f
Showing
17 changed files
with
419 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ SONATYPE_HOST=DEFAULT | |
SONATYPE_AUTOMATIC_RELEASE=false | ||
GROUP=com.pubnub | ||
POM_PACKAGING=jar | ||
VERSION_NAME=0.9.1 | ||
VERSION_NAME=0.9.2 | ||
|
||
POM_NAME=PubNub Chat SDK | ||
POM_DESCRIPTION=This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application. | ||
|
@@ -30,7 +30,7 @@ POM_DEVELOPER_NAME=PubNub | |
POM_DEVELOPER_URL=[email protected] | ||
|
||
IOS_SIMULATOR_ID=iPhone 15 Pro | ||
SWIFT_PATH=pubnub-kotlin/swift | ||
#SWIFT_PATH=../swift | ||
|
||
ENABLE_TARGET_JS=true | ||
ENABLE_TARGET_IOS_OTHER=false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export * from "../build/dist/js/productionLibrary/pubnub-chat.mjs" | ||
export const INTERNAL_MODERATION_PREFIX = "PUBNUB_INTERNAL_MODERATION_" | ||
export const MESSAGE_THREAD_ID_PREFIX = "PUBNUB_INTERNAL_THREAD"; | ||
export const INTERNAL_ADMIN_CHANNEL = "PUBNUB_INTERNAL_ADMIN_CHANNEL"; | ||
export const ERROR_LOGGER_KEY_PREFIX = "PUBNUB_INTERNAL_ERROR_LOGGER"; | ||
|
||
import PubNub from "pubnub" | ||
export let CryptoModule = PubNub.CryptoModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { Channel, Chat, MessageDraftV2, MixedTextTypedElement } from "../dist" | ||
import { | ||
createChatInstance, | ||
createRandomChannel, | ||
createRandomUser, | ||
renderMessagePart, | ||
sleep, | ||
makeid | ||
} from "./utils" | ||
import { jest } from "@jest/globals" | ||
|
||
describe("MessageDraft", function () { | ||
jest.retryTimes(2) | ||
let chat: Chat | ||
let channel: Channel | ||
let messageDraft: MessageDraftV2 | ||
|
||
beforeAll(async () => { | ||
chat = await createChatInstance() | ||
}) | ||
|
||
beforeEach(async () => { | ||
channel = await createRandomChannel() | ||
messageDraft = channel.createMessageDraftV2({ userSuggestionSource: "global" }) | ||
}) | ||
|
||
test("should mention 2 users", async () => { | ||
const [user1, user2] = await Promise.all([createRandomUser(), createRandomUser()]) | ||
|
||
messageDraft.update("Hello @user1 and @user2") | ||
messageDraft.addMention(6, 6, "mention", user1.id) | ||
messageDraft.addMention(17, 6, "mention", user2.id) | ||
const messagePreview = messageDraft.getMessagePreview() | ||
expect(messagePreview.length).toBe(4) | ||
expect(messagePreview[0].type).toBe("text") | ||
expect(messagePreview[1].type).toBe("mention") | ||
expect(messagePreview[2].type).toBe("text") | ||
expect(messagePreview[3].type).toBe("mention") | ||
expect(messageDraft.value).toBe(`Hello @user1 and @user2`) | ||
expect(messagePreview.map(renderMessagePart).join("")).toBe( | ||
`Hello @@user1 and @@user2` | ||
) | ||
await Promise.all([user1.delete({ soft: false }), user2.delete({ soft: false })]) | ||
}) | ||
|
||
test("should mention 2 - 3 users next to each other", async () => { | ||
const [user1, user2, user3] = await Promise.all([ | ||
createRandomUser(), | ||
createRandomUser(), | ||
createRandomUser(), | ||
]) | ||
|
||
let elements: MixedTextTypedElement[][] = [] | ||
let resolve, reject; | ||
const promise = new Promise((res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
|
||
messageDraft.addChangeListener(async function(state) { | ||
elements.push(state.messageElements) | ||
if (elements.length == 3) { | ||
resolve() | ||
return | ||
} | ||
let mentions = await state.suggestedMentions | ||
messageDraft.insertSuggestedMention(mentions[0], mentions[0].replaceWith) | ||
}) | ||
|
||
messageDraft.update("Hello @Te @Tes @Test") | ||
await promise | ||
|
||
const messagePreview = messageDraft.getMessagePreview() | ||
expect(messagePreview.length).toBe(4) | ||
expect(messagePreview[0].type).toBe("text") | ||
expect(messagePreview[1].type).toBe("mention") | ||
expect(messagePreview[2].type).toBe("text") | ||
expect(messagePreview[3].type).toBe("mention") | ||
expect(messagePreview.map(renderMessagePart).join("")).toBe( | ||
elements[2].map(renderMessagePart).join("") | ||
) | ||
await Promise.all([ | ||
user1.delete({ soft: false }), | ||
user2.delete({ soft: false }), | ||
user3.delete({ soft: false }), | ||
]) | ||
}) | ||
|
||
test("should mix every type of message part", async () => { | ||
const [channel1, channel2] = await Promise.all([createRandomChannel(makeid()), createRandomChannel(makeid())]) | ||
const [user1, user2, user4, user5] = await Promise.all([ | ||
createRandomUser(makeid()), | ||
createRandomUser(makeid()), | ||
createRandomUser(makeid()), | ||
createRandomUser(makeid()), | ||
]) | ||
messageDraft.update("Hello ") | ||
messageDraft.addLinkedText({ | ||
text: "pubnub", | ||
link: "https://pubnub.com", | ||
positionInInput: messageDraft.value.length, | ||
}) | ||
messageDraft.update("Hello pubnub at https://pubnub.com! Hello to ") | ||
messageDraft.addLinkedText({ | ||
text: "google", | ||
link: "https://google.com", | ||
positionInInput: messageDraft.value.length, | ||
}) | ||
|
||
let elements: MixedTextTypedElement[][] = [] | ||
let resolve, reject; | ||
const promise = new Promise((res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
|
||
messageDraft.addChangeListener(async function(state) { | ||
elements.push(state.messageElements) | ||
let mentions = await state.suggestedMentions | ||
if (mentions.length == 0) { | ||
resolve() | ||
return | ||
} | ||
messageDraft.insertSuggestedMention(mentions[0], mentions[0].replaceWith) | ||
}) | ||
|
||
|
||
messageDraft.update( | ||
`Hello pubnub at https://pubnub.com! Hello to google at https://google.com. Referencing #${channel1.name.substring(0,8)}, #${channel2.name.substring(0,8)}, #blankchannel, @${user1.name.substring(0,8)}, @${user2.name.substring(0,8)}, and mentioning @blankuser3 @${user4.name.substring(0,8)} @${user5.name.substring(0,8)}` | ||
) | ||
await promise | ||
|
||
const messagePreview = messageDraft.getMessagePreview() | ||
|
||
expect(messagePreview.length).toBe(16) | ||
expect(messagePreview[0].type).toBe("text") | ||
expect(messagePreview[1].type).toBe("textLink") | ||
expect(messagePreview[2].type).toBe("text") | ||
expect(messagePreview[3].type).toBe("textLink") | ||
expect(messagePreview[4].type).toBe("text") | ||
expect(messagePreview[5].type).toBe("channelReference") | ||
expect(messagePreview[6].type).toBe("text") | ||
expect(messagePreview[7].type).toBe("channelReference") | ||
expect(messagePreview[8].type).toBe("text") | ||
expect(messagePreview[9].type).toBe("mention") | ||
expect(messagePreview[10].type).toBe("text") | ||
expect(messagePreview[11].type).toBe("mention") | ||
expect(messagePreview[12].type).toBe("text") | ||
expect(messagePreview[13].type).toBe("mention") | ||
expect(messagePreview[14].type).toBe("text") | ||
expect(messagePreview[15].type).toBe("mention") | ||
expect(messagePreview.map(renderMessagePart).join("")).toBe( | ||
`Hello pubnub at https://pubnub.com! Hello to google at https://google.com. Referencing #${channel1.name}, #${channel2.name}, #blankchannel, @${user1.name}, @${user2.name}, and mentioning @blankuser3 @${user4.name} @${user5.name}` | ||
) | ||
expect(messageDraft.value).toBe( | ||
`Hello pubnub at https://pubnub.com! Hello to google at https://google.com. Referencing ${channel1.name}, ${channel2.name}, #blankchannel, ${user1.name}, ${user2.name}, and mentioning @blankuser3 ${user4.name} ${user5.name}` | ||
) | ||
await Promise.all([channel1.delete({ soft: false }), channel2.delete({ soft: false })]) | ||
await Promise.all([ | ||
user1.delete({ soft: false }), | ||
user2.delete({ soft: false }), | ||
user4.delete({ soft: false }), | ||
]) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
pubnub-chat-impl/src/commonTest/kotlin/com/pubnub/kmp/UuidTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.pubnub.kmp | ||
|
||
import com.pubnub.chat.internal.generateRandomUuid | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
class UuidTest { | ||
@Test | ||
fun generateUuid() { | ||
val uuid = generateRandomUuid() | ||
assertTrue { uuid.matches(Regex("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.