This commit is contained in:
كارل مبارك 2021-06-30 11:27:16 +02:00
parent 609f595293
commit b616e16ec6
4 changed files with 99 additions and 90 deletions

View file

@ -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,33 +114,53 @@ 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') {
if (
sub.widget_type &&
sub.widget_type == 'poll'
) {
className = sub.extra_data.question
emoji_code = this.toEmojiCode(className)
console.log(emoji_code)
options = sub.extra_data.options
emoji_code = this.toEmojiCode(className)
// 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) {
@ -140,10 +170,18 @@ export default {
s.type == 'vote' &&
s.key.replace('canned,', '') == options.indexOf(option)
)),
weight = votes.length > 0 ? votes
weight =
votes.length > 0
?
votes
.map(s => s.vote)
.reduce((a,b) => a + b) : 0
return { text, weight }
.reduce((a,b) => a + b)
:
0
return {
text,
weight
}
},
toEmojiCode: emoji => emoji.replace(

View file

@ -1,7 +1,5 @@
import resources from './resources'
import zulip from './zulip'
export default {
resources,
zulip
}

View file

@ -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
}

View file

@ -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({
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",