mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Do not allow posting too large messages
This commit is contained in:
parent
349f0e0c31
commit
778c5ea47d
@ -75,6 +75,12 @@ PostedCreatePostDialog::~PostedCreatePostDialog()
|
|||||||
|
|
||||||
void PostedCreatePostDialog::createPost()
|
void PostedCreatePostDialog::createPost()
|
||||||
{
|
{
|
||||||
|
if(ui->titleEdit->text().isEmpty()) {
|
||||||
|
/* error message */
|
||||||
|
QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
return; //Don't add a empty title!!
|
||||||
|
}
|
||||||
|
|
||||||
RsGxsId authorId;
|
RsGxsId authorId;
|
||||||
switch (ui->idChooser->getChosenId(authorId)) {
|
switch (ui->idChooser->getChosenId(authorId)) {
|
||||||
case GxsIdChooser::KnowId:
|
case GxsIdChooser::KnowId:
|
||||||
@ -108,13 +114,14 @@ void PostedCreatePostDialog::createPost()
|
|||||||
{
|
{
|
||||||
// send posted image
|
// send posted image
|
||||||
post.mImage.copy((uint8_t *) imagebytes.data(), imagebytes.size());
|
post.mImage.copy((uint8_t *) imagebytes.data(), imagebytes.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
int msgsize = post.mLink.length() + post.mMeta.mMsgName.length() + post.mNotes.length() + imagebytes.size();
|
||||||
|
if(msgsize > MAXMESSAGESIZE) {
|
||||||
|
QString errormessage = QString(tr("Message is too large.<br />actual size: %1 bytes, maximum size: %2 bytes.")).arg(msgsize).arg(MAXMESSAGESIZE);
|
||||||
|
QMessageBox::warning(this, "RetroShare", errormessage, QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ui->titleEdit->text().isEmpty()) {
|
|
||||||
/* error message */
|
|
||||||
QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok);
|
|
||||||
return; //Don't add a empty title!!
|
|
||||||
}//if(ui->titleEdit->text().isEmpty())
|
|
||||||
|
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
mPosted->createPost(token, post);
|
mPosted->createPost(token, post);
|
||||||
@ -145,7 +152,6 @@ void PostedCreatePostDialog::addPicture()
|
|||||||
// select a picture file
|
// select a picture file
|
||||||
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
||||||
QString encodedImage;
|
QString encodedImage;
|
||||||
int maxMessageSize = 34000; //34 kB
|
|
||||||
QImage image;
|
QImage image;
|
||||||
if (image.load(imagefilename) == false) {
|
if (image.load(imagefilename) == false) {
|
||||||
fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", imagefilename.toLatin1().constData());
|
fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", imagefilename.toLatin1().constData());
|
||||||
@ -154,7 +160,7 @@ void PostedCreatePostDialog::addPicture()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QImage opt;
|
QImage opt;
|
||||||
if(ImageUtil::optimizeSizeBytes(imagebytes, image, opt, 800*600, maxMessageSize)) {
|
if(ImageUtil::optimizeSizeBytes(imagebytes, image, opt, 800*600, MAXMESSAGESIZE - 1000)) { //Leave space for other stuff
|
||||||
ui->imageLabel->setPixmap(QPixmap::fromImage(opt));
|
ui->imageLabel->setPixmap(QPixmap::fromImage(opt));
|
||||||
} else {
|
} else {
|
||||||
imagefilename = "";
|
imagefilename = "";
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QString imagefilename;
|
QString imagefilename;
|
||||||
QByteArray imagebytes;
|
QByteArray imagebytes;
|
||||||
|
const int MAXMESSAGESIZE = 32000;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void createPost();
|
void createPost();
|
||||||
|
@ -366,7 +366,7 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Picture size is limited to 34 KB</string>
|
<string>Post size is limited to 32 KB, pictures will be downscaled.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user