2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project
|
|
|
|
|
2014-07-07 00:19:45 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-07-07 00:19:45 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-07-07 00:19:45 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-07 00:19:45 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "group.h"
|
2014-06-27 06:42:45 +08:00
|
|
|
#include "widget/groupwidget.h"
|
|
|
|
#include "widget/form/groupchatform.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "friendlist.h"
|
|
|
|
#include "friend.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2015-02-07 02:01:31 +08:00
|
|
|
#include "widget/gui.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
#include <QDebug>
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QTimer>
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-11-13 20:11:23 +08:00
|
|
|
Group::Group(int GroupId, QString Name, bool IsAvGroupchat)
|
|
|
|
: groupId(GroupId), nPeers{0}, avGroupchat{IsAvGroupchat}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
|
|
|
widget = new GroupWidget(groupId, Name);
|
|
|
|
chatForm = new GroupChatForm(this);
|
2014-06-28 07:10:02 +08:00
|
|
|
|
2014-10-06 14:46:30 +08:00
|
|
|
//in groupchats, we only notify on messages containing your name <-- dumb
|
|
|
|
// sound notifications should be on all messages, but system popup notification
|
|
|
|
// on naming is appropriate
|
2014-06-28 07:10:02 +08:00
|
|
|
hasNewMessages = 0;
|
2014-06-28 07:46:13 +08:00
|
|
|
userWasMentioned = 0;
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Group::~Group()
|
|
|
|
{
|
|
|
|
delete chatForm;
|
2015-06-11 00:11:50 +08:00
|
|
|
widget->deleteLater();
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::updatePeer(int peerId, QString name)
|
|
|
|
{
|
2015-05-24 02:58:41 +08:00
|
|
|
ToxId id = Core::getInstance()->getGroupPeerToxId(groupId, peerId);
|
2014-11-24 00:22:41 +08:00
|
|
|
QString toxid = id.publicKey;
|
2014-06-25 04:11:11 +08:00
|
|
|
peers[peerId] = name;
|
2014-11-23 23:55:49 +08:00
|
|
|
toxids[toxid] = name;
|
2015-10-10 20:49:30 +08:00
|
|
|
|
2014-11-24 00:22:41 +08:00
|
|
|
Friend *f = FriendList::findFriend(id);
|
2015-10-10 20:49:30 +08:00
|
|
|
|
2015-10-15 01:53:46 +08:00
|
|
|
if (f != nullptr && f->hasAlias())
|
2014-11-24 00:22:41 +08:00
|
|
|
{
|
2015-10-15 01:53:46 +08:00
|
|
|
widget->onUserListChanged();
|
|
|
|
chatForm->onUserListChanged();
|
|
|
|
emit userListChanged(getGroupWidget());
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
2014-11-06 08:22:50 +08:00
|
|
|
|
|
|
|
void Group::setName(const QString& name)
|
|
|
|
{
|
|
|
|
chatForm->setName(name);
|
2014-11-15 08:28:44 +08:00
|
|
|
|
|
|
|
if (widget->isActive())
|
2015-06-23 02:01:50 +08:00
|
|
|
GUI::setWindowTitle(name);
|
|
|
|
|
|
|
|
emit titleChanged(this->getGroupWidget());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Group::getName() const
|
|
|
|
{
|
|
|
|
return widget->getName();
|
2014-11-06 08:22:50 +08:00
|
|
|
}
|
2014-11-23 23:22:29 +08:00
|
|
|
|
|
|
|
void Group::regeneratePeerList()
|
|
|
|
{
|
2015-03-13 14:00:12 +08:00
|
|
|
peers = Core::getInstance()->getGroupPeerNames(groupId);
|
2014-11-23 23:55:49 +08:00
|
|
|
toxids.clear();
|
2015-03-13 14:00:12 +08:00
|
|
|
nPeers = peers.size();
|
|
|
|
for (int i = 0; i < nPeers; i++)
|
2014-11-23 23:55:49 +08:00
|
|
|
{
|
2015-05-24 02:58:41 +08:00
|
|
|
ToxId id = Core::getInstance()->getGroupPeerToxId(groupId, i);
|
2015-12-17 18:24:01 +08:00
|
|
|
if (id.isSelf())
|
2015-03-13 14:00:12 +08:00
|
|
|
selfPeerNum = i;
|
2015-04-24 19:01:50 +08:00
|
|
|
|
2014-11-24 00:22:41 +08:00
|
|
|
QString toxid = id.publicKey;
|
2015-03-13 14:00:12 +08:00
|
|
|
toxids[toxid] = peers[i];
|
2014-11-24 00:22:41 +08:00
|
|
|
Friend *f = FriendList::findFriend(id);
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
peers[i] = f->getDisplayedName();
|
|
|
|
toxids[toxid] = f->getDisplayedName();
|
|
|
|
}
|
2014-11-23 23:55:49 +08:00
|
|
|
}
|
2014-11-23 23:22:29 +08:00
|
|
|
|
|
|
|
widget->onUserListChanged();
|
|
|
|
chatForm->onUserListChanged();
|
2015-06-23 02:01:50 +08:00
|
|
|
emit userListChanged(getGroupWidget());
|
2014-11-23 23:22:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Group::isAvGroupchat() const
|
|
|
|
{
|
|
|
|
return avGroupchat;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Group::getGroupId() const
|
|
|
|
{
|
|
|
|
return groupId;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Group::getPeersCount() const
|
|
|
|
{
|
|
|
|
return nPeers;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupChatForm *Group::getChatForm()
|
|
|
|
{
|
|
|
|
return chatForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupWidget *Group::getGroupWidget()
|
|
|
|
{
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Group::getPeerList() const
|
|
|
|
{
|
2015-03-13 14:00:12 +08:00
|
|
|
return peers;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Group::isSelfPeerNumber(int num) const
|
|
|
|
{
|
|
|
|
return num == selfPeerNum;
|
2014-11-23 23:22:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setEventFlag(int f)
|
|
|
|
{
|
|
|
|
hasNewMessages = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Group::getEventFlag() const
|
|
|
|
{
|
|
|
|
return hasNewMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::setMentionedFlag(int f)
|
|
|
|
{
|
|
|
|
userWasMentioned = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Group::getMentionedFlag() const
|
|
|
|
{
|
|
|
|
return userWasMentioned;
|
|
|
|
}
|
2014-11-23 23:55:49 +08:00
|
|
|
|
2015-05-24 02:58:41 +08:00
|
|
|
QString Group::resolveToxId(const ToxId &id) const
|
2014-11-23 23:55:49 +08:00
|
|
|
{
|
|
|
|
QString key = id.publicKey;
|
|
|
|
auto it = toxids.find(key);
|
|
|
|
|
|
|
|
if (it != toxids.end())
|
|
|
|
return *it;
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|