Filter message PNs on status go side
This commit is contained in:
parent
42ab47a9ee
commit
99a304686f
|
@ -490,16 +490,6 @@ func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error {
|
||||||
// Add to response
|
// Add to response
|
||||||
state.Response.Messages = append(state.Response.Messages, receivedMessage)
|
state.Response.Messages = append(state.Response.Messages, receivedMessage)
|
||||||
|
|
||||||
// Create notification body to be eventually passed to `localnotifications.SendMessageNotifications()`
|
|
||||||
state.Response.Notifications = append(
|
|
||||||
state.Response.Notifications,
|
|
||||||
MessageNotificationBody{
|
|
||||||
Message: receivedMessage,
|
|
||||||
Contact: contact,
|
|
||||||
Chat: chat,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2796,7 +2796,7 @@ func (m *Messenger) markDeliveredMessages(acks [][]byte) {
|
||||||
|
|
||||||
// addNewMessageNotification takes a common.Message and generates a new MessageNotificationBody and appends it to the
|
// addNewMessageNotification takes a common.Message and generates a new MessageNotificationBody and appends it to the
|
||||||
// []Response.Notifications if the message is m.New
|
// []Response.Notifications if the message is m.New
|
||||||
func (r *ReceivedMessageState) addNewMessageNotification(m *common.Message) error {
|
func (r *ReceivedMessageState) addNewMessageNotification(publicKey ecdsa.PublicKey, m *common.Message, responseTo *common.Message) error {
|
||||||
if !m.New {
|
if !m.New {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2807,14 +2807,19 @@ func (r *ReceivedMessageState) addNewMessageNotification(m *common.Message) erro
|
||||||
}
|
}
|
||||||
contactID := contactIDFromPublicKey(pubKey)
|
contactID := contactIDFromPublicKey(pubKey)
|
||||||
|
|
||||||
r.Response.Notifications = append(
|
chat := r.AllChats[m.LocalChatID]
|
||||||
r.Response.Notifications,
|
notification := MessageNotificationBody{
|
||||||
MessageNotificationBody{
|
Message: m,
|
||||||
Message: m,
|
Contact: r.AllContacts[contactID],
|
||||||
Contact: r.AllContacts[contactID],
|
Chat: chat,
|
||||||
Chat: r.AllChats[m.ChatId],
|
}
|
||||||
},
|
|
||||||
)
|
if showNotification(publicKey, notification, responseTo) {
|
||||||
|
r.Response.Notifications = append(
|
||||||
|
r.Response.Notifications,
|
||||||
|
notification,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3299,6 +3304,10 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
messagesByID := map[string]*common.Message{}
|
||||||
|
for _, message := range messagesWithResponses {
|
||||||
|
messagesByID[message.ID] = message
|
||||||
|
}
|
||||||
messageState.Response.Messages = messagesWithResponses
|
messageState.Response.Messages = messagesWithResponses
|
||||||
|
|
||||||
for _, message := range messageState.Response.Messages {
|
for _, message := range messageState.Response.Messages {
|
||||||
|
@ -3306,7 +3315,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
||||||
message.New = true
|
message.New = true
|
||||||
|
|
||||||
// Create notification body to be eventually passed to `localnotifications.SendMessageNotifications()`
|
// Create notification body to be eventually passed to `localnotifications.SendMessageNotifications()`
|
||||||
if err = messageState.addNewMessageNotification(message); err != nil {
|
if err = messageState.addNewMessageNotification(m.identity.PublicKey, message, messagesByID[message.ResponseTo]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3318,6 +3327,30 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
||||||
return messageState.Response, nil
|
return messageState.Response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showNotification(publicKey ecdsa.PublicKey, n MessageNotificationBody, responseTo *common.Message) bool {
|
||||||
|
if n.Chat != nil && n.Chat.ChatType == ChatTypeOneToOne {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeyString := common.PubkeyToHex(&publicKey)
|
||||||
|
mentioned := false
|
||||||
|
for _, mention := range n.Message.Mentions {
|
||||||
|
if publicKeyString == mention {
|
||||||
|
mentioned = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mentioned {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if responseTo != nil {
|
||||||
|
return responseTo.From == publicKeyString
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// SetMailserver sets the currently used mailserver
|
// SetMailserver sets the currently used mailserver
|
||||||
func (m *Messenger) SetMailserver(peer []byte) {
|
func (m *Messenger) SetMailserver(peer []byte) {
|
||||||
m.mailserver = peer
|
m.mailserver = peer
|
||||||
|
|
Loading…
Reference in New Issue