Fix syncing of public chats

Timeline chats are created as public chats, in any place where we sync
them we need to check that they are excluded.
This commit is contained in:
Andrea Maria Piana 2021-03-02 16:20:25 +01:00
parent 09942bf200
commit 0a686bba4c
5 changed files with 8 additions and 9 deletions

View File

@ -1 +1 @@
0.72.1
0.72.2

View File

@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"errors"
"math/rand"
"strings"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
@ -100,8 +101,10 @@ func (c *Chat) ProfileUpdates() bool {
return c.ChatType == ChatTypeProfile
}
// It looks like status-react created profile chats as public chats
// so for now we need to check for the presence of "@" in their chatID
func (c *Chat) Timeline() bool {
return c.ChatType == ChatTypeTimeline
return c.ChatType == ChatTypeTimeline || (c.Public() && strings.HasPrefix(c.ID, "@"))
}
func (c *Chat) OneToOne() bool {

View File

@ -4,7 +4,6 @@ import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"strings"
"github.com/pkg/errors"
@ -449,9 +448,7 @@ func (m *MessageHandler) HandleChatMessage(state *ReceivedMessageState) error {
return err // matchChatEntity returns a descriptive error message
}
// It looks like status-react created profile chats as public chats
// so for now we need to check for the presence of "@" in their chatID
if chat.Public() && receivedMessage.ContentType == protobuf.ChatMessage_IMAGE && !strings.HasPrefix(chat.ID, "@") {
if chat.Public() && receivedMessage.ContentType == protobuf.ChatMessage_IMAGE && !chat.Timeline() {
return errors.New("images are not allowed in public chats")
}

View File

@ -2210,7 +2210,7 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string)
}
for _, chat := range m.allChats {
if chat.Public() && chat.Active {
if !chat.Timeline() && chat.Public() && chat.Active {
if err := m.syncPublicChat(ctx, chat); err != nil {
return err
}

View File

@ -3,7 +3,6 @@ package protocol
import (
"context"
"errors"
"strings"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/requests"
@ -155,7 +154,7 @@ func (m *Messenger) saveChat(chat *Chat) error {
chat.Identicon = identicon
}
// Sync chat if it's a new active public chat, but not a timeline chat
if !ok && chat.Active && chat.Public() && !strings.HasPrefix(chat.ID, "@") {
if !ok && chat.Active && chat.Public() && !chat.Timeline() {
if err := m.syncPublicChat(context.Background(), chat); err != nil {
return err