Browse Source

Merge pull request #5480

Monsterovich (3):
      fix(core): this should resolve message handling in persistent groups
      fix(core): also print PKs in group userlist
      fix(core): if your username is empty, use toxPK instead in groups
pull/5347/merge
Anthony Bilinski 7 years ago
parent
commit
52853485eb
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 20
      src/model/group.cpp
  2. 2
      src/model/group.h
  3. 3
      src/widget/form/genericchatform.cpp
  4. 10
      src/widget/form/groupchatform.cpp

20
src/model/group.cpp

@ -104,21 +104,29 @@ void Group::regeneratePeerList()
for (int i = 0; i < nPeers; ++i) { for (int i = 0; i < nPeers; ++i) {
const auto pk = core->getGroupPeerPk(groupId, i); const auto pk = core->getGroupPeerPk(groupId, i);
toxpks[pk] = peers[i];
if (toxpks[pk].isEmpty()) {
toxpks[pk] =
tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
}
Friend* f = FriendList::findFriend(pk); Friend* f = FriendList::findFriend(pk);
if (f != nullptr && f->hasAlias()) { if (f != nullptr && f->hasAlias()) {
toxpks[pk] = f->getDisplayedName(); toxpks[pk] = f->getDisplayedName();
empty_nick[pk] = false;
continue;
}
empty_nick[pk] = peers[i].isEmpty();
if (empty_nick[pk]) {
toxpks[pk] = tr("<Empty>", "Placeholder when someone's name in a group chat is empty");
} else {
toxpks[pk] = peers[i];
} }
} }
emit userListChanged(groupId, toxpks); emit userListChanged(groupId, toxpks);
} }
bool Group::peerHasNickname(ToxPk pk)
{
return !empty_nick[pk];
}
void Group::updateUsername(ToxPk pk, const QString newName) void Group::updateUsername(ToxPk pk, const QString newName)
{ {
toxpks[pk] = newName; toxpks[pk] = newName;

2
src/model/group.h

@ -39,6 +39,7 @@ public:
int getPeersCount() const; int getPeersCount() const;
void regeneratePeerList(); void regeneratePeerList();
const QMap<ToxPk, QString>& getPeerList() const; const QMap<ToxPk, QString>& getPeerList() const;
bool peerHasNickname(ToxPk pk);
void setEventFlag(bool f) override; void setEventFlag(bool f) override;
bool getEventFlag() const override; bool getEventFlag() const override;
@ -67,6 +68,7 @@ private:
QString selfName; QString selfName;
QString title; QString title;
QMap<ToxPk, QString> toxpks; QMap<ToxPk, QString> toxpks;
QMap<ToxPk, bool> empty_nick;
bool hasNewMessages; bool hasNewMessages;
bool userWasMentioned; bool userWasMentioned;
int groupId; int groupId;

3
src/widget/form/genericchatform.cpp

@ -377,7 +377,8 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
{ {
const Core* core = Core::getInstance(); const Core* core = Core::getInstance();
bool isSelf = author == core->getSelfId().getPublicKey(); bool isSelf = author == core->getSelfId().getPublicKey();
QString authorStr = isSelf ? core->getUsername() : resolveToxPk(author); QString myNickName = core->getUsername().isEmpty() ? author.toString() : core->getUsername();
QString authorStr = isSelf ? myNickName : resolveToxPk(author);
if (getLatestDate() != QDate::currentDate()) { if (getLatestDate() != QDate::currentDate()) {
addSystemDateMessage(); addSystemDateMessage();
} }

10
src/widget/form/groupchatform.cpp

@ -266,7 +266,7 @@ void GroupChatForm::updateUserNames()
const QString editedName = editName(fullName).append(QLatin1String(", ")); const QString editedName = editName(fullName).append(QLatin1String(", "));
QLabel* const label = new QLabel(editedName); QLabel* const label = new QLabel(editedName);
if (editedName != fullName) { if (editedName != fullName) {
label->setToolTip(fullName); label->setToolTip(fullName + " (" + peerPk.toString() + ")");
} }
label->setTextFormat(Qt::PlainText); label->setTextFormat(Qt::PlainText);
label->setContextMenuPolicy(Qt::CustomContextMenu); label->setContextMenuPolicy(Qt::CustomContextMenu);
@ -325,14 +325,20 @@ void GroupChatForm::sendJoinLeaveMessages()
// user joins // user joins
for (const auto& peerPk : peers.keys()) { for (const auto& peerPk : peers.keys()) {
const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk));
if (!firstTime.value(peerPk, false)) { if (!firstTime.value(peerPk, false)) {
if (!groupLast.contains(peerPk)) { if (!groupLast.contains(peerPk)) {
if (group->peerHasNickname(peerPk)) {
firstTime[peerPk] = true;
groupLast.insert(peerPk, name);
addSystemInfoMessage(tr("%1 is online").arg(name), ChatMessage::INFO, QDateTime::currentDateTime());
continue;
}
addSystemInfoMessage(tr("A new user has connected to the group"), ChatMessage::INFO, QDateTime::currentDateTime()); addSystemInfoMessage(tr("A new user has connected to the group"), ChatMessage::INFO, QDateTime::currentDateTime());
} }
firstTime[peerPk] = true; firstTime[peerPk] = true;
continue; continue;
} }
const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk));
if (!groupLast.contains(peerPk)) { if (!groupLast.contains(peerPk)) {
groupLast.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());

Loading…
Cancel
Save