-
Notifications
You must be signed in to change notification settings - Fork 246
/
activity_center.go
70 lines (56 loc) · 2.26 KB
/
activity_center.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package protocol
import (
"crypto/ecdsa"
"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 (
ActivityCenterNotificationNoType ActivityCenterType = iota
ActivityCenterNotificationTypeNewOneToOne
ActivityCenterNotificationTypeNewPrivateGroupChat
ActivityCenterNotificationTypeMention
ActivityCenterNotificationTypeReply
)
var ErrInvalidActivityCenterNotification = errors.New("invalid activity center notification")
type ActivityCenterNotification struct {
ID types.HexBytes `json:"id"`
ChatID string `json:"chatId"`
Name string `json:"name"`
Author string `json:"author"`
Type ActivityCenterType `json:"type"`
LastMessage *common.Message `json:"lastMessage"`
Message *common.Message `json:"message"`
ReplyMessage *common.Message `json:"replyMessage"`
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
}
func showMentionOrReplyActivityCenterNotification(publicKey ecdsa.PublicKey, message *common.Message, chat *Chat, responseTo *common.Message) (bool, ActivityCenterType) {
if chat == nil || !chat.Active || (!chat.CommunityChat() && !chat.PrivateGroupChat()) {
return false, ActivityCenterNotificationNoType
}
if message.Mentioned {
return true, ActivityCenterNotificationTypeMention
}
publicKeyString := common.PubkeyToHex(&publicKey)
if responseTo != nil && responseTo.From == publicKeyString {
return true, ActivityCenterNotificationTypeReply
}
return false, ActivityCenterNotificationNoType
}