RetroShare / RSNewWebUI

30 stars 20 forks source link

Channel tab 2 #54

Closed Sukhamjot-Singh closed 2 years ago

Sukhamjot-Singh commented 2 years ago

@rottencandy Can you pleasereview this. I don't know why it take so much time to call the content summaries and loading the post. This is taking too much of my time. Can you run this on your system?

rottencandy commented 2 years ago

@Sukhamjot-Singh noticed a few things,

https://user-images.githubusercontent.com/20013884/174241151-344a6dab-9ed9-48c5-a0b9-aebe1fbf9a6a.mp4

Sukhamjot-Singh commented 2 years ago

@Sukhamjot-Singh noticed a few things,

  • On selecting the channel page it doesn't immediately load the data. I think it's because you have an onupdate hook, but no oninit hook, so data is not fetched until a different tab is selected.
  • The summary and posts seem to be loading fine, although now the page is continuously polling the endpoint. I think we should avoid that since it could put a lot of unnecessary load on the client. It's likely happening because of the infinite loop with the onupdate handler: onupdate triggers data fetch > return data causes mithril to rerender > rerender causes onupdate to fire again ...

https://user-images.githubusercontent.com/20013884/174241151-344a6dab-9ed9-48c5-a0b9-aebe1fbf9a6a.mp4

  • Wow. Thanks for pointing out the problem.
  • Yeah I fixed the problem for loading. Basically I was storing empty requests in the client and later loading them which was causing some errors.
rottencandy commented 2 years ago

You might also want to look at the setBackgroundTask util in rswebui. See how the downloads page uses it.

Sukhamjot-Singh commented 2 years ago

You might also want to look at the setBackgroundTask util in rswebui. See how the downloads page uses it.

Okay, it looks like a useful tool. I can also use it call the load after some intervals. Thanks :)

Sukhamjot-Singh commented 2 years ago

I wanted to understand how files work.

csoler commented 2 years ago

I think it's optional. Just don't supply this parameter, and RS will download in the configured download directory (~/.retroshare/[location]/Download). While it's downloading, the data goes into the Partials/ directory.

Sukhamjot-Singh commented 2 years ago

I think it's optional. Just don't supply this parameter, and RS will download in the configured download directory (~/.retroshare/[location]/Download). While it's downloading, the data goes into the Partials/ directory.

Okay thanks a lot

Sukhamjot-Singh commented 2 years ago

Possible minor bug: The mCommentCount in getChannelContent -> posts[] is not updated and always returns 0. image

Sukhamjot-Singh commented 2 years ago

Update : Displayed posts and comments Fixed minor things, displayed date/size. image

Sukhamjot-Singh commented 2 years ago

The upvote, downvotes, score is not updated in the commentsrequest.(getChannelContent -> comments[]). Do I have to calculate using the votes[] or is there a way this can be corrected?

image

Sukhamjot-Singh commented 2 years ago

The upvote, downvotes, score is not updated in the commentsrequest.(getChannelContent -> comments[]). Do I have to calculate using the votes[] or is there a way this can be corrected?

image

@csoler @G10h4ck

defnax commented 2 years ago

hi im not sure why it not works here the code on qt source:

void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments)
{
    std::list<RsGxsMessageId> new_comments;

    for(auto vit = comments.begin(); vit != comments.end(); ++vit)
    {
        const RsGxsComment &comment = *vit;

        if(IS_MSG_NEW(comment.mMeta.mMsgStatus))
            new_comments.push_back(comment.mMeta.mMsgId);

        /* convert to a QTreeWidgetItem */
        std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
        std::cerr << std::endl;

        GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(NULL,GxsIdDetails::ICON_TYPE_AVATAR) ;
        QString text;

        {
            QDateTime qtime ;
            qtime.setTime_t(comment.mMeta.mPublishTs) ;

            text = qtime.toString("yyyy-MM-dd hh:mm:ss") ;
            item->setText(PCITEM_COLUMN_DATE, text) ;
            item->setToolTip(PCITEM_COLUMN_DATE, text) ;
            item->setData(PCITEM_COLUMN_DATE, ROLE_SORT, QVariant(qlonglong(comment.mMeta.mPublishTs)));

        }

        text = QString::fromUtf8(comment.mComment.c_str());
        item->setText(PCITEM_COLUMN_COMMENT, text);
        item->setToolTip(PCITEM_COLUMN_COMMENT, text);

        RsGxsId authorId = comment.mMeta.mAuthorId;
        item->setId(authorId, PCITEM_COLUMN_AUTHOR, false);
        item->setData(PCITEM_COLUMN_COMMENT,POST_COLOR_ROLE,QVariant(authorId.toByteArray()[1]));

        text = QString::number(comment.mScore);
        item->setText(PCITEM_COLUMN_SCORE, text);

        text = QString::number(comment.mUpVotes);
        item->setText(PCITEM_COLUMN_UPVOTES, text);

        text = QString::number(comment.mDownVotes);
        item->setText(PCITEM_COLUMN_DOWNVOTES, text);

        text = QString::number(comment.mOwnVote);
        item->setText(PCITEM_COLUMN_OWNVOTE, text);

        text = QString::fromUtf8(comment.mMeta.mMsgId.toStdString().c_str());
        item->setText(PCITEM_COLUMN_MSGID, text);

        text = QString::fromUtf8(comment.mMeta.mParentId.toStdString().c_str());
        item->setText(PCITEM_COLUMN_PARENTID, text);

        text = QString::fromUtf8(comment.mMeta.mAuthorId.toStdString().c_str());
        item->setText(PCITEM_COLUMN_AUTHORID, text);

#ifdef USE_NEW_DELEGATE
        // Allows to call createEditor() in the delegate. Without this, createEditor() is never called in
        // the styled item delegate.
        item->setFlags(Qt::ItemIsEditable | item->flags());
#endif

        addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
    }

    // now set all loaded comments as not new, since they have been loaded.

    for(auto cid:new_comments)
    {
        uint32_t token=0;
        mCommentService->setCommentAsRead(token,mGroupId,cid);
    }
}
csoler commented 2 years ago

This is because in the qt interface, comments are displayed in multiple steps: first we get the post, then the comments for this post, then the votes for the comments. This is all done asynchronously. It's possible that the synchronous API that is used for comments is not doing all the job. I'll look into it asap and will keep you posted.

Sukhamjot-Singh commented 2 years ago

Yes, Here it is the same thing, I receive the posts first and then the comments and votes separately. I compare the msgIds and filter them. I can count the Votes if required as I receive them. It would be just easier if that Info could be provided in the comments API as I saw there was a provision.

csoler commented 2 years ago

I'll try to provide an API that does all the job. Give me a few days.

Sukhamjot-Singh commented 2 years ago

I'll try to provide an API that does all the job. Give me a few days.

I mean synchronous API would be great, but I can work around with this as well and save the extra work. We can discuss it in the meet tomorrow.

csoler commented 2 years ago

ok. In the mean time, I read the code. It seems to me that the sync API already does the right thing:

For now, in Qt UI, mCommentCount is updated after getting the post data (GxsChannelPostsModel.cpp:177)

To me more specific, after calling getChannelContent() / getChannelAllContent() (depending on getting all posts, or just one),

Sukhamjot-Singh commented 2 years ago

ok. In the mean time, I read the code. It seems to me that the sync API already does the right thing:

  • getChannelContent gets all the data for the requested posts, including comments and votes as lists. You have to use the thread IDs and parentIDs to know which post/comment they correspond to.

For now, in Qt UI, mCommentCount is updated after getting the post data (GxsChannelPostsModel.cpp:177)

To me more specific, after calling getChannelContent() / getChannelAllContent() (depending on getting all posts, or just one),

  • in RsGxsComment.mMeta, mThreadId is the ID of the channel post the comment is about, and mParentID is the id of the parent comment. When mParentID is equal to mThreadID, the comment is a top-level comment.
  • in RsGxsVote.mMeta, mThreadId is the ID of the channel post, and mParentId is the Id of the comment.
csoler commented 2 years ago

exactly. In C++ we use a map for quickly updating the correct post/comment for each comment/vote.

Sukhamjot-Singh commented 2 years ago

exactly. In C++ we use a map for quickly updating the correct post/comment for each comment/vote.

Yes, same here. I am using an object with keys as msgId, threadID etc.

Sukhamjot-Singh commented 2 years ago

Is there a way to delete comments on post in Retroshare qt?

defnax commented 2 years ago

No you cant delete anything, In rs there is no feature for delete comments or posts.

Sukhamjot-Singh commented 2 years ago

No you cant delete anything, In rs there is no feature for delete comments or posts.

Okay, thank you

Sukhamjot-Singh commented 2 years ago

I was trying createVoteV2() -> https://github.com/RetroShare/libretroshare/blob/72f8b7e8e240923731a141c6f2a0438588f04f59/src/retroshare/rsgxschannels.h#L281 Retroshare keeps crashing as soon as I call the API. Maybe it is some syntax issue but not sure.

{"channelId":"8a602a04b918d2aadef52a420a6d9dea","postId":"24e244f100b22b19695188fb2d04e7745a2e7583","authorId":"feb1ce7628ea69e1d89ca82e80e18d11","commentId":"95ac4d00914823d12c69da4c443db56daa6e76ec","vote":2}

csoler commented 2 years ago

it crashes because of a bug in the code. I'm currently working on this part, so hopefully it should solve soon.

Sukhamjot-Singh commented 2 years ago

image

In the files and thumbnail field, what all exactly do I need to send?

csoler commented 2 years ago

Thumbnail is the image the channel posts appears with in the Qt UI. Files is the list of attached file links, but you need to supply them as structured data: filename, size and hash are the minimum you need to supply.

Sukhamjot-Singh commented 2 years ago

Thumbnail is the image the channel posts appears with in the Qt UI. Files is the list of attached file links, but you need to supply them as structured data: filename, size and hash are the minimum you need to supply.

I have filename and size, where do I obtain hash from?

csoler commented 2 years ago

it's a SHA1 hash. I suppose that JS has some lib to compute it?

Sukhamjot-Singh commented 2 years ago

it's a SHA1 hash. I suppose that JS has some lib to compute it?

Okay, I searched about this. There may be some external libraries but nothing inbuilt in JS.

Sukhamjot-Singh commented 2 years ago

it's a SHA1 hash. I suppose that JS has some lib to compute it?

Okay, I searched about this. There may be some external libraries but nothing inbuilt in JS.

I would have to use node.js for the 'crypto' module which helps compute the sha1 hash. I don't think we can use it in this project?

rottencandy commented 2 years ago

See this lib https://github.com/emn178/js-sha1 It's a single file src, I think it's okay to just include the file in our code.

csoler commented 2 years ago

That's what we need. For files, you'd need to load chunks from the file until the end, updating the sha1 for each chunk using

var hash = sha1.create();

for each chunk in the file hash.update(chunk);

hash.hex();

csoler commented 2 years ago

If you want to test it, compare to what "sha1sum" (a shell command) returns.

Sukhamjot-Singh commented 2 years ago

Thumbnail is the image the channel posts appears with in the Qt UI. Files is the list of attached file links, but you need to supply them as structured data: filename, size and hash are the minimum you need to supply.

retroshare://file?name=...&size=...&hash=... Do I have to send a list of these urls in the createPostV2 API -> files -> []

csoler commented 2 years ago

"files" is a list of RsGxsFile, which is a structure containing the hash, name and size of each file. It's not a URL.

Sukhamjot-Singh commented 2 years ago

"files" is a list of RsGxsFile, which is a structure containing the hash, name and size of each file. It's not a URL.

Okay, i think I got confused

defnax commented 2 years ago

hi maybe you can develope a better comment viewer for channel/boards? like youtubes one? retroshare using wrong method to display comments on qt ui (channels/boards)

screen2 screen1

Sukhamjot-Singh commented 2 years ago

hi maybe you can develope a better comment viewer for channel/boards? like youtubes one? retroshare using wrong method to display comments on qt ui (channels/boards)

screen2 screen1

image

Something like this?

defnax commented 2 years ago

hi but without that right side, you has cloned right side like a table from qt ui add left side avatar, top name + timestamp under comment show reply, like (4) dislike (5), Score & ownvote

image

Sukhamjot-Singh commented 2 years ago

hi but without that right side, you has cloned right side like a table from qt ui add left side avatar, top name + timestamp under comment show reply, like (4) dislike (5), Score & ownvote

image

Okay I understand✅

csoler commented 2 years ago

would be nice to merge this at some point. It's getting too big a PR.

Sukhamjot-Singh commented 2 years ago

would be nice to merge this at some point. It's getting too big a PR.

We can merge. It is stable I will work with the updated in a new PR.

Sukhamjot-Singh commented 2 years ago

Okay to merge I guess. @csoler

csoler commented 2 years ago

could you fix the conflicts first?

Sukhamjot-Singh commented 2 years ago

could you fix the conflicts first?

I have no idea how to :) I will look into it.

csoler commented 2 years ago

could you fix the conflicts first?

I have no idea how to :) I will look into it.

just do a:

Sukhamjot-Singh commented 2 years ago

could you fix the conflicts first?

I have no idea how to :) I will look into it.

just do a:

  • git fetch upstream
  • git merge upstream/master Then fix the files that have conflicts, commit, and finally push to origin/[your working branch]

Right, I think this is the way to go. In this case I had an option on github only, so I made the changes.

Sukhamjot-Singh commented 2 years ago

Now I think it is okay to merge.