1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr595'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-01 14:52:01 +01:00
commit 4c0ae2503a
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
5 changed files with 34 additions and 7 deletions

View File

@ -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*>(_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*>(_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<CString> 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);
}

View File

@ -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);

View File

@ -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()

View File

@ -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<GenericChatroomWidget*>(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;
}

View File

@ -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);