bundling timeouts from same user

This commit is contained in:
fourtf
2018-01-05 23:14:55 +01:00
parent 47a813d5d6
commit 315cfd8605
10 changed files with 124 additions and 14 deletions
+34
View File
@@ -132,6 +132,40 @@ public:
return acceptedItems;
}
// replaces a single item, return true if successful
int replaceItem(const T &item, const T &replacement)
{
std::lock_guard<std::mutex> lock(this->mutex);
int x = 0;
for (size_t i = 0; i < this->chunks->size(); i++) {
Chunk &chunk = this->chunks->at(i);
size_t start = i == 0 ? this->firstChunkOffset : 0;
size_t end = i == chunk->size() - 1 ? this->lastChunkEnd : chunk->size();
for (size_t j = start; j < end; j++) {
if (chunk->at(j) == item) {
Chunk newChunk = std::make_shared<std::vector<T>>();
newChunk->resize(chunk->size());
for (size_t k = 0; k < chunk->size(); k++) {
newChunk->at(k) = chunk->at(k);
}
newChunk->at(j) = replacement;
this->chunks->at(i) = newChunk;
return x;
}
x++;
}
}
return -1;
}
// void insertAfter(const std::vector<T> &items, const T &index)
messages::LimitedQueueSnapshot<T> getSnapshot()
+30 -2
View File
@@ -55,6 +55,26 @@ std::vector<Word> &Message::getWords()
return this->words;
}
Message::MessageFlags Message::getFlags() const
{
return this->flags;
}
void Message::setFlags(MessageFlags _flags)
{
this->flags = flags;
}
void Message::addFlags(MessageFlags _flags)
{
this->flags = (MessageFlags)((MessageFlagsType)this->flags | (MessageFlagsType)_flags);
}
void Message::removeFlags(MessageFlags _flags)
{
this->flags = (MessageFlags)((MessageFlagsType)this->flags & ~((MessageFlagsType)_flags));
}
bool Message::isDisabled() const
{
return this->disabled;
@@ -147,12 +167,13 @@ Message *Message::createSystemMessage(const QString &text)
MessageColor(MessageColor::Type::System),
singletons::FontManager::Medium, word, QString()));
}
message->addFlags(Message::System);
return message;
}
Message *Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason)
const QString &reason, bool multipleTimes)
{
QString text;
@@ -181,7 +202,14 @@ Message *Message::createTimeoutMessage(const QString &username, const QString &d
}
text.append(".");
return Message::createSystemMessage(text);
if (multipleTimes) {
text.append(" (multiple times)");
}
Message *message = Message::createSystemMessage(text);
message->addFlags(Message::Timeout);
message->timeoutUser = username;
return message;
}
} // namespace messages
+14 -1
View File
@@ -14,10 +14,17 @@ namespace messages {
class Message;
typedef std::shared_ptr<Message> SharedMessage;
typedef uint32_t MessageFlagsType;
class Message
{
public:
enum MessageFlags : uint32_t {
None = 0,
System = (1 << 1),
Timeout = (1 << 2),
};
bool containsHighlightedPhrase() const;
void setHighlight(bool value);
const QString &getTimeoutUser() const;
@@ -25,6 +32,10 @@ public:
const QString &getContent() const;
const std::chrono::time_point<std::chrono::system_clock> &getParseTime() const;
std::vector<Word> &getWords();
MessageFlags getFlags() const;
void setFlags(MessageFlags flags);
void addFlags(MessageFlags flags);
void removeFlags(MessageFlags flags);
bool isDisabled() const;
void setDisabled(bool value);
const QString &getId() const;
@@ -45,7 +56,7 @@ public:
static Message *createSystemMessage(const QString &text);
static Message *createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason);
const QString &reason, bool multipleTimes);
private:
static LazyLoadedImage *badgeStaff;
@@ -58,6 +69,8 @@ private:
static QRegularExpression *cheerRegex;
MessageFlags flags = MessageFlags::None;
// what is highlightTab?
bool highlightTab = false;
-1
View File
@@ -1 +0,0 @@
#pragma once