Avoid concurrent access to contacts

We were not locking before accessing the contacts map and it would panic
in some cases.

I have changed the code to pull contacts from db so we move away from
having locks.
This commit is contained in:
Andrea Maria Piana 2021-01-27 10:33:50 +01:00
parent e5115d60f1
commit ee8f333dbf
2 changed files with 6 additions and 2 deletions

View File

@ -1 +1 @@
0.69.1
0.69.2

View File

@ -3292,7 +3292,11 @@ func (m *Messenger) MessageByChatID(chatID, cursor string, limit int) ([]*common
if chat.Timeline() {
var chatIDs = []string{"@" + contactIDFromPublicKey(&m.identity.PublicKey)}
for _, contact := range m.allContacts {
contacts, err := m.persistence.Contacts()
if err != nil {
return nil, "", err
}
for _, contact := range contacts {
if contact.IsAdded() {
chatIDs = append(chatIDs, "@"+contact.ID)
}