Skip to content

Commit

Permalink
refactor(messages): update complete message handling and make it more…
Browse files Browse the repository at this point in the history
… understandable
  • Loading branch information
ph1p committed Nov 6, 2021
1 parent a38b359 commit 6f6c090
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 324 deletions.
13 changes: 13 additions & 0 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@
"permissions": [
"currentuser"
],
"menu": [
{
"name": "Open Chat",
"command": "open"
},
{
"separator": true
},
{
"name": "Reset Chat",
"command": "reset"
}
],
"relaunchButtons": [
{
"command": "open",
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin/src/Ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ const App = observer(() => {
store.setStatus(ConnectionEnum.ERROR)
);

socket.on('chat message', (data) => store.addMessage(data));
socket.on('chat message', (data) =>
store.addMessage(data, socket, false)
);

socket.on('join leave message', (data) => {
const username = data.user.name || 'Anon';
Expand All @@ -124,6 +126,10 @@ const App = observer(() => {
store.setOnline(data);
});

socket.on('remove message', (messageId) =>
store.removeMessage(messageId)
);

store.setStatus(ConnectionEnum.CONNECTED);

socket.emit('set user', toJS(store.currentUser));
Expand All @@ -143,6 +149,7 @@ const App = observer(() => {
socket.io.off('error');
socket.io.off('reconnect_error');
socket.off('chat message');
socket.off('remove message');
socket.off('join leave message');
socket.off('online');
socket.disconnect();
Expand Down
Loading

0 comments on commit 6f6c090

Please sign in to comment.