diff --git a/src/groupchatdlg.cpp b/src/groupchatdlg.cpp index 06c717bc..7b9a72c6 100644 --- a/src/groupchatdlg.cpp +++ b/src/groupchatdlg.cpp @@ -1112,7 +1112,7 @@ GCMainDlg::GCMainDlg(PsiAccount *pa, const Jid &j, TabManager *tabManager) : Tab connect(ui_.log, &ChatView::editMessageRequested, ui_.mle->chatEdit(), &ChatEdit::startCorrection); connect(ui_.log, &ChatView::forwardMessageRequested, account(), [this](const QString &messageId, const QString &nick, const QString &text) { - account()->psi()->invokeForwardMessage(jid().withResource(nick), text); + account()->psi()->invokeForwardMessage(messageId, jid().withResource(nick), text); }); connect(ui_.log, &ChatView::openInfoRequested, account(), [this](const QString &nick) { account()->invokeGCInfo(jid().withResource(nick)); }); diff --git a/src/psicon.cpp b/src/psicon.cpp index 42ff17e7..010b876c 100644 --- a/src/psicon.cpp +++ b/src/psicon.cpp @@ -41,6 +41,7 @@ #include "edbsqlite.h" #include "eventdlg.h" #include "globalshortcut/globalshortcutmanager.h" +#include "xmpp/xmpp-im/xmpp_forwarding.h" #ifdef GROUPCHAT #include "groupchatdlg.h" #endif @@ -1986,9 +1987,38 @@ int PsiCon::idle() const { return d->idleSettings_.secondsIdle; } ContactUpdatesManager *PsiCon::contactUpdatesManager() const { return contactUpdatesManager_; } -void PsiCon::invokeForwardMessage(const Jid &from, const QString &text) +void PsiCon::invokeForwardMessage(const QString &fromMessageId, const Jid &from, const QString &text) { + Message m, dm; + dm.setFrom(from); + dm.setBody(text); + dm.setId(fromMessageId); + + Forwarding fwd; + fwd.setMessage(dm); + fwd.setType(Forwarding::ForwardedMessage); + + m.setType(Message::Type::Chat); + m.setForwarded(fwd); + + auto sender = [m = std::move(m)](const QList &destinationsContacts) { + QHash> perAcc; + for (auto contact : destinationsContacts) { + if (contact->account()->isAvailable()) { + perAcc[contact->account()].append(contact); + } + } + for (auto it = perAcc.begin(); it != perAcc.end(); ++it) { + for (auto c : it.value()) { + Message m_ = m; + m_.setTo(c->jid()); + it.key()->dj_sendMessage(m_); + } + } + }; + auto dlg = new QDialog(d->mainwin); + dlg->setAttribute(Qt::WA_DeleteOnClose, true); dlg->resize(200, 600); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->setWindowIcon(IconsetFactory::icon("psi/action_contacts_manager").icon()); @@ -1998,11 +2028,21 @@ void PsiCon::invokeForwardMessage(const Jid &from, const QString &text) auto roster = new PsiRosterWidget(d->mainwin); roster->setContactList(d->contactList); roster->setPickContactMode(true); - connect(roster, &PsiRosterWidget::contactPick, this, - [](PsiContact *c) { qDebug("TODO forwarding to: %s", qPrintable(c->jid().full())); }); + connect(roster, &PsiRosterWidget::contactPick, this, [this, roster, sender, dlg](PsiContact *c) { + sender(QList { c }); + roster->deleteLater(); + dlg->close(); + }); auto btn = new QPushButton(tr("Forward")); - connect(btn, &QPushButton::clicked, dlg, [this, roster](bool) { qDebug("TODO: implement forwarding"); }); + connect(btn, &QPushButton::clicked, dlg, [this, roster, sender, dlg](bool) { + auto contacts = roster->selectedContacts(); + if (!contacts.empty()) { + sender(roster->selectedContacts()); + roster->deleteLater(); + dlg->close(); + } + }); layout->addWidget(roster); layout->addWidget(btn); diff --git a/src/psicon.h b/src/psicon.h index 13e41c3c..0c9be37e 100644 --- a/src/psicon.h +++ b/src/psicon.h @@ -47,6 +47,7 @@ class ProxyManager; class PsiAccount; class PsiActionList; class PsiCon; +class PsiContact; class PsiContactList; class PsiThemeManager; class PsiToolBar; @@ -137,8 +138,7 @@ class PsiCon : public QObject { PopupManager *popupManager() const; QStringList xmppFatures() const; - void invokeForwardMessage(const Jid &from, const QString &text); - + void invokeForwardMessage(const QString &fromMessageId, const Jid &from, const QString &text); signals: void quit(int); void accountAdded(PsiAccount *); diff --git a/version b/version index cc9ee7d9..585dd7d7 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.5.2051 (2024-09-29, 56f6c039) +1.5.2052 (2024-09-30, 31774cb5)