diff --git a/src/core.cpp b/src/core.cpp index 8685aab1e..37b795bfd 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -473,7 +473,8 @@ void Core::onAction(Tox*/* tox*/, int friendId, const uint8_t *cMessage, uint16_ void Core::onGroupAction(Tox*, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void* _core) { Core* core = static_cast(_core); - emit core->groupMessageReceived(groupnumber, CString::toString(action, length), core->getGroupPeerName(groupnumber, peernumber)); + emit core->groupMessageReceived(groupnumber, CString::toString(action, length), + core->getGroupPeerName(groupnumber, peernumber), true); } void Core::onGroupInvite(Tox*, int friendnumber, const uint8_t *group_public_key, uint16_t length,void *core) @@ -485,7 +486,8 @@ void Core::onGroupInvite(Tox*, int friendnumber, const uint8_t *group_public_key void Core::onGroupMessage(Tox*, int groupnumber, int peernumber, const uint8_t * message, uint16_t length, void *_core) { Core* core = static_cast(_core); - emit core->groupMessageReceived(groupnumber, CString::toString(message, length), core->getGroupPeerName(groupnumber, peernumber)); + emit core->groupMessageReceived(groupnumber, CString::toString(message, length), + core->getGroupPeerName(groupnumber, peernumber), false); } void Core::onGroupNamelistChange(Tox*, int groupnumber, int peernumber, uint8_t change, void *core) @@ -769,6 +771,20 @@ void Core::sendGroupMessage(int groupId, const QString& message) for (auto &cMsg :cMessages) { int ret = tox_group_message_send(tox, groupId, cMsg.data(), cMsg.size()); + + if (ret == -1) + emit groupSentResult(groupId, message, ret); + } +} + +void Core::sendGroupAction(int groupId, const QString& message) +{ + QList cMessages = splitMessage(message); + + for (auto &cMsg :cMessages) + { + int ret = tox_group_action_send(tox, groupId, cMsg.data(), cMsg.size()); + if (ret == -1) emit groupSentResult(groupId, message, ret); } diff --git a/src/core.h b/src/core.h index 15c5c7b82..95ea10a41 100644 --- a/src/core.h +++ b/src/core.h @@ -89,6 +89,7 @@ public slots: void sendMessage(int friendId, const QString& message); void sendGroupMessage(int groupId, const QString& message); + void sendGroupAction(int groupId, const QString& message); void sendAction(int friendId, const QString& action); void sendTyping(int friendId, bool typing); @@ -137,7 +138,7 @@ signals: void emptyGroupCreated(int groupnumber); void groupInviteReceived(int friendnumber, const uint8_t *group_public_key,uint16_t length); - void groupMessageReceived(int groupnumber, const QString& message, const QString& author); + void groupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction); void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void usernameSet(const QString& username); diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index f0056c150..03370d279 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -76,8 +76,16 @@ void GroupChatForm::onSendTriggered() QString msg = msgEdit->toPlainText(); if (msg.isEmpty()) return; + msgEdit->clear(); - emit sendMessage(group->groupId, msg); + + if (msg.startsWith("/me ")) + { + msg = msg.right(msg.length() - 4); + emit sendAction(group->groupId, msg); + } else { + emit sendMessage(group->groupId, msg); + } } void GroupChatForm::onUserListChanged() diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 1d79087ba..a6d9b99f9 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -834,18 +834,19 @@ void Widget::onGroupInviteReceived(int32_t friendId, const uint8_t* publicKey,ui } } -void Widget::onGroupMessageReceived(int groupnumber, const QString& message, const QString& author) +void Widget::onGroupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction) { Group* g = GroupList::findGroup(groupnumber); if (!g) return; QString name = core->getUsername(); + bool targeted = (author != name) && message.contains(name, Qt::CaseInsensitive); if (targeted) g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime()); else - g->chatForm->addMessage(author, message, false, QDateTime::currentDateTime()); + g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime()); if ((static_cast(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) { @@ -932,6 +933,7 @@ Group *Widget::createGroup(int groupId) connect(newgroup->widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(newgroup->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newgroup->chatForm, SLOT(focusInput())); connect(newgroup->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString))); + connect(newgroup->chatForm, SIGNAL(sendAction(int,QString)), core, SLOT(sendGroupAction(int,QString))); return newgroup; } diff --git a/src/widget/widget.h b/src/widget/widget.h index c0360e267..0f1fc8888 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -109,7 +109,7 @@ private slots: void onFriendRequestReceived(const QString& userId, const QString& message); void onEmptyGroupCreated(int groupId); void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length); - void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author); + void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction); void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void removeFriend(int friendId); void copyFriendIdToClipboard(int friendId);