dont sync chats with pending notifications (#2458)
* dont sync chats with pending notifications * set accepted/dismissed notifications as read * activate chat if message is sent from us
This commit is contained in:
parent
3564630c33
commit
9feea4fe25
|
@ -55,7 +55,7 @@ func (db sqlitePersistence) DeleteActivityCenterNotificationForMessage(chatID st
|
||||||
}
|
}
|
||||||
|
|
||||||
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
||||||
query := "UPDATE activity_center_notifications SET dismissed = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
query := "UPDATE activity_center_notifications SET read = 1, dismissed = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
||||||
_, err = tx.Exec(query, idsArgs...)
|
_, err = tx.Exec(query, idsArgs...)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -297,6 +297,15 @@ func (db sqlitePersistence) GetToProcessActivityCenterNotificationIds() ([][]byt
|
||||||
return db.runActivityCenterIDQuery("SELECT a.id FROM activity_center_notifications a WHERE NOT a.dismissed AND NOT a.accepted")
|
return db.runActivityCenterIDQuery("SELECT a.id FROM activity_center_notifications a WHERE NOT a.dismissed AND NOT a.accepted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db sqlitePersistence) HasPendingNotificationsForChat(chatID string) (bool, error) {
|
||||||
|
rows, err := db.db.Query("SELECT 1 FROM activity_center_notifications a WHERE a.chat_id = ? NOT a.dismissed AND NOT a.accepted", chatID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows.Next(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) GetActivityCenterNotificationsByID(ids []types.HexBytes) ([]*ActivityCenterNotification, error) {
|
func (db sqlitePersistence) GetActivityCenterNotificationsByID(ids []types.HexBytes) ([]*ActivityCenterNotification, error) {
|
||||||
idsArgs := make([]interface{}, 0, len(ids))
|
idsArgs := make([]interface{}, 0, len(ids))
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
@ -362,12 +371,12 @@ func (db sqlitePersistence) ActivityCenterNotifications(currCursor string, limit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) DismissAllActivityCenterNotifications() error {
|
func (db sqlitePersistence) DismissAllActivityCenterNotifications() error {
|
||||||
_, err := db.db.Exec(`UPDATE activity_center_notifications SET dismissed = 1 WHERE NOT dismissed AND NOT accepted`)
|
_, err := db.db.Exec(`UPDATE activity_center_notifications SET read = 1, dismissed = 1 WHERE NOT dismissed AND NOT accepted`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) DismissAllActivityCenterNotificationsFromUser(userPublicKey string) error {
|
func (db sqlitePersistence) DismissAllActivityCenterNotificationsFromUser(userPublicKey string) error {
|
||||||
_, err := db.db.Exec(`UPDATE activity_center_notifications SET dismissed = 1 WHERE NOT dismissed AND NOT accepted AND author = ?`, userPublicKey)
|
_, err := db.db.Exec(`UPDATE activity_center_notifications SET read = 1, dismissed = 1 WHERE NOT dismissed AND NOT accepted AND author = ?`, userPublicKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +388,7 @@ func (db sqlitePersistence) DismissActivityCenterNotifications(ids []types.HexBy
|
||||||
}
|
}
|
||||||
|
|
||||||
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
||||||
query := "UPDATE activity_center_notifications SET dismissed = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
query := "UPDATE activity_center_notifications SET read = 1, dismissed = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
||||||
_, err := db.db.Exec(query, idsArgs...)
|
_, err := db.db.Exec(query, idsArgs...)
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
@ -404,7 +413,7 @@ func (db sqlitePersistence) AcceptAllActivityCenterNotifications() ([]*ActivityC
|
||||||
|
|
||||||
_, notifications, err := db.buildActivityCenterQuery(tx, "", 0, nil, "", "", ActivityCenterNotificationNoType)
|
_, notifications, err := db.buildActivityCenterQuery(tx, "", 0, nil, "", "", ActivityCenterNotificationNoType)
|
||||||
|
|
||||||
_, err = tx.Exec(`UPDATE activity_center_notifications SET accepted = 1 WHERE NOT accepted AND NOT dismissed`)
|
_, err = tx.Exec(`UPDATE activity_center_notifications SET read = 1, accepted = 1 WHERE NOT accepted AND NOT dismissed`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -441,7 +450,7 @@ func (db sqlitePersistence) AcceptActivityCenterNotifications(ids []types.HexByt
|
||||||
}
|
}
|
||||||
|
|
||||||
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
inVector := strings.Repeat("?, ", len(ids)-1) + "?"
|
||||||
query := "UPDATE activity_center_notifications SET accepted = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
query := "UPDATE activity_center_notifications SET read = 1, accepted = 1 WHERE id IN (" + inVector + ")" // nolint: gosec
|
||||||
_, err = tx.Exec(query, idsArgs...)
|
_, err = tx.Exec(query, idsArgs...)
|
||||||
return notifications, err
|
return notifications, err
|
||||||
}
|
}
|
||||||
|
@ -469,7 +478,7 @@ func (db sqlitePersistence) AcceptActivityCenterNotificationsForInvitesFromUser(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(`UPDATE activity_center_notifications SET accepted = 1 WHERE NOT accepted AND NOT dismissed AND author = ? AND notification_type = ?`, userPublicKey, ActivityCenterNotificationTypeNewPrivateGroupChat)
|
_, err = tx.Exec(`UPDATE activity_center_notifications SET read = 1, accepted = 1 WHERE NOT accepted AND NOT dismissed AND author = ? AND notification_type = ?`, userPublicKey, ActivityCenterNotificationTypeNewPrivateGroupChat)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1894,6 +1894,10 @@ func (m *Messenger) leaveGroupChat(ctx context.Context, response *MessengerRespo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shouldBeSynced is false if we got here because a synced client has already
|
||||||
|
// sent the leave group message. In that case we don't need to send it again.
|
||||||
|
if shouldBeSynced {
|
||||||
_, err = m.dispatchMessage(ctx, common.RawMessage{
|
_, err = m.dispatchMessage(ctx, common.RawMessage{
|
||||||
LocalChatID: chat.ID,
|
LocalChatID: chat.ID,
|
||||||
Payload: encodedMessage,
|
Payload: encodedMessage,
|
||||||
|
@ -1903,6 +1907,7 @@ func (m *Messenger) leaveGroupChat(ctx context.Context, response *MessengerRespo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chat.updateChatFromGroupMembershipChanges(group)
|
chat.updateChatFromGroupMembershipChanges(group)
|
||||||
response.AddMessages(buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations))
|
response.AddMessages(buildSystemMessages([]v1protocol.MembershipUpdateEvent{event}, m.systemMessagesTranslations))
|
||||||
|
@ -2346,10 +2351,17 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPublicChat || chat.OneToOne() || chat.PrivateGroupChat()) && !chat.Active {
|
if (isPublicChat || chat.OneToOne() || chat.PrivateGroupChat()) && !chat.Active {
|
||||||
err := m.syncChatRemoving(ctx, chatID)
|
pending, err := m.persistence.HasPendingNotificationsForChat(chat.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !pending {
|
||||||
|
err = m.syncChatRemoving(ctx, chatID)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPublicChat || chat.OneToOne() || chat.PrivateGroupChat() || chat.CommunityChat()) && chat.Active {
|
if (isPublicChat || chat.OneToOne() || chat.PrivateGroupChat() || chat.CommunityChat()) && chat.Active {
|
||||||
|
|
|
@ -121,6 +121,7 @@ func (m *Messenger) processAcceptedActivityCenterNotifications(ctx context.Conte
|
||||||
for i := range notifications {
|
for i := range notifications {
|
||||||
ids[i] = notifications[i].ID
|
ids[i] = notifications[i].ID
|
||||||
notifications[i].Accepted = true
|
notifications[i].Accepted = true
|
||||||
|
notifications[i].Read = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if sync {
|
if sync {
|
||||||
|
|
|
@ -1209,6 +1209,8 @@ func (m *Messenger) matchChatEntity(chatEntity common.ChatEntity) (*Chat, error)
|
||||||
|
|
||||||
chat = CreateOneToOneChat(chatID[:8], pubKey, m.getTimesource())
|
chat = CreateOneToOneChat(chatID[:8], pubKey, m.getTimesource())
|
||||||
}
|
}
|
||||||
|
// if we are the sender, the chat must be active
|
||||||
|
chat.Active = true
|
||||||
return chat, nil
|
return chat, nil
|
||||||
case chatEntity.GetMessageType() == protobuf.MessageType_ONE_TO_ONE:
|
case chatEntity.GetMessageType() == protobuf.MessageType_ONE_TO_ONE:
|
||||||
// It's an incoming private chatEntity. ChatID is calculated from the signature.
|
// It's an incoming private chatEntity. ChatID is calculated from the signature.
|
||||||
|
|
Loading…
Reference in New Issue