mirror of
https://github.com/lxsang/antd-web-apps
synced 2025-07-26 02:29:47 +02:00
WIP: make code compatible with new SILK API
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
This commit is contained in:
@ -21,7 +21,15 @@ class QuickTalk {
|
||||
this.instant_compose.parentNode.removeChild(this.instant_compose);
|
||||
}
|
||||
this.instant_compose = this.compose(editor, 0, true, (data) => {
|
||||
this.show_comment(container, data, true).scrollIntoView();
|
||||
this.show_comment(container, data, true);
|
||||
if(this.options.page)
|
||||
{
|
||||
this.options.page.scrollTop = this.options.page.scrollHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -199,9 +207,9 @@ class QuickTalk {
|
||||
container.appendChild(preview);
|
||||
container.appendChild(footer);
|
||||
at.appendChild(container);
|
||||
if (this.options.page) {
|
||||
this.options.page.scrollTop = container.offsetTop - this.options.page.offsetTop;
|
||||
}
|
||||
//if (this.options.page) {
|
||||
// this.options.page.scrollTop = container.offsetTop - this.options.page.offsetTop;
|
||||
//}
|
||||
|
||||
//container.scrollIntoView();
|
||||
return container;
|
||||
@ -228,6 +236,7 @@ class QuickTalk {
|
||||
show_comment(at, comment, show_footer) {
|
||||
let container = document.createElement("div");
|
||||
container.setAttribute("class", "quick-talk-comment");
|
||||
container.setAttribute("id", "comment-" + comment.id);
|
||||
let header = document.createElement("div");
|
||||
header.setAttribute("class", "quick-talk-comment-header");
|
||||
let username = document.createElement("span");
|
||||
@ -265,7 +274,8 @@ class QuickTalk {
|
||||
this.instant_compose.parentNode.removeChild(this.instant_compose);
|
||||
}
|
||||
this.instant_compose = this.compose(editor, parseInt(comment.id), true, (data) => {
|
||||
this.show_comment(sub_comments, data, false).scrollIntoView();
|
||||
this.show_comment(sub_comments, data, false);
|
||||
//.scrollIntoView();
|
||||
});
|
||||
});
|
||||
container.appendChild(footer);
|
||||
|
@ -10,6 +10,7 @@ local function process_md(input)
|
||||
end
|
||||
|
||||
local function sendmail(to, subject, content)
|
||||
LOG_DEBUG("Sending email to %s", to)
|
||||
local from = "From: contact@iohub.dev\nTo: " .. to .. "\n"
|
||||
local suject = "Subject: " .. subject .. "\n"
|
||||
|
||||
@ -31,17 +32,17 @@ function CommentController:index(...)
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.json))
|
||||
if (rq) then
|
||||
local pages, order = self.pages:find({exp = {["="] = {uri = rq.page}}})
|
||||
local pages, order = self.pages:find({where = {uri = rq.page}})
|
||||
if not pages or #order == 0 then
|
||||
fail("Be the first to comment")
|
||||
else
|
||||
local pid = pages[1].id
|
||||
local comments, order = self.comment:find(
|
||||
{
|
||||
exp = {
|
||||
["and"] = {{["="] = {pid = pid}}, {[" = "] = {rid = 0}}}
|
||||
local comments, order = self.comment:find({
|
||||
where = {
|
||||
pid = pid,
|
||||
rid = 0
|
||||
},
|
||||
order = {time = "ASC"},
|
||||
order = {"time$asc"},
|
||||
fields = {"id", "time", "name", "rid", "pid", "content"}
|
||||
})
|
||||
if not comments or #order == 0 then
|
||||
@ -55,13 +56,11 @@ function CommentController:index(...)
|
||||
local sub_comments, suborder =
|
||||
self.comment:find(
|
||||
{
|
||||
exp = {
|
||||
["and"] = {
|
||||
{["="] = {pid = pid}},
|
||||
{[" = "] = {rid = data.id}}
|
||||
}
|
||||
where = {
|
||||
pid = pid,
|
||||
rid = data.id
|
||||
},
|
||||
order = {time = "ASC"}
|
||||
order = {"time$asc"}
|
||||
|
||||
})
|
||||
if sub_comments and #suborder ~= 0 then
|
||||
@ -92,7 +91,7 @@ function CommentController:post(...)
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.json))
|
||||
if rq then
|
||||
local pages, order = self.pages:find({exp = {["="] = rq.page}})
|
||||
local pages, order = self.pages:find({where = rq.page})
|
||||
if not pages or #order == 0 then
|
||||
-- insert data
|
||||
if self.pages:create(rq.page) then
|
||||
@ -120,19 +119,27 @@ function CommentController:post(...)
|
||||
".\nBest regards,\nEmail automatically sent by QuickTalk API")
|
||||
end
|
||||
-- send mail to all users of current page
|
||||
local cmts, cmti = self.comment:select("MIN(id) as id,email",
|
||||
"pid=" .. rq.comment.pid ..
|
||||
" AND email != '" ..
|
||||
rq.comment.email ..
|
||||
"' GROUP BY email")
|
||||
local cmts, cmti = self.comment:find(
|
||||
{
|
||||
where = {
|
||||
pid = rq.comment.pid,
|
||||
["email$ne"] = rq.comment.email
|
||||
},
|
||||
fields = {"id", "email"}
|
||||
})
|
||||
-- check duplicate email
|
||||
if cmts and #cmti > 0 then
|
||||
local sent = {}
|
||||
for idx, v in pairs(cmti) do
|
||||
sendmail(cmts[v].email, rq.comment.name ..
|
||||
if not sent[cmts[v].email] then
|
||||
sendmail(cmts[v].email, rq.comment.name ..
|
||||
" has written something on a page that you've commented on",
|
||||
rq.comment.name ..
|
||||
" has written something on a page that you've commented. \nPlease visit this page: " ..
|
||||
rq.page.uri ..
|
||||
rq.page.uri..
|
||||
" for updates on the discussion.\nBest regards,\nEmail automatically sent by QuickTalk API")
|
||||
sent[cmts[v].email] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
rq.comment.email = ""
|
||||
|
@ -2,6 +2,13 @@
|
||||
-- should be something like this
|
||||
-- ^\/apps\/+(.*)$ = /apps/router.lua?r=<1>&<query>
|
||||
-- some global variables
|
||||
package.path = _SERVER["LIB_DIR"].."/lua/?.lua"
|
||||
require("silk.api")
|
||||
-- crypto lib
|
||||
enc = require("enc")
|
||||
WWW_ROOT = __ROOT__.."/talk"
|
||||
-- TODO change me
|
||||
DB_FILE = "/home/dany/databases/quicktalk.db"
|
||||
function fail(msg)
|
||||
std.json()
|
||||
std.t(JSON.encode({error = msg}))
|
||||
@ -12,34 +19,30 @@ function result(obj)
|
||||
std.t(JSON.encode({result = obj, error = false}))
|
||||
end
|
||||
DIR_SEP = "/"
|
||||
WWW_ROOT = __ROOT__ .. "/talk"
|
||||
if HEADER.Host then
|
||||
HTTP_ROOT = "https://" .. HEADER.Host
|
||||
else
|
||||
HTTP_ROOT = "https://talk.iohub.dev"
|
||||
end
|
||||
-- class path: path.to.class
|
||||
BASE_FRW = ""
|
||||
-- class path: path.to.class
|
||||
CONTROLLER_ROOT = BASE_FRW .. "talk.controllers"
|
||||
MODEL_ROOT = BASE_FRW .. "talk.models"
|
||||
-- file path: path/to/file
|
||||
VIEW_ROOT = WWW_ROOT .. DIR_SEP .. "views"
|
||||
LOG_ROOT = WWW_ROOT .. DIR_SEP .. "logs"
|
||||
|
||||
-- require needed library
|
||||
require(BASE_FRW .. "silk.api")
|
||||
-- TODO remove me
|
||||
HTTP_ROOT = HTTP_ROOT.."/next/talk"
|
||||
|
||||
-- class path: path.to.class
|
||||
CONTROLLER_ROOT = "talk.controllers"
|
||||
MODEL_ROOT = "talk.models"
|
||||
-- file path: path/to/file
|
||||
VIEW_ROOT = WWW_ROOT..DIR_SEP.."views"
|
||||
|
||||
|
||||
-- registry object store global variables
|
||||
local REGISTRY = {}
|
||||
-- set logging level
|
||||
REGISTRY.logger = Logger:new{
|
||||
levels = {INFO = false, ERROR = false, DEBUG = false}
|
||||
}
|
||||
REGISTRY.logger = Logger:new{ level = Logger.INFO}
|
||||
|
||||
REGISTRY.layout = 'default'
|
||||
REGISTRY.fileaccess = true
|
||||
REGISTRY.db = DBHelper:new{db = "quicktalk"}
|
||||
REGISTRY.db = DBModel:new{db = DB_FILE}
|
||||
REGISTRY.db:open()
|
||||
|
||||
local router = Router:new{registry = REGISTRY}
|
||||
|
Reference in New Issue
Block a user