Browse Source

refactor: Save GroupChatForm in Widget

reviewable/pr4943/r2
Diadlo 8 years ago
parent
commit
f6bb71db93
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 48
      src/widget/widget.cpp
  2. 2
      src/widget/widget.h

48
src/widget/widget.cpp

@ -1143,8 +1143,8 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
form = chatForms[id]; form = chatForms[id];
} else { } else {
Group* g = widget->getGroup(); Group* g = widget->getGroup();
form = g->getChatForm();
id = g->getId(); id = g->getId();
form = groupChatForms[id];
} }
bool chatFormIsSet; bool chatFormIsSet;
@ -1289,8 +1289,8 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
GroupWidget* groupWidget = dialog->addGroup(groupId, group->getName()); GroupWidget* groupWidget = dialog->addGroup(groupId, group->getName());
connect(groupWidget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(groupWidget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, group->getChatForm(), auto chatForm = groupChatForms[groupId];
&ChatForm::focusInput); connect(groupWidget, &GroupWidget::chatroomWidgetClicked, chatForm, &GroupChatForm::focusInput);
// Signal transmission from the created `groupWidget` (which shown in // Signal transmission from the created `groupWidget` (which shown in
// ContentDialog) to the `widget` (which shown in main widget) // ContentDialog) to the `widget` (which shown in main widget)
@ -1719,15 +1719,18 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
return; return;
} }
bool targeted = const auto mention = message.contains(nameMention) || message.contains(sanitizedNameMention);
!isSelf && (message.contains(nameMention) || message.contains(sanitizedNameMention)); const auto targeted = !isSelf && mention;
const auto groupId = g->getId();
const auto date = QDateTime::currentDateTime();
auto form = groupChatForms[groupId];
if (targeted && !isAction) { if (targeted && !isAction) {
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime()); form->addAlertMessage(author, message, date);
} else { } else {
g->getChatForm()->addMessage(author, message, QDateTime::currentDateTime(), isAction); form->addMessage(author, message, date, isAction);
} }
newGroupMessageAlert(g->getId(), targeted || Settings::getInstance().getGroupAlwaysNotify()); newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify());
} }
void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Change) void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Change)
@ -1790,7 +1793,8 @@ void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber)
return; return;
} }
g->getChatForm()->peerAudioPlaying(peernumber); auto form = groupChatForms[g->getId()];
form->peerAudioPlaying(peernumber);
} }
void Widget::removeGroup(Group* g, bool fake) void Widget::removeGroup(Group* g, bool fake)
@ -1835,32 +1839,23 @@ Group* Widget::createGroup(int groupId)
return g; return g;
} }
const auto groupName = tr("Groupchat #%1").arg(groupId);
Core* core = Nexus::getCore(); Core* core = Nexus::getCore();
if (!core) {
qWarning() << "Can't create group. Core does not exist";
return nullptr;
}
QString groupName = tr("Groupchat #%1").arg(groupId);
CoreAV* coreAv = core->getAv(); CoreAV* coreAv = core->getAv();
if (!coreAv) {
qWarning() << "Can't create group. CoreAv does not exist";
return nullptr;
}
bool enabled = coreAv->isGroupAvEnabled(groupId); bool enabled = coreAv->isGroupAvEnabled(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, enabled, core->getUsername()); Group* newgroup = GroupList::addGroup(groupId, groupName, enabled, core->getUsername());
bool compact = Settings::getInstance().getCompactLayout(); bool compact = Settings::getInstance().getCompactLayout();
GroupWidget* widget = new GroupWidget(groupId, groupName, compact); GroupWidget* widget = new GroupWidget(groupId, groupName, compact);
groupWidgets[groupId] = widget; groupWidgets[groupId] = widget;
auto form = newgroup->getChatForm();
groupChatForms[groupId] = form;
contactListWidget->addGroupWidget(widget); contactListWidget->addGroupWidget(widget);
widget->updateStatusLight(); widget->updateStatusLight();
contactListWidget->activateWindow(); contactListWidget->activateWindow();
GroupChatForm* form = newgroup->getChatForm();
connect(widget, &GroupWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked); connect(widget, &GroupWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(widget, &GroupWidget::newWindowOpened, this, &Widget::openNewDialog); connect(widget, &GroupWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
@ -2053,9 +2048,10 @@ void Widget::onGroupSendFailed(int groupId)
return; return;
} }
QString message = tr("Message failed to send"); const auto message = tr("Message failed to send");
QDateTime curTime = QDateTime::currentDateTime(); const auto curTime = QDateTime::currentDateTime();
g->getChatForm()->addSystemInfoMessage(message, ChatMessage::INFO, curTime); auto form = groupChatForms[g->getId()];
form->addSystemInfoMessage(message, ChatMessage::INFO, curTime);
} }
void Widget::onFriendTypingChanged(int friendId, bool isTyping) void Widget::onFriendTypingChanged(int friendId, bool isTyping)
@ -2476,7 +2472,7 @@ void Widget::focusChatInput()
if (const Friend* f = activeChatroomWidget->getFriend()) { if (const Friend* f = activeChatroomWidget->getFriend()) {
chatForms[f->getId()]->focusInput(); chatForms[f->getId()]->focusInput();
} else if (Group* g = activeChatroomWidget->getGroup()) { } else if (Group* g = activeChatroomWidget->getGroup()) {
g->getChatForm()->focusInput(); groupChatForms[g->getId()]->focusInput();
} }
} }
} }

2
src/widget/widget.h

@ -52,6 +52,7 @@ class FriendListWidget;
class FriendWidget; class FriendWidget;
class GenericChatroomWidget; class GenericChatroomWidget;
class Group; class Group;
class GroupChatForm;
class GroupInvite; class GroupInvite;
class GroupInviteForm; class GroupInviteForm;
class GroupWidget; class GroupWidget;
@ -302,6 +303,7 @@ private:
QMap<uint32_t, GroupWidget*> groupWidgets; QMap<uint32_t, GroupWidget*> groupWidgets;
QMap<uint32_t, FriendWidget*> friendWidgets; QMap<uint32_t, FriendWidget*> friendWidgets;
QMap<uint32_t, ChatForm*> chatForms; QMap<uint32_t, ChatForm*> chatForms;
QMap<uint32_t, GroupChatForm*> groupChatForms;
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QAction* fileMenu; QAction* fileMenu;

Loading…
Cancel
Save