1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #5469

Monsterovich (10):
      feat(core): print a chat log entry when a user joins/leaves the group chat
      fix(core): fixed Timestamps
      fix(core): simplify the code
      fix(core): fix formatting
      fix(core): this fixes displaying nickname refreshes in groups
      fix(core): support user aliases
      fix(core): update group peerLists on local changes
      fix(core): fix for users without nicknames
      fix(core): ignore mentioning users with empty nicknames
      fix(core): fixed syntax
This commit is contained in:
sudden6 2019-01-04 14:56:55 +01:00
commit aa83edf759
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
10 changed files with 94 additions and 8 deletions

View File

@ -87,3 +87,13 @@ QList<Friend*> FriendList::getAllFriends()
{
return friendList.values();
}
QString FriendList::decideNickname(ToxPk peerPk, const QString origName)
{
Friend* f = FriendList::findFriend(peerPk);
if (f != nullptr && f->hasAlias()) {
return f->getDisplayedName();
} else {
return origName;
}
}

View File

@ -28,6 +28,7 @@ template <class A, class B>
class QHash;
class Friend;
class QByteArray;
class QString;
class ToxPk;
class FriendList
@ -39,6 +40,7 @@ public:
static QList<Friend*> getAllFriends();
static void removeFriend(uint32_t friendId, bool fake = false);
static void clear();
static QString decideNickname(ToxPk peerPk, const QString origName);
private:
static QHash<uint32_t, Friend*> friendList;

View File

@ -84,6 +84,14 @@ void Friend::setAlias(const QString& alias)
if (oldDisplayed != newDisplayed) {
emit displayedNameChanged(newDisplayed);
}
for (Group* g : GroupList::getAllGroups()) {
if (userAlias.isEmpty()) {
g->updateUsername(friendPk, userName);
continue;
}
g->updateUsername(friendPk, userAlias);
}
}
void Friend::setStatusMessage(const QString& message)

View File

@ -46,12 +46,7 @@ void Group::updatePeer(int peerId, QString name)
{
ToxPk peerKey = Core::getInstance()->getGroupPeerPk(groupId, peerId);
toxpks[peerKey] = name;
Friend* f = FriendList::findFriend(peerKey);
if (f != nullptr) {
// use the displayed name from the friends list
toxpks[peerKey] = f->getDisplayedName();
}
qDebug() << "name change: " + name;
emit userListChanged(groupId, toxpks);
}
@ -124,6 +119,12 @@ void Group::regeneratePeerList()
emit userListChanged(groupId, toxpks);
}
void Group::updateUsername(ToxPk pk, const QString newName)
{
toxpks[pk] = newName;
emit userListChanged(groupId, toxpks);
}
bool Group::isAvGroupchat() const
{
return avGroupchat;

View File

@ -47,6 +47,7 @@ public:
bool getMentionedFlag() const;
void updatePeer(int peerId, QString newName);
void updateUsername(ToxPk pk, const QString newName);
void setName(const QString& newTitle) override;
void setTitle(const QString& author, const QString& newTitle);
QString getName() const;

View File

@ -213,6 +213,7 @@ void Nexus::showMainGUI()
connect(core, &Core::friendTypingChanged, widget, &Widget::onFriendTypingChanged);
connect(core, &Core::messageSentResult, widget, &Widget::onMessageSendResult);
connect(core, &Core::groupSentFailed, widget, &Widget::onGroupSendFailed);
connect(core, &Core::usernameSet, widget, &Widget::refreshPeerListsLocal);
connect(widget, &Widget::statusSet, core, &Core::setStatus);
connect(widget, &Widget::friendRequested, core, &Core::requestFriendship);

View File

@ -176,6 +176,7 @@ void GroupChatForm::onUserListChanged()
{
updateUserCount();
updateUserNames();
sendJoinLeaveMessages();
// Enable or disable call button
const int peersCount = group->getPeersCount();
@ -261,7 +262,7 @@ void GroupChatForm::updateUserNames()
* and then sort them by their text and add them to the layout in that order */
const auto selfPk = Core::getInstance()->getSelfPublicKey();
for (const auto& peerPk : peers.keys()) {
const QString fullName = peers.value(peerPk);
const QString fullName = FriendList::decideNickname(peerPk, peers.value(peerPk));
const QString editedName = editName(fullName).append(QLatin1String(", "));
QLabel* const label = new QLabel(editedName);
if (editedName != fullName) {
@ -307,6 +308,57 @@ void GroupChatForm::updateUserNames()
}
}
void GroupChatForm::sendJoinLeaveMessages()
{
const auto peers = group->getPeerList();
// no need to do anything without any peers
if (peers.isEmpty()) {
return;
}
// generate user list from the current group if it's empty
if (groupLast.isEmpty()) {
groupLast = group->getPeerList();
return;
}
// user joins
for (const auto& peerPk : peers.keys()) {
if (!firstTime.value(peerPk, false)) {
if (!groupLast.contains(peerPk)) {
addSystemInfoMessage(tr("A new user has connected to the group"), ChatMessage::INFO, QDateTime::currentDateTime());
}
firstTime[peerPk] = true;
continue;
}
const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk));
if (!groupLast.contains(peerPk)) {
groupLast.insert(peerPk, name);
addSystemInfoMessage(tr("%1 has joined the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
} else {
Friend *f = FriendList::findFriend(peerPk);
if (groupLast[peerPk] != name
&& peers.value(peerPk) == name
&& peerPk != Core::getInstance()->getSelfPublicKey() // ignore myself
&& !(f != nullptr && f->hasAlias()) // ignore friends with aliases
) {
addSystemInfoMessage(tr("%1 is now known as %2").arg(groupLast[peerPk], name), ChatMessage::INFO, QDateTime::currentDateTime());
groupLast[peerPk] = name;
}
}
}
// user leaves
for (const auto& peerPk : groupLast.keys()) {
const QString name = FriendList::decideNickname(peerPk, groupLast.value(peerPk));
if (!peers.contains(peerPk)) {
groupLast.remove(peerPk);
firstTime.remove(peerPk);
addSystemInfoMessage(tr("%1 has left the group").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
}
}
}
void GroupChatForm::peerAudioPlaying(ToxPk peerPk)
{
peerLabels[peerPk]->setProperty("playingAudio", LABEL_PEER_PLAYING_AUDIO);

View File

@ -67,11 +67,14 @@ private:
void retranslateUi();
void updateUserCount();
void updateUserNames();
void sendJoinLeaveMessages();
private:
Group* group;
QMap<ToxPk, QLabel*> peerLabels;
QMap<ToxPk, QTimer*> peerAudioTimers;
QMap<ToxPk, QString> groupLast;
QMap<ToxPk, bool> firstTime;
FlowLayout* namesListLayout;
QLabel* nusersLabel;
TabCompleter* tabber;

View File

@ -1745,7 +1745,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
return;
}
const auto mention = message.contains(nameMention) || message.contains(sanitizedNameMention);
const auto mention = !core->getUsername().isEmpty() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
const auto targeted = !isSelf && mention;
const auto groupId = g->getId();
const auto date = QDateTime::currentDateTime();
@ -2506,3 +2506,10 @@ void Widget::focusChatInput()
}
}
}
void Widget::refreshPeerListsLocal(const QString &username)
{
for (Group* g : GroupList::getAllGroups()) {
g->updateUsername(Core::getInstance()->getSelfPublicKey(), username);
}
}

View File

@ -182,6 +182,7 @@ public slots:
void onFriendDialogShown(const Friend* f);
void onGroupDialogShown(Group* g);
void toggleFullscreen();
void refreshPeerListsLocal(const QString &username);
signals:
void friendRequestAccepted(const ToxPk& friendPk);