Added comments and fixed posts.

This commit is contained in:
Sukhamjot Singh 2022-06-18 21:14:36 +05:30
parent b3c22f55cf
commit 41c5ad65d4
2 changed files with 56 additions and 6 deletions

View File

@ -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;
}

View File

@ -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'),
])
)
)
),
]),
};
};