mirror of
https://github.com/RetroShare/RSNewWebUI.git
synced 2026-09-14 11:05:47 +05:00
Developed forums idea
This commit is contained in:
parent
226d60a026
commit
89d3a7285a
@ -19,6 +19,7 @@ async function parseFile(file, type) {
|
||||
let offset = 0;
|
||||
let chunkReaderBlock = null;
|
||||
const hash = sha1.create();
|
||||
const ansList = [];
|
||||
|
||||
const readEventHandler = async function (evt) {
|
||||
if (evt.target.error == null) {
|
||||
@ -31,6 +32,7 @@ async function parseFile(file, type) {
|
||||
if (offset >= fileSize) {
|
||||
const ans = await hash.hex();
|
||||
console.log(ans);
|
||||
ansList.push(ans);
|
||||
if (type.localeCompare('multiple') === 0) {
|
||||
filesUploadHashes.PostFiles.push(ans);
|
||||
} else {
|
||||
@ -41,6 +43,7 @@ async function parseFile(file, type) {
|
||||
|
||||
// of to the next chunk
|
||||
await chunkReaderBlock(offset, chunkSize, file);
|
||||
return ansList;
|
||||
};
|
||||
|
||||
chunkReaderBlock = async function (_offset, length, _file) {
|
||||
@ -52,6 +55,7 @@ async function parseFile(file, type) {
|
||||
|
||||
// read with the first block
|
||||
await chunkReaderBlock(offset, chunkSize, file);
|
||||
return ansList;
|
||||
}
|
||||
|
||||
const AddPost = () => {
|
||||
@ -71,8 +75,9 @@ const AddPost = () => {
|
||||
m('input[type=file][name=files][id=thumbnail][accept=image/*]', {
|
||||
onchange: async (e) => {
|
||||
filesUploadHashes.Thumbnail = [];
|
||||
await parseFile(e.target.files[0], '');
|
||||
console.log(filesUploadHashes.Thumbnail, filesUploadHashes.Thumbnail.length);
|
||||
const ansList = await parseFile(e.target.files[0], '');
|
||||
console.log(ansList, ansList.length);
|
||||
// console.log(filesUploadHashes.Thumbnail, filesUploadHashes.Thumbnail.length);
|
||||
|
||||
if (filesUploadHashes.Thumbnail.length === e.target.files.length) {
|
||||
pthumbnail.push({
|
||||
@ -239,7 +244,7 @@ const ChannelView = () => {
|
||||
m(
|
||||
'button',
|
||||
{ onclick: () => util.popupMessage(m(AddPost, { chanId: v.attrs.id })) },
|
||||
'Add Post'
|
||||
['Add Post', m('i.fas.fa-edit')]
|
||||
),
|
||||
m('hr'),
|
||||
|
||||
@ -279,7 +284,7 @@ const ChannelView = () => {
|
||||
};
|
||||
};
|
||||
|
||||
async function AddVote(voteType, vchannelId, vpostId, vauthorId, vcommentId) {
|
||||
// async function AddVote(voteType, vchannelId, vpostId, vauthorId, vcommentId) {
|
||||
// const res = await rs.rsJsonApiRequest('/rsgxschannels/createVoteV2', {
|
||||
// channelId: vchannelId,
|
||||
// postId: vpostId,
|
||||
@ -288,7 +293,7 @@ async function AddVote(voteType, vchannelId, vpostId, vauthorId, vcommentId) {
|
||||
// vote: voteType,
|
||||
// });
|
||||
// if (res.body.retval) util.updateDisplayChannels(vchannelId);
|
||||
}
|
||||
// }
|
||||
|
||||
const AddComment = () => {
|
||||
let inputComment = '';
|
||||
|
||||
@ -15,7 +15,7 @@ const Data = {
|
||||
DisplayChannels: {},
|
||||
Posts: {},
|
||||
Comments: {},
|
||||
TopComments: [],
|
||||
TopComments: {},
|
||||
ParentCommentMap: {},
|
||||
};
|
||||
|
||||
@ -80,7 +80,6 @@ async function updateDisplayChannels(keyid, details) {
|
||||
posts: details.mMeta.mVisibleMsgCount,
|
||||
activity: details.mMeta.mLastPost,
|
||||
created: details.mMeta.mPublishTs,
|
||||
all: details,
|
||||
};
|
||||
|
||||
if (Data.Posts[keyid] === undefined) {
|
||||
|
||||
161
webui-src/app/forums/forum_view.js
Normal file
161
webui-src/app/forums/forum_view.js
Normal file
@ -0,0 +1,161 @@
|
||||
const m = require('mithril');
|
||||
const rs = require('rswebui');
|
||||
const util = require('forums/forums_util');
|
||||
|
||||
const ThreadView = () => {
|
||||
return {
|
||||
view: (v) =>
|
||||
m('.widget', { key: v.attrs.msgId }, [
|
||||
m(
|
||||
'a[title=Back]',
|
||||
{
|
||||
onclick: () =>
|
||||
m.route.set('/forums/:tab/:mGroupId', {
|
||||
tab: m.route.param().tab,
|
||||
mGroupId: m.route.param().mGroupId,
|
||||
}),
|
||||
},
|
||||
m('i.fas.fa-arrow-left')
|
||||
),
|
||||
]),
|
||||
};
|
||||
};
|
||||
|
||||
const ForumView = () => {
|
||||
let fname = '';
|
||||
let fauthor = '';
|
||||
let fsubscribed = {};
|
||||
let createDate = {};
|
||||
let lastActivity = {};
|
||||
let topThreads = {};
|
||||
return {
|
||||
oninit: (v) => {
|
||||
if (util.Data.DisplayForums[v.attrs.id]) {
|
||||
fname = util.Data.DisplayForums[v.attrs.id].name;
|
||||
fsubscribed = util.Data.DisplayForums[v.attrs.id].isSubscribed;
|
||||
createDate = util.Data.DisplayForums[v.attrs.id].created;
|
||||
lastActivity = util.Data.DisplayForums[v.attrs.id].activity;
|
||||
if (rs.userList.userMap[util.Data.DisplayForums[v.attrs.id].author]) {
|
||||
fauthor = rs.userList.userMap[util.Data.DisplayForums[v.attrs.id].author];
|
||||
} else if (Number(util.Data.DisplayForums[v.attrs.id].author) === 0) {
|
||||
fauthor = 'No Contact Author';
|
||||
} else {
|
||||
fauthor = 'Unknown';
|
||||
}
|
||||
}
|
||||
if (util.Data.ParentThreads[v.attrs.id]) {
|
||||
topThreads = util.Data.ParentThreads[v.attrs.id];
|
||||
}
|
||||
console.log(util.Data.ParentThreads, v.attrs.id);
|
||||
},
|
||||
view: (v) =>
|
||||
m(
|
||||
'.widget',
|
||||
{
|
||||
key: v.attrs.id,
|
||||
},
|
||||
[
|
||||
m(
|
||||
'a[title=Back]',
|
||||
{
|
||||
onclick: () =>
|
||||
m.route.set('/forums/:tab', {
|
||||
tab: m.route.param().tab,
|
||||
}),
|
||||
},
|
||||
m('i.fas.fa-arrow-left')
|
||||
),
|
||||
|
||||
m('h3', fname),
|
||||
m(
|
||||
'button',
|
||||
{
|
||||
onclick: async () => {
|
||||
const res = await rs.rsJsonApiRequest('/rsgxsforums/subscribeToForum', {
|
||||
forumId: v.attrs.id,
|
||||
subscribe: !fsubscribed,
|
||||
});
|
||||
if (res.body.retval) {
|
||||
fsubscribed = !fsubscribed;
|
||||
util.Data.DisplayForums[v.attrs.id].isSubscribed = fsubscribed;
|
||||
}
|
||||
},
|
||||
},
|
||||
fsubscribed ? 'Subscribed' : 'Subscribe'
|
||||
),
|
||||
m('[id=forumdetails]', [
|
||||
m(
|
||||
'p',
|
||||
m('b', 'Date created: '),
|
||||
typeof createDate === 'object'
|
||||
? new Date(createDate.xint64 * 1000).toLocaleString()
|
||||
: 'undefined'
|
||||
),
|
||||
m('p', m('b', 'Admin: '), fauthor),
|
||||
m(
|
||||
'p',
|
||||
m('b', 'Last activity: '),
|
||||
typeof lastActivity === 'object'
|
||||
? new Date(lastActivity.xint64 * 1000).toLocaleString()
|
||||
: 'undefined'
|
||||
),
|
||||
]),
|
||||
m('hr'),
|
||||
m('forumdesc', m('b', 'Description: '), util.Data.DisplayForums[v.attrs.id].description),
|
||||
m('hr'),
|
||||
m(
|
||||
'threaddetails',
|
||||
{
|
||||
style: 'display:' + (fsubscribed ? 'block' : 'none'),
|
||||
},
|
||||
m('h3', 'Threads'),
|
||||
m('button', { onclick: () => util.popupMessage() }, [
|
||||
'New Thread',
|
||||
m('i.fas.fa-pencil-alt'),
|
||||
]),
|
||||
m('hr'),
|
||||
m(
|
||||
util.ThreadsTable,
|
||||
m(
|
||||
'tbody',
|
||||
Object.keys(topThreads).map((key, index) =>
|
||||
m(
|
||||
'tr',
|
||||
{
|
||||
onclick: () => {
|
||||
m.route.set('/forums/:tab/:mGroupId/:mMsgId', {
|
||||
tab: m.route.param().tab,
|
||||
mGroupId: v.attrs.id,
|
||||
mMsgId: topThreads[key].mMsgId,
|
||||
});
|
||||
},
|
||||
},
|
||||
[
|
||||
m('td', topThreads[key].mMsgName),
|
||||
m(
|
||||
'td',
|
||||
typeof topThreads[key].mPublishTs === 'object'
|
||||
? new Date(topThreads[key].mPublishTs.xint64 * 1000).toLocaleString()
|
||||
: 'undefined'
|
||||
),
|
||||
m(
|
||||
'td',
|
||||
rs.userList.userMap[topThreads[key].mAuthorId]
|
||||
? rs.userList.userMap[topThreads[key].mAuthorId]
|
||||
: 'Unknown'
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ForumView,
|
||||
ThreadView,
|
||||
};
|
||||
@ -36,7 +36,6 @@ table.forums tr.hidden{
|
||||
|
||||
#forumdetails{
|
||||
position: relative;
|
||||
margin-left: 150px;
|
||||
padding: 10px;
|
||||
}
|
||||
.p{
|
||||
@ -45,4 +44,9 @@ table.forums tr.hidden{
|
||||
#toggleunsub{
|
||||
position: relative;
|
||||
background: gray;
|
||||
}
|
||||
}
|
||||
|
||||
table.threads tr:hover {
|
||||
background-color: #eef3f6;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ const m = require('mithril');
|
||||
const widget = require('widgets');
|
||||
const rs = require('rswebui');
|
||||
const util = require('forums/forums_util');
|
||||
const viewUtil = require('forums/forum_view');
|
||||
|
||||
const getForums = {
|
||||
All: [],
|
||||
@ -13,8 +14,9 @@ const getForums = {
|
||||
getForums.All = res.body.forums;
|
||||
getForums.PopularForums = getForums.All;
|
||||
getForums.SubscribedForums = getForums.All.filter(
|
||||
(forum) => forum.mSubscribeFlags === util.GROUP_SUBSCRIBE_SUBSCRIBED ||
|
||||
forum.mSubscribeFlags === util.GROUP_MY_FORUM
|
||||
(forum) =>
|
||||
forum.mSubscribeFlags === util.GROUP_SUBSCRIBE_SUBSCRIBED ||
|
||||
forum.mSubscribeFlags === util.GROUP_MY_FORUM
|
||||
);
|
||||
getForums.MyForums = getForums.All.filter(
|
||||
(forum) => forum.mSubscribeFlags === util.GROUP_MY_FORUM
|
||||
@ -29,7 +31,7 @@ const sections = {
|
||||
};
|
||||
|
||||
const Layout = {
|
||||
oninit : () => {
|
||||
oninit: () => {
|
||||
rs.setBackgroundTask(getForums.load, 5000, () => {
|
||||
// return m.route.get() === '/files/files';
|
||||
});
|
||||
@ -46,8 +48,13 @@ const Layout = {
|
||||
m(
|
||||
'.forums-node-panel',
|
||||
|
||||
Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId')
|
||||
? m(util.MessageView, {
|
||||
Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mMsgId')
|
||||
? m(viewUtil.ThreadView, {
|
||||
msgId: vnode.attrs.pathInfo.mMsgId,
|
||||
forumId: vnode.attrs.pathInfo.mGroupId,
|
||||
})
|
||||
: Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId')
|
||||
? m(viewUtil.ForumView, {
|
||||
id: vnode.attrs.pathInfo.mGroupId,
|
||||
})
|
||||
: m(sections[vnode.attrs.pathInfo.tab], {
|
||||
|
||||
@ -5,12 +5,12 @@ const GROUP_SUBSCRIBE_ADMIN = 0x01; // means: you have the admin key for this gr
|
||||
const GROUP_SUBSCRIBE_PUBLISH = 0x02; // means: you have the publish key for thiss group. Typical use: publish key in forums are shared with specific friends.
|
||||
const GROUP_SUBSCRIBE_SUBSCRIBED = 0x04; // means: you are subscribed to a group, which makes you a source for this group to your friend nodes.
|
||||
const GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08;
|
||||
const GROUP_MY_FORUM =
|
||||
GROUP_SUBSCRIBE_ADMIN + GROUP_SUBSCRIBE_SUBSCRIBED + GROUP_SUBSCRIBE_PUBLISH;
|
||||
|
||||
const GROUP_MY_FORUM = GROUP_SUBSCRIBE_ADMIN + GROUP_SUBSCRIBE_SUBSCRIBED + GROUP_SUBSCRIBE_PUBLISH;
|
||||
|
||||
const Data = {
|
||||
DisplayForums: {},
|
||||
Posts: {},
|
||||
ParentThreads: {},
|
||||
};
|
||||
|
||||
async function updateDisplayForums(keyid, details = {}) {
|
||||
@ -18,13 +18,32 @@ async function updateDisplayForums(keyid, details = {}) {
|
||||
forumIds: [keyid],
|
||||
});
|
||||
details = res.body.forumsInfo[0];
|
||||
if (Data.DisplayForums[keyid] === undefined) {
|
||||
Data.DisplayForums[keyid] = {
|
||||
name: details.mMeta.mGroupName,
|
||||
isSearched: true,
|
||||
description: details.mDescription,
|
||||
isSubscribed: details.mMeta.mSubscribeFlags === GROUP_SUBSCRIBE_SUBSCRIBED,
|
||||
};
|
||||
Data.DisplayForums[keyid] = {
|
||||
name: details.mMeta.mGroupName,
|
||||
author: details.mMeta.mAuthorId,
|
||||
isSearched: true,
|
||||
description: details.mDescription,
|
||||
isSubscribed:
|
||||
details.mMeta.mSubscribeFlags === GROUP_SUBSCRIBE_SUBSCRIBED ||
|
||||
details.mMeta.mSubscribeFlags === GROUP_MY_FORUM,
|
||||
activity: details.mMeta.mLastPost,
|
||||
created: details.mMeta.mPublishTs,
|
||||
};
|
||||
if (Data.Posts[keyid] === undefined) {
|
||||
Data.Posts[keyid] = {};
|
||||
}
|
||||
const res2 = await rs.rsJsonApiRequest('/rsgxsforums/getForumMsgMetaData', {
|
||||
forumId: keyid,
|
||||
});
|
||||
if (res2.body.retval) {
|
||||
res2.body.msgMetas.map((thread) => {
|
||||
if (Data.ParentThreads[thread.mGroupId] === undefined) {
|
||||
Data.ParentThreads[thread.mGroupId] = {};
|
||||
}
|
||||
if (thread.mThreadId === thread.mParentId) {
|
||||
Data.ParentThreads[thread.mGroupId][thread.mMsgId] = thread;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,68 +83,26 @@ const ForumSummary = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const MessageView = () => {
|
||||
let fname = '';
|
||||
let fsubscribed = {};
|
||||
return {
|
||||
oninit: (v) => {
|
||||
if (Data.DisplayForums[v.attrs.id]) {
|
||||
fname = Data.DisplayForums[v.attrs.id].name;
|
||||
fsubscribed = Data.DisplayForums[v.attrs.id].isSubscribed;
|
||||
}
|
||||
},
|
||||
view: (v) =>
|
||||
m(
|
||||
'.widget',
|
||||
{
|
||||
key: v.attrs.id,
|
||||
},
|
||||
[
|
||||
m(
|
||||
'a[title=Back]',
|
||||
{
|
||||
onclick: () =>
|
||||
m.route.set('/forums/:tab', {
|
||||
tab: m.route.param().tab,
|
||||
}),
|
||||
},
|
||||
m('i.fas.fa-arrow-left')
|
||||
),
|
||||
m(
|
||||
'button',
|
||||
{
|
||||
onclick: async () => {
|
||||
const res = await rs.rsJsonApiRequest('/rsgxsforums/subscribeToForum', {
|
||||
forumId: v.attrs.id,
|
||||
subscribe: !fsubscribed,
|
||||
});
|
||||
if (res.body.retval) {
|
||||
fsubscribed = !fsubscribed;
|
||||
Data.DisplayForums[v.attrs.id].isSubscribed = fsubscribed;
|
||||
}
|
||||
},
|
||||
},
|
||||
fsubscribed ? 'Subscribed' : 'Subscribe'
|
||||
),
|
||||
m('h3', fname),
|
||||
m('[id=forumdetails]', [
|
||||
m('p', m('b', 'Posts: '), 'posts'),
|
||||
m('p', m('b', 'Date created: '), '1/1/11'),
|
||||
m('p', m('b', 'Admin: '), 'name_of_admin'),
|
||||
m('p', m('b', 'Last activity: '), '1/1/11'),
|
||||
]),
|
||||
m('hr'),
|
||||
m('forumdesc', m('b', 'Description: '), Data.DisplayForums[v.attrs.id].description),
|
||||
]
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
const Table = () => {
|
||||
const ForumTable = () => {
|
||||
return {
|
||||
view: (v) => m('table.forums', [m('tr', [m('th', 'Forum Name')]), v.children]),
|
||||
};
|
||||
};
|
||||
const ThreadsTable = () => {
|
||||
return {
|
||||
oninit: (v) => {},
|
||||
view: (v) =>
|
||||
m('table.threads', [
|
||||
m('tr', [
|
||||
m('th', 'Comment'),
|
||||
m('th', 'Author'),
|
||||
m('th', 'Date'),
|
||||
]),
|
||||
v.children,
|
||||
]),
|
||||
};
|
||||
};
|
||||
|
||||
const SearchBar = () => {
|
||||
let searchString = '';
|
||||
return {
|
||||
@ -147,14 +124,15 @@ const SearchBar = () => {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
Data,
|
||||
SearchBar,
|
||||
ForumSummary,
|
||||
MessageView,
|
||||
DisplayForumsFromList,
|
||||
Table,
|
||||
ForumTable,
|
||||
ThreadsTable,
|
||||
GROUP_SUBSCRIBE_ADMIN,
|
||||
GROUP_SUBSCRIBE_NOT_SUBSCRIBED,
|
||||
GROUP_SUBSCRIBE_PUBLISH,
|
||||
GROUP_SUBSCRIBE_SUBSCRIBED,
|
||||
GROUP_MY_FORUM
|
||||
GROUP_MY_FORUM,
|
||||
};
|
||||
|
||||
@ -1,9 +1,32 @@
|
||||
const m = require('mithril');
|
||||
const util = require('forums/forums_util');
|
||||
|
||||
const Layout = () => {
|
||||
return {
|
||||
view: () => [m('.widget', [m('h2', 'My Forums'), m('hr')])],
|
||||
view: (v) => [
|
||||
m('.widget', [
|
||||
m('h3', 'My Forums'),
|
||||
m('hr'),
|
||||
m(
|
||||
util.ForumTable,
|
||||
m('tbody', [
|
||||
v.attrs.list.map((forum) =>
|
||||
m(util.ForumSummary, {
|
||||
details: forum,
|
||||
category: 'MyForums',
|
||||
})
|
||||
),
|
||||
v.attrs.list.map((forum) =>
|
||||
m(util.DisplayForumsFromList, {
|
||||
id: forum.mGroupId,
|
||||
category: 'MyForums',
|
||||
})
|
||||
),
|
||||
])
|
||||
),
|
||||
]),
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Layout();
|
||||
module.exports = Layout;
|
||||
|
||||
@ -8,7 +8,7 @@ const Layout = () => {
|
||||
m('h3', 'Popular Forums'),
|
||||
m('hr'),
|
||||
m(
|
||||
util.Table,
|
||||
util.ForumTable,
|
||||
m('tbody', [
|
||||
v.attrs.list.map((forum) =>
|
||||
m(util.ForumSummary, {
|
||||
|
||||
@ -8,7 +8,7 @@ const Layout = () => {
|
||||
m('h3', 'Subscribed Forums'),
|
||||
m('hr'),
|
||||
m(
|
||||
util.Table,
|
||||
util.ForumTable,
|
||||
m('tbody', [
|
||||
v.attrs.list.map((forum) =>
|
||||
m(util.ForumSummary, {
|
||||
|
||||
@ -112,6 +112,9 @@ m.route(document.getElementById('main'), '/', {
|
||||
'/forums/:tab/:mGroupId': {
|
||||
render: (v) => m(Layout, m(forums, v.attrs)),
|
||||
},
|
||||
'/forums/:tab/:mGroupId/:mMsgId': {
|
||||
render: (v) => m(Layout, m(forums, v.attrs)),
|
||||
},
|
||||
'/config/:tab': {
|
||||
render: (v) => m(Layout, m(config, v.attrs)),
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user