mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
notification cleanup
This commit is contained in:
parent
0beabeb713
commit
367e863c91
@ -112,64 +112,10 @@ func SetProfileNotification(account *store.Account) {
|
||||
}
|
||||
}
|
||||
|
||||
// notify single card of profile revision
|
||||
func SetContactProfileNotification(account *store.Account, card *store.Card) {
|
||||
|
||||
if card.Status != APP_CARDCONNECTED {
|
||||
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) {
|
||||
// notify single card of article change:
|
||||
// for each card of groups in updated artcile data
|
||||
// for each card of group set or cleared from article (does not update data)
|
||||
func SetContactArticleNotification(account *store.Account, card *store.Card) {
|
||||
|
||||
if card.Status != APP_CARDCONNECTED {
|
||||
return
|
||||
@ -190,41 +136,9 @@ func SetContactContentNotification(account *store.Account, card *store.Card) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// notify all cards of view change
|
||||
// account.View incremented by removing a group or label or adding or removing a group from a label
|
||||
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
|
||||
// notify single card of view change:
|
||||
// card set or cleared from a group
|
||||
// for each card in deleted group
|
||||
func SetContactViewNotification(account *store.Account, card *store.Card) {
|
||||
|
||||
if card.Status != APP_CARDCONNECTED {
|
||||
@ -246,42 +160,10 @@ func SetContactViewNotification(account *store.Account, card *store.Card) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// notify all cards of label change
|
||||
// account.Label incremented by adding, updating, removing a label & setting or clearning group from article
|
||||
func SetLabelNotification(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_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) {
|
||||
// notify single card of channel change:
|
||||
// for each card of groups in updated channel data
|
||||
// for each card of group set or cleared from channel (updates data)
|
||||
func SetContactChannelNotification(account *store.Account, card *store.Card) {
|
||||
|
||||
if card.Status != APP_CARDCONNECTED {
|
||||
return
|
||||
|
@ -25,13 +25,11 @@ func TestUpdateProfile(t *testing.T) {
|
||||
// reset revision
|
||||
bCardRev = GetTestRevision(set.B.Revisions).Card
|
||||
cCardRev = GetTestRevision(set.C.Revisions).Card
|
||||
|
||||
param["cardId"] = set.B.A.CardId
|
||||
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
|
||||
¶m, nil,
|
||||
APP_TOKENAPP, set.B.Token, &card, nil))
|
||||
bProfileRev = card.Data.NotifiedProfile
|
||||
|
||||
param["cardId"] = set.C.A.CardId
|
||||
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
|
||||
¶m, nil,
|
||||
@ -48,9 +46,11 @@ func TestUpdateProfile(t *testing.T) {
|
||||
nil, profileData,
|
||||
APP_TOKENAPP, set.A.Token, nil, nil))
|
||||
|
||||
// recv websocket event
|
||||
assert.NotEqual(t, bCardRev, GetTestRevision(set.B.Revisions).Card)
|
||||
assert.NotEqual(t, cCardRev, GetTestRevision(set.C.Revisions).Card)
|
||||
|
||||
// check B notified
|
||||
param["cardId"] = set.B.A.CardId
|
||||
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
|
||||
¶m, nil,
|
||||
@ -58,6 +58,7 @@ func TestUpdateProfile(t *testing.T) {
|
||||
assert.NotEqual(t, bProfileRev, card.Data.NotifiedProfile)
|
||||
assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
|
||||
|
||||
// check C notified
|
||||
param["cardId"] = set.C.A.CardId
|
||||
assert.NoError(t, SendEndpointTest(GetCard, "GET", "/contact/cards/{cardId}",
|
||||
¶m, nil,
|
||||
@ -65,7 +66,7 @@ func TestUpdateProfile(t *testing.T) {
|
||||
assert.NotEqual(t, cProfileRev, card.Data.NotifiedProfile)
|
||||
assert.NotEqual(t, card.Data.ProfileRevision, card.Data.NotifiedProfile)
|
||||
|
||||
// update profile
|
||||
// sync profile
|
||||
assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message",
|
||||
nil, 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.CardProfile.Name, "Namer")
|
||||
|
||||
// update profile
|
||||
// sync profile
|
||||
assert.NoError(t, SendEndpointTest(GetProfileMessage, "GET", "/profile/message",
|
||||
nil, 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.CardProfile.Name, "Namer")
|
||||
|
||||
// TODO set image
|
||||
// "iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAIAAADxLsZiAAAFzElEQVR4nOzWUY3jMBhG0e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