feat: add replies to activity center (#2257)
This commit is contained in:
parent
f2678ea950
commit
43fa2edc1e
|
@ -15,9 +15,11 @@ import (
|
|||
type ActivityCenterType int
|
||||
|
||||
const (
|
||||
ActivityCenterNotificationTypeNewOneToOne = iota + 1
|
||||
ActivityCenterNotificationNoType ActivityCenterType = iota
|
||||
ActivityCenterNotificationTypeNewOneToOne
|
||||
ActivityCenterNotificationTypeNewPrivateGroupChat
|
||||
ActivityCenterNotificationTypeMention
|
||||
ActivityCenterNotificationTypeReply
|
||||
)
|
||||
|
||||
var ErrInvalidActivityCenterNotification = errors.New("invalid activity center notification")
|
||||
|
@ -48,14 +50,19 @@ func (n *ActivityCenterNotification) Valid() error {
|
|||
|
||||
}
|
||||
|
||||
func showMentionActivityCenterNotification(publicKey ecdsa.PublicKey, message *common.Message, chat *Chat, responseTo *common.Message) bool {
|
||||
if chat != nil && !chat.Active {
|
||||
return false
|
||||
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 && chat != nil && (chat.CommunityChat() || chat.PrivateGroupChat()) {
|
||||
return true
|
||||
if message.Mentioned {
|
||||
return true, ActivityCenterNotificationTypeMention
|
||||
}
|
||||
|
||||
return false
|
||||
publicKeyString := common.PubkeyToHex(&publicKey)
|
||||
if responseTo != nil && responseTo.From == publicKeyString {
|
||||
return true, ActivityCenterNotificationTypeReply
|
||||
}
|
||||
|
||||
return false, ActivityCenterNotificationNoType
|
||||
}
|
||||
|
|
|
@ -2415,12 +2415,13 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
|||
return fmt.Errorf("chat ID '%s' not present", message.LocalChatID)
|
||||
}
|
||||
|
||||
if showMentionActivityCenterNotification(publicKey, message, chat, responseTo) {
|
||||
isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo)
|
||||
if isNotification {
|
||||
notification := &ActivityCenterNotification{
|
||||
ID: types.FromHex(message.ID),
|
||||
Name: chat.Name,
|
||||
Message: message,
|
||||
Type: ActivityCenterNotificationTypeMention,
|
||||
Type: notificationType,
|
||||
Timestamp: message.WhisperTimestamp,
|
||||
ChatID: chat.ID,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue