fix offline messages marked as seen (#2713)
This commit is contained in:
parent
62e212abf4
commit
1c77f2ed6e
|
@ -604,6 +604,25 @@ func (db sqlitePersistence) MessageByChatID(chatID string, currCursor string, li
|
|||
return result, newCursor, nil
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) latestIncomingMessageClock(chatID string) (uint64, error) {
|
||||
var clock uint64
|
||||
err := db.db.QueryRow(
|
||||
`
|
||||
SELECT
|
||||
clock_value
|
||||
FROM
|
||||
user_messages m1
|
||||
WHERE
|
||||
m1.local_chat_id = ? AND m1.outgoing_status = ''
|
||||
ORDER BY substr('0000000000000000000000000000000000000000000000000000000000000000' || m1.clock_value, -64, 64) || m1.id DESC
|
||||
LIMIT 1
|
||||
`, chatID).Scan(&clock)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return clock, nil
|
||||
}
|
||||
|
||||
func (db sqlitePersistence) PendingContactRequests(currCursor string, limit int) ([]*common.Message, string, error) {
|
||||
cursorWhere := ""
|
||||
if currCursor != "" {
|
||||
|
|
|
@ -4218,6 +4218,10 @@ func (m *Messenger) MessagesExist(ids []string) (map[string]bool, error) {
|
|||
return m.persistence.MessagesExist(ids)
|
||||
}
|
||||
|
||||
func (m *Messenger) latestIncomingMessageClock(chatID string) (uint64, error) {
|
||||
return m.persistence.latestIncomingMessageClock(chatID)
|
||||
}
|
||||
|
||||
func (m *Messenger) MessageByChatID(chatID, cursor string, limit int) ([]*common.Message, string, error) {
|
||||
chat, err := m.persistence.Chat(chatID)
|
||||
if err != nil {
|
||||
|
@ -4395,11 +4399,15 @@ func (m *Messenger) MarkAllRead(chatID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
chat, ok := m.allChats.Load(chatID)
|
||||
if !ok {
|
||||
return errors.New("chat not found")
|
||||
clock, _ := m.latestIncomingMessageClock(chatID)
|
||||
|
||||
if clock == 0 {
|
||||
chat, ok := m.allChats.Load(chatID)
|
||||
if !ok {
|
||||
return errors.New("chat not found")
|
||||
}
|
||||
clock, _ = chat.NextClockAndTimestamp(m.getTimesource())
|
||||
}
|
||||
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
||||
|
||||
return m.markAllRead(chatID, clock, true)
|
||||
}
|
||||
|
|
|
@ -1137,7 +1137,7 @@ func (m *Messenger) HandleChatMessage(state *ReceivedMessageState) error {
|
|||
return err // matchChatEntity returns a descriptive error message
|
||||
}
|
||||
|
||||
if chat.ReadMessagesAtClockValue > state.CurrentMessageState.WhisperTimestamp {
|
||||
if chat.ReadMessagesAtClockValue >= receivedMessage.Clock {
|
||||
receivedMessage.Seen = true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue