-
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.
* Adds the ability to mute and unmute users through `Chat.mutedUsers.muteUser()` / `unmuteUser()` * Adds the option to automatically sync the mute list using AppContext by enabling `ChatConfiguration.syncMutedUsers` * Unrelated change: missing function to parse quoted message text into parts * Unrelated change: technical channels and users will have type set to "pn.prv"
- Loading branch information
1 parent
c3c0ada
commit 6128fad
Showing
31 changed files
with
725 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Channel, | ||
Message, | ||
Chat, | ||
MessageDraft, | ||
INTERNAL_MODERATION_PREFIX, | ||
Membership, | ||
} from "../dist-test" | ||
import { | ||
sleep, | ||
extractMentionedUserIds, | ||
createRandomUser, | ||
createRandomChannel, | ||
createChatInstance, | ||
sendMessageAndWaitForHistory, | ||
makeid, | ||
} from "./utils" | ||
|
||
import { jest } from "@jest/globals" | ||
|
||
describe("Mute list test", () => { | ||
jest.retryTimes(3) | ||
|
||
let chat: Chat | ||
let channel: Channel | ||
let messageDraft: MessageDraft | ||
|
||
beforeAll(async () => { | ||
chat = await createChatInstance() | ||
}) | ||
|
||
beforeEach(async () => { | ||
channel = await createRandomChannel() | ||
messageDraft = channel.createMessageDraft() | ||
}) | ||
|
||
afterEach(async () => { | ||
await channel.delete() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test("should add user to mute set", async () => { | ||
await chat.mutedUsersManager.muteUser("abc") | ||
expect(chat.mutedUsersManager.mutedUsers[0]).toBe("abc") | ||
}) | ||
|
||
test("should remove user from mute set", async () => { | ||
await chat.mutedUsersManager.muteUser("abc") | ||
await chat.mutedUsersManager.muteUser("def") | ||
await chat.mutedUsersManager.unmuteUser("abc") | ||
expect(chat.mutedUsersManager.mutedUsers[0]).toBe("def") | ||
expect(chat.mutedUsersManager.mutedUsers.length).toBe(1) | ||
}) | ||
|
||
}) |
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
37 changes: 37 additions & 0 deletions
37
pubnub-chat-api/src/commonMain/kotlin/com/pubnub/chat/mutelist/MutedUsersManager.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,37 @@ | ||
package com.pubnub.chat.mutelist | ||
|
||
import com.pubnub.chat.config.ChatConfiguration | ||
import com.pubnub.kmp.PNFuture | ||
|
||
interface MutedUsersManager { | ||
/** | ||
* The current set of muted users. | ||
*/ | ||
val mutedUsers: Set<String> | ||
|
||
/** | ||
* Add a user to the list of muted users. | ||
* | ||
* @param userId the ID of the user to mute | ||
* @return a PNFuture to monitor syncing data to the server. | ||
* | ||
* When [ChatConfiguration.syncMutedUsers] is enabled, it can fail e.g. because of network | ||
* conditions or when number of muted users exceeds the limit. | ||
* | ||
* When `syncMutedUsers` is false, it always succeeds (data is not synced in that case). | ||
*/ | ||
fun muteUser(userId: String): PNFuture<Unit> | ||
|
||
/** | ||
* Add a user to the list of muted users. | ||
* | ||
* @param userId the ID of the user to mute | ||
* @return a PNFuture to monitor syncing data to the server. | ||
* | ||
* When [ChatConfiguration.syncMutedUsers] is enabled, it can fail e.g. because of network | ||
* conditions or when number of muted users exceeds the limit. | ||
* | ||
* When `syncMutedUsers` is false, it always succeeds (data is not synced in that case). | ||
*/ | ||
fun unmuteUser(userId: String): PNFuture<Unit> | ||
} |
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,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<baseline version="1.0"> | ||
<file name="src/jsMain/kotlin/converters.kt"> | ||
<error line="147" column="14" source="standard:function-naming" /> | ||
<error line="145" column="14" source="standard:function-naming" /> | ||
</file> | ||
</baseline> |
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.