mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 18:54:52 +00:00
Different notification message according to message type
This commit is contained in:
parent
901a1157f9
commit
8e7b782f0b
@ -45,11 +45,41 @@ const WithNewMessageNotification = WrappedComponent => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lastMessage = activities[activities.length - 1];
|
const lastMessage = activities[activities.length - 1];
|
||||||
const { username, text } = lastMessage;
|
const { username, type, text, fileName, locked, newUsername, currentUsername, action } = lastMessage;
|
||||||
|
|
||||||
if (lastMessage !== prevState.lastMessage && !windowIsFocused) {
|
if (lastMessage !== prevState.lastMessage && !windowIsFocused) {
|
||||||
const title = `Message from ${username} (${roomId})`;
|
if (notificationIsAllowed && notificationIsEnabled) {
|
||||||
if (notificationIsAllowed && notificationIsEnabled) notify(title, text);
|
// Generate the proper notification according to the message type
|
||||||
|
switch (type) {
|
||||||
|
case 'USER_ENTER':
|
||||||
|
notify(`User ${username} joined`);
|
||||||
|
break;
|
||||||
|
case 'USER_EXIT':
|
||||||
|
notify(`User ${username} left`);
|
||||||
|
break;
|
||||||
|
case 'RECEIVE_FILE':
|
||||||
|
notify(`${username} sent file <${fileName}>`);
|
||||||
|
break;
|
||||||
|
case 'TEXT_MESSAGE':
|
||||||
|
notify(`${username} said:`, text);
|
||||||
|
break;
|
||||||
|
case 'USER_ACTION':
|
||||||
|
notify(`${username} ${action}`);
|
||||||
|
break;
|
||||||
|
case 'CHANGE_USERNAME':
|
||||||
|
notify(`${currentUsername} changed their name to ${newUsername}`);
|
||||||
|
break;
|
||||||
|
case 'TOGGLE_LOCK_ROOM':
|
||||||
|
if (locked) {
|
||||||
|
notify(`Room ${roomId} is now locked`);
|
||||||
|
} else {
|
||||||
|
notify(`Room ${roomId} is now unlocked`);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (soundIsEnabled) beep.play();
|
if (soundIsEnabled) beep.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ describe('Connected Home component', () => {
|
|||||||
</Provider>,
|
</Provider>,
|
||||||
);
|
);
|
||||||
expect(store.getState().app.unreadMessageCount).toBe(1);
|
expect(store.getState().app.unreadMessageCount).toBe(1);
|
||||||
expect(notify).toHaveBeenLastCalledWith('Message from sender ()', 'new message');
|
expect(notify).toHaveBeenLastCalledWith('sender said:', 'new message');
|
||||||
expect(beep.play).toHaveBeenLastCalledWith();
|
expect(beep.play).toHaveBeenLastCalledWith();
|
||||||
expect(Tinycon.setBubble).toHaveBeenLastCalledWith(1);
|
expect(Tinycon.setBubble).toHaveBeenLastCalledWith(1);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const showNotification = (title, message, avatarUrl) => {
|
|||||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const notify = (title, content) => {
|
export const notify = (title, content = '') => {
|
||||||
if (!('Notification' in window)) {
|
if (!('Notification' in window)) {
|
||||||
alert('This browser does not support desktop notification');
|
alert('This browser does not support desktop notification');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user