From e5dbd6aaa82947d2686691205bb44a25f54581a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=83=D8=A7=D8=B1=D9=84=20=D9=85=D8=A8=D8=A7=D8=B1=D9=83?= Date: Fri, 23 Jul 2021 21:27:52 +0200 Subject: [PATCH] now it checks for _PUB_ ind escription instrad of looking through topics, cleanned up logs, streaams have slugs (for rotuting and classes) --- front/src/App.vue | 35 ++++++++++++++++--------- front/src/components/Content/index.vue | 6 +++-- front/src/components/Streams/Stream.vue | 2 +- front/src/store/index.js | 10 +++---- front/src/views/Home.vue | 2 +- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/front/src/App.vue b/front/src/App.vue index e6e5721..61fe9a5 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -50,11 +50,22 @@ export default { if (to.path !== from.path) { this.$store.commit("setTopics", []); this.$store.commit("setRules", []); - this.$store.commit("setCurStream", to.path.replace("/", "")); - if (this.currentStream != "" - && this.streams.find(s => s.name == this.currentStream) + this.$store.commit("setCurStream", { + name: to.path.replace('/', '').replaceAll('_', ' '), + slug: to.path.replace('/', '').replaceAll(' ', '_') + }); + if ( + this.currentStream.slug != "" + && + this.streams.find(s => + s.name == this.currentStream.name && + s.slug == this.currentStream.slug + ) ) { + console.log('found stream') this.setUpDoc(this.currentStream); + } else { + console.log('stream does not exist') } } }); @@ -67,15 +78,15 @@ export default { return new Promise(resolve => { api.zulip.init().then((client) => { this.zulipClient = client; - api.zulip.getStreams(client).then(async (streams) => { - for (let stream of streams) { - stream.topics = await api.zulip.getTopics(client, stream.stream_id) + api.zulip.getStreams(client).then(streams => { + for (const stream of streams) { + stream.slug = stream.name.replaceAll(' ', '_') } this.$store.commit( "setStreams", streams.filter((s) => ( - s.topics.find(t => t.name == 'rules') || - s.name.startsWith(this.pubStr) + s.name.startsWith(this.pubStr) || + s.description.includes('_PUB_') )) ); resolve() @@ -88,13 +99,13 @@ export default { setUpDoc(stream) { api.zulip.getSubs(this.zulipClient).then((result) => { if ( - !result.subscriptions.map((s) => s.name).includes(this.currentStream) + !result.subscriptions.map((s) => s.name).includes(this.currentStream.name) ) { - api.zulip.addSub(this.zulipClient, this.currentStream); + api.zulip.addSub(this.zulipClient, this.currentStream.name); } }); - api.zulip.getAllMsgs(this.zulipClient, stream).then((result) => { + api.zulip.getAllMsgs(this.zulipClient, stream.name).then((result) => { for (let m = 0; m < result.messages.length; m++) { const message = result.messages[m]; if (message.subject == "rules") { @@ -107,7 +118,7 @@ export default { }, eventHandler(event) { - console.log(event); + console.log('event:', event); switch (event.type) { case "message": switch (event.message.subject) { diff --git a/front/src/components/Content/index.vue b/front/src/components/Content/index.vue index bdfeec6..06d6a2a 100644 --- a/front/src/components/Content/index.vue +++ b/front/src/components/Content/index.vue @@ -37,8 +37,10 @@ export default { ...mapState(["currentStream", "streams"]), ...mapGetters(["sortedTopics"]), title() { - return this.streams.find((s) => s.name == this.currentStream) - ? this.currentStream.replace("pub-", "") + return this.streams.find((s) => s.name == this.currentStream.name) + ? this.currentStream.name + : this.$route.path == '/' + ? "<= pick a stream" : "Stream does not exist."; }, }, diff --git a/front/src/components/Streams/Stream.vue b/front/src/components/Streams/Stream.vue index 1f21d96..0377d98 100644 --- a/front/src/components/Streams/Stream.vue +++ b/front/src/components/Streams/Stream.vue @@ -1,7 +1,7 @@