• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CMU-17313Q / fall23-nodebb-inshallah-a / 6239420468

19 Sep 2023 06:18PM UTC coverage: 77.199% (+0.01%) from 77.188%
6239420468

push

github

web-flow
Merge pull request #59 from CMU-17313Q/Adding-isAnonymous-if-conditions

Adding is anonymous if conditions

9091 of 13356 branches covered (0.0%)

Branch coverage included in aggregate %.

20876 of 25462 relevant lines covered (81.99%)

2463.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.7
/src/topics/merge.js
1
'use strict';
2

3
const plugins = require('../plugins');
20✔
4
const posts = require('../posts');
20✔
5

6
module.exports = function (Topics) {
20✔
7
    Topics.merge = async function (tids, uid, options) {
20✔
8
        options = options || {};
×
9

10
        const topicsData = await Topics.getTopicsFields(tids, ['scheduled']);
×
11
        if (topicsData.some(t => t.scheduled)) {
×
12
            throw new Error('[[error:cant-merge-scheduled]]');
×
13
        }
14

15
        const oldestTid = findOldestTopic(tids);
×
16
        let mergeIntoTid = oldestTid;
×
17
        if (options.mainTid) {
×
18
            mergeIntoTid = options.mainTid;
×
19
        } else if (options.newTopicTitle) {
×
20
            mergeIntoTid = await createNewTopic(options.newTopicTitle, oldestTid);
×
21
        }
22

23
        const otherTids = tids.sort((a, b) => a - b)
×
24
            .filter(tid => tid && parseInt(tid, 10) !== parseInt(mergeIntoTid, 10));
×
25

26
        for (const tid of otherTids) {
×
27
            /* eslint-disable no-await-in-loop */
28
            const pids = await Topics.getPids(tid);
×
29
            for (const pid of pids) {
×
30
                await Topics.movePostToTopic(uid, pid, mergeIntoTid);
×
31
            }
32

33
            await Topics.setTopicField(tid, 'mainPid', 0);
×
34
            await Topics.delete(tid, uid);
×
35
            await Topics.setTopicFields(tid, {
×
36
                mergeIntoTid: mergeIntoTid,
37
                mergerUid: uid,
38
                mergedTimestamp: Date.now(),
39
            });
40
        }
41

42
        await Promise.all([
×
43
            posts.updateQueuedPostsTopic(mergeIntoTid, otherTids),
44
            updateViewCount(mergeIntoTid, tids),
45
        ]);
46

47
        plugins.hooks.fire('action:topic.merge', {
×
48
            uid: uid,
49
            tids: tids,
50
            mergeIntoTid: mergeIntoTid,
51
            otherTids: otherTids,
52
        });
53
        return mergeIntoTid;
×
54
    };
55

56
    async function createNewTopic(title, oldestTid) {
57
        const topicData = await Topics.getTopicFields(oldestTid, ['uid', 'cid']);
×
58
        const params = {
×
59
            uid: topicData.uid,
60
            cid: topicData.cid,
61
            title: title,
62
        };
63
        const result = await plugins.hooks.fire('filter:topic.mergeCreateNewTopic', {
×
64
            oldestTid: oldestTid,
65
            params: params,
66
        });
67
        const tid = await Topics.create(result.params);
×
68
        return tid;
×
69
    }
70

71
    async function updateViewCount(mergeIntoTid, tids) {
72
        const topicData = await Topics.getTopicsFields(tids, ['viewcount']);
×
73
        const totalViewCount = topicData.reduce(
×
74
            (count, topic) => count + parseInt(topic.viewcount, 10), 0
×
75
        );
76
        await Topics.setTopicField(mergeIntoTid, 'viewcount', totalViewCount);
×
77
    }
78

79
    function findOldestTopic(tids) {
80
        return Math.min.apply(null, tids);
×
81
    }
82
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc