• 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

13.51
/src/socket.io/topics/unread.js
1
'use strict';
2

3
const db = require('../../database');
4✔
4
const user = require('../../user');
4✔
5
const topics = require('../../topics');
4✔
6

7
module.exports = function (SocketTopics) {
4✔
8
    SocketTopics.markAsRead = async function (socket, tids) {
4✔
9
        if (!Array.isArray(tids) || socket.uid <= 0) {
×
10
            throw new Error('[[error:invalid-data]]');
×
11
        }
12
        const hasMarked = await topics.markAsRead(tids, socket.uid);
×
13
        const promises = [topics.markTopicNotificationsRead(tids, socket.uid)];
×
14
        if (hasMarked) {
×
15
            promises.push(topics.pushUnreadCount(socket.uid));
×
16
        }
17
        await Promise.all(promises);
×
18
    };
19

20
    SocketTopics.markTopicNotificationsRead = async function (socket, tids) {
4✔
21
        if (!Array.isArray(tids) || !socket.uid) {
×
22
            throw new Error('[[error:invalid-data]]');
×
23
        }
24
        await topics.markTopicNotificationsRead(tids, socket.uid);
×
25
    };
26

27
    SocketTopics.markAllRead = async function (socket) {
4✔
28
        if (socket.uid <= 0) {
×
29
            throw new Error('[[error:invalid-uid]]');
×
30
        }
31
        await topics.markAllRead(socket.uid);
×
32
        topics.pushUnreadCount(socket.uid);
×
33
    };
34

35
    SocketTopics.markCategoryTopicsRead = async function (socket, cid) {
4✔
36
        const tids = await topics.getUnreadTids({ cid: cid, uid: socket.uid, filter: '' });
×
37
        await SocketTopics.markAsRead(socket, tids);
×
38
    };
39

40
    SocketTopics.markUnread = async function (socket, tid) {
4✔
41
        if (!tid || socket.uid <= 0) {
×
42
            throw new Error('[[error:invalid-data]]');
×
43
        }
44
        await topics.markUnread(tid, socket.uid);
×
45
        topics.pushUnreadCount(socket.uid);
×
46
    };
47

48
    SocketTopics.markAsUnreadForAll = async function (socket, tids) {
4✔
49
        if (!Array.isArray(tids)) {
×
50
            throw new Error('[[error:invalid-tid]]');
×
51
        }
52

53
        if (socket.uid <= 0) {
×
54
            throw new Error('[[error:no-privileges]]');
×
55
        }
56
        const isAdmin = await user.isAdministrator(socket.uid);
×
57
        const now = Date.now();
×
58
        await Promise.all(tids.map(async (tid) => {
×
59
            const topicData = await topics.getTopicFields(tid, ['tid', 'cid']);
×
60
            if (!topicData.tid) {
×
61
                throw new Error('[[error:no-topic]]');
×
62
            }
63
            const isMod = await user.isModerator(socket.uid, topicData.cid);
×
64
            if (!isAdmin && !isMod) {
×
65
                throw new Error('[[error:no-privileges]]');
×
66
            }
67
            await topics.markAsUnreadForAll(tid);
×
68
            await topics.updateRecent(tid, now);
×
69
            await db.sortedSetAdd(`cid:${topicData.cid}:tids:lastposttime`, now, tid);
×
70
            await topics.setTopicField(tid, 'lastposttime', now);
×
71
        }));
72
        topics.pushUnreadCount(socket.uid);
×
73
    };
74
};
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