Exemplo n.º 1
0
 render: h => h(IssueVote, {
   props: {
     issue: factories.makeIssue({
       createdAt: subHours(new Date(), 2000),
       topic: 'Just some random thought',
       votings: [
         factories.makeVoting({
           acceptedOption: null,
           expiresAt: addHours(new Date(), 150),
         }),
         factories.makeVoting({
           acceptedOption: 73,
           expiresAt: subHours(new Date(), 150),
           options: [
             factories.makeOption({
               type: 'remove_user',
               meanScore: 0,
             }),
             factories.makeOption({
               type: 'further_discussion',
               meanScore: 0.4,
             }),
             factories.makeOption({
               id: 73,
               type: 'no_change',
               meanScore: 1.4,
             }),
           ],
         }),
       ],
     }),
   },
 }),
Exemplo n.º 2
0
export const makeHistory = data => {
  return {
    id: historyIdCnt++,
    date: subHours(new Date(), 26),
    typus: 'GROUP_CHANGE_PHOTO',
    group: makeGroup(),
    users: [ 222 ],
    store: null,
    message: 'Changed the group picture',
    ...data,
  }
}
Exemplo n.º 3
0
    const updateThreads = async (freshThreads = false, freshMarkedPosts = false, includeNewThreads = false) => {
        // fresh chatty load from server
        let {threads: nextThreads} = freshThreads ? await getChatty() : {}

        // process marked posts if needed
        let markedPosts
        if (freshMarkedPosts) markedPosts = await getMarkedPosts(freshMarkedPosts)

        // compile new thread state
        nextThreads = nextThreads || chatty.threads

        // only add in new threads when needed
        nextThreads = includeNewThreads ? chatty.newThreads.concat(nextThreads) : nextThreads
        let nextNewThreads = includeNewThreads ? [] : chatty.newThreads

        // if we're loading marked posts, process the data
        if (markedPosts) {
            const markedPostsById = markedPosts
                .reduce((acc, post) => ({
                    ...acc,
                    [post.id]: post.type
                }), {})

            // update post markings
            nextThreads = nextThreads
                .map(thread => ({
                    ...thread,
                    markType: markedPostsById[thread.threadId] || 'unmarked'
                }))
        }

        // order by recent activity
        let maxPostIdByThread = nextThreads
            .reduce((acc, thread) => {
                acc[thread.threadId] = thread.posts.reduce((acc, post) => Math.max(post.id, acc), 0)
                return acc
            }, {})

        // remove expired threads
        const expireDate = subHours(Date.now(), 18)
        nextThreads = nextThreads.filter(thread => {
            const threadId = +thread.threadId
            const post = thread.posts.find(post => post.id === threadId)
            return isBefore(expireDate, post.date)
        })

        // sort by activity, pinned first
        nextThreads = nextThreads
            .sort((a, b) => maxPostIdByThread[b.threadId] - maxPostIdByThread[a.threadId])
            .sort((a, b) => a.markType === 'pinned' ? -1 : (b.markType === 'pinned' ? 1 : 0))

        // update state to trigger render
        setChatty({
            threads: nextThreads,
            newThreads: nextNewThreads
        })

        // clean up any old posts after loading, doesn't impact state
        if (markedPosts) {
            let ids = markedPosts
                .filter(post => !maxPostIdByThread[post.id])
                .map(({id}) => id)
            if (ids.length) {
                try {
                    await fetchJson('clientData/markPost', {
                        method: 'POST',
                        body: {username, postId: ids.join(','), type: 'unmarked'}
                    })
                } catch (ex) {
                    console.error('Error unmarking old posts.', ex)
                }
            }
        }
    }