feat: add replies to activity center (#2257)
This commit is contained in:
parent
f2678ea950
commit
43fa2edc1e
|
@ -15,9 +15,11 @@ import (
|
||||||
type ActivityCenterType int
|
type ActivityCenterType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActivityCenterNotificationTypeNewOneToOne = iota + 1
|
ActivityCenterNotificationNoType ActivityCenterType = iota
|
||||||
|
ActivityCenterNotificationTypeNewOneToOne
|
||||||
ActivityCenterNotificationTypeNewPrivateGroupChat
|
ActivityCenterNotificationTypeNewPrivateGroupChat
|
||||||
ActivityCenterNotificationTypeMention
|
ActivityCenterNotificationTypeMention
|
||||||
|
ActivityCenterNotificationTypeReply
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidActivityCenterNotification = errors.New("invalid activity center notification")
|
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 {
|
func showMentionOrReplyActivityCenterNotification(publicKey ecdsa.PublicKey, message *common.Message, chat *Chat, responseTo *common.Message) (bool, ActivityCenterType) {
|
||||||
if chat != nil && !chat.Active {
|
if chat == nil || !chat.Active || (!chat.CommunityChat() && !chat.PrivateGroupChat()) {
|
||||||
return false
|
return false, ActivityCenterNotificationNoType
|
||||||
}
|
}
|
||||||
|
|
||||||
if message.Mentioned && chat != nil && (chat.CommunityChat() || chat.PrivateGroupChat()) {
|
if message.Mentioned {
|
||||||
return true
|
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)
|
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{
|
notification := &ActivityCenterNotification{
|
||||||
ID: types.FromHex(message.ID),
|
ID: types.FromHex(message.ID),
|
||||||
Name: chat.Name,
|
Name: chat.Name,
|
||||||
Message: message,
|
Message: message,
|
||||||
Type: ActivityCenterNotificationTypeMention,
|
Type: notificationType,
|
||||||
Timestamp: message.WhisperTimestamp,
|
Timestamp: message.WhisperTimestamp,
|
||||||
ChatID: chat.ID,
|
ChatID: chat.ID,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue