Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscant committed Feb 10, 2020
2 parents ded4749 + 4b222a4 commit 1be1e86
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 26 deletions.
13 changes: 9 additions & 4 deletions api/BaseAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ export default class BaseAPI {

if (!status || !data) {
// We're investigating some cases, with some evidence of it happening in page unload, where we don't go
// through the exception handler, but we end up with nothing in status/data.
// through the exception handler, but we end up with nothing in status/data. Throw an exception to trigger
// a single retry.
console.log('Suspicious return from axios - perhaps cancelled?', ret)
throw new Error('Axios empty')
}
} catch (e) {
// We have seen exceptions such as "Error: timeout of 0ms exceeded". These appear to be generated by
// mobile browsers in response to network errors, and not respect the axios retrying. But the network can't
// be that bad if the Sentry reports ever get through. So do a simple extra retry here.
console.log('Axios error', e)

if (e.message.match(/.*timeout.*/i)) {
console.log('Timeout - sleep')
if (
e.message.match(/.*timeout.*/i) ||
e.message.match(/.*Axios empty.*/i)
) {
console.log('Timeout or empty - sleep')
await new Promise(resolve => setTimeout(resolve, 2000))

// Timeout. Try again. If it fails this time then we will throw another error.
console.log('Timeout - retry')
console.log('Timeout or empty - retry')
;({ status, data } = await this.$axios.request({
...config,
method,
Expand Down
10 changes: 9 additions & 1 deletion components/ChatPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ import InfiniteLoading from 'vue-infinite-loading'
import ChatBlockModal from './ChatBlockModal'
import ChatHideModal from './ChatHideModal'
import twem from '~/assets/js/twem'
import chatCollate from '@/mixins/chatCollate.js'
// Don't use dynamic imports because it stops us being able to scroll to the bottom after render.
import ChatMessage from '~/components/ChatMessage.vue'
Expand Down Expand Up @@ -238,6 +239,7 @@ export default {
ChatReportModal,
ChatRSVPModal
},
mixins: [chatCollate],
props: {
id: {
type: Number,
Expand Down Expand Up @@ -299,7 +301,9 @@ export default {
},
chatmessages() {
return this.$store.getters['chatmessages/getMessages'](this.id)
return this.chatCollate(
this.$store.getters['chatmessages/getMessages'](this.id)
)
},
chatusers() {
Expand Down Expand Up @@ -625,11 +629,15 @@ export default {
this.$store.dispatch('chats/hide', {
id: this.id
})
this.$router.push('/chats')
},
block() {
this.$store.dispatch('chats/block', {
id: this.id
})
this.$router.push('/chats')
},
report() {
this.$refs.chatreport.show()
Expand Down
6 changes: 5 additions & 1 deletion components/ChatPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ import twem from '~/assets/js/twem'
// Don't use dynamic imports because it stops us being able to scroll to the bottom after render.
import ChatMessage from '~/components/ChatMessage.vue'
import chatCollate from '@/mixins/chatCollate.js'
Vue.use(TooltipPlugin)
const VueDraggableResizable = () => import('vue-draggable-resizable')
Expand All @@ -225,6 +226,7 @@ export default {
AvailabilityModal,
AddressModal
},
mixins: [chatCollate],
props: {
id: {
type: Number,
Expand Down Expand Up @@ -291,7 +293,9 @@ export default {
},
chatmessages() {
return this.$store.getters['chatmessages/getMessages'](this.id)
return this.chatCollate(
this.$store.getters['chatmessages/getMessages'](this.id)
)
},
chatusers() {
Expand Down
7 changes: 6 additions & 1 deletion components/DraggableMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export default {
created() {
this.zoom = this.initialZoom
},
async mounted() {},
mounted() {
setTimeout(() => {
// This fixes a problem where the map displays grey when you reopen the modal.
window.google.maps.event.trigger(this.$refs.gmap.$mapObject, 'resize')
}, 1000)
},
methods: {
zoomChanged: function(zoom) {
Expand Down
3 changes: 1 addition & 2 deletions components/MyMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
</b-list-group-item>
<b-list-group-item v-else-if="message.type === 'Wanted' && !received">
<b-btn variant="success" class="d-inline mr-1" @click="outcome('Received')">
<v-icon name="check" /> Mark as Received
<v-icon name="check" /> Mark as RECEIVED
</b-btn>
</b-list-group-item>
<b-list-group-item v-if="!taken && !received && !withdrawn">
Expand Down Expand Up @@ -369,7 +369,6 @@ export default {
return unseen
},
outcome(type) {
console.log('Show outcome', type)
this.$refs.outcomeModal.show(type)
},
share() {
Expand Down
2 changes: 1 addition & 1 deletion components/NewsAboutMe.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<NewsUserIntro v-if="userid" :userid="userid" :users="users" :newsfeed="newsfeed" append="introduced themselves" />
<span v-if="newsfeed.message" class="font-weight-bold prewrap forcebreak">{{ emessage }}</span>
<read-more v-if="newsfeed.message && emessage" :text="emessage" :max-chars="1024" class="font-weight-bold prewrap forcebreak nopara" />
<div>
<b-row v-if="newsfeed.image">
<b-col>
Expand Down
25 changes: 10 additions & 15 deletions components/OutcomeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
</b-row>
<b-row>
<b-col>
<b-select v-model="type" class="font-weight-bold" @change="changeType">
<option value="Taken">
Taken by
</option>
<option value="Received">
Received from
</option>
<option value="Withdrawn">
<span class="font-weight-bold align-middle">
<span v-if="type === 'Taken'">
Taken by:
</span>
<span v-if="type === 'Received'">
Received from:
</span>
<span v-if="type === 'Withdrawn'">
Withdrawn
</option>
</b-select>
</span>
</span>
</b-col>
<b-col>
<b-select
Expand Down Expand Up @@ -209,11 +209,6 @@ export default {
this.showModal = false
},
changeType() {
this.selectedUser = -1
this.setComments()
},
async fetchUser(userid) {
if (userid) {
await this.$store.dispatch('user/fetch', {
Expand Down
2 changes: 1 addition & 1 deletion components/PosterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<b-input
v-model="name"
placeholder="Where is it? E.g. village green, supermarket, name of cafe..."
:size="60"
size="60"
maxlength="60"
spellcheck="true"
class="mb-1"
Expand Down
49 changes: 49 additions & 0 deletions mixins/chatCollate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export default {
methods: {
chatCollate(msgs) {
const ret = []
let last = ''

for (let i = 0; i < msgs.length; i++) {
// console.log(
// 'Collate consider',
// i + 1 < msgs.length,
// msgs[i].sameasnext,
// msgs[i].message,
// i + 1 < msgs.length ? msgs[i + 1].message : null,
// new Date(msgs[i].date).getTime(),
// i + 1 < msgs.length ? new Date(msgs[i + 1].date).getTime() : null,
// i + 1 < msgs.length
// ? new Date(msgs[i + 1].date).getTime() -
// new Date(msgs[i].date).getTime()
// : null,
// msgs[i],
// i + 1 < msgs.length ? msgs[i + 1] : null
// )
//
if (
i + 1 < msgs.length &&
msgs[i].sameasnext &&
msgs[i].message &&
msgs[i + 1].message &&
new Date(msgs[i + 1].date).getTime() -
new Date(msgs[i].date).getTime() <
10 * 60 * 1000
) {
// The next message is within from the same user, within ten minutes. Collate.
last += '\n' + msgs[i].message
} else if (last) {
// We have collated text to pull in. Need to avoid references.
const thisone = JSON.parse(JSON.stringify(msgs[i]))
thisone.message = last + '\n' + msgs[i].message
ret.push(thisone)
last = ''
} else {
ret.push(msgs[i])
}
}

return ret
}
}
}
21 changes: 21 additions & 0 deletions pages/find/whatisit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</li>
</ul>
<div class="d-flex justify-content-end ml-1 mr-1">
<b-btn v-if="ids.length === 1 && notblank" variant="white" class="mr-1" @click="deleteItem">
<v-icon name="trash-alt" />&nbsp;Clear item
</b-btn>
<b-btn v-if="ids.length > 1" variant="white" class="mr-1" @click="deleteItem">
<v-icon name="trash-alt" />&nbsp;Delete item
</b-btn>
Expand Down Expand Up @@ -83,6 +86,24 @@ export default {
return {}
},
computed: {
notblank() {
let ret = false
const messages = Object.values(this.$store.getters['compose/getMessages'])
if (messages && messages.length > 0) {
const message = messages[0]
const atts = Object.values(
this.$store.getters['compose/getAttachments'](message.id)
)
ret =
(message.item && message.item.trim()) ||
(message.description && message.description.trim()) ||
atts.length
}
return ret
},
uploadingPhoto() {
return this.$store.getters['compose/getUploading']
},
Expand Down
21 changes: 21 additions & 0 deletions pages/give/whatisit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
</li>
</ul>
<div class="d-flex justify-content-end ml-1 mr-1">
<b-btn v-if="ids.length === 1 && notblank" variant="white" class="mr-1" @click="deleteItem">
<v-icon name="trash-alt" />&nbsp;Clear item
</b-btn>
<b-btn v-if="ids.length > 1" variant="white" class="mr-1" @click="deleteItem">
<v-icon name="trash-alt" />&nbsp;Delete last item
</b-btn>
Expand Down Expand Up @@ -83,6 +86,24 @@ export default {
return {}
},
computed: {
notblank() {
let ret = false
const messages = Object.values(this.$store.getters['compose/getMessages'])
if (messages && messages.length > 0) {
const message = messages[0]
const atts = Object.values(
this.$store.getters['compose/getAttachments'](message.id)
)
ret =
(message.item && message.item.trim()) ||
(message.description && message.description.trim()) ||
atts.length
}
return ret
},
uploadingPhoto() {
return this.$store.getters['compose/getUploading']
},
Expand Down

0 comments on commit 1be1e86

Please sign in to comment.