Skip to content

Commit

Permalink
feat: initial port of websocket check for online status in posts view
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Kinsey authored and Anthony Kinsey committed Jan 26, 2022
1 parent a8bf2bd commit 0653731
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/views/Posts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ import { BreadcrumbStore } from '@/composables/stores/breadcrumbs'
import BanStore from '@/composables/stores/ban'
import TrustDisplay from '@/components/trust/TrustDisplay.vue'
import Editor from '@/components/layout/Editor.vue'
import { isOnline } from '@/composables/services/websocket'
export default {
name: 'Posts',
Expand All @@ -457,6 +458,7 @@ export default {
return postsApi.byThread(params)
.then(data => next(vm => {
vm.postData.data = data
vm.checkUsersOnline()
BanStore.updateBanNotice(vm.postData.data.banned_from_board)
vm.bannedFromBoard = vm.postData.data.banned_from_board
vm.highlightPost()
Expand All @@ -476,6 +478,7 @@ export default {
threadsApi.viewed(threadId)
return postsApi.byThread(params).then(data => {
this.postData.data = data
this.checkUsersOnline()
BanStore.updateBanNotice(this.postData.data.banned_from_board)
this.bannedFromBoard = this.postData.data.banned_from_board
this.highlightPost()
Expand All @@ -500,6 +503,10 @@ export default {
}
if (params.page && params.start) delete params.page
return postsApi.byThread(params)
.then(data => {
checkUsersOnline()
return data
})
})
}
const postEditDisabled = (createdAt) => {
Expand Down Expand Up @@ -969,6 +976,23 @@ export default {
.then(processPosts)
.then(data => v.postData.data = data)
const checkUsersOnline = () => {
let uniqueUsers = {}
v.postData.data.posts.forEach(post => uniqueUsers[post.user.id] = 'user')
Object.keys(uniqueUsers).map(user => isOnline(user, setOnline))
}
const setOnline = (err, data) => {
if (err) console.log(err)
else {
v.postData.data.posts.map(post => {
if (post.user.id === data.id) {
post.user.online = data.online
}
})
}
}
/* Internal Data */
const $route = useRoute()
const $router = useRouter()
Expand Down Expand Up @@ -1060,7 +1084,8 @@ export default {
showUserControls,
watchThread,
toggleIgnoredPosts,
openMoveThreadModal
openMoveThreadModal,
checkUsersOnline
}
}
}
Expand Down

0 comments on commit 0653731

Please sign in to comment.