Fix issues pointed out in reviews :)

Fixed PR BabyRage
This commit is contained in:
Mm2PL 2020-01-03 14:43:05 +01:00
parent 86318590bf
commit a86367f4be
No known key found for this signature in database
GPG key ID: 1C400DA5602DE62E
4 changed files with 13 additions and 12 deletions

View file

@ -27,7 +27,7 @@ Arguments:
- None - None
Notes: Notes:
- If you want to host the images yourself. You need [Nuuls' filehost software](https://github.com/nuuls/fiehost) - If you want to host the images yourself. You need [Nuuls' filehost software](https://github.com/nuuls/filehost)
- Other image hosting software is currently not supported. - Other image hosting software is currently not supported.
### CHATTERINO2_TWITCH_SERVER_HOST ### CHATTERINO2_TWITCH_SERVER_HOST
@ -42,4 +42,5 @@ Default value: `443`
### CHATTERINO2_TWITCH_SERVER_SECURE ### CHATTERINO2_TWITCH_SERVER_SECURE
Bool value used to tell Chatterino whether to try to connect securely (secure irc) to the Twitch chat server. Bool value used to tell Chatterino whether to try to connect securely (secure irc) to the Twitch chat server.
Default value: `true` Default value: `true`

View file

@ -11,7 +11,7 @@
namespace { namespace {
QString getImageFileFormat(QString path) QString getImageFileFormat(const QString &path)
{ {
static QStringList listOfImageFormats = {".png", ".jpg", ".jpeg"}; static QStringList listOfImageFormats = {".png", ".jpg", ".jpeg"};
for (const QString &format : listOfImageFormats) for (const QString &format : listOfImageFormats)
@ -49,8 +49,8 @@ std::queue<RawImageData> uploadQueue;
void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel, void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel,
ResizingTextEdit &textEdit) ResizingTextEdit &textEdit)
{ {
const char *boundary = "thisistheboudaryasd"; const static char *boundary = "thisistheboudaryasd";
QString contentType = const static QString contentType =
QString("multipart/form-data; boundary=%1").arg(boundary); QString("multipart/form-data; boundary=%1").arg(boundary);
static QUrl url(Env::get().imageUploaderUrl); static QUrl url(Env::get().imageUploaderUrl);
@ -86,12 +86,8 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel,
"wait until all of them are uploaded. About %2 " "wait until all of them are uploaded. About %2 "
"seconds left.") "seconds left.")
.arg(uploadQueue.size(), .arg(uploadQueue.size(),
uploadQueue.size() * uploadQueue.size() * (UPLOAD_DELAY / 1000 + 1))));
(UPLOAD_DELAY / 1000 + // 2 seconds for the timer that's there not to spam the remote server
1) // convert UPLOAD_DELAY to seconds
)));
// Argument number 2 is the ETA.
// 2 seconds for the timer that's there not to spam Nuuls' server
// and 1 second of actual uploading. // and 1 second of actual uploading.
QTimer::singleShot(UPLOAD_DELAY, [channel, &textEdit]() { QTimer::singleShot(UPLOAD_DELAY, [channel, &textEdit]() {
@ -156,6 +152,7 @@ void upload(const QMimeData *source, ChannelPtr channel,
{ {
channel->addMessage( channel->addMessage(
makeSystemMessage(QString("Couldn't load image :("))); makeSystemMessage(QString("Couldn't load image :(")));
isUploading = false;
return; return;
} }
@ -183,6 +180,7 @@ void upload(const QMimeData *source, ChannelPtr channel,
{ {
channel->addMessage( channel->addMessage(
makeSystemMessage(QString("Failed to open file. :("))); makeSystemMessage(QString("Failed to open file. :(")));
isUploading = false;
return; return;
} }
RawImageData data = {file.readAll(), "gif"}; RawImageData data = {file.readAll(), "gif"};
@ -217,6 +215,7 @@ void upload(const QMimeData *source, ChannelPtr channel,
{ {
channel->addMessage(makeSystemMessage( channel->addMessage(makeSystemMessage(
QString("Cannot upload file, failed to convert to png."))); QString("Cannot upload file, failed to convert to png.")));
isUploading = false;
} }
} }
} }

View file

@ -9,6 +9,7 @@ struct RawImageData {
QByteArray data; QByteArray data;
QString format; QString format;
}; };
void upload(QByteArray imageData, ChannelPtr channel, void upload(QByteArray imageData, ChannelPtr channel,
ResizingTextEdit &textEdit, std::string format); ResizingTextEdit &textEdit, std::string format);
void upload(RawImageData imageData, ChannelPtr channel, void upload(RawImageData imageData, ChannelPtr channel,

View file

@ -301,7 +301,7 @@ void ResizingTextEdit::dropEvent(QDropEvent *event)
{ {
this->imagePasted.invoke(event->mimeData()); this->imagePasted.invoke(event->mimeData());
} }
else // allow for previous functionality of dropping text. else
{ {
QTextEdit::dropEvent(event); QTextEdit::dropEvent(event);
} }