From 41c5ad65d401b2e0f67f2da8b38f19f6c4fff617 Mon Sep 17 00:00:00 2001 From: Sukhamjot Singh Date: Sat, 18 Jun 2022 21:14:36 +0530 Subject: [PATCH] Added comments and fixed posts. --- webui-src/app/channels/channel.css | 6 +++ webui-src/app/channels/channels_util.js | 56 ++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/webui-src/app/channels/channel.css b/webui-src/app/channels/channel.css index bc85242..2e626d6 100644 --- a/webui-src/app/channels/channel.css +++ b/webui-src/app/channels/channel.css @@ -28,6 +28,7 @@ table.channels tr.hidden{ display: none; } + #searchchannel{ position:relative; margin-left: 250px; @@ -73,4 +74,9 @@ img.channelpic { .card-title{ position: absolute; bottom: 0px; +} + +/* subject */ +table.comments td { + word-wrap: break-word; } \ No newline at end of file diff --git a/webui-src/app/channels/channels_util.js b/webui-src/app/channels/channels_util.js index 6446f12..7d7717c 100644 --- a/webui-src/app/channels/channels_util.js +++ b/webui-src/app/channels/channels_util.js @@ -7,19 +7,32 @@ const GROUP_SUBSCRIBE_SUBSCRIBED = 0x04; // means: you are subscribed to a group const GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08; const GROUP_MY_CHANNEL = GROUP_SUBSCRIBE_ADMIN + GROUP_SUBSCRIBE_SUBSCRIBED + GROUP_SUBSCRIBE_PUBLISH; +// const GXS_VOTE_DOWN = 0x0001; +// const GXS_VOTE_UP = 0x0002; + + + const Data = { DisplayChannels: {}, Posts: {}, + Comments: {}, }; -async function updateContent(post, channelid) { +async function updateContent(content, channelid) { const res = await rs.rsJsonApiRequest('/rsgxschannels/getChannelContent', { channelId: channelid, - contentsIds: [post.mMsgId], + contentsIds: [content.mMsgId], }); - console.log(res.body.posts); + // console.log(res.body.posts); if (res.body.retval && res.body.posts.length > 0) { - Data.Posts[channelid][post.mMsgId] = res.body.posts[0]; + Data.Posts[channelid][content.mMsgId] = res.body.posts[0]; + } + if (res.body.retval && res.body.comments.length > 0) { + if (Data.Comments[content.mThreadId] === undefined) { + Data.Comments[content.mThreadId] = {}; + } + Data.Comments[content.mThreadId][content.mMsgId] = res.body.comments[0]; + // console.log(Data.Comments[content.mThreadId][content.mMsgId]); } } @@ -52,8 +65,8 @@ async function updateDisplayChannels(keyid, details) { // console.log(res2); if (res2.body.retval) { - res2.body.summaries.map((post) => { - updateContent(post, keyid); + res2.body.summaries.map((content) => { + updateContent(content, keyid); }); } } @@ -224,6 +237,16 @@ const ChannelView = () => { ), }; }; +const CommentsTable = () => { + return { + oninit: (v) => {}, + view: (v) => + m('table.comments', [ + m('tr', [m('th', 'Comment'), m('th', 'Author'), m('th', 'Date')]), + v.children, + ]), + }; +}; const FilesTable = () => { return { oninit: (v) => {}, @@ -247,11 +270,15 @@ function formatBytes(bytes, decimals = 2) { } const PostView = () => { let post = {}; + let comments = {}; return { oninit: (v) => { if (Data.Posts[v.attrs.channelId] && Data.Posts[v.attrs.channelId][v.attrs.msgId]) { post = Data.Posts[v.attrs.channelId][v.attrs.msgId]; } + if (Data.Comments[v.attrs.msgId]) { + comments = Data.Comments[v.attrs.msgId]; + } }, view: (v) => m('.widget', { key: v.attrs.msgId }, [ @@ -283,6 +310,23 @@ const PostView = () => { ) ) ), + m('hr'), + m('h3', 'Comments' + comments.length), + m( + CommentsTable, + m( + 'tbody', + Object.keys(comments).map((key, index) => + m('tr', [ + m('td', comments[key].mComment), + m('td', rs.userList.userMap[comments[key].mMeta.mAuthorId]), + m('td', typeof comments[key].mMeta.mPublishTs === 'object' + ? new Date(comments[key].mMeta.mPublishTs.xint64 * 1000).toLocaleString() + : 'undefined'), + ]) + ) + ) + ), ]), }; };