2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
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.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "core.h"
|
2014-11-15 08:28:44 +08:00
|
|
|
#include "widget/widget.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;
|
|
|
|
delete widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::addPeer(int peerId, QString name)
|
|
|
|
{
|
|
|
|
if (peers.contains(peerId))
|
|
|
|
qWarning() << "Group::addPeer: peerId already used, overwriting anyway";
|
|
|
|
if (name.isEmpty())
|
|
|
|
peers[peerId] = "<Unknown>";
|
|
|
|
else
|
|
|
|
peers[peerId] = name;
|
|
|
|
nPeers++;
|
|
|
|
widget->onUserListChanged();
|
|
|
|
chatForm->onUserListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::removePeer(int peerId)
|
|
|
|
{
|
|
|
|
peers.remove(peerId);
|
2014-07-01 02:45:41 +08:00
|
|
|
nPeers--;
|
2014-06-25 04:11:11 +08:00
|
|
|
widget->onUserListChanged();
|
|
|
|
chatForm->onUserListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::updatePeer(int peerId, QString name)
|
|
|
|
{
|
|
|
|
peers[peerId] = name;
|
|
|
|
widget->onUserListChanged();
|
|
|
|
chatForm->onUserListChanged();
|
|
|
|
}
|
2014-11-06 08:22:50 +08:00
|
|
|
|
|
|
|
void Group::setName(const QString& name)
|
|
|
|
{
|
|
|
|
widget->setName(name);
|
|
|
|
chatForm->setName(name);
|
2014-11-15 08:28:44 +08:00
|
|
|
|
|
|
|
if (widget->isActive())
|
|
|
|
Widget::getInstance()->setWindowTitle(name);
|
2014-11-06 08:22:50 +08:00
|
|
|
}
|