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

2
src/widget/widget.h

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

Loading…
Cancel
Save