Added new method to retrieve groupname or title

This commit is contained in:
defnax 2026-04-18 16:14:56 +02:00
parent 6e4f9b0322
commit f8eac31a0c
2 changed files with 121 additions and 183 deletions

View File

@ -1904,181 +1904,43 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
case RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_CREATION: // not typically used, since most services do not require group author signatures
return tr("Creation of author signature in service %1").arg(service_name);
case RsIdentityUsage::MESSAGE_AUTHOR_SIGNATURE_CREATION: // most common use case. Messages are signed by authors in e.g. forums.
{
RetroShareLink l;
QString groupName;
bool groupFound = false;
{
QString label = getGroupName(service_type, u.mGrpId);
RetroShareLink l = RetroShareLink::createGxsGroupLink(service_type, u.mGrpId, label);
// Prepare the list containing the single Group ID for the lookup
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(u.mGrpId);
// Fetch the Group Name from the appropriate service
if (service_type == RetroShareLink::TYPE_CHANNEL && rsGxsChannels) {
std::vector<RsGxsChannelGroup> groups;
if (rsGxsChannels->getChannelsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
else if (service_type == RetroShareLink::TYPE_FORUM && rsGxsForums) {
std::vector<RsGxsForumGroup> groups;
if (rsGxsForums->getForumsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
else if (service_type == RetroShareLink::TYPE_POSTED && rsPosted) {
std::vector<RsPostedGroup> groups;
if (rsPosted->getBoardsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
// Prepare the label:
QString label;
if (groupFound) {
label = groupName;
} else {
label = QString::fromStdString(u.mGrpId.toStdString());
}
// Create the GXS Group Link
l = RetroShareLink::createGxsGroupLink(service_type, u.mGrpId, label);
// Return the formatted string
return tr("Message signature creation in group %1 of service %2").arg(l.toHtml(), service_name);
}
return tr("Message signature creation in group %1 of service %2").arg(l.toHtml(), service_name);
}
case RsIdentityUsage::GROUP_AUTHOR_KEEP_ALIVE: // Identities are stamped regularly by crawlign the set of messages for all groups. That helps keepign the useful identities in hand.
case RsIdentityUsage::GROUP_AUTHOR_SIGNATURE_VALIDATION:
{
RetroShareLink l;
QString groupName;
bool groupFound = false;
{
// label is either the Name or the ID string (from helper)
QString label = getGroupName(service_type, u.mGrpId);
RetroShareLink l = RetroShareLink::createGxsGroupLink(service_type, u.mGrpId, label);
// Prepare a list containing the single Group ID we want to look up
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(u.mGrpId);
// Fetch the Group Name from the appropriate service
if (service_type == RetroShareLink::TYPE_CHANNEL && rsGxsChannels) {
std::vector<RsGxsChannelGroup> groups;
// API requires std::list input and std::vector output
if (rsGxsChannels->getChannelsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
else if (service_type == RetroShareLink::TYPE_FORUM && rsGxsForums) {
std::vector<RsGxsForumGroup> groups;
// Forums API requires a list of IDs and a vector for results
if (rsGxsForums->getForumsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
else if (service_type == RetroShareLink::TYPE_POSTED && rsPosted) {
std::vector<RsPostedGroup> groups;
// Posted/Boards API requires a list of IDs and a vector for results
if (rsPosted->getBoardsInfo(groupIds, groups) && !groups.empty()) {
groupName = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
groupFound = !groupName.isEmpty();
}
}
QString label;
if (groupFound) {
label = groupName;
} else {
// If not found, we use the raw ID string as the original code did
label = QString::fromStdString(u.mGrpId.toStdString());
}
// Create the GXS Group Link
l = RetroShareLink::createGxsGroupLink(service_type, u.mGrpId, label);
// Return the final formatted string
return tr("Group author for group %1 in service %2").arg(l.toHtml(), service_name);
}
return tr("Group author for group %1 in service %2").arg(l.toHtml(), service_name);
}
case RsIdentityUsage::MESSAGE_AUTHOR_SIGNATURE_VALIDATION:
case RsIdentityUsage::MESSAGE_AUTHOR_KEEP_ALIVE: // Identities are stamped regularly by crawling the set of messages for all groups. That helps keepign the useful identities in hand.
{
{
QString title = getMessageTitle(service_type, u.mGrpId, u.mMsgId);
bool titleFound = !title.isEmpty();
// Label for the link (Title or "Message")
QString label = titleFound ? title : tr("Message");
// Create the Link
RetroShareLink l;
QString title;
bool titleFound = false;
// Create a set containing only the ID we are looking for
std::set<RsGxsMessageId> msgIds;
msgIds.insert(u.mMsgId);
if (service_type == RetroShareLink::TYPE_CHANNEL && rsGxsChannels) {
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> cmts; // Local variable to avoid rvalue error
std::vector<RsGxsVote> vots; // Local variable to avoid rvalue error
if (rsGxsChannels->getChannelContent(u.mGrpId, msgIds, posts, cmts, vots)) {
if (!posts.empty()) {
title = QString::fromUtf8(posts[0].mMeta.mMsgName.c_str());
titleFound = !title.isEmpty();
}
}
}
else if (service_type == RetroShareLink::TYPE_FORUM && rsGxsForums) {
std::vector<RsGxsForumMsg> msgs;
// getForumContent only needs 3 arguments, so no extra vectors needed
if (rsGxsForums->getForumContent(u.mGrpId, msgIds, msgs)) {
if (!msgs.empty()) {
title = QString::fromUtf8(msgs[0].mMeta.mMsgName.c_str());
titleFound = !title.isEmpty();
}
}
}
else if (service_type == RetroShareLink::TYPE_POSTED && rsPosted) {
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> cmts;
std::vector<RsGxsVote> vots;
if (rsPosted->getBoardContent(u.mGrpId, msgIds, posts, cmts, vots)) {
if (!posts.empty()) {
title = QString::fromUtf8(posts[0].mMeta.mMsgName.c_str());
titleFound = !title.isEmpty();
}
}
}
// Prepare the label
QString label;
if (titleFound) {
label = title;
} else {
// Use raw Group ID string if it's a group validation case or total failure
label = QString::fromStdString(u.mGrpId.toStdString());
}
std::cerr << "Signature validation/keep alive signature:" << std::endl;
std::cerr << " service ID = " << std::hex << (uint16_t)u.mServiceId << std::dec << std::endl;
std::cerr << " u.mGrpId = " << u.mGrpId << std::endl;
std::cerr << " u.mMsgId = " << u.mMsgId << std::endl;
std::cerr << " u.mParentId = " << u.mParentId << std::endl;
std::cerr << " u.mThreadId = " << u.mThreadId << std::endl;
// Generate the link
if ((service_type == RetroShareLink::TYPE_CHANNEL || service_type == RetroShareLink::TYPE_POSTED) && !u.mThreadId.isNull()) {
l = RetroShareLink::createGxsMessageLink(service_type, u.mGrpId, u.mThreadId, label);
}
else {
} else {
l = RetroShareLink::createGxsMessageLink(service_type, u.mGrpId, u.mMsgId, label);
}
// Determine the suffix based on the service type
QString suffix;
if (service_type == RetroShareLink::TYPE_CHANNEL || service_type == RetroShareLink::TYPE_POSTED) {
suffix = tr("Vote/comment");
} else {
suffix = tr("Message");
}
// Suffix based on service
QString suffix = (service_type == RetroShareLink::TYPE_CHANNEL || service_type == RetroShareLink::TYPE_POSTED)
? tr("Vote/comment") : tr("Message");
// Return formatted: "[Link] Suffix in [Service] service"
return tr("%2 in %3 service %1").arg(l.toHtml(), suffix, service_name);
}
case RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION: // Chat lobby msgs are signed, so each time one comes, or a chat lobby event comes, a signature verificaiton happens.
@ -2127,30 +1989,29 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
{
RetroShareLink l;
RsGxsCircleDetails det;
bool circleFound = false;
// Try to fetch circle details to get the name
if (rsGxsCircles && rsGxsCircles->getCircleDetails(RsGxsCircleId(u.mGrpId), det)) {
circleFound = true;
if (rsGxsCircles->getCircleDetails(RsGxsCircleId(u.mGrpId), det)) {
// Prepare the label:
QString label;
if (!det.mCircleName.empty()) {
label = QString::fromUtf8(det.mCircleName.c_str()) ;
} else {
label = QString::fromStdString(u.mGrpId.toStdString());
}
// Create the RetroShareLink for the circle
l = RetroShareLink::createCircle(RsGxsCircleId(u.mGrpId), label);
// Return the formatted string with the clickable link
if (!det.mCircleName.empty()) {
return tr("Membership verification in circle %1.").arg(l.toHtml());
} else {
return tr("Membership verification in circle (ID=%1).").arg(l.toHtml());
}
}
// Prepare the label:
QString label;
if (circleFound && !det.mCircleName.empty()) {
label = QString::fromUtf8(det.mCircleName.c_str()) ;
} else {
label = QString::fromStdString(u.mGrpId.toStdString());
}
// Create the RetroShareLink for the circle
l = RetroShareLink::createCircle(RsGxsCircleId(u.mGrpId), label);
// Return the formatted string with the clickable link
if (circleFound) {
return tr("Membership verification in circle %1.").arg(l.toHtml());
} else {
return tr("Membership verification in circle (ID=%1).").arg(l.toHtml());
}
}
#warning TODO! csoler 2017-01-03: Add the different strings and translations here.
@ -2160,6 +2021,81 @@ QString IdDialog::createUsageString(const RsIdentityUsage& u) const
return QString("Unknown");
}
QString IdDialog::getGroupName(uint32_t service_type, const RsGxsGroupId& groupId) const
{
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(groupId);
if (service_type == RetroShareLink::TYPE_CHANNEL && rsGxsChannels) {
std::vector<RsGxsChannelGroup> groups;
if (rsGxsChannels->getChannelsInfo(groupIds, groups) && !groups.empty()) {
QString name = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
if (!name.isEmpty()) return name;
}
}
else if (service_type == RetroShareLink::TYPE_FORUM && rsGxsForums) {
std::vector<RsGxsForumGroup> groups;
if (rsGxsForums->getForumsInfo(groupIds, groups) && !groups.empty()) {
QString name = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
if (!name.isEmpty()) return name;
}
}
else if (service_type == RetroShareLink::TYPE_POSTED && rsPosted) {
std::vector<RsPostedGroup> groups;
if (rsPosted->getBoardsInfo(groupIds, groups) && !groups.empty()) {
QString name = QString::fromUtf8(groups[0].mMeta.mGroupName.c_str());
if (!name.isEmpty()) return name;
}
}
else if (service_type == RetroShareLink::TYPE_CIRCLES && rsGxsCircles) {
RsGxsCircleDetails det;
if (rsGxsCircles->getCircleDetails(RsGxsCircleId(groupId), det)) {
QString name = QString::fromUtf8(det.mCircleName.c_str());
if (!name.isEmpty()) return name;
}
}
// Returns the raw ID string as the label
return QString::fromStdString(groupId.toStdString());
}
QString IdDialog::getMessageTitle(uint32_t service_type, const RsGxsGroupId& groupId, const RsGxsMessageId& msgId) const
{
std::set<RsGxsMessageId> msgIds;
msgIds.insert(msgId);
if (service_type == RetroShareLink::TYPE_CHANNEL && rsGxsChannels) {
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> cmts;
std::vector<RsGxsVote> vots;
if (rsGxsChannels->getChannelContent(groupId, msgIds, posts, cmts, vots) && !posts.empty()) {
return QString::fromUtf8(posts[0].mMeta.mMsgName.c_str());
}
}
else if (service_type == RetroShareLink::TYPE_FORUM && rsGxsForums) {
std::vector<RsGxsForumMsg> msgs;
if (rsGxsForums->getForumContent(groupId, msgIds, msgs) && !msgs.empty()) {
return QString::fromUtf8(msgs[0].mMeta.mMsgName.c_str());
}
}
else if (service_type == RetroShareLink::TYPE_POSTED && rsPosted) {
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> cmts;
std::vector<RsGxsVote> vots;
if (rsPosted->getBoardContent(groupId, msgIds, posts, cmts, vots) && !posts.empty()) {
return QString::fromUtf8(posts[0].mMeta.mMsgName.c_str());
}
}
else if (service_type == RetroShareLink::TYPE_CIRCLES && rsGxsCircles) {
RsGxsCircleDetails det;
if (rsGxsCircles->getCircleDetails(RsGxsCircleId(groupId), det)) {
return QString::fromUtf8(det.mCircleName.c_str());
}
}
return QString(); // Return empty if not found
}
void IdDialog::modifyReputation()
{
#ifdef ID_DEBUG

View File

@ -148,6 +148,8 @@ private:
void showIdEdit(uint32_t token);
void clearPerson();
QString getGroupName(uint32_t service_type, const RsGxsGroupId& groupId) const;
QString getMessageTitle(uint32_t service_type, const RsGxsGroupId& groupId, const RsGxsMessageId& msgId) const;
private:
UIStateHelper *mStateHelper;