Enable users to reject friend requests

This commit is contained in:
Ninetime 2024-08-11 10:20:19 -04:00 committed by Elad Ashkenazi
parent 60b7448d8a
commit b0d07a75e5

View File

@ -1135,17 +1135,36 @@ rpcn_friends_dialog::rpcn_friends_dialog(QWidget* parent)
} }
QListWidgetItem* selected_item = m_lst_requests->selectedItems().first(); QListWidgetItem* selected_item = m_lst_requests->selectedItems().first();
std::string str_sel_friend = selected_item->text().toStdString();
// Only create context menu for incoming requests QMenu* context_menu = new QMenu();
// Presents different context based on role
if (selected_item->data(Qt::UserRole) == false) if (selected_item->data(Qt::UserRole) == false)
{ {
QAction* cancel_friend_request = context_menu->addAction(tr("&Cancel Request"));
connect(cancel_friend_request, &QAction::triggered, this, [this, str_sel_friend]()
{
if (!m_rpcn->remove_friend(str_sel_friend))
{
QMessageBox::critical(this, tr("Error cancelling friend request!"), tr("An error occurred while trying to cancel friend request!"), QMessageBox::Ok);
}
else
{
QMessageBox::information(this, tr("Friend request cancelled!"), tr("You've successfully cancelled the friend request!"), QMessageBox::Ok);
}
});
context_menu->exec(m_lst_requests->viewport()->mapToGlobal(pos));
context_menu->deleteLater();
return; return;
} }
std::string str_sel_friend = selected_item->text().toStdString();
QMenu* context_menu = new QMenu();
QAction* accept_request_action = context_menu->addAction(tr("&Accept Request")); QAction* accept_request_action = context_menu->addAction(tr("&Accept Request"));
QAction* reject_friend_request = context_menu->addAction(tr("&Reject Request"));
connect(accept_request_action, &QAction::triggered, this, [this, str_sel_friend]() connect(accept_request_action, &QAction::triggered, this, [this, str_sel_friend]()
{ {
@ -1159,6 +1178,18 @@ rpcn_friends_dialog::rpcn_friends_dialog(QWidget* parent)
} }
}); });
connect(reject_friend_request, &QAction::triggered, this, [this, str_sel_friend]()
{
if (!m_rpcn->remove_friend(str_sel_friend))
{
QMessageBox::critical(this, tr("Error rejecting friend request!"), tr("An error occurred while trying to reject the friend request!"), QMessageBox::Ok);
}
else
{
QMessageBox::information(this, tr("Friend request cancelled!"), tr("You've successfully rejected the friend request!"), QMessageBox::Ok);
}
});
context_menu->exec(m_lst_requests->viewport()->mapToGlobal(pos)); context_menu->exec(m_lst_requests->viewport()->mapToGlobal(pos));
context_menu->deleteLater(); context_menu->deleteLater();
}); });