feat(albums): Adds album of images to AC notification (#3977)
This commit is contained in:
parent
1dca3adb89
commit
d3c4ba315a
|
@ -72,6 +72,7 @@ type ActivityCenterNotification struct {
|
|||
//Used for synchronization. Each update should increment the UpdatedAt.
|
||||
//The value should represent the time when the update occurred.
|
||||
UpdatedAt uint64 `json:"updatedAt"`
|
||||
AlbumMessages []*common.Message `json:"albumMessages"`
|
||||
}
|
||||
|
||||
type ActivityCenterNotificationsRequest struct {
|
||||
|
|
|
@ -3311,19 +3311,31 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
|||
|
||||
// Use albumId as notificationId to prevent multiple notifications
|
||||
// for same message with multiple images
|
||||
var idToUse string
|
||||
var notificationID string
|
||||
|
||||
image := message.GetImage()
|
||||
var albumMessages = []*common.Message{}
|
||||
if image != nil && image.GetAlbumId() != "" {
|
||||
idToUse = message.GetImage().GetAlbumId()
|
||||
notificationID = image.GetAlbumId()
|
||||
album, err := m.persistence.albumMessages(message.LocalChatID, image.AlbumId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m.httpServer != nil {
|
||||
for _, msg := range album {
|
||||
m.prepareMessage(msg, m.httpServer)
|
||||
}
|
||||
}
|
||||
|
||||
albumMessages = album
|
||||
} else {
|
||||
idToUse = message.ID
|
||||
notificationID = message.ID
|
||||
}
|
||||
|
||||
isNotification, notificationType := showMentionOrReplyActivityCenterNotification(publicKey, message, chat, responseTo)
|
||||
if isNotification {
|
||||
notification := &ActivityCenterNotification{
|
||||
ID: types.FromHex(idToUse),
|
||||
ID: types.FromHex(notificationID),
|
||||
Name: chat.Name,
|
||||
Message: message,
|
||||
ReplyMessage: responseTo,
|
||||
|
@ -3333,6 +3345,7 @@ func (r *ReceivedMessageState) addNewActivityCenterNotification(publicKey ecdsa.
|
|||
CommunityID: chat.CommunityID,
|
||||
Author: message.From,
|
||||
UpdatedAt: m.getCurrentTimeInMillis(),
|
||||
AlbumMessages: albumMessages,
|
||||
}
|
||||
|
||||
return m.addActivityCenterNotification(r.Response, notification)
|
||||
|
|
|
@ -46,6 +46,20 @@ func (m *Messenger) ActivityCenterNotifications(request ActivityCenterNotificati
|
|||
for _, notification := range notifications {
|
||||
if notification.Message != nil {
|
||||
m.prepareMessage(notification.Message, m.httpServer)
|
||||
|
||||
image := notification.Message.GetImage()
|
||||
if image != nil && image.AlbumId != "" {
|
||||
album, err := m.persistence.albumMessages(notification.Message.LocalChatID, image.AlbumId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notification.AlbumMessages = album
|
||||
}
|
||||
}
|
||||
if notification.AlbumMessages != nil {
|
||||
for _, message := range notification.AlbumMessages {
|
||||
m.prepareMessage(message, m.httpServer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +395,23 @@ func (m *Messenger) DeleteActivityCenterNotifications(ctx context.Context, ids [
|
|||
}
|
||||
|
||||
func (m *Messenger) ActivityCenterNotification(id types.HexBytes) (*ActivityCenterNotification, error) {
|
||||
return m.persistence.GetActivityCenterNotificationByID(id)
|
||||
notification, err := m.persistence.GetActivityCenterNotificationByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if notification.Message != nil {
|
||||
image := notification.Message.GetImage()
|
||||
if image != nil && image.AlbumId != "" {
|
||||
album, err := m.persistence.albumMessages(notification.Message.LocalChatID, image.AlbumId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notification.AlbumMessages = album
|
||||
}
|
||||
}
|
||||
|
||||
return notification, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) HandleSyncActivityCenterRead(state *ReceivedMessageState, message *protobuf.SyncActivityCenterRead, statusMessage *v1protocol.StatusMessage) error {
|
||||
|
|
|
@ -318,3 +318,59 @@ func (s *MessengerSendImagesAlbumSuite) TestAlbumImageEditText() {
|
|||
s.Require().Equal(message.Text, editedText)
|
||||
}
|
||||
}
|
||||
|
||||
// This test makes sure that if you get a mention with an album of images in a community, it sends it correctly and has correct AC notif with album
|
||||
func (s *MessengerSendImagesAlbumSuite) TestAlbumImagesMessageWithMentionInCommunitySend() {
|
||||
theirMessenger := s.newMessenger()
|
||||
_, err := theirMessenger.Start()
|
||||
s.Require().NoError(err)
|
||||
defer theirMessenger.Shutdown() // nolint: errcheck
|
||||
|
||||
community, chat := createCommunity(&s.Suite, s.m)
|
||||
|
||||
s.advertiseCommunityTo(community, theirMessenger)
|
||||
|
||||
s.joinCommunity(community, theirMessenger)
|
||||
|
||||
const messageCount = 3
|
||||
var album []*common.Message
|
||||
|
||||
for i := 0; i < messageCount; i++ {
|
||||
outgoingMessage, err := buildImageWithoutAlbumIDMessage(*chat)
|
||||
s.NoError(err)
|
||||
outgoingMessage.Mentioned = true
|
||||
outgoingMessage.Text = "hey @" + common.PubkeyToHex(&theirMessenger.identity.PublicKey)
|
||||
album = append(album, outgoingMessage)
|
||||
}
|
||||
|
||||
err = s.m.SaveChat(chat)
|
||||
s.NoError(err)
|
||||
response, err := s.m.SendChatMessages(context.Background(), album)
|
||||
s.NoError(err)
|
||||
s.Require().Equal(messageCount, len(response.Messages()), "it returns the messages")
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(response.Messages(), messageCount)
|
||||
|
||||
response, err = WaitOnMessengerResponse(
|
||||
theirMessenger,
|
||||
func(r *MessengerResponse) bool { return len(r.messages) == messageCount },
|
||||
"no messages",
|
||||
)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(response.Chats(), 1)
|
||||
s.Require().Len(response.Messages(), messageCount)
|
||||
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
||||
|
||||
for _, notif := range response.ActivityCenterNotifications() {
|
||||
s.Require().Equal(messageCount, len(notif.AlbumMessages), "AC notification should have AlbumMessages")
|
||||
}
|
||||
|
||||
for _, message := range response.Messages() {
|
||||
image := message.GetImage()
|
||||
s.Require().NotNil(image, "Message.ID=%s", message.ID)
|
||||
s.Require().NotEmpty(image.AlbumId)
|
||||
}
|
||||
|
||||
s.Require().Equal(uint(1), response.Chats()[0].UnviewedMessagesCount, "Just one unread message")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue