fix: 'Join Community' notification is not getting dismissed (#4267)
This commit is contained in:
parent
9820acd74d
commit
76b6745666
|
@ -859,6 +859,37 @@ func (db sqlitePersistence) DismissActivityCenterNotifications(ids []types.HexBy
|
||||||
return updateActivityCenterState(tx, updatedAt)
|
return updateActivityCenterState(tx, updatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db sqlitePersistence) DismissActivityCenterNotificationsByCommunity(communityID string, updatedAt uint64) ([]*ActivityCenterNotification, error) {
|
||||||
|
var tx *sql.Tx
|
||||||
|
var err error
|
||||||
|
|
||||||
|
tx, err = db.db.BeginTx(context.Background(), &sql.TxOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
err = tx.Commit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// don't shadow original error
|
||||||
|
_ = tx.Rollback()
|
||||||
|
}()
|
||||||
|
|
||||||
|
query := "UPDATE activity_center_notifications SET read = 1, dismissed = 1, updated_at = ? WHERE community_id = ? AND notification_type IN (?, ?) AND NOT deleted" // nolint: gosec
|
||||||
|
_, err = tx.Exec(query, updatedAt, communityID, ActivityCenterNotificationTypeCommunityRequest, ActivityCenterNotificationTypeCommunityKicked)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, notifications, err := db.buildActivityCenterQuery(tx, activityCenterQueryParams{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return notifications, updateActivityCenterState(tx, updatedAt)
|
||||||
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) DismissAllActivityCenterNotificationsFromCommunity(communityID string, updatedAt uint64) ([]*ActivityCenterNotification, error) {
|
func (db sqlitePersistence) DismissAllActivityCenterNotificationsFromCommunity(communityID string, updatedAt uint64) ([]*ActivityCenterNotification, error) {
|
||||||
var tx *sql.Tx
|
var tx *sql.Tx
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/protocol/common"
|
"github.com/status-im/status-go/protocol/common"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errOnlyOneNotificationID = errors.New("only one notification id is supported")
|
var errOnlyOneNotificationID = errors.New("only one notification id is supported")
|
||||||
|
@ -452,6 +453,20 @@ func (m *Messenger) DismissAllActivityCenterNotificationsFromUser(ctx context.Co
|
||||||
return notifications, m.syncActivityCenterDismissed(ctx, notifications, updatedAt)
|
return notifications, m.syncActivityCenterDismissed(ctx, notifications, updatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) DismissActivityCenterNotificationsByCommunity(ctx context.Context, request *requests.DismissCommunityNotifications) error {
|
||||||
|
err := request.Validate()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
updatedAt := m.GetCurrentTimeInMillis()
|
||||||
|
notifications, err := m.persistence.DismissActivityCenterNotificationsByCommunity(request.CommunityID.String(), updatedAt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return m.syncActivityCenterDismissed(ctx, notifications, updatedAt)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Messenger) DismissAllActivityCenterNotificationsFromCommunity(ctx context.Context, communityID string, updatedAt uint64) ([]*ActivityCenterNotification, error) {
|
func (m *Messenger) DismissAllActivityCenterNotificationsFromCommunity(ctx context.Context, communityID string, updatedAt uint64) ([]*ActivityCenterNotification, error) {
|
||||||
notifications, err := m.persistence.DismissAllActivityCenterNotificationsFromCommunity(communityID, updatedAt)
|
notifications, err := m.persistence.DismissAllActivityCenterNotificationsFromCommunity(communityID, updatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -267,6 +267,31 @@ func (s *MessengerActivityCenterMessageSuite) TestMuteCommunityActivityCenterNot
|
||||||
s.Require().Len(response.ActivityCenterNotifications(), 0)
|
s.Require().Len(response.ActivityCenterNotifications(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MessengerActivityCenterMessageSuite) TestReadCommunityOverviewNotifications() {
|
||||||
|
alice := s.m
|
||||||
|
bob := s.newMessenger()
|
||||||
|
_, err := bob.Start()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
defer bob.Shutdown() // nolint: errcheck
|
||||||
|
|
||||||
|
// Create a community
|
||||||
|
community, chat := s.createCommunity(bob)
|
||||||
|
s.Require().NotNil(community)
|
||||||
|
s.Require().NotNil(chat)
|
||||||
|
|
||||||
|
// Alice joins the community
|
||||||
|
s.advertiseCommunityTo(community, bob, alice)
|
||||||
|
s.joinCommunity(community, bob, alice)
|
||||||
|
|
||||||
|
// Mark community overview notification read
|
||||||
|
err = alice.DismissActivityCenterNotificationsByCommunity(context.Background(), &requests.DismissCommunityNotifications{CommunityID: community.ID()})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
response, err := alice.GetActivityCenterState()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(response.HasSeen, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMentionAndReply() (*Messenger, *Messenger, *common.Message, *common.Message, *communities.Community) {
|
func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMentionAndReply() (*Messenger, *Messenger, *common.Message, *common.Message, *communities.Community) {
|
||||||
alice := s.m
|
alice := s.m
|
||||||
bob := s.newMessenger()
|
bob := s.newMessenger()
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package requests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrDismissCommunityNotificationsInvalidID = errors.New("dismiss-community-notifications: invalid id")
|
||||||
|
)
|
||||||
|
|
||||||
|
type DismissCommunityNotifications struct {
|
||||||
|
CommunityID types.HexBytes `json:"communityId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *DismissCommunityNotifications) Validate() error {
|
||||||
|
if len(r.CommunityID) == 0 {
|
||||||
|
return ErrDismissCommunityNotificationsInvalidID
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -820,6 +820,10 @@ func (api *PublicAPI) MarkAllRead(ctx context.Context, chatID string) (*protocol
|
||||||
return api.service.messenger.MarkAllRead(ctx, chatID)
|
return api.service.messenger.MarkAllRead(ctx, chatID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *PublicAPI) DismissActivityCenterNotificationsByCommunity(ctx context.Context, request *requests.DismissCommunityNotifications) error {
|
||||||
|
return api.service.messenger.DismissActivityCenterNotificationsByCommunity(ctx, request)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) MarkAllReadInCommunity(ctx context.Context, communityID string) (*protocol.MessengerResponse, error) {
|
func (api *PublicAPI) MarkAllReadInCommunity(ctx context.Context, communityID string) (*protocol.MessengerResponse, error) {
|
||||||
return api.service.messenger.MarkAllReadInCommunity(ctx, communityID)
|
return api.service.messenger.MarkAllReadInCommunity(ctx, communityID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue