qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
groupchatroom.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "groupchatroom.h"
21 
22 #include "src/core/core.h"
23 #include "src/core/toxpk.h"
24 #include "src/friendlist.h"
26 #include "src/model/friend.h"
27 #include "src/model/group.h"
28 #include "src/model/status.h"
30 
31 GroupChatroom::GroupChatroom(Group* group, IDialogsManager* dialogsManager, Core& _core)
32  : group{group}
33  , dialogsManager{dialogsManager}
34  , core{_core}
35 {
36 }
37 
39 {
40  return group;
41 }
42 
44 {
45  return group;
46 }
47 
49 {
50  return group->getEventFlag();
51 }
52 
54 {
55  group->setEventFlag(false);
56  group->setMentionedFlag(false);
57 }
58 
60 {
61  return FriendList::findFriend(pk) != nullptr;
62 }
63 
65 {
66  const Friend* frnd = FriendList::findFriend(pk);
67  const auto friendId = frnd->getId();
68  const auto groupId = group->getId();
69  const auto canInvite = Status::isOnline(frnd->getStatus());
70 
71  if (canInvite) {
72  core.groupInviteFriend(friendId, groupId);
73  }
74 }
75 
77 {
78  const auto groupId = group->getPersistentId();
79  const auto dialogs = dialogsManager->getGroupDialogs(groupId);
80  return !dialogs || dialogs->chatroomCount() > 1;
81 }
82 
84 {
85  const auto groupId = group->getPersistentId();
86  const auto dialogs = dialogsManager->getGroupDialogs(groupId);
87  return dialogs && dialogs->hasContact(groupId);
88 }
89 
91 {
92  const auto groupId = group->getPersistentId();
93  auto dialogs = dialogsManager->getGroupDialogs(groupId);
94  dialogs->removeGroup(groupId);
95 }
IDialogsManager::getGroupDialogs
virtual IDialogs * getGroupDialogs(const GroupId &groupId) const =0
IDialogsManager
Definition: idialogsmanager.h:27
friend.h
friendlist.h
settings.h
GroupChatroom::inviteFriend
void inviteFriend(const ToxPk &pk)
Definition: groupchatroom.cpp:64
idialogsmanager.h
GroupChatroom::dialogsManager
IDialogsManager * dialogsManager
Definition: groupchatroom.h:53
GroupChatroom::getGroup
Group * getGroup()
Definition: groupchatroom.cpp:43
group.h
toxpk.h
GroupChatroom::hasNewMessage
bool hasNewMessage() const
Definition: groupchatroom.cpp:48
Group::setEventFlag
void setEventFlag(bool f) override
Definition: group.cpp:164
Group::getId
uint32_t getId() const override
Definition: group.cpp:140
FriendList::findFriend
static Friend * findFriend(const ToxPk &friendPk)
Definition: friendlist.cpp:47
IDialogs::chatroomCount
virtual int chatroomCount() const =0
GroupChatroom::possibleToOpenInNewWindow
bool possibleToOpenInNewWindow() const
Definition: groupchatroom.cpp:76
Friend::getStatus
Status::Status getStatus() const
Definition: friend.cpp:190
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
GroupChatroom::removeGroupFromDialogs
void removeGroupFromDialogs()
Definition: groupchatroom.cpp:90
Contact
Definition: contact.h:26
Friend
Definition: friend.h:31
GroupChatroom::group
Group * group
Definition: groupchatroom.h:52
Group::getEventFlag
bool getEventFlag() const override
Definition: group.cpp:169
Group::getPersistentId
const GroupId & getPersistentId() const override
Definition: group.cpp:145
GroupChatroom::core
Core & core
Definition: groupchatroom.h:54
GroupChatroom::resetEventFlags
void resetEventFlags()
Definition: groupchatroom.cpp:53
Group
Definition: group.h:34
GroupChatroom::canBeRemovedFromWindow
bool canBeRemovedFromWindow() const
Definition: groupchatroom.cpp:83
GroupChatroom::getContact
Contact * getContact() override
Definition: groupchatroom.cpp:38
core.h
Group::setMentionedFlag
void setMentionedFlag(bool f)
Definition: group.cpp:174
groupchatroom.h
IDialogs::hasContact
virtual bool hasContact(const ContactId &contactId) const =0
Friend::getId
uint32_t getId() const override
Definition: friend.cpp:136
Status::isOnline
bool isOnline(Status status)
Definition: status.cpp:83
GroupChatroom::friendExists
bool friendExists(const ToxPk &pk)
Definition: groupchatroom.cpp:59
GroupChatroom::GroupChatroom
GroupChatroom(Group *group, IDialogsManager *dialogsManager, Core &_core)
Definition: groupchatroom.cpp:31
status.h
Core::groupInviteFriend
void groupInviteFriend(uint32_t friendId, int groupId)
Definition: core.cpp:1650
IDialogs::removeGroup
virtual void removeGroup(const GroupId &groupId)=0
Core
Definition: core.h:59