Add emit self pubsub config (#59)
This commit is contained in:
parent
771392c960
commit
a722e8527a
|
@ -62,15 +62,22 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||
});
|
||||
}, []);
|
||||
|
||||
const addNewMessageRaw = useCallback(
|
||||
(
|
||||
signer: Uint8Array,
|
||||
content: string,
|
||||
date: Date,
|
||||
id: string,
|
||||
image?: string
|
||||
) => {
|
||||
const sender = signer.reduce((p, c) => p + c.toString(16), "0x");
|
||||
const addNewMessage = useCallback(
|
||||
(msg: ApplicationMetadataMessage, id: string, date: Date) => {
|
||||
if (
|
||||
msg.signer &&
|
||||
(msg.chatMessage?.text || msg.chatMessage?.image) &&
|
||||
msg.chatMessage.clock
|
||||
) {
|
||||
const content = msg.chatMessage.text ?? "";
|
||||
let image: string | undefined = undefined;
|
||||
if (msg.chatMessage?.image) {
|
||||
image = uintToImgUrl(msg.chatMessage?.image.payload);
|
||||
}
|
||||
const sender = msg.signer.reduce(
|
||||
(p: string, c: number): string => p + c.toString(16),
|
||||
"0x"
|
||||
);
|
||||
const newMessage = { sender, content, date, image };
|
||||
setMessages((prev) => {
|
||||
return {
|
||||
|
@ -89,28 +96,11 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||
[id]: prev[id] + 1,
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const addNewMessage = useCallback(
|
||||
(msg: ApplicationMetadataMessage, id: string, date: Date) => {
|
||||
if (
|
||||
msg.signer &&
|
||||
(msg.chatMessage?.text || msg.chatMessage?.image) &&
|
||||
msg.chatMessage.clock
|
||||
) {
|
||||
const content = msg.chatMessage.text ?? "";
|
||||
let img: string | undefined = undefined;
|
||||
if (msg.chatMessage?.image) {
|
||||
img = uintToImgUrl(msg.chatMessage?.image.payload);
|
||||
}
|
||||
addNewMessageRaw(msg.signer, content, date, id, img);
|
||||
}
|
||||
},
|
||||
[addNewMessageRaw]
|
||||
);
|
||||
|
||||
const loadNextDay = useCallback(
|
||||
async (id: string) => {
|
||||
if (messenger) {
|
||||
|
@ -147,6 +137,14 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||
const identity = Identity.generate();
|
||||
|
||||
const messenger = await Messenger.create(identity, {
|
||||
libp2p: {
|
||||
config: {
|
||||
pubsub: {
|
||||
enabled: true,
|
||||
emitSelf: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
bootstrap: getBootstrapNodes.bind({}, [
|
||||
"fleets",
|
||||
"wakuv2.test",
|
||||
|
@ -200,13 +198,6 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||
contentType: 0,
|
||||
};
|
||||
await messenger?.sendMessage(chatId, content);
|
||||
addNewMessageRaw(
|
||||
messenger?.identity.publicKey ?? new Uint8Array(),
|
||||
messageText,
|
||||
new Date(),
|
||||
chatId,
|
||||
image ? uintToImgUrl(image) : undefined
|
||||
);
|
||||
},
|
||||
[chatId, messenger]
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue