notification cleanup

This commit is contained in:
Roland Osborne 2022-02-09 10:04:32 -08:00
parent 0beabeb713
commit 367e863c91
2 changed files with 19 additions and 133 deletions

View File

@ -112,64 +112,10 @@ func SetProfileNotification(account *store.Account) {
} }
} }
// notify single card of profile revision // notify single card of article change:
func SetContactProfileNotification(account *store.Account, card *store.Card) { // for each card of groups in updated artcile data
// for each card of group set or cleared from article (does not update data)
if card.Status != APP_CARDCONNECTED { func SetContactArticleNotification(account *store.Account, card *store.Card) {
return
}
// add new notification for card
notification := &store.Notification{
Node: card.Node,
Module: APP_NOTIFYPROFILE,
Token: card.OutToken,
Revision: account.ProfileRevision,
}
if res := store.DB.Save(notification).Error; res != nil {
ErrMsg(res)
} else {
notify <- notification
}
}
// notify all cards of content change
// account.Content incremented by adding, updating, removing article & setting or clearning group or label from article
func SetContentNotification(account *store.Account) {
// select all connected cards
var cards []store.Card
if err := store.DB.Where("account_id = ? AND status = ?", account.Guid, APP_CARDCONNECTED).Find(&cards).Error; err != nil {
ErrMsg(err)
return
}
// add new notification for each card
err := store.DB.Transaction(func(tx *gorm.DB) error {
for _, card := range cards {
notification := &store.Notification{
Node: card.Node,
Module: APP_NOTIFYARTICLE,
Token: card.OutToken,
Revision: account.ArticleRevision,
}
if err := tx.Save(notification).Error; err != nil {
return err
}
notify <- notification
}
return nil
})
if err != nil {
ErrMsg(err)
}
}
// notify single card of content change
// card.View incremented by adding or removing card from group or label
func SetContactContentNotification(account *store.Account, card *store.Card) {
if card.Status != APP_CARDCONNECTED { if card.Status != APP_CARDCONNECTED {
return return
@ -190,41 +136,9 @@ func SetContactContentNotification(account *store.Account, card *store.Card) {
} }
} }
// notify single card of view change:
// notify all cards of view change // card set or cleared from a group
// account.View incremented by removing a group or label or adding or removing a group from a label // for each card in deleted group
func SetViewNotification(account *store.Account) {
// select all connected cards
var cards []store.Card
if err := store.DB.Where("account_id = ? AND status = ?", account.Guid, APP_CARDCONNECTED).Find(&cards).Error; err != nil {
ErrMsg(err)
return
}
// add new notification for each card
err := store.DB.Transaction(func(tx *gorm.DB) error {
for _, card := range cards {
notification := &store.Notification{
Node: card.Node,
Module: APP_NOTIFYVIEW,
Token: card.OutToken,
Revision: card.ViewRevision,
}
if err := tx.Save(notification).Error; err != nil {
return err
}
notify <- notification
}
return nil
})
if err != nil {
ErrMsg(err)
}
}
// notify single card of content change
// card.View incremented by adding or removing card from group or label
func SetContactViewNotification(account *store.Account, card *store.Card) { func SetContactViewNotification(account *store.Account, card *store.Card) {
if card.Status != APP_CARDCONNECTED { if card.Status != APP_CARDCONNECTED {
@ -246,42 +160,10 @@ func SetContactViewNotification(account *store.Account, card *store.Card) {
} }
} }
// notify single card of channel change:
// notify all cards of label change // for each card of groups in updated channel data
// account.Label incremented by adding, updating, removing a label & setting or clearning group from article // for each card of group set or cleared from channel (updates data)
func SetLabelNotification(account *store.Account) { func SetContactChannelNotification(account *store.Account, card *store.Card) {
// select all connected cards
var cards []store.Card
if err := store.DB.Where("account_id = ? AND status = ?", account.Guid, APP_CARDCONNECTED).Find(&cards).Error; err != nil {
ErrMsg(err)
return
}
// add new notification for each card
err := store.DB.Transaction(func(tx *gorm.DB) error {
for _, card := range cards {
notification := &store.Notification{
Node: card.Node,
Module: APP_NOTIFYCHANNEL,
Token: card.OutToken,
Revision: account.ChannelRevision,
}
if err := tx.Save(notification).Error; err != nil {
return err
}
notify <- notification
}
return nil
})
if err != nil {
ErrMsg(err)
}
}
// notify single card of label change
// card.Label incremented by adding or removing group from label
func SetContactLabelNotification(account *store.Account, card *store.Card) {
if card.Status != APP_CARDCONNECTED { if card.Status != APP_CARDCONNECTED {
return return

View File

@ -25,13 +25,11 @@ func TestUpdateProfile(t *testing.T) {
// reset revision // reset revision
bCardRev = GetTestRevision(set.B.Revisions).Card bCardRev = GetTestRevision(set.B.Revisions).Card
cCardRev = GetTestRevision(set.C.Revisions).Card cCardRev = GetTestRevision(set.C.Revisions).Card
param["cardId"] = set.B.A.CardId param["cardId"] = set.B.A.CardId
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}", assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
&param, nil, &param, nil,
APP_TOKENAPP, set.B.Token, &card, nil)) APP_TOKENAPP, set.B.Token, &card, nil))
bProfileRev = card.Data.NotifiedProfile bProfileRev = card.Data.NotifiedProfile
param["cardId"] = set.C.A.CardId param["cardId"] = set.C.A.CardId
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}", assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
&param, nil, &param, nil,
@ -48,9 +46,11 @@ func TestUpdateProfile(t *testing.T) {
nil, profileData, nil, profileData,
APP_TOKENAPP, set.A.Token, nil, nil)) APP_TOKENAPP, set.A.Token, nil, nil))
// recv websocket event
assert.NotEqual(t, bCardRev, GetTestRevision(set.B.Revisions).Card) assert.NotEqual(t, bCardRev, GetTestRevision(set.B.Revisions).Card)
assert.NotEqual(t, cCardRev, GetTestRevision(set.C.Revisions).Card) assert.NotEqual(t, cCardRev, GetTestRevision(set.C.Revisions).Card)
// check B notified
param["cardId"] = set.B.A.CardId param["cardId"] = set.B.A.CardId
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}", assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
&param, nil, &param, nil,
@ -58,6 +58,7 @@ func TestUpdateProfile(t *testing.T) {
assert.NotEqual(t, bProfileRev, card.Data.NotifiedProfile) assert.NotEqual(t, bProfileRev, card.Data.NotifiedProfile)
assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile) assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
// check C notified
param["cardId"] = set.C.A.CardId param["cardId"] = set.C.A.CardId
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}", assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
&param, nil, &param, nil,
@ -65,7 +66,7 @@ func TestUpdateProfile(t *testing.T) {
assert.NotEqual(t, cProfileRev, card.Data.NotifiedProfile) assert.NotEqual(t, cProfileRev, card.Data.NotifiedProfile)
assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile) assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
// update profile // sync profile
assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message", assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message",
nil, nil, nil, nil,
APP_TOKENCONTACT, set.B.A.Token, &msg, nil)) APP_TOKENCONTACT, set.B.A.Token, &msg, nil))
@ -76,7 +77,7 @@ func TestUpdateProfile(t *testing.T) {
assert.Equal(t, card.Data.ProfileRevision, card.Data.NotifiedProfile) assert.Equal(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
assert.Equal(t, card.Data.CardProfile.Name, "Namer") assert.Equal(t, card.Data.CardProfile.Name, "Namer")
// update profile // sync profile
assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message", assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message",
nil, nil, nil, nil,
APP_TOKENCONTACT, set.C.A.Token, &msg, nil)) APP_TOKENCONTACT, set.C.A.Token, &msg, nil))
@ -87,6 +88,9 @@ func TestUpdateProfile(t *testing.T) {
assert.Equal(t, card.Data.ProfileRevision, card.Data.NotifiedProfile) assert.Equal(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
assert.Equal(t, card.Data.CardProfile.Name, "Namer") assert.Equal(t, card.Data.CardProfile.Name, "Namer")
// TODO set image
// "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAIAAADxLsZiAAAFzElEQVR4nOzWUY3jMBhG0e0qSEqoaIqiaEIoGAxh3gZAldid3nMI+JOiXP3bGOMfwLf7v3oAwAxiBySIHZAgdkCC2AEJYgckiB2QIHZAgtgBCWIHJIgdkCB2QILYAQliBySIHZAgdkCC2AEJYgckiB2QIHZAg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