fix: remove mailserver topic when deactivating a chat (#2460)
This fixes an issue where re-joining a chat does not load the messages again from the mailserver
This commit is contained in:
parent
90122f3e2e
commit
ebd4511d24
|
@ -356,9 +356,28 @@ func (m *Messenger) deactivateChat(chatID string, shouldBeSynced bool) (*Messeng
|
|||
return nil, ErrChatNotFound
|
||||
}
|
||||
|
||||
// Reset mailserver last request to allow re-fetching messages if joining a chat again
|
||||
filters, err := m.filtersForChat(chatID)
|
||||
if err != nil && err != ErrNoFiltersForChat {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if m.mailserversDatabase != nil {
|
||||
for _, filter := range filters {
|
||||
if !filter.Listen || filter.Ephemeral {
|
||||
continue
|
||||
}
|
||||
|
||||
err := m.mailserversDatabase.ResetLastRequest(filter.Topic.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clock, _ := chat.NextClockAndTimestamp(m.getTimesource())
|
||||
|
||||
err := m.persistence.DeactivateChat(chat, clock)
|
||||
err = m.persistence.DeactivateChat(chat, clock)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -23,6 +23,8 @@ var tolerance uint32 = 60
|
|||
var mailserverRequestTimeout = 45 * time.Second
|
||||
var oneMonthInSeconds uint32 = 31 * 24 * 60 * 60
|
||||
|
||||
var ErrNoFiltersForChat = errors.New("no filter registered for given chat")
|
||||
|
||||
func (m *Messenger) shouldSync() (bool, error) {
|
||||
if m.mailserver == nil || !m.online() {
|
||||
return false, nil
|
||||
|
@ -140,7 +142,7 @@ func (m *Messenger) filtersForChat(chatID string) ([]*transport.Filter, error) {
|
|||
} else {
|
||||
filter := m.transport.FilterByChatID(chatID)
|
||||
if filter == nil {
|
||||
return nil, errors.New("no filter registered for given chat")
|
||||
return nil, ErrNoFiltersForChat
|
||||
}
|
||||
filters = []*transport.Filter{filter}
|
||||
}
|
||||
|
@ -277,6 +279,7 @@ func (m *Messenger) syncFilters(filters []*transport.Filter) (*MessengerResponse
|
|||
LastRequest: int(lastRequest),
|
||||
}
|
||||
}
|
||||
|
||||
batch, ok := batches[topicData.LastRequest]
|
||||
if !ok {
|
||||
from, err := m.capToDefaultSyncPeriod(uint32(topicData.LastRequest))
|
||||
|
|
|
@ -297,6 +297,11 @@ func (d *Database) Topics() ([]MailserverTopic, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (d *Database) ResetLastRequest(topic string) error {
|
||||
_, err := d.db.Exec("UPDATE mailserver_topics SET last_request = 0 WHERE topic = ?", topic)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Database) DeleteTopic(topic string) error {
|
||||
_, err := d.db.Exec(`DELETE FROM mailserver_topics WHERE topic = ?`, topic)
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue