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