Merge pull request #55 from status-im/integrate-community
This commit is contained in:
commit
02647e967d
|
@ -149,7 +149,7 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
chatIdList.map(async (id) => {
|
chatIdList.map(async (id) => {
|
||||||
await messenger.joinChat(id);
|
await messenger.joinChatById(id);
|
||||||
setLastLoadTime((prev) => {
|
setLastLoadTime((prev) => {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
|
|
|
@ -62,8 +62,8 @@ describe("Messenger", () => {
|
||||||
it("Sends & Receive public chat messages", async function () {
|
it("Sends & Receive public chat messages", async function () {
|
||||||
this.timeout(10_000);
|
this.timeout(10_000);
|
||||||
|
|
||||||
await messengerAlice.joinChat(testChatId);
|
await messengerAlice.joinChatById(testChatId);
|
||||||
await messengerBob.joinChat(testChatId);
|
await messengerBob.joinChatById(testChatId);
|
||||||
|
|
||||||
const text = "This is a message.";
|
const text = "This is a message.";
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ describe("Messenger", () => {
|
||||||
it("public chat messages have signers", async function () {
|
it("public chat messages have signers", async function () {
|
||||||
this.timeout(10_000);
|
this.timeout(10_000);
|
||||||
|
|
||||||
await messengerAlice.joinChat(testChatId);
|
await messengerAlice.joinChatById(testChatId);
|
||||||
await messengerBob.joinChat(testChatId);
|
await messengerBob.joinChatById(testChatId);
|
||||||
|
|
||||||
const text = "This is a message.";
|
const text = "This is a message.";
|
||||||
|
|
||||||
|
|
|
@ -36,16 +36,27 @@ export class Messenger {
|
||||||
return new Messenger(identity, waku);
|
return new Messenger(identity, waku);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Joins a public chat using its id.
|
||||||
|
*
|
||||||
|
* For community chats, prefer [[joinChat]].
|
||||||
|
*
|
||||||
|
* Use `addListener` to get messages received on this chat.
|
||||||
|
*/
|
||||||
|
public async joinChatById(chatId: string): Promise<void> {
|
||||||
|
const chat = await Chat.create(chatId);
|
||||||
|
|
||||||
|
await this.joinChat(chat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joins a public chat.
|
* Joins a public chat.
|
||||||
*
|
*
|
||||||
* Use `addListener` to get messages received on this chat.
|
* Use `addListener` to get messages received on this chat.
|
||||||
*/
|
*/
|
||||||
public async joinChat(chatId: string): Promise<void> {
|
public async joinChat(chat: Chat): Promise<void> {
|
||||||
if (this.chatsById.has(chatId))
|
if (this.chatsById.has(chat.id))
|
||||||
throw `Failed to join chat, it is already joined: ${chatId}`;
|
throw `Failed to join chat, it is already joined: ${chat.id}`;
|
||||||
|
|
||||||
const chat = await Chat.create(chatId);
|
|
||||||
|
|
||||||
this.waku.addDecryptionKey(chat.symKey);
|
this.waku.addDecryptionKey(chat.symKey);
|
||||||
|
|
||||||
|
@ -66,7 +77,7 @@ export class Messenger {
|
||||||
[chat.contentTopic]
|
[chat.contentTopic]
|
||||||
);
|
);
|
||||||
|
|
||||||
this.chatsById.set(chatId, chat);
|
this.chatsById.set(chat.id, chat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue