Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core): this should resolve message handling in persistent groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Jan 5, 2019
1 parent aa83edf commit ee50070
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/model/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,29 @@ void Group::regeneratePeerList()
for (int i = 0; i < nPeers; ++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);
if (f != nullptr && f->hasAlias()) {
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);
}

bool Group::peerHasNickname(ToxPk pk)
{
return !empty_nick[pk];
}

void Group::updateUsername(ToxPk pk, const QString newName)
{
toxpks[pk] = newName;
Expand Down
2 changes: 2 additions & 0 deletions src/model/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Group : public Contact
int getPeersCount() const;
void regeneratePeerList();
const QMap<ToxPk, QString>& getPeerList() const;
bool peerHasNickname(ToxPk pk);

void setEventFlag(bool f) override;
bool getEventFlag() const override;
Expand Down Expand Up @@ -67,6 +68,7 @@ class Group : public Contact
QString selfName;
QString title;
QMap<ToxPk, QString> toxpks;
QMap<ToxPk, bool> empty_nick;
bool hasNewMessages;
bool userWasMentioned;
int groupId;
Expand Down
8 changes: 7 additions & 1 deletion src/widget/form/groupchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,20 @@ void GroupChatForm::sendJoinLeaveMessages()

// user joins
for (const auto& peerPk : peers.keys()) {
const QString name = FriendList::decideNickname(peerPk, peers.value(peerPk));
if (!firstTime.value(peerPk, false)) {
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());
}
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());
Expand Down

0 comments on commit ee50070

Please sign in to comment.