mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(core): simplify the code
This commit is contained in:
parent
6872ead850
commit
8c239c8ef6
|
@ -44,9 +44,6 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
QMap <uint32_t, QMap <ToxPk, QString>> groups;
|
|
||||||
QMap <uint32_t, QMap <ToxPk, bool>> firstTime;
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const auto LABEL_PEER_TYPE_OUR = QVariant(QStringLiteral("our"));
|
const auto LABEL_PEER_TYPE_OUR = QVariant(QStringLiteral("our"));
|
||||||
|
@ -139,8 +136,6 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||||
|
|
||||||
GroupChatForm::~GroupChatForm()
|
GroupChatForm::~GroupChatForm()
|
||||||
{
|
{
|
||||||
groups[group->getId()].clear();
|
|
||||||
firstTime[group->getId()].clear();
|
|
||||||
Translator::unregister(this);
|
Translator::unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,37 +318,35 @@ void GroupChatForm::sendJoinLeaveMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate user list from the current group if it's empty
|
// generate user list from the current group if it's empty
|
||||||
if (!groups.contains(group->getId()))
|
if (groupLast.isEmpty())
|
||||||
{
|
{
|
||||||
groups[group->getId()] = group->getPeerList();
|
groupLast = group->getPeerList();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ¤t = groups[group->getId()];
|
|
||||||
auto &ft = firstTime[group->getId()];
|
|
||||||
// user joins
|
// user joins
|
||||||
for (const auto& peerPk : peers.keys()) {
|
for (const auto& peerPk : peers.keys()) {
|
||||||
const QString name = peers.value(peerPk);
|
const QString name = peers.value(peerPk);
|
||||||
// ignore weird issue: when user joins the group, the name is empty, then it's renamed to normal nickname (why?)
|
// ignore weird issue: when user joins the group, the name is empty, then it's renamed to normal nickname (why?)
|
||||||
// so, just ignore the first insertion
|
// so, just ignore the first insertion
|
||||||
if (!ft.value(peerPk, false))
|
if (!firstTime.value(peerPk, false))
|
||||||
{
|
{
|
||||||
ft[peerPk] = true;
|
firstTime[peerPk] = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!current.contains(peerPk))
|
if (!groupLast.contains(peerPk))
|
||||||
{
|
{
|
||||||
current.insert(peerPk, name);
|
groupLast.insert(peerPk, name);
|
||||||
addSystemInfoMessage(tr("%1 has joined the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("%1 has joined the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// user leaves
|
// user leaves
|
||||||
for (const auto& peerPk : current.keys()) {
|
for (const auto& peerPk : groupLast.keys()) {
|
||||||
const QString name = current.value(peerPk);
|
const QString name = groupLast.value(peerPk);
|
||||||
if (!peers.contains(peerPk))
|
if (!peers.contains(peerPk))
|
||||||
{
|
{
|
||||||
current.remove(peerPk);
|
groupLast.remove(peerPk);
|
||||||
ft.remove(peerPk);
|
firstTime.remove(peerPk);
|
||||||
addSystemInfoMessage(tr("%1 has left the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
|
addSystemInfoMessage(tr("%1 has left the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ private:
|
||||||
Group* group;
|
Group* group;
|
||||||
QMap<ToxPk, QLabel*> peerLabels;
|
QMap<ToxPk, QLabel*> peerLabels;
|
||||||
QMap<ToxPk, QTimer*> peerAudioTimers;
|
QMap<ToxPk, QTimer*> peerAudioTimers;
|
||||||
|
QMap<ToxPk, QString> groupLast;
|
||||||
|
QMap<ToxPk, bool> firstTime;
|
||||||
FlowLayout* namesListLayout;
|
FlowLayout* namesListLayout;
|
||||||
QLabel* nusersLabel;
|
QLabel* nusersLabel;
|
||||||
TabCompleter* tabber;
|
TabCompleter* tabber;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user