Merge pull request #1012 from apa420/apa-deleted-messages

Added support for single deleted messages
This commit is contained in:
pajlada 2019-04-28 12:51:57 +02:00 committed by GitHub
commit 77f57bcff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 214 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32mm"
height="32mm"
viewBox="0 0 32 32"
version="1.1"
id="svg8"
inkscape:export-filename="/home/pajlada/git/chatterino2/resources/buttons/trashcan2.png"
inkscape:export-xdpi="50.799999"
inkscape:export-ydpi="50.799999"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="trashcan.svg">
<defs
id="defs2">
<linearGradient
inkscape:collect="always"
id="linearGradient4536"
osb:paint="gradient">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop4532" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop4534" />
</linearGradient>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6"
inkscape:cx="58.051498"
inkscape:cy="84.215087"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1529"
inkscape:window-height="1419"
inkscape:window-x="2160"
inkscape:window-y="2400"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid4818"
originx="-74.790005"
originy="-199.8473"
units="mm"
spacingx="1"
spacingy="1" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-74.789996,-65.152683)">
<path
style="fill:none;stroke:#898395;stroke-width:3.5999999;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 82.789996,69.152684 v 25 h 16 v -25"
id="path4820"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
<path
style="fill:none;stroke:#898395;stroke-width:3.6;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 102.79,69.152684 H 78.789994"
id="path4826"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc">
<title
id="title4970">Trashcan top</title>
</path>
<path
style="fill:none;stroke:#898395;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 87.789996,74.999984 v 14"
id="path4830"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#898395;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 93.789996,88.999984 v -14"
id="path4832"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<circle
style="fill:#898395;fill-opacity:1;stroke:none;stroke-width:6.75056219;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
id="path4974"
cx="90.789993"
cy="67.069061"
r="1.75" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2"
transform="translate(-74.789996,-65.152683)" />
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

View file

@ -24,6 +24,7 @@
<file>buttons/modModeEnabled.png</file>
<file>buttons/modModeEnabled2.png</file>
<file>buttons/timeout.png</file>
<file>buttons/trashCan.png</file>
<file>buttons/unban.png</file>
<file>buttons/unmod.png</file>
<file>buttons/update.png</file>

View file

@ -264,6 +264,7 @@ void Application::initPubsub()
auto msg = MessageBuilder(action).release();
postToThread([chan, msg] { chan->addMessage(msg); });
chan->deleteMessage(msg->id);
});
this->twitch.pubsub->start();

View file

@ -18,6 +18,7 @@ Resources2::Resources2()
this->buttons.modModeEnabled = QPixmap(":/buttons/modModeEnabled.png");
this->buttons.modModeEnabled2 = QPixmap(":/buttons/modModeEnabled2.png");
this->buttons.timeout = QPixmap(":/buttons/timeout.png");
this->buttons.trashCan = QPixmap(":/buttons/trashCan.png");
this->buttons.unban = QPixmap(":/buttons/unban.png");
this->buttons.unmod = QPixmap(":/buttons/unmod.png");
this->buttons.update = QPixmap(":/buttons/update.png");

View file

@ -24,6 +24,7 @@ public:
QPixmap modModeEnabled;
QPixmap modModeEnabled2;
QPixmap timeout;
QPixmap trashCan;
QPixmap unban;
QPixmap unmod;
QPixmap update;

View file

@ -212,6 +212,25 @@ void Channel::replaceMessage(MessagePtr message, MessagePtr replacement)
}
}
void Channel::deleteMessage(QString messageID)
{
LimitedQueueSnapshot<MessagePtr> snapshot = this->getMessageSnapshot();
int snapshotLength = snapshot.size();
int end = std::max(0, snapshotLength - 200);
for (int i = snapshotLength - 1; i >= end; --i)
{
auto &s = snapshot[i];
if (s->id == messageID)
{
s->flags.set(MessageFlag::Disabled);
break;
}
}
}
void Channel::addRecentChatter(const MessagePtr &message)
{
}

View file

@ -62,6 +62,7 @@ public:
void addOrReplaceTimeout(MessagePtr message);
void disableAllMessages();
void replaceMessage(MessagePtr message, MessagePtr replacement);
void deleteMessage(QString messageID);
QStringList modList;

View file

@ -73,6 +73,10 @@ ModerationAction::ModerationAction(const QString &action)
{
this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban);
}
else if (action.startsWith("/delete"))
{
this->image_ = Image::fromPixmap(getApp()->resources->buttons.trashCan);
}
else
{
QString xD = action;

View file

@ -266,6 +266,41 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
}
}
void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
{
// check parameter count
if (message->parameters().length() < 1)
{
return;
}
QString chanName;
if (!trimChannelName(message->parameter(0), chanName))
{
return;
}
auto app = getApp();
// get channel
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
if (chan->isEmpty())
{
log("[IrcMessageHandler:handleClearMessageMessage] Twitch channel {} "
"not "
"found",
chanName);
return;
}
auto tags = message->tags();
QString targetID = tags.value("target-msg-id").toString();
chan->deleteMessage(targetID);
}
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
{
auto app = getApp();
@ -516,7 +551,17 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
return;
}
channel->addMessage(msg);
QString tags = message->tags().value("msg-id", "").toString();
if (tags == "bad_delete_message_error" || tags == "usage_delete")
{
channel->addMessage(makeSystemMessage(
"Usage: \"/delete <msg-id>\" - can't take more "
"than one argument"));
}
else
{
channel->addMessage(msg);
}
}
}

View file

@ -27,6 +27,7 @@ public:
void handleRoomStateMessage(Communi::IrcMessage *message);
void handleClearChatMessage(Communi::IrcMessage *message);
void handleClearMessageMessage(Communi::IrcMessage *message);
void handleUserStateMessage(Communi::IrcMessage *message);
void handleWhisperMessage(Communi::IrcMessage *message);

View file

@ -580,7 +580,7 @@ void TwitchMessageBuilder::parseMessageID()
if (iterator != this->tags.end())
{
this->messageID = iterator.value().toString();
this->message().id = iterator.value().toString();
}
}
@ -607,7 +607,7 @@ void TwitchMessageBuilder::parseRoomID()
void TwitchMessageBuilder::appendChannelName()
{
QString channelName("#" + this->channel->getName());
Link link(Link::Url, this->channel->getName() + "\n" + this->messageID);
Link link(Link::Url, this->channel->getName() + "\n" + this->message().id);
this->emplace<TextElement>(channelName, MessageElementFlag::ChannelName,
MessageColor::System) //

View file

@ -41,7 +41,6 @@ public:
MessageParseArgs args;
const QVariantMap tags;
QString messageID;
QString userName;
bool isIgnored() const;
@ -55,8 +54,10 @@ private:
void appendUsername();
void parseHighlights(bool isPastMsg);
void appendTwitchEmote(const QString &emote,
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec, std::vector<int> &correctPositions);
void appendTwitchEmote(
const QString &emote,
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec,
std::vector<int> &correctPositions);
Outcome tryAppendEmote(const EmoteName &name);
void addWords(

View file

@ -156,6 +156,10 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message)
{
handler.handleClearChatMessage(message);
}
else if (command == "CLEARMSG")
{
handler.handleClearMessageMessage(message);
}
else if (command == "USERSTATE")
{
handler.handleUserStateMessage(message);

View file

@ -1667,7 +1667,9 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
case Link::UserAction:
{
QString value = link.value;
value.replace("{user}", layout->getMessage()->loginName).replace("{channel}", this->channel_->getName());
value.replace("{user}", layout->getMessage()->loginName)
.replace("{channel}", this->channel_->getName())
.replace("{msg-id}", layout->getMessage()->id);
this->channel_->sendMessage(value);
}
break;

View file

@ -161,7 +161,8 @@ ModerationPage::ModerationPage()
// clang-format off
auto label = modMode.emplace<QLabel>(
"Moderation mode is enabled by clicking <img width='18' height='18' src=':/buttons/modModeDisabled.png'> in a channel that you moderate.<br><br>"
"Moderation buttons can be bound to chat commands such as \"/ban {user}\", \"/timeout {user} 1000\", \"/w someusername !report {user} was bad in channel {channel}\" or any other custom text commands.<br>");
"Moderation buttons can be bound to chat commands such as \"/ban {user}\", \"/timeout {user} 1000\", \"/w someusername !report {user} was bad in channel {channel}\" or any other custom text commands.<br>"
"For deleting messages use /delete {msg-id}.");
label->setWordWrap(true);
label->setStyleSheet("color: #bbb");
// clang-format on