diff --git a/app/src/react/components/chat/messages/index.jsx b/app/src/react/components/chat/messages/index.jsx
index 511f705..623655e 100644
--- a/app/src/react/components/chat/messages/index.jsx
+++ b/app/src/react/components/chat/messages/index.jsx
@@ -36,8 +36,11 @@ export default function Messages() {
diff --git a/app/src/react/components/chat/messages/message/index.jsx b/app/src/react/components/chat/messages/message/index.jsx
index 8c3e520..fc97251 100644
--- a/app/src/react/components/chat/messages/message/index.jsx
+++ b/app/src/react/components/chat/messages/message/index.jsx
@@ -35,6 +35,14 @@ export default function Message(props) {
});
const username = useSelector((state) => usernameSelector(state, owner));
const $messageTime = ;
+ const $distinction = (
+
+ {/* eslint-disable-next-line no-bitwise */}
+ {!!(distinction & ADMIN) && }
+ {/* eslint-disable-next-line no-bitwise */}
+ {!!(distinction & MOD) && }
+
+ );
return (
- {
- !isShort && (
-
- )
- }
+
{isShort && $messageTime}
diff --git a/app/src/react/components/dispatcher.jsx b/app/src/react/components/dispatcher.jsx
index 2b3c12f..08f5eab 100644
--- a/app/src/react/components/dispatcher.jsx
+++ b/app/src/react/components/dispatcher.jsx
@@ -5,6 +5,7 @@ import {
addMessage,
joined,
left,
+ toggleMessageDistinction,
} from '@reddichat/chat/client';
import {
addFriendship,
@@ -44,6 +45,10 @@ export default function Dispatcher() {
dispatch(addMessage(packet.data));
break;
}
+ case 'MessageDistinction': {
+ dispatch(toggleMessageDistinction(packet.data));
+ break;
+ }
case 'Join': {
dispatch(joined(packet.data));
break;
diff --git a/packages/chat/src/client/state.js b/packages/chat/src/client/state.js
index c917df1..e54595d 100644
--- a/packages/chat/src/client/state.js
+++ b/packages/chat/src/client/state.js
@@ -123,6 +123,9 @@ const slice = createSlice({
submitMessageDistinction: () => {},
toggleMessageDistinction: ({messages}, {payload: {distinction, uuid}}) => {
const message = messages[uuid];
+ if (!message) {
+ return;
+ }
/* eslint-disable no-bitwise */
message.distinction = message.distinction & distinction
? message.distinction & ~distinction
diff --git a/packages/chat/src/message-channel.js b/packages/chat/src/message-channel.js
index 4461050..8a72064 100644
--- a/packages/chat/src/message-channel.js
+++ b/packages/chat/src/message-channel.js
@@ -2,7 +2,11 @@ import {createClient, keys} from '@latus/redis';
import {parseChannel} from '@reddichat/core';
const messageChannel = async (latus, uuid) => {
- const key = (await keys(createClient(latus), `*:messages:${uuid}`)).pop();
+ const results = (await keys(createClient(latus), `*:messages:${uuid}`));
+ if (0 === results.length) {
+ return undefined;
+ }
+ const key = results.pop();
return parseChannel(key.split(':')[0]);
};
diff --git a/packages/chat/src/packets/message-distinction.server.js b/packages/chat/src/packets/message-distinction.server.js
index 0526891..d6899b3 100644
--- a/packages/chat/src/packets/message-distinction.server.js
+++ b/packages/chat/src/packets/message-distinction.server.js
@@ -10,7 +10,7 @@ export default (latus) => class MessageDistinctionServer extends MessageDistinct
static async respond({data: {distinction, uuid}}, socket) {
const {req} = socket;
- const message = await replaceMessage(
+ await replaceMessage(
req,
uuid,
(msg) => ({
@@ -23,9 +23,12 @@ export default (latus) => class MessageDistinctionServer extends MessageDistinct
}),
);
const channel = await messageChannel(latus, uuid);
+ if (!channel) {
+ return;
+ }
socket
.to(renderChannel(channel))
- .send(['MessageDistinction', {uuid, distinction: message.distinction}]);
+ .send(['MessageDistinction', {uuid, distinction}]);
}
static async validate(packet, socket) {
diff --git a/packages/chat/src/replace-message.js b/packages/chat/src/replace-message.js
index 0f2fa28..85662f4 100644
--- a/packages/chat/src/replace-message.js
+++ b/packages/chat/src/replace-message.js
@@ -6,10 +6,23 @@ const replaceMessage = async (req, uuid, fn) => {
const {pubClient} = req.adapter;
const get = promisify(pubClient.get.bind(pubClient));
const key = (await keys(pubClient, `*:messages:${uuid}`)).pop();
+ if (!key) {
+ return Promise.resolve();
+ }
const message = fn(JSON.parse(await get(key)));
return new Promise((resolve, reject) => pubClient
.multi()
- .set(key, JSON.stringify(message))
+ .eval(
+ [
+ "local ttl = redis.call('ttl', ARGV[1])",
+ 'if ttl > 0 then',
+ "return redis.call('SETEX', ARGV[1], ttl, ARGV[2])",
+ 'end',
+ ].join(' '),
+ 0,
+ key,
+ JSON.stringify(message),
+ )
.exec((error) => (error ? reject(error) : resolve(message))));
};