Fixed display of the names and avatars in ForumMsgItem.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3985 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-01-26 21:36:13 +00:00
parent 9263710f9e
commit c2a81daf01
4 changed files with 74 additions and 47 deletions

View File

@ -580,7 +580,11 @@ bool p3Forums::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std::
bool p3Forums::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id)
{
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, msg->grpId, msg->msgId, msg->personalSignature.keyId);
std::string grpId = msg->grpId;
std::string msgId = msg->msgId;
std::string nullId;
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, grpId, msgId, nullId);
return true;
}

View File

@ -330,7 +330,7 @@ void NewsFeed::addFeedItemForumUpdate(RsFeedItem &fi)
void NewsFeed::addFeedItemForumMsg(RsFeedItem &fi)
{
/* make new widget */
ForumMsgItem *fm = new ForumMsgItem(this, NEWSFEED_FORUMMSGLIST, fi.mId1, fi.mId2, fi.mId3, false);
ForumMsgItem *fm = new ForumMsgItem(this, NEWSFEED_FORUMMSGLIST, fi.mId1, fi.mId2, false);
/* store in forum list */

View File

@ -40,9 +40,8 @@
****/
/** Constructor */
ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mForumId(forumId), mPostId(postId), mGpgId(gpgId), mIsHome(isHome), mIsTop(false)
ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), mForumId(forumId), mPostId(postId), mIsHome(isHome), mIsTop(false)
{
/* Invoke the Qt Designer generated object setup routine */
setupUi(this);
@ -63,7 +62,6 @@ ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string foru
small();
updateItemStatic();
updateItem();
showAvatar("");
}
@ -72,7 +70,6 @@ void ForumMsgItem::updateItemStatic()
if (!rsForums)
return;
/* fill in */
#ifdef DEBUG_ITEM
std::cerr << "ForumMsgItem::updateItemStatic()";
@ -121,6 +118,10 @@ void ForumMsgItem::updateItemStatic()
mIsTop = true;
}
if (mIsTop)
{
mGpgIdPrev = msg.srcId;
if (rsPeers->getPeerName(msg.srcId) !="")
{
namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
@ -130,10 +131,6 @@ void ForumMsgItem::updateItemStatic()
namelabel->setText(tr("Anonymous"));
}
if (mIsTop)
{
prevSHLabel->setText("Subject: ");
prevSubLabel->setText(QString::fromStdWString(msg.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
@ -146,6 +143,17 @@ void ForumMsgItem::updateItemStatic()
}
else
{
mGpgIdNext = msg.srcId;
if (rsPeers->getPeerName(msg.srcId) !="")
{
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
}
else
{
nextnamelabel->setText(tr("Anonymous"));
}
nextSubLabel->setText(QString::fromStdWString(msg.title));
nextMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
@ -159,18 +167,19 @@ void ForumMsgItem::updateItemStatic()
ForumMsgInfo msgParent;
if (rsForums->getForumMessage(mForumId, msg.parentId, msgParent))
{
mGpgIdPrev = msgParent.srcId;
prevSubLabel->setText(QString::fromStdWString(msgParent.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msgParent.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
if (rsPeers->getPeerName(msgParent.srcId) !="")
{
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId)));
namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId)));
}
else
{
nextnamelabel->setText(tr("Anonymous"));
namelabel->setText(tr("Anonymous"));
}
}
else
{
@ -195,6 +204,9 @@ void ForumMsgItem::updateItemStatic()
}
unsubscribeButton->hide();
showAvatar("", true);
showAvatar("", false);
}
@ -306,44 +318,54 @@ void ForumMsgItem::replyToPost()
void ForumMsgItem::updateAvatar(const QString &peer_id)
{
if (mGpgId.empty()) {
/* Message is not signed */
return;
}
if (mGpgIdPrev.empty() == false) {
/* Is this one of the ssl ids of the gpg id ? */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) {
if (rsPeers->getSSLChildListOfGPGId(mGpgIdPrev, sslIds) == false) {
return;
}
if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) == sslIds.end()) {
/* Not one of the ssl ids of the gpg id */
if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) != sslIds.end()) {
/* One of the ssl ids of the gpg id */
showAvatar(peer_id.toStdString(), false);
}
}
if (mGpgIdNext.empty() == false) {
/* Is this one of the ssl ids of the gpg id ? */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgIdNext, sslIds) == false) {
return;
}
showAvatar(peer_id.toStdString());
if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) != sslIds.end()) {
/* One of the ssl ids of the gpg id */
showAvatar(peer_id.toStdString(), true);
}
}
}
void ForumMsgItem::showAvatar(const std::string &peer_id)
void ForumMsgItem::showAvatar(const std::string &peer_id, bool next)
{
if (mGpgId.empty()) {
/* Message is not signed */
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png"));
std::string gpgId = next ? mGpgIdNext : mGpgIdPrev;
QLabel *avatar = next ? nextavatarlabel : avatarlabel;
if (gpgId.empty()) {
avatar->setPixmap(QPixmap(":/images/user/personal64.png"));
return;
}
unsigned char *data = NULL;
int size = 0 ;
if (mGpgId == rsPeers->getGPGOwnId()) {
if (gpgId == rsPeers->getGPGOwnId()) {
/* Its me */
rsMsgs->getOwnAvatarData(data,size);
} else {
if (peer_id.empty()) {
/* Show the first available avatar of one of the ssl ids */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) {
if (rsPeers->getSSLChildListOfGPGId(gpgId, sslIds) == false) {
return;
}
@ -363,9 +385,9 @@ void ForumMsgItem::showAvatar(const std::string &peer_id)
// set the image
QPixmap pix ;
pix.loadFromData(data,size,"PNG") ;
avatarlabel->setPixmap(pix);
avatar->setPixmap(pix);
delete[] data ;
} else {
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png"));
avatar->setPixmap(QPixmap(":/images/user/personal64.png"));
}
}

View File

@ -33,7 +33,7 @@ class ForumMsgItem : public QWidget, private Ui::ForumMsgItem
public:
/** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome);
ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome);
/** Default Destructor */
@ -54,14 +54,15 @@ private slots:
void updateAvatar(const QString &peer_id);
private:
void showAvatar(const std::string &peer_id);
void showAvatar(const std::string &peer_id, bool next);
FeedHolder *mParent;
uint32_t mFeedId;
std::string mForumId;
std::string mPostId;
std::string mGpgId;
std::string mGpgIdPrev;
std::string mGpgIdNext;
bool mIsHome;
bool mIsTop;
};