color, weigth, locale, config
This commit is contained in:
@@ -17,7 +17,7 @@ const botController = {
|
||||
access_token,
|
||||
api_url: `https://${instance}/api/v1`
|
||||
})
|
||||
const listener = botController.bot.stream('/streaming/direct')
|
||||
const listener = botController.bot.stream('/streaming/public')
|
||||
listener.on('message', botController.message)
|
||||
listener.on('error', botController.error)
|
||||
// const botUsers = await User.findAll({ where: { mastodon_auth: { [Op.ne]: null } } })
|
||||
@@ -51,12 +51,13 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
|
||||
media = await bot.post('media', { file: fs.createReadStream(file) })
|
||||
}
|
||||
}
|
||||
return botController.bot.post('/statuses', { status, visibility: 'direct', media_ids: media ? [media.data.id] : [] })
|
||||
return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] })
|
||||
},
|
||||
|
||||
// TOFIX: enable message deletion
|
||||
async message(msg) {
|
||||
const replyid = msg.data.in_reply_to_id || msg.data.last_status.in_reply_to_id
|
||||
const type = msg.event
|
||||
const replyid = msg.data.in_reply_to_id
|
||||
if (!replyid) return
|
||||
let event = await Event.findOne({ where: { activitypub_id: replyid } })
|
||||
if (!event) {
|
||||
@@ -65,8 +66,8 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
|
||||
if (!comment) return
|
||||
event = comment.event
|
||||
}
|
||||
const comment = await Comment.create({
|
||||
activitypub_id: msg.data.last_status.id,
|
||||
await Comment.create({
|
||||
activitypub_id: msg.data.id,
|
||||
data: msg.data,
|
||||
eventId: event.id
|
||||
})
|
||||
|
||||
@@ -23,7 +23,7 @@ const eventController = {
|
||||
const places = await Place.findAll({
|
||||
order: [[Sequelize.literal('weigth'), 'DESC']],
|
||||
attributes: {
|
||||
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) , 'weigth']], // <---- Here you will get the total count of user
|
||||
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) , 'weigth']],
|
||||
exclude: ['weigth', 'createdAt', 'updatedAt']
|
||||
},
|
||||
include: [{ model: Event, attributes: [] }],
|
||||
@@ -32,10 +32,9 @@ const eventController = {
|
||||
|
||||
const tags = await Tag.findAll({
|
||||
order: [['weigth', 'DESC']],
|
||||
includeIgnoreAttributes: false,
|
||||
attributes: {
|
||||
exclude: ['createdAt', 'updatedAt']
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
res.json({ tags, places })
|
||||
@@ -84,20 +83,20 @@ const eventController = {
|
||||
|
||||
// TODO retrieve next/prev event also
|
||||
// select id, start_datetime, title from events where start_datetime > (select start_datetime from events where id=89) order by start_datetime limit 20;
|
||||
// weigth is not updated
|
||||
async get(req, res) {
|
||||
const id = req.params.event_id
|
||||
const event = await Event.findByPk(id, {
|
||||
let event = await Event.findByPk(id, {
|
||||
plain: true,
|
||||
attributes: { exclude: ['createdAt', 'updatedAt'] },
|
||||
include: [
|
||||
Tag,
|
||||
Comment,
|
||||
{ model: Place, attributes: ['name', 'address'] }
|
||||
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
||||
{ model: Place, attributes: ['name', 'address'] },
|
||||
Comment
|
||||
],
|
||||
order: [ [Comment, 'id', 'DESC'], [Tag, 'weigth', 'DESC'] ]
|
||||
order: [ [Comment, 'id', 'DESC'] ]
|
||||
})
|
||||
|
||||
if (event) {
|
||||
event.activitypub_id = event.activitypub_id ? String(event.activitypub_id) : null
|
||||
res.json(event)
|
||||
} else {
|
||||
res.sendStatus(404)
|
||||
@@ -171,17 +170,18 @@ const eventController = {
|
||||
async getAll(req, res) {
|
||||
// this is due how v-calendar shows dates
|
||||
const start = moment().year(req.params.year).month(req.params.month)
|
||||
.startOf('month').startOf('isoWeek').unix()
|
||||
.startOf('month').startOf('isoWeek')
|
||||
let end = moment().utc().year(req.params.year).month(req.params.month).endOf('month')
|
||||
const shownDays = end.diff(start, 'days')
|
||||
if (shownDays <= 34) end = end.add(1, 'week')
|
||||
end = end.endOf('isoWeek').unix()
|
||||
console.error(shownDays)
|
||||
if (shownDays <= 35) end = end.add(1, 'week')
|
||||
end = end.endOf('isoWeek')
|
||||
const events = await Event.findAll({
|
||||
where: {
|
||||
is_visible: true,
|
||||
[Op.and]: [
|
||||
Sequelize.literal(`start_datetime >= ${start}`),
|
||||
Sequelize.literal(`start_datetime <= ${end}`)
|
||||
Sequelize.literal(`start_datetime >= ${start.unix()}`),
|
||||
Sequelize.literal(`start_datetime <= ${end.unix()}`)
|
||||
]
|
||||
},
|
||||
order: [
|
||||
|
||||
@@ -9,26 +9,25 @@ const exportController = {
|
||||
const type = req.params.type
|
||||
const tags = req.query.tags
|
||||
const places = req.query.places
|
||||
const whereTag = {}
|
||||
const wherePlace = {}
|
||||
const yesterday = moment().subtract('1', 'day')
|
||||
const where = {}
|
||||
const yesterday = moment().subtract('1', 'day').unix()
|
||||
if (tags) {
|
||||
whereTag.tag = tags.split(',')
|
||||
where.tag = tags.split(',')
|
||||
}
|
||||
if (places) {
|
||||
wherePlace.id = places.split(',')
|
||||
where.placeId = places.split(',')
|
||||
}
|
||||
const events = await Event.findAll({
|
||||
order: ['start_datetime'],
|
||||
where: {
|
||||
is_visible: true,
|
||||
start_datetime: { [Op.gte]: yesterday },
|
||||
placeId: places.split(',')
|
||||
...where
|
||||
},
|
||||
attributes: {
|
||||
exclude: ['createdAt', 'updatedAt']
|
||||
},
|
||||
include: [{ model: Place, attributes: ['name', 'id', 'address', 'weigth'] }]
|
||||
include: [{ model: Place, attributes: ['name', 'id', 'address'] }]
|
||||
})
|
||||
switch (type) {
|
||||
case 'feed':
|
||||
|
||||
@@ -77,7 +77,7 @@ const settingsController = {
|
||||
`https://${instance}`, callback)
|
||||
const mastodon_auth = { client_id, client_secret, access_token }
|
||||
await settingsController.set('mastodon_auth', mastodon_auth, true)
|
||||
const botController = require('./bot')
|
||||
const botController = require('./bot')
|
||||
botController.initialize()
|
||||
res.redirect('/admin')
|
||||
} catch (e) {
|
||||
|
||||
@@ -98,23 +98,24 @@ const userController = {
|
||||
defaults: { address: body.place_address } })
|
||||
.spread((place, created) => place)
|
||||
await event.setPlace(place)
|
||||
event.place = place
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
// create/assign tags
|
||||
if (body.tags) {
|
||||
await Tag.bulkCreate(body.tags.map(t => ({ tag: t })), { ignoreDuplicates: true })
|
||||
const tags = await Tag.findAll({ where: { tag: { [Op.in]: body.tags } } })
|
||||
await Promise.all(tags.map(t => t.update({weigth: Number(t.weigth)+1})))
|
||||
await event.addTags(tags)
|
||||
event.tags = tags
|
||||
}
|
||||
|
||||
if (req.user) {
|
||||
await req.user.addEvent(event)
|
||||
await event.setUser(req.user)
|
||||
}
|
||||
|
||||
// event = await Event.findByPk(event.id, { include: [Tag, Place] })
|
||||
|
||||
// send response to client
|
||||
res.json(event)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user