app
This commit is contained in:
parent
609f595293
commit
b616e16ec6
4 changed files with 99 additions and 90 deletions
|
|
@ -46,8 +46,8 @@ export default {
|
||||||
if (stream != '') {
|
if (stream != '') {
|
||||||
this.setUpDoc(stream)
|
this.setUpDoc(stream)
|
||||||
} else {
|
} else {
|
||||||
this.$store.commit('setContents', [])
|
this.$store.commit( 'setContents', [] )
|
||||||
this.$store.commit('setRules', [])
|
this.$store.commit( 'setRules', [] )
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -58,18 +58,22 @@ export default {
|
||||||
checkIfMobile: () => window.innerWidth < 700,
|
checkIfMobile: () => window.innerWidth < 700,
|
||||||
|
|
||||||
getStreams() {
|
getStreams() {
|
||||||
api.zulip
|
api
|
||||||
|
.zulip
|
||||||
.init()
|
.init()
|
||||||
.then(client => {
|
.then(client => {
|
||||||
this.zulipClient = client
|
this.zulipClient = client
|
||||||
api.zulip
|
api
|
||||||
|
.zulip
|
||||||
.getStreams(client)
|
.getStreams(client)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.$store.commit( 'setStreams',
|
this
|
||||||
|
.$store
|
||||||
|
.commit( 'setStreams',
|
||||||
result
|
result
|
||||||
.streams
|
.streams
|
||||||
.filter(
|
.filter(s =>
|
||||||
s => s.name.startsWith(this.pubStr)
|
s.name.startsWith(this.pubStr)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -78,19 +82,25 @@ export default {
|
||||||
|
|
||||||
setUpDoc(stream) {
|
setUpDoc(stream) {
|
||||||
|
|
||||||
api.zulip
|
api
|
||||||
|
.zulip
|
||||||
.getMsgs(this.zulipClient, stream, 'content')
|
.getMsgs(this.zulipClient, stream, 'content')
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.$store.commit('setContents',
|
this
|
||||||
|
.$store
|
||||||
|
.commit( 'setContents',
|
||||||
result
|
result
|
||||||
.messages
|
.messages
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
api.zulip
|
api
|
||||||
|
.zulip
|
||||||
.getMsgs(this.zulipClient, stream, 'rules')
|
.getMsgs(this.zulipClient, stream, 'rules')
|
||||||
.then(result => {
|
.then(result => {
|
||||||
this.$store.commit('setRules',
|
this
|
||||||
|
.$store
|
||||||
|
.commit( 'setRules',
|
||||||
result
|
result
|
||||||
.messages
|
.messages
|
||||||
.map(m =>
|
.map(m =>
|
||||||
|
|
@ -104,46 +114,74 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
toCSS(poll) {
|
toCSS(poll) {
|
||||||
let
|
|
||||||
className = '',
|
const
|
||||||
emoji_code = '',
|
|
||||||
options = [],
|
|
||||||
rules = [],
|
|
||||||
subs = poll
|
subs = poll
|
||||||
.submessages
|
.submessages
|
||||||
.map(s => JSON.parse(s.content))
|
.map(s => JSON.parse(s.content))
|
||||||
|
|
||||||
subs
|
let
|
||||||
.forEach(sub => {
|
className = '',
|
||||||
|
emoji_code = '',
|
||||||
|
options = [],
|
||||||
|
rules = []
|
||||||
|
|
||||||
|
subs.forEach(sub => {
|
||||||
// console.log(sub)
|
// console.log(sub)
|
||||||
if (sub.widget_type && sub.widget_type == 'poll') {
|
if (
|
||||||
className = sub.extra_data.question
|
sub.widget_type &&
|
||||||
|
sub.widget_type == 'poll'
|
||||||
|
) {
|
||||||
|
className = sub.extra_data.question
|
||||||
|
options = sub.extra_data.options
|
||||||
emoji_code = this.toEmojiCode(className)
|
emoji_code = this.toEmojiCode(className)
|
||||||
console.log(emoji_code)
|
// console.log(emoji_code)
|
||||||
options = sub.extra_data.options
|
|
||||||
if (options) {
|
if (options) {
|
||||||
options.forEach(option => {
|
options.forEach(option =>
|
||||||
rules.push(this.constructRule(option, options, subs))
|
rules
|
||||||
})
|
.push(
|
||||||
|
this.constructRule(option, options, subs)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else if (sub.type && sub.type == 'new_option') {
|
} else if (
|
||||||
rules.push(this.constructRule(sub.option, options, subs))
|
sub.type &&
|
||||||
|
sub.type == 'new_option'
|
||||||
|
) {
|
||||||
|
rules
|
||||||
|
.push(
|
||||||
|
this.constructRule(sub.option, options, subs)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { className, emoji_code, rules }
|
|
||||||
|
return {
|
||||||
|
className,
|
||||||
|
emoji_code,
|
||||||
|
rules
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
constructRule(option, options, subs) {
|
constructRule(option, options, subs) {
|
||||||
const
|
const
|
||||||
text = option,
|
text = option,
|
||||||
votes = subs.filter(s => (
|
votes = subs.filter(s => (
|
||||||
s.type == 'vote' &&
|
s.type == 'vote' &&
|
||||||
s.key.replace('canned,', '') == options.indexOf(option)
|
s.key.replace('canned,', '') == options.indexOf(option)
|
||||||
)),
|
)),
|
||||||
weight = votes.length > 0 ? votes
|
weight =
|
||||||
.map(s => s.vote)
|
votes.length > 0
|
||||||
.reduce((a,b) => a + b) : 0
|
?
|
||||||
return { text, weight }
|
votes
|
||||||
|
.map(s => s.vote)
|
||||||
|
.reduce((a,b) => a + b)
|
||||||
|
:
|
||||||
|
0
|
||||||
|
return {
|
||||||
|
text,
|
||||||
|
weight
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toEmojiCode: emoji => emoji.replace(
|
toEmojiCode: emoji => emoji.replace(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import resources from './resources'
|
|
||||||
import zulip from './zulip'
|
import zulip from './zulip'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
resources,
|
|
||||||
zulip
|
zulip
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
import axios from 'axios'
|
|
||||||
// import {
|
|
||||||
// toObject,
|
|
||||||
// sortAlphabetically,
|
|
||||||
// sortByUpdate
|
|
||||||
// } from '../utils'
|
|
||||||
|
|
||||||
const
|
|
||||||
|
|
||||||
URL = process.env.VUE_APP_API + '/',
|
|
||||||
|
|
||||||
getAll = () => {
|
|
||||||
return new Promise ((resolve, reject) => axios
|
|
||||||
.get(URL + 'resources')
|
|
||||||
.then(response =>
|
|
||||||
resolve(
|
|
||||||
response
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.catch(error =>
|
|
||||||
reject(
|
|
||||||
error
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
getTicker = () => {
|
|
||||||
return new Promise ((resolve, reject) => axios
|
|
||||||
.get(URL + 'ticker')
|
|
||||||
.then(response => resolve(
|
|
||||||
response.data
|
|
||||||
))
|
|
||||||
.catch(error => reject(
|
|
||||||
error
|
|
||||||
))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
getTicker,
|
|
||||||
getAll
|
|
||||||
}
|
|
||||||
|
|
@ -15,9 +15,11 @@ const
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
|
||||||
getStreams = (client) => ( new
|
getStreams = client => ( new
|
||||||
Promise((resolve, reject) => {
|
Promise((resolve, reject) => {
|
||||||
client.streams.retrieve()
|
client
|
||||||
|
.streams
|
||||||
|
.retrieve()
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
|
|
@ -25,7 +27,9 @@ const
|
||||||
|
|
||||||
getMsgs = (client, stream, topic, params) => ( new
|
getMsgs = (client, stream, topic, params) => ( new
|
||||||
Promise((resolve, reject) => {
|
Promise((resolve, reject) => {
|
||||||
client.messages.retrieve(params || {
|
client
|
||||||
|
.messages
|
||||||
|
.retrieve(params || {
|
||||||
anchor: "newest",
|
anchor: "newest",
|
||||||
num_before: 100,
|
num_before: 100,
|
||||||
num_after: 0,
|
num_after: 0,
|
||||||
|
|
@ -41,7 +45,8 @@ const
|
||||||
),
|
),
|
||||||
|
|
||||||
listen = client => {
|
listen = client => {
|
||||||
client.callOnEachEvent(
|
client
|
||||||
|
.callOnEachEvent(
|
||||||
event => console.log('Got Event:', event),
|
event => console.log('Got Event:', event),
|
||||||
[ 'message' ],
|
[ 'message' ],
|
||||||
[ { operator: "stream", operand: "chatty" } ]
|
[ { operator: "stream", operand: "chatty" } ]
|
||||||
|
|
@ -50,7 +55,10 @@ const
|
||||||
|
|
||||||
getSubs = client => ( new
|
getSubs = client => ( new
|
||||||
Promise((resolve, reject) => {
|
Promise((resolve, reject) => {
|
||||||
client.streams.subscriptions.retrieve()
|
client
|
||||||
|
.streams
|
||||||
|
.subscriptions
|
||||||
|
.retrieve()
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
|
|
@ -58,9 +66,15 @@ const
|
||||||
|
|
||||||
addSub = (client, stream) => ( new
|
addSub = (client, stream) => ( new
|
||||||
Promise((resolve, reject) => {
|
Promise((resolve, reject) => {
|
||||||
client.users.me.subscriptions.add({
|
client
|
||||||
subscriptions: JSON.stringify([{ name: stream }]),
|
.users
|
||||||
})
|
.me
|
||||||
|
.subscriptions
|
||||||
|
.add(
|
||||||
|
{
|
||||||
|
subscriptions: JSON.stringify([{ name: stream }]),
|
||||||
|
}
|
||||||
|
)
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
|
|
@ -68,7 +82,9 @@ const
|
||||||
|
|
||||||
sendMsg = (client, params) => ( new
|
sendMsg = (client, params) => ( new
|
||||||
Promise((resolve, reject) => {
|
Promise((resolve, reject) => {
|
||||||
client.messages.send(params || {
|
client
|
||||||
|
.messages
|
||||||
|
.send(params || {
|
||||||
to: "chatty",
|
to: "chatty",
|
||||||
type: "stream",
|
type: "stream",
|
||||||
topic: "content",
|
topic: "content",
|
||||||
|
|
@ -88,4 +104,4 @@ export default {
|
||||||
sendMsg,
|
sendMsg,
|
||||||
getSubs,
|
getSubs,
|
||||||
addSub,
|
addSub,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue