mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-16 18:29:08 +00:00
v2: init -- UI is nuked from orbit, major app restructuring
This commit is contained in:
parent
c6f5b55c1c
commit
b8da886601
108 changed files with 6717 additions and 17430 deletions
72
services/presentation.js
Normal file
72
services/presentation.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
const Service = require('./Service')
|
||||
const LRU = require('lru-cache')
|
||||
|
||||
class PresentationService extends Service {
|
||||
constructor (ctx) {
|
||||
super(ctx)
|
||||
this.M = ctx.M
|
||||
this.discord = ctx.discord
|
||||
|
||||
this.cache = new LRU({ max: 500, maxAge: 100 * 60 * 5 })
|
||||
}
|
||||
|
||||
serverSlug (server) {
|
||||
return {
|
||||
id: server.id,
|
||||
name: server.name,
|
||||
ownerID: server.ownerID,
|
||||
icon: server.icon
|
||||
}
|
||||
}
|
||||
|
||||
async oldPresentableServers (collection, userId) {
|
||||
let servers = []
|
||||
|
||||
for (let server of collection.array()) {
|
||||
const gm = server.members.get(userId)
|
||||
|
||||
servers.push(await this.presentableServer(server, gm))
|
||||
}
|
||||
|
||||
return servers
|
||||
}
|
||||
|
||||
async presentableServers (collection, userId) {
|
||||
return collection.array().areduce(async (acc, server) => {
|
||||
const gm = server.members.get(userId)
|
||||
acc.push(await this.presentableServer(server, gm, { incRoles: false }))
|
||||
return acc
|
||||
})
|
||||
}
|
||||
|
||||
async presentableServer (server, gm, { incRoles = true } = {}) {
|
||||
const sd = await this.ctx.server.get(server.id)
|
||||
|
||||
return {
|
||||
id: server.id,
|
||||
gm: {
|
||||
nickname: gm.nickname,
|
||||
color: gm.displayHexColor
|
||||
},
|
||||
server: this.serverSlug(server),
|
||||
roles: (incRoles) ? (await this.rolesByServer(server, sd)).map(r => ({ ...r, selected: gm.roles.has(r.id) })) : [],
|
||||
message: sd.message,
|
||||
categories: sd.categories,
|
||||
perms: this.discord.getPermissions(gm)
|
||||
}
|
||||
}
|
||||
|
||||
async rolesByServer (server) {
|
||||
return server.roles
|
||||
.filter(r => r.id !== server.id) // get rid of @everyone
|
||||
.map(r => ({
|
||||
id: r.id,
|
||||
color: r.color,
|
||||
name: r.name,
|
||||
position: r.position,
|
||||
safe: this.discord.safeRole(server.id, r.id)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PresentationService
|
Loading…
Add table
Add a link
Reference in a new issue