mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-07 06:53:09 -06:00
Feature - unread count (#14)
* Pass unread count even when pusher format is event_id_only * Count distinct roomID in select contifications count * Fix notifications tests
This commit is contained in:
parent
1214c6137a
commit
8f9c0901a5
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
|
|
@ -1,3 +1,9 @@
|
||||||
{
|
{
|
||||||
"go.lintTool": "golangci-lint"
|
"go.lintTool": "golangci-lint",
|
||||||
|
"go.testEnvVars": {
|
||||||
|
"POSTGRES_HOST": "localhost",
|
||||||
|
"POSTGRES_USER": "postgres",
|
||||||
|
"POSTGRES_PASSWORD": "foobar",
|
||||||
|
"POSTGRES_DB": "postgres"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -529,7 +529,9 @@ func (s *OutputStreamEventConsumer) notifyHTTP(ctx context.Context, event *gomat
|
||||||
case "event_id_only":
|
case "event_id_only":
|
||||||
req = pushgateway.NotifyRequest{
|
req = pushgateway.NotifyRequest{
|
||||||
Notification: pushgateway.Notification{
|
Notification: pushgateway.Notification{
|
||||||
Counts: &pushgateway.Counts{},
|
Counts: &pushgateway.Counts{
|
||||||
|
Unread: userNumUnreadNotifs,
|
||||||
|
},
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
EventID: event.EventID(),
|
EventID: event.EventID(),
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID(),
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ const selectNotificationSQL = "" +
|
||||||
") AND NOT read ORDER BY localpart, id LIMIT $4"
|
") AND NOT read ORDER BY localpart, id LIMIT $4"
|
||||||
|
|
||||||
const selectNotificationCountSQL = "" +
|
const selectNotificationCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM userapi_notifications WHERE localpart = $1 AND (" +
|
"SELECT COUNT(DISTINCT(room_id)) FROM userapi_notifications WHERE localpart = $1 AND (" +
|
||||||
"(($2 & 1) <> 0 AND highlight) OR (($2 & 2) <> 0 AND NOT highlight)" +
|
"(($2 & 1) <> 0 AND highlight) OR (($2 & 2) <> 0 AND NOT highlight)" +
|
||||||
") AND NOT read"
|
") AND NOT read"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ const selectNotificationSQL = "" +
|
||||||
") AND NOT read ORDER BY localpart, id LIMIT $4"
|
") AND NOT read ORDER BY localpart, id LIMIT $4"
|
||||||
|
|
||||||
const selectNotificationCountSQL = "" +
|
const selectNotificationCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM userapi_notifications WHERE localpart = $1 AND (" +
|
"SELECT COUNT(DISTINCT(room_id)) FROM userapi_notifications WHERE localpart = $1 AND (" +
|
||||||
"(($2 & 1) <> 0 AND highlight) OR (($2 & 2) <> 0 AND NOT highlight)" +
|
"(($2 & 1) <> 0 AND highlight) OR (($2 & 2) <> 0 AND NOT highlight)" +
|
||||||
") AND NOT read"
|
") AND NOT read"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,7 @@ func Test_Notification(t *testing.T) {
|
||||||
// get notifications
|
// get notifications
|
||||||
count, err := db.GetNotificationCount(ctx, aliceLocalpart, tables.AllNotifications)
|
count, err := db.GetNotificationCount(ctx, aliceLocalpart, tables.AllNotifications)
|
||||||
assert.NoError(t, err, "unable to get notification count")
|
assert.NoError(t, err, "unable to get notification count")
|
||||||
assert.Equal(t, int64(10), count)
|
assert.Equal(t, int64(2), count)
|
||||||
notifs, count, err := db.GetNotifications(ctx, aliceLocalpart, 0, 15, tables.AllNotifications)
|
notifs, count, err := db.GetNotifications(ctx, aliceLocalpart, 0, 15, tables.AllNotifications)
|
||||||
assert.NoError(t, err, "unable to get notifications")
|
assert.NoError(t, err, "unable to get notifications")
|
||||||
assert.Equal(t, int64(10), count)
|
assert.Equal(t, int64(10), count)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue