Skip to content

Commit 01cf8c2

Browse files
committed
chore: delivery receipt
1 parent 4ca1d06 commit 01cf8c2

7 files changed

Lines changed: 15 additions & 52 deletions

File tree

backend/api/messaging/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ router.post(
4545
const { sid } = clients.getReceiverByChannel(channel, sender);
4646
socketEmit('chat-message', sid, dataToPublish);
4747

48-
return res.send({ message: 'message sent' });
48+
return res.send({ message: 'message sent', id });
4949
})
5050
);
5151

backend/socket.io/listeners.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ const connectionListener = (socket, io) => {
3434
receiverSocket.emit('on-alice-join', { publicKey });
3535
}
3636
});
37+
3738
socket.on('received', ({ channel, sender, id }) => {
3839
const { sid } = clients.getSenderByChannel(channel, sender);
3940
const senderSocket = io.sockets.sockets[sid];
4041
senderSocket.emit('delivered', id);
4142
});
43+
4244
socket.on('disconnect', () => {
4345
const { channelID, userID } = socket;
4446
if (!(channelID && userID)) {

client/src/components/Messaging/EmojiRow/index.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,14 @@ import styles from './Style.module.css';
33
import Emoji from '../Emoji';
44
import '../Emoji/index.js';
55
import { ThemeContext } from '../../../ThemeContext.js';
6+
const emojis = ['🙂', '😀', '😂', '😍', '😘', '😜', '🧐', '😎', '🤩', '😏', '😒', '😔', '😩', '😭'];
67

78
const EmojiRow = ({ text, setText }) => {
89
const [darkMode] = useContext(ThemeContext);
910

1011
const selectEmoji = (symbol) => {
1112
setText(text + symbol);
1213
};
13-
const emojis = [
14-
'🙂',
15-
'😀',
16-
'😂',
17-
'😍',
18-
'😘',
19-
'😜',
20-
'🧐',
21-
'😎',
22-
'🤩',
23-
'🥳',
24-
'😏',
25-
'😒',
26-
'😔',
27-
'😩',
28-
'😭'
29-
];
3014

3115
return (
3216
<div className={`${styles.emojiRow} ${!darkMode && styles.lightEmojiRow}`}>

client/src/components/Messaging/Message.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const Message = ({
3434
}, []);
3535

3636
const [darkMode] = useContext(ThemeContext);
37-
// const regex = /\bdata:image\b/g;
38-
// const isImg = body.match(regex);
37+
3938
return (
4039
<div className={owner === true ? styles.messageRight : styles.messageLeft}>
4140
<div className={styles.messageInfo}>
@@ -52,8 +51,8 @@ export const Message = ({
5251
</div>
5352
</div>
5453
)}
55-
{owner && deliveredID.includes(id) && !sending && !failed && (
56-
<div className={styles.messageDelivered}>Delivered</div>
54+
{deliveredID.includes(id) && (
55+
<div className={styles.messageDelivered}>Delivered&nbsp;&#10004;</div>
5756
)}
5857
</div>
5958
</div>

client/src/components/Messaging/styles/Message.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
font-size: 13px;
5454
}
5555
.messageDelivered {
56-
color: #c8afaf;
56+
color: #828282;
5757
font-size: 13px;
5858
}
5959

client/src/pages/messaging/index.js

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ const Chat = () => {
110110
alicePublicKey: publicKeyRef.current
111111
});
112112

113-
// TODO: need to handle image
114-
115-
await sendMessage({
113+
const { id } = await sendMessage({
116114
channelID,
117115
userId,
118116
image,
@@ -125,6 +123,7 @@ const Chat = () => {
125123
setMessages((prevMsg) => {
126124
const { ...message } = prevMsg[index];
127125
message.local = false;
126+
message.id = id;
128127
prevMsg[index] = message;
129128
return [...prevMsg];
130129
});
@@ -148,25 +147,7 @@ const Chat = () => {
148147
};
149148

150149
const initChat = async () => {
151-
// TODO: handle error
152-
// const messages = await fetchMessages(pubnub, channelID);
153-
//
154-
// const formatMessages = messages.map((msg) => {
155-
// const {
156-
// image,
157-
// sender,
158-
// body: { box, nonce }
159-
// } = msg;
160-
//
161-
// return {
162-
// encrypted: true,
163-
// encryptionDetail: { box, nonce },
164-
// sender,
165-
// image,
166-
// body: btoa(strToTypedArr(box)) // let's just stringify the array, to decrypt later
167-
// };
168-
// });
169-
// setMessages(formatMessages);
150+
// TODO: restore previous messages from local storage
170151
};
171152

172153
useEffect(() => {
@@ -190,11 +171,6 @@ const Chat = () => {
190171
});
191172
socket.on('delivered', (id) => {
192173
setDeliveredID((prev) => [...prev, id]);
193-
setMessages((prev) => {
194-
const copy = [...prev];
195-
copy[copy.length - 1].id = id;
196-
return [...copy];
197-
});
198174
});
199175
// an event to notify that the other person is joined.
200176
socket.on('on-alice-join', ({ publicKey }) => {
@@ -213,6 +189,7 @@ const Chat = () => {
213189
getSetUsers(channelID);
214190
});
215191

192+
//handle incoming message
216193
socket.on('chat-message', (msg) => {
217194
try {
218195
const box = strToTypedArr(msg.message.box);
@@ -245,6 +222,7 @@ const Chat = () => {
245222
}, [channelID]);
246223

247224
const alice = usersInChannel.find((u) => u.uuid !== userId);
225+
console.log(messages);
248226
const messagesFormatted = messages.map(({ body, sender, image, local, id }, i) => {
249227
return {
250228
owner: sender === userId,

client/src/service/sendMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import makeRequest from '../utils/makeRequest';
22

3-
const sendMessage = async ({ channelID, userId, image, text }) => {
4-
await makeRequest('chat/message', {
3+
const sendMessage = ({ channelID, userId, image, text }) => {
4+
return makeRequest('chat/message', {
55
method: 'POST',
66
body: {
77
channel: channelID,

0 commit comments

Comments
 (0)