finish redux feature parity

This commit is contained in:
41666 2017-12-16 17:39:53 -06:00
parent f5220aa6dc
commit 5510d5a1c4
29 changed files with 220 additions and 100 deletions

View file

@ -15,6 +15,7 @@ class DiscordService extends Service {
this.client = new discord.Client()
this.startBot()
}
async startBot () {
@ -25,42 +26,12 @@ class DiscordService extends Service {
return this.client.guilds.filter((g) => g.members.has(userId))
}
presentableServers (collection, userId) {
return collection.map((server) => {
const gm = server.members.get(userId)
return {
id: server.id,
gm: {
nickname: gm.nickname,
color: gm.displayHexColor
},
server: {
id: server.id,
name: server.name,
ownerID: server.ownerID,
icon: server.icon
},
roles: this.presentableRoles(server.id, gm),
message: 'moe moe kyuuuuuuuuun~',
perms: this.getPermissions(gm)
}
})
gm (serverId, userId) {
return this.client.guilds.get(serverId).members.get(userId)
}
presentableRoles (serverId, gm) {
return this.client.guilds
.get(serverId)
.roles
.filter(r => r.id !== serverId)
.map((role) => ({
color: role.hexColor,
position: role.position,
calculatedPosition: role.calculatedPosition,
id: role.id,
name: role.name,
selected: gm.roles.has(role.id)
}))
getRoles (server) {
return this.client.guilds.get(server).roles
}
getPermissions (gm) {

View file

@ -0,0 +1,49 @@
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 = LRU({ max: 500, maxAge: 100 * 60 * 5 })
}
oldPresentableServers (collection, userId) {
return collection.map((server) => {
const gm = server.members.get(userId)
return {
id: server.id,
gm: {
nickname: gm.nickname,
color: gm.displayHexColor
},
server: {
id: server.id,
name: server.name,
ownerID: server.ownerID,
icon: server.icon
},
roles: server.roles.filter(r => r.id !== server.id).map(r => ({
id: r.id,
color: r.color,
name: r.name,
selected: gm.roles.has(r.id),
position: r.position
})),
message: 'moe moe kyuuuuuuuuun~',
perms: this.discord.getPermissions(gm)
}
})
}
rolesByServer (serverId, userId) {
// get from discord, merge with server categories
}
}
module.exports = PresentationService

42
Server/services/server.js Normal file
View file

@ -0,0 +1,42 @@
const Service = require('./Service')
class ServerService extends Service {
constructor (ctx) {
super(ctx)
this.Server = ctx.M.Server
this.P = ctx.P
}
async ensure (server) {
const srv = await this.get(server.id)
if (srv == null) {
return this.create({
id: server.id,
message: '',
categories: {}
})
}
}
create ({ id, message, categories }) {
const srv = this.Server.build({ id, message, categories })
return srv.save()
}
update (id, newData) {
const srv = this.get(id)
return srv.update(newData)
}
get (id) {
return this.Server.findOne({
where: {
id
}
})
}
}
module.exports = ServerService