-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
NotificationPage.qml
220 lines (193 loc) · 7.58 KB
/
NotificationPage.qml
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// SPDX-FileCopyrightText: 2021 Carl Schwan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls 2 as QQC2
import QtQuick.Layouts
import Qt.labs.qmlmodels 1.0
import org.kde.kirigami 2 as Kirigami
import org.kde.tokodon
import "./PostDelegate"
import "./StatusComposer"
Kirigami.ScrollablePage {
id: timelinePage
title: i18n("Notifications")
property var dialog: null
property alias listViewHeader: listview.header
readonly property bool typesAreGroupable: !mentionOnlyAction.checked && !followsOnlyAction.checked && !pollResultsOnlyAction.checked
property bool shouldGroupNotifications: typesAreGroupable
readonly property var currentModel: shouldGroupNotifications ? groupedNotificationModel : notificationModel
onBackRequested: if (dialog) {
dialog.close();
dialog = null;
event.accepted = true;
}
property Kirigami.Action showAllAction: Kirigami.Action {
id: showAllAction
text: i18nc("Show all notifications", "All")
icon.name: "notifications"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = [];
}
}
property Kirigami.Action mentionOnlyAction: Kirigami.Action {
id: onlyMentionAction
text: i18nc("Show only mentions", "Mentions")
icon.name: "tokodon-chat-reply"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['status', 'reblog', 'follow', 'follow_request', 'favourite', 'poll', 'update', 'admin.sign_up'];
}
}
property Kirigami.Action boostsOnlyAction: Kirigami.Action {
text: i18nc("Show only boosts", "Boosts")
icon.name: "tokodon-post-boost"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['mention', 'status', 'follow', 'follow_request', 'favourite', 'poll', 'update', 'admin.sign_up'];
}
}
property Kirigami.Action favoritesOnlyAction: Kirigami.Action {
text: i18nc("Show only favorites", "Favorites")
icon.name: "tokodon-post-favorite"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['mention', 'status', 'reblog', 'follow', 'follow_request', 'poll', 'update', 'admin.sign_up'];
}
}
property Kirigami.Action pollResultsOnlyAction: Kirigami.Action {
text: i18nc("Show only poll results", "Poll Results")
icon.name: "office-chart-bar"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['mention', 'status', 'reblog', 'follow', 'follow_request', 'favourite', 'update', 'admin.sign_up'];
}
}
property Kirigami.Action postsOnlyAction: Kirigami.Action {
text: i18nc("Show only followed statuses", "Posts")
icon.name: "user-home-symbolic"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['mention', 'reblog', 'follow', 'follow_request', 'favourite', 'poll', 'update', 'admin.sign_up'];
}
}
property Kirigami.Action followsOnlyAction: Kirigami.Action {
text: i18nc("Show only follows", "Follows")
icon.name: "list-add-user"
checkable: true
onCheckedChanged: (checked) => {
if (checked)
notificationModel.excludeTypes = ['mention', 'status', 'reblog', 'follow_request', 'favourite', 'poll', 'update', 'admin.sign_up'];
}
}
header: Kirigami.NavigationTabBar {
anchors.left: parent.left
anchors.right: parent.right
actions: [showAllAction, mentionOnlyAction, favoritesOnlyAction, boostsOnlyAction, pollResultsOnlyAction, postsOnlyAction, followsOnlyAction]
enabled: !listview.model.loading
Kirigami.Theme.colorSet: Kirigami.Theme.Window
Kirigami.Theme.inherit: false
}
NotificationModel {
id: notificationModel
}
NotificationGroupingModel {
id: groupedNotificationModel
sourceModel: notificationModel
}
Component.onCompleted: showAllAction.checked = true
ListView {
id: listview
model: timelinePage.currentModel
Connections {
target: timelinePage.currentModel
function onPostSourceReady(backend) {
const item = pageStack.layers.push("./StatusComposer/StatusComposer.qml", {
purpose: StatusComposer.Edit,
backend: backend
});
item.refreshData(); // to refresh spoiler text, etc
}
}
delegate: DelegateChooser {
role: "type"
DelegateChoice {
roleValue: Notification.Favorite
PostDelegate {
width: ListView.view.width
secondary: true
timelineModel: notificationModel
loading: listview.model.loading
showSeparator: index !== ListView.view.count - 1
showInteractionButton: false
}
}
DelegateChoice {
roleValue: Notification.Repeat
PostDelegate {
width: ListView.view.width
secondary: true
timelineModel: notificationModel
loading: listview.model.loading
showSeparator: index !== ListView.view.count - 1
showInteractionButton: false
}
}
DelegateChoice {
roleValue: Notification.Mention
PostDelegate {
width: ListView.view.width
timelineModel: notificationModel
loading: listview.model.loading
showSeparator: index !== ListView.view.count - 1
}
}
DelegateChoice {
roleValue: Notification.Follow
FollowDelegate {}
}
DelegateChoice {
roleValue: Notification.Update
PostDelegate {
width: ListView.view.width
secondary: true
timelineModel: notificationModel
loading: listview.model.loading
showSeparator: index !== ListView.view.count - 1
showInteractionButton: false
}
}
DelegateChoice {
roleValue: Notification.Poll
PostDelegate {
width: ListView.view.width
secondary: true
timelineModel: notificationModel
loading: listview.model.loading
showSeparator: index !== ListView.view.count - 1
showInteractionButton: false
}
}
DelegateChoice {
roleValue: Notification.AdminSignUp
FollowDelegate {}
}
}
QQC2.ProgressBar {
visible: listview.model.loading && listview.count === 0
anchors.centerIn: parent
indeterminate: true
}
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
text: i18n("No Notifications")
visible: listview.count === 0 && !timelinePage.currentModel.loading
}
}
}