Create forums

This commit is contained in:
Sukhamjot Singh 2022-08-02 16:26:51 +05:30
parent b6f43246a0
commit a6ea4c09c3
2 changed files with 154 additions and 44 deletions

View File

@ -4,6 +4,79 @@ const util = require('forums/forums_util');
const peopleUtil = require('people/people_util');
const { updatedisplayforums } = require('./forums_util');
function addpost() {
let title;
let body;
let identity;
return {
oninit: (vnode) => {
if (vnode.attrs.authorId) {
identity = vnode.attrs.authorId[0];
}
},
view: (vnode) =>
m('.widget', [
m('h3', 'Create Forum'),
m('hr'),
m('input[type=text][placeholder=Title]', {
oninput: (e) => (title = e.target.value),
}),
m('label[for=tags]', 'Select identity'),
m(
'select[id=idtags]',
{
value: identity,
onchange: (e) => {
identity = vnode.attrs.authorId[e.target.selectedIndex];
},
},
[
vnode.attrs.authorId &&
vnode.attrs.authorId.map((o) =>
m(
'option',
{ value: o },
rs.userList.userMap[o] ? rs.userList.userMap[o].toLocaleString() : 'No Signature'
)
),
]
),
m('textarea[rows=5][placeholder=Description]', {
style: { width: '90%', display: 'block' },
oninput: (e) => (body = e.target.value),
value: body,
}),
m(
'button',
{
onclick: async () => {
const res = await rs.rsJsonApiRequest('/rsgxsforums/createForumV2', {
name: title,
description: body,
...((Number(identity) !== 0) && {authorId: identity}),
});
if(res.body.retval)
{
util.updatedisplayforums(res.body.forumId);
m.redraw();
}
res.body.retval === false
? util.popupmessage([m('h3', 'Error'), m('hr'), m('p', res.body.errorMessage)])
: util.popupmessage([
m('h3', 'Success'),
m('hr'),
m('p', 'Forum created successfully'),
]);
},
},
'Create'
),
]),
};
}
function displaythread() {
let groupmessagepair;
let unread;
@ -91,15 +164,17 @@ function displaythread() {
{
style: { fontSize: '15px' },
onclick: async () => {
if(!unread){const res = await rs.rsJsonApiRequest('/rsgxsforums/markRead', {
messageId: groupmessagepair,
read: false,
});
if (!unread) {
const res = await rs.rsJsonApiRequest('/rsgxsforums/markRead', {
messageId: groupmessagepair,
read: false,
});
if (res.body.retval) {
updatedisplayforums(thread.mMeta.mGroupId);
m.redraw();
}}
if (res.body.retval) {
updatedisplayforums(thread.mMeta.mGroupId);
m.redraw();
}
}
},
},
'Mark Unread'
@ -133,7 +208,9 @@ const AddThread = () => {
let identity;
return {
oninit: (vnode) => {
identity = vnode.attrs.authorId[0];
if (vnode.attrs.authorId) {
identity = vnode.attrs.authorId[0];
}
},
view: (vnode) =>
m('.widget', [
@ -155,9 +232,10 @@ const AddThread = () => {
},
},
[
vnode.attrs.authorId.map((o) =>
m('option', { value: o }, rs.userList.userMap[o].toLocaleString())
),
vnode.attrs.authorId &&
vnode.attrs.authorId.map((o) =>
m('option', { value: o }, rs.userList.userMap[o].toLocaleString())
),
]
),
m('textarea[rows=5]', {
@ -204,9 +282,10 @@ const AddThread = () => {
const ThreadView = () => {
let thread = {};
let ownId;
let onlineId;
return {
showThread: '',
oninit: (v) => {
oninit: async (v) => {
if (
util.Data.ParentThreads[v.attrs.forumId] &&
util.Data.ParentThreads[v.attrs.forumId][v.attrs.msgId]
@ -222,6 +301,9 @@ const ThreadView = () => {
}
}
});
// const res = await rs.rsJsonApiRequest('/rsPeers/getOwnId',{});
// console.log(res);
},
view: (v) =>
m('.widget', { key: v.attrs.msgId }, [
@ -426,4 +508,5 @@ const ForumView = () => {
module.exports = {
ForumView,
ThreadView,
addpost,
};

View File

@ -3,6 +3,7 @@ const widget = require('widgets');
const rs = require('rswebui');
const util = require('forums/forums_util');
const viewUtil = require('forums/forum_view');
const peopleUtil = require('people/people_util');
const getForums = {
All: [],
@ -30,38 +31,64 @@ const sections = {
OtherForums: require('forums/other_forums'),
};
const Layout = {
oninit: () => {
rs.setBackgroundTask(getForums.load, 5000, () => {
// return m.route.get() === '/files/files';
});
},
view: (vnode) =>
m('.tab-page', [
m(util.SearchBar, {
list: getForums.All,
}),
m(widget.Sidebar, {
tabs: Object.keys(sections),
baseRoute: '/forums/',
}),
m(
'.forums-node-panel',
const Layout = () => {
let ownId;
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], {
list: getForums[vnode.attrs.pathInfo.tab],
})
),
]),
return {
oninit: () => {
rs.setBackgroundTask(getForums.load, 5000, () => {
// return m.route.get() === '/files/files';
});
peopleUtil.ownIds((data) => {
ownId = data;
for (let i = 0; i < ownId.length; i++) {
if (Number(ownId[i]) === 0) {
ownId.splice(i, 1);
}
}
ownId.unshift(0);
});
},
view: (vnode) =>
m('.tab-page', [
m(util.SearchBar, {
list: getForums.All,
}),
m(
'button',
{
style: {fontSize: '1.2em', width: '200px'},
onclick: () =>
util.popupmessage(
m(viewUtil.addpost, {
authorId: ownId,
})
),
},
'Create Forum'
),
m(widget.Sidebar, {
tabs: Object.keys(sections),
baseRoute: '/forums/',
}),
m(
'.forums-node-panel',
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], {
list: getForums[vnode.attrs.pathInfo.tab],
})
),
]),
};
};
module.exports = {