openvibers/openvibe.live Commits

A picture alone is a comment on a recording or a clip (#863)

OP OpenVibers committed 14 h ago · 2c25034ca9 · 2 files, +11 −2

A VOD or clip comment with a picture and no words was refused; words are now optional when a file is attached (the owner, 11-12: "it shouldn't require you to type text if you just put a picture"). Community takes it as of OpenVibe.Community #412.

Changes

ddiff --git a/server/media-proxy/comments.js b/server/media-proxy/comments.js
iindex 1e8e4de4..698174b5 100644
---- a/server/media-proxy/comments.js
++++ b/server/media-proxy/comments.js
@@@ -255,8 +255,10 @@ router.post('/:type/:id', requireAuth, async (req, res) => {
return res.status(400).json({ error: 'Invalid content type or ID' });
}
const message = String(req.body.message || '').trim();
-- if (!message || message.length > MAX_MESSAGE) {
-- return res.status(400).json({ error: `Comment must be 1-${MAX_MESSAGE} characters` });
++ // A picture alone is a comment, as on any social app (the owner, 11-12): words are optional with a file attached.
++ const hasFiles = Array.isArray(req.body.attachments) && req.body.attachments.length > 0;
++ if ((!message && !hasFiles) || message.length > MAX_MESSAGE) {
++ return res.status(400).json({ error: `Write something or attach a picture (up to ${MAX_MESSAGE} characters)` });
}
const parentId = req.body.parent_id ? parseInt(req.body.parent_id) : null;
const target = await visibleTarget(req.user, contentType, contentId);
ddiff --git a/test/comments-community.test.js b/test/comments-community.test.js
iindex dde7eca2..11c9986f 100644
---- a/test/comments-community.test.js
++++ b/test/comments-community.test.js
@@@ -216,6 +216,13 @@ async function check(name, fn) {
{ method: 'POST', headers: { 'x-test-user': '5' }, body: form });
assert.strictEqual(other.status, 404, 'a non-owner cannot upload to a private VOD');
assert.strictEqual((await call('POST', '/api/comments/vod/100', 5, { message: 'Too many', attachments: Array(5).fill(uploaded.attachment) })).status, 400);
++ // A picture alone is a comment (the owner, 11-12); nothing at all is still refused.
++ const quiet = await call('POST', '/api/comments/vod/100', 5, { message: '', attachments: [uploaded.attachment] });
++ assert.strictEqual(quiet.status, 201, quiet.text);
++ assert.strictEqual(last('POST', /\/comments$/).body.message, '', 'Community gets the picture with no words');
++ const bare = await call('POST', '/api/comments/vod/100', 5, { message: ' ' });
++ assert.strictEqual(bare.status, 400);
++ assert.match(bare.json.error, /Write something or attach a picture/);
});
await check('edit: the author only (as their subject); edits show as edited', async () => {