Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
b02ef837
Commit
b02ef837
authored
May 31, 2023
by
benjamin
Browse files
Options
Downloads
Patches
Plain Diff
fixed notifications callbacks
parent
b86435db
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!617
Project/haven beta
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
notifications/manager.go
+5
-2
5 additions, 2 deletions
notifications/manager.go
notifications/manager_test.go
+9
-1
9 additions, 1 deletion
notifications/manager_test.go
notifications/notifications.go
+21
-1
21 additions, 1 deletion
notifications/notifications.go
with
35 additions
and
4 deletions
notifications/manager.go
+
5
−
2
View file @
b02ef837
...
...
@@ -308,10 +308,11 @@ func (m *manager) addToGroupUnsafeRAM(nID *id.ID, reg registration) {
// deleteNotificationUnsafeRAM removes the given notification registration from
// the in ram storage, both to notification and groups
// must be called under the lock
func
(
m
*
manager
)
deleteNotificationUnsafeRAM
(
nid
*
id
.
ID
)
{
// returns the group becasue it may be nesseary
func
(
m
*
manager
)
deleteNotificationUnsafeRAM
(
nid
*
id
.
ID
)
string
{
reg
,
exists
:=
m
.
notifications
[
*
nid
]
if
!
exists
{
return
return
""
}
groupList
:=
m
.
group
[
reg
.
Group
]
...
...
@@ -323,6 +324,8 @@ func (m *manager) deleteNotificationUnsafeRAM(nid *id.ID) {
}
delete
(
m
.
notifications
,
*
nid
)
return
reg
.
Group
}
// setTokenUnsafe sets the token in ram and on disk, locally only. Returns true
...
...
This diff is collapsed.
Click to expand it.
notifications/manager_test.go
+
9
−
1
View file @
b02ef837
...
...
@@ -426,6 +426,7 @@ func TestManager_maxStateUpdate(t *testing.T) {
var
setMax
NotificationState
skip
:=
true
for
i
:=
0
;
i
<
numGroups
;
i
++
{
groupName
:=
fmt
.
Sprintf
(
"grp_%d"
,
i
)
nid
:=
id
.
NewIdFromUInt
(
uint64
(
i
),
id
.
User
,
t
)
...
...
@@ -434,6 +435,9 @@ func TestManager_maxStateUpdate(t *testing.T) {
localI
:=
i
cb
:=
func
(
group
Group
,
created
,
edits
,
deletions
[]
*
id
.
ID
,
maxState
NotificationState
)
{
if
skip
{
return
}
if
created
!=
nil
||
edits
!=
nil
||
deletions
!=
nil
{
t
.
Errorf
(
"actions are not nil"
)
}
...
...
@@ -448,6 +452,7 @@ func TestManager_maxStateUpdate(t *testing.T) {
}
m
.
Set
(
nid
,
groupName
,
[]
byte
{
0
},
NotificationState
(
i
%
3
))
}
skip
=
false
for
i
:=
Mute
;
i
<=
Push
;
i
++
{
setMax
=
i
...
...
@@ -623,10 +628,13 @@ func TestManager_deleteNotificationUnsafeRAM(t *testing.T) {
// some groups and partially from other
for
i
:=
0
;
i
<
numTests
;
i
++
{
if
(
i
%
2
)
==
1
||
i
<
numTests
/
2
{
mInternal
.
deleteNotificationUnsafeRAM
(
nids
[
i
])
grp
:=
mInternal
.
deleteNotificationUnsafeRAM
(
nids
[
i
])
if
_
,
exists
:=
mInternal
.
notifications
[
*
nids
[
i
]];
exists
{
t
.
Errorf
(
"Failed to delete %s"
,
nids
[
i
])
}
if
grp
!=
regs
[
i
]
.
Group
{
t
.
Errorf
(
"group does not match, %s vs %s"
,
grp
,
regs
[
i
]
.
Group
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
notifications/notifications.go
+
21
−
1
View file @
b02ef837
...
...
@@ -63,6 +63,19 @@ func (m *manager) Set(toBeNotifiedOn *id.ID, group string, metadata []byte,
// update in ram storage
m
.
upsertNotificationUnsafeRAM
(
toBeNotifiedOn
,
reg
)
// call the callback if it exists to notify that an update exists
if
cb
,
cbExists
:=
m
.
callbacks
[
group
];
cbExists
{
// can be nil if the last element was deleted
g
,
_
:=
m
.
group
[
group
]
var
created
,
updated
[]
*
id
.
ID
if
exists
{
updated
=
[]
*
id
.
ID
{
toBeNotifiedOn
}
}
else
{
created
=
[]
*
id
.
ID
{
toBeNotifiedOn
}
}
go
cb
(
g
.
DeepCopy
(),
created
,
updated
,
nil
,
m
.
maxState
)
}
return
nil
}
...
...
@@ -97,7 +110,14 @@ func (m *manager) Delete(toBeNotifiedOn *id.ID) error {
_
,
err
:=
m
.
remote
.
DeleteMapElement
(
notificationsMap
,
elementName
,
notificationsMapVersion
)
m
.
deleteNotificationUnsafeRAM
(
toBeNotifiedOn
)
group
:=
m
.
deleteNotificationUnsafeRAM
(
toBeNotifiedOn
)
// call the callback if it exists to notify that an update exists
if
cb
,
cbExists
:=
m
.
callbacks
[
group
];
cbExists
{
// can be nil if the last element was deleted
g
,
_
:=
m
.
group
[
group
]
go
cb
(
g
.
DeepCopy
(),
nil
,
nil
,
[]
*
id
.
ID
{
toBeNotifiedOn
},
m
.
maxState
)
}
return
err
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment