This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
channel.js
147 lines (130 loc) · 3.7 KB
/
channel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {combineReducers} from 'redux';
import {ChannelTypes, PostTypes, UserTypes} from 'mattermost-redux/action_types';
import {ActionTypes, Constants, NotificationLevels} from 'utils/constants';
function postVisibility(state = {}, action) {
switch (action.type) {
case ChannelTypes.SELECT_CHANNEL: {
const nextState = {...state};
nextState[action.data] = Constants.POST_CHUNK_SIZE / 2;
return nextState;
}
case ActionTypes.INCREASE_POST_VISIBILITY: {
const nextState = {...state};
nextState[action.data] += action.amount;
return nextState;
}
case ActionTypes.RECEIVED_FOCUSED_POST: {
const nextState = {...state};
nextState[action.channelId] = Constants.POST_CHUNK_SIZE / 2;
return nextState;
}
case PostTypes.RECEIVED_NEW_POST: {
if (action.data && state[action.data.channel_id]) {
const nextState = {...state};
nextState[action.data.channel_id] += 1;
return nextState;
}
return state;
}
default:
return state;
}
}
function lastChannelViewTime(state = {}, action) {
switch (action.type) {
case ActionTypes.SELECT_CHANNEL_WITH_MEMBER: {
if (action.member) {
const nextState = {...state};
nextState[action.data] = action.member.last_viewed_at;
return nextState;
}
return state;
}
default:
return state;
}
}
function loadingPosts(state = {}, action) {
switch (action.type) {
case ActionTypes.LOADING_POSTS: {
const nextState = {...state};
nextState[action.channelId] = action.data;
return nextState;
}
default:
return state;
}
}
function focusedPostId(state = '', action) {
switch (action.type) {
case ActionTypes.RECEIVED_FOCUSED_POST:
return action.data;
case ChannelTypes.SELECT_CHANNEL:
return '';
default:
return state;
}
}
function mobileView(state = false, action) {
switch (action.type) {
case ActionTypes.UPDATE_MOBILE_VIEW:
return action.data;
default:
return state;
}
}
function keepChannelIdAsUnread(state = null, action) {
switch (action.type) {
case ActionTypes.SELECT_CHANNEL_WITH_MEMBER: {
const member = action.member;
const channel = action.channel;
if (!member || !channel) {
return state;
}
const msgCount = channel.total_msg_count - member.msg_count;
const hadMentions = member.mention_count > 0;
const hadUnreads = member.notify_props && member.notify_props.mark_unread !== NotificationLevels.MENTION && msgCount > 0;
if (hadMentions || hadUnreads) {
return {
id: member.channel_id,
hadMentions,
};
}
return null;
}
case ActionTypes.RECEIVED_FOCUSED_POST: {
if (state && action.channelId !== state.id) {
return null;
}
return state;
}
case UserTypes.LOGOUT_SUCCESS:
return null;
default:
return state;
}
}
function lastGetPosts(state = {}, action) {
switch (action.type) {
case ActionTypes.RECEIVED_POSTS_FOR_CHANNEL_AT_TIME:
return {
...state,
[action.channelId]: action.time,
};
case UserTypes.LOGOUT_SUCCESS:
return {};
default:
return state;
}
}
export default combineReducers({
postVisibility,
lastChannelViewTime,
loadingPosts,
focusedPostId,
mobileView,
keepChannelIdAsUnread,
lastGetPosts,
});