mirror of
https://github.com/status-im/status-web.git
synced 2025-02-12 12:38:30 +00:00
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(
|
const addNewMessage = useCallback(
|
||||||
(
|
(msg: ApplicationMetadataMessage, id: string, date: Date) => {
|
||||||
signer: Uint8Array,
|
if (
|
||||||
content: string,
|
msg.signer &&
|
||||||
date: Date,
|
(msg.chatMessage?.text || msg.chatMessage?.image) &&
|
||||||
id: string,
|
msg.chatMessage.clock
|
||||||
image?: string
|
) {
|
||||||
) => {
|
const content = msg.chatMessage.text ?? "";
|
||||||
const sender = signer.reduce((p, c) => p + c.toString(16), "0x");
|
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 };
|
const newMessage = { sender, content, date, image };
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
return {
|
return {
|
||||||
@ -89,28 +96,11 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||||||
[id]: prev[id] + 1,
|
[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(
|
const loadNextDay = useCallback(
|
||||||
async (id: string) => {
|
async (id: string) => {
|
||||||
if (messenger) {
|
if (messenger) {
|
||||||
@ -147,6 +137,14 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||||||
const identity = Identity.generate();
|
const identity = Identity.generate();
|
||||||
|
|
||||||
const messenger = await Messenger.create(identity, {
|
const messenger = await Messenger.create(identity, {
|
||||||
|
libp2p: {
|
||||||
|
config: {
|
||||||
|
pubsub: {
|
||||||
|
enabled: true,
|
||||||
|
emitSelf: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
bootstrap: getBootstrapNodes.bind({}, [
|
bootstrap: getBootstrapNodes.bind({}, [
|
||||||
"fleets",
|
"fleets",
|
||||||
"wakuv2.test",
|
"wakuv2.test",
|
||||||
@ -200,13 +198,6 @@ export function useMessenger(chatId: string, chatIdList: string[]) {
|
|||||||
contentType: 0,
|
contentType: 0,
|
||||||
};
|
};
|
||||||
await messenger?.sendMessage(chatId, content);
|
await messenger?.sendMessage(chatId, content);
|
||||||
addNewMessageRaw(
|
|
||||||
messenger?.identity.publicKey ?? new Uint8Array(),
|
|
||||||
messageText,
|
|
||||||
new Date(),
|
|
||||||
chatId,
|
|
||||||
image ? uintToImgUrl(image) : undefined
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
[chatId, messenger]
|
[chatId, messenger]
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user