Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed username bug #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dump.rdb
Binary file not shown.
2 changes: 1 addition & 1 deletion public/src/client/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ define('forum/register', [
if (results.every(obj => obj.status === 'rejected')) {
showSuccess(usernameInput, username_notify, successIcon);
} else {
showError(usernameInput, username_notify, '[[error:username-taken]]');
showError(usernameInput, username_notify, 'Username taken. Try 1234' + username);
}

callback();
Expand Down
12 changes: 12 additions & 0 deletions src/socket.io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const apiHelpers = require('../api/helpers');
const Namespaces = Object.create(null);

const Sockets = module.exports;
const SocketPlugins = {};

Sockets.init = async function (server) {
requireModules();
Expand Down Expand Up @@ -336,3 +337,14 @@ Sockets.warnDeprecated = (socket, replacement) => {
` ${replacement ? `use ${replacement}` : 'there is no replacement for this call.'}`,
].join('\n'));
};

SocketPlugins.chat = {
messageRead: function (socket, data, callback) {
const { messageId, userId } = data;
db.collection('messages').update(
{ _id: messageId },
{ $addToSet: { readBy: userId } }
);
callback(null, true);
},
};
46 changes: 44 additions & 2 deletions src/views/partials/chats/message.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
{{{ end }}}
<span class="chat-timestamp text-muted timeago" title="{messages.timestampISO}"></span>

<div component="chat/message/edited" class="text-muted ms-auto {{{ if !messages.edited }}}hidden{{{ end }}}" title="[[global:edited-timestamp, {isoTimeToLocaleString(messages.editedISO, config.userLang)}]]"><i class="fa fa-edit"></i></span></div>
<!-- Add the read receipt tick as a clickable button -->
<button class="read-receipt text-muted" title="Message Read" onclick="markAsRead('{messages.messageId}')">✔</button>

<div component="chat/message/edited" class="text-muted ms-auto {{{ if !messages.edited }}}hidden{{{ end }}}" title="[[global:edited-timestamp, {isoTimeToLocaleString(messages.editedISO, config.userLang)}]]"><i class="fa fa-edit"></i></div>
</div>

<div class="message-body-wrapper">
<div component="chat/message/body" class="message-body ps-0 py-0 overflow-auto text-break">
{messages.content}
Expand Down Expand Up @@ -73,4 +77,42 @@
</div>
</div>
</div>
</li>
</li>
<style>
.read-receipt {
font-size: 12px;
color: green; /* Default tick color */
margin-left: 5px;
border: none;
background: none;
cursor: pointer;
}

.read-receipt.all-read {
color: blue; /* Change to blue when all users have clicked */
}
</style>
<script>
if (typeof usersWhoRead === 'undefined') {
var usersWhoRead = {}; // Use var for global scope if needed, or let/const if scoped
}
function markAsRead(messageId) {
const userId = app.user.uid; // Replace this with the actual user ID of the logged-in user
const totalUsers = 2;

// If this message is not being tracked, initialize it
if (!usersWhoRead[messageId]) {
usersWhoRead[messageId] = new Set();
}

// Add the current user to the set of users who have clicked
usersWhoRead[messageId].add(userId);

// If all users have clicked the tick, change the color to blue
if (usersWhoRead[messageId].size === totalUsers) {
const messageElement = document.querySelector(`li[data-mid="${messageId}"] .read-receipt`);
messageElement.classList.add('all-read');
}
}

</script>