mirror of
https://github.com/ancsemi/Haven
synced 2026-04-21 13:37:41 +00:00
fix: allow media uploads when text is disabled (#154)
This commit is contained in:
parent
3d664ac304
commit
b44cca07a0
2 changed files with 28 additions and 4 deletions
|
|
@ -56,9 +56,30 @@ async switchChannel(code) {
|
|||
// Show/hide topic bar
|
||||
this._updateTopicBar(channel?.topic || '');
|
||||
|
||||
// Show/hide message input for voice-only channels
|
||||
// Show/hide message input — keep upload button visible for media-only channels
|
||||
const msgInputArea = document.getElementById('message-input-area');
|
||||
if (msgInputArea) msgInputArea.style.display = channel && channel.text_enabled === 0 ? 'none' : '';
|
||||
const _textOff = channel && channel.text_enabled === 0;
|
||||
const _mediaOff = channel && channel.media_enabled === 0;
|
||||
if (msgInputArea) msgInputArea.style.display = (_textOff && _mediaOff) ? 'none' : '';
|
||||
// Text-only elements
|
||||
const _msgInput = document.getElementById('message-input');
|
||||
const _sendBtn = document.getElementById('send-btn');
|
||||
const _emojiBtn = document.getElementById('emoji-btn');
|
||||
const _gifBtn = document.getElementById('gif-btn');
|
||||
const _pollBtn = document.getElementById('poll-btn');
|
||||
if (_msgInput) _msgInput.style.display = _textOff ? 'none' : '';
|
||||
if (_sendBtn) _sendBtn.style.display = _textOff ? 'none' : '';
|
||||
if (_emojiBtn) _emojiBtn.style.display = _textOff ? 'none' : '';
|
||||
if (_gifBtn) _gifBtn.style.display = _textOff ? 'none' : '';
|
||||
if (_pollBtn) _pollBtn.style.display = _textOff ? 'none' : '';
|
||||
// Upload button tied to media toggle
|
||||
const _uploadBtn = document.getElementById('upload-btn');
|
||||
if (_uploadBtn) _uploadBtn.style.display = _mediaOff ? 'none' : '';
|
||||
// Dividers: first one only if both upload and text buttons visible, rest if text is on
|
||||
const _dividers = document.querySelectorAll('.input-actions-box .input-actions-divider');
|
||||
if (_dividers[0]) _dividers[0].style.display = (!_textOff && !_mediaOff) ? '' : 'none';
|
||||
if (_dividers[1]) _dividers[1].style.display = _textOff ? 'none' : '';
|
||||
if (_dividers[2]) _dividers[2].style.display = _textOff ? 'none' : '';
|
||||
|
||||
const messagesEl = document.getElementById('messages');
|
||||
messagesEl.innerHTML = '';
|
||||
|
|
|
|||
|
|
@ -1405,9 +1405,12 @@ function setupSocketHandlers(io, db) {
|
|||
).get(channel.id, socket.user.id);
|
||||
if (!member) return socket.emit('error-msg', 'Not a member of this channel');
|
||||
|
||||
// Block text messages when text is disabled
|
||||
// Block text messages when text is disabled (allow media uploads if media is enabled)
|
||||
if (channel.text_enabled === 0) {
|
||||
return socket.emit('error-msg', 'Text messages are disabled in this channel');
|
||||
const isMedia = /^\/uploads\b/i.test(content.trim()) || /^\[file:[^\]]+\]\(/i.test(content.trim());
|
||||
if (!isMedia || channel.media_enabled === 0) {
|
||||
return socket.emit('error-msg', 'Text messages are disabled in this channel');
|
||||
}
|
||||
}
|
||||
|
||||
// Block media uploads if media is disabled in this channel
|
||||
|
|
|
|||
Loading…
Reference in a new issue