2021-04-07 12:57:14 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2021-05-29 17:05:25 +00:00
|
|
|
"crypto/ecdsa"
|
2021-04-07 12:57:14 +00:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/protocol/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// The activity center is a place where we store incoming notifications before
|
|
|
|
// they are shown to the users as new chats, in order to mitigate the impact of spam
|
|
|
|
// on the messenger
|
|
|
|
|
|
|
|
type ActivityCenterType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ActivityCenterNotificationTypeNewOneToOne = iota + 1
|
|
|
|
ActivityCenterNotificationTypeNewPrivateGroupChat
|
2021-05-29 17:05:25 +00:00
|
|
|
ActivityCenterNotificationTypeMention
|
2021-04-07 12:57:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ErrInvalidActivityCenterNotification = errors.New("invalid activity center notification")
|
|
|
|
|
|
|
|
type ActivityCenterNotification struct {
|
|
|
|
ID types.HexBytes `json:"id"`
|
|
|
|
ChatID string `json:"chatId"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type ActivityCenterType `json:"type"`
|
|
|
|
LastMessage *common.Message `json:"lastMessage"`
|
2021-05-29 17:05:25 +00:00
|
|
|
Message *common.Message `json:"message"`
|
2021-04-07 12:57:14 +00:00
|
|
|
Timestamp uint64 `json:"timestamp"`
|
|
|
|
Read bool `json:"read"`
|
|
|
|
Dismissed bool `json:"dismissed"`
|
|
|
|
Accepted bool `json:"accepted"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActivityCenterPaginationResponse struct {
|
|
|
|
Cursor string `json:"cursor"`
|
|
|
|
Notifications []*ActivityCenterNotification `json:"notifications"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *ActivityCenterNotification) Valid() error {
|
|
|
|
if len(n.ID) == 0 || n.Type == 0 || n.Timestamp == 0 {
|
|
|
|
return ErrInvalidActivityCenterNotification
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
2021-05-29 17:05:25 +00:00
|
|
|
|
|
|
|
func showMentionActivityCenterNotification(publicKey ecdsa.PublicKey, message *common.Message, chat *Chat, responseTo *common.Message) bool {
|
|
|
|
if chat != nil && !chat.Active {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if message.Mentioned && chat != nil && (chat.CommunityChat() || chat.PrivateGroupChat()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|