address feedback

This commit is contained in:
Andrea Maria Piana 2021-06-01 11:29:37 +02:00
parent af1e47c258
commit 60de443e89
6 changed files with 75 additions and 77 deletions

View File

@ -37,6 +37,7 @@ var (
SigningPhrase: "yurt joey vibe", SigningPhrase: "yurt joey vibe",
SendPushNotifications: true, SendPushNotifications: true,
ProfilePicturesVisibility: ProfilePicturesVisibilityContactsOnly, ProfilePicturesVisibility: ProfilePicturesVisibilityContactsOnly,
DefaultSyncPeriod: 86400,
UseMailservers: true, UseMailservers: true,
LinkPreviewRequestEnabled: true, LinkPreviewRequestEnabled: true,
WalletRootAddress: types.HexToAddress("0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")} WalletRootAddress: types.HexToAddress("0x3B591fd819F86D0A6a2EF2Bcb94f77807a7De1a6")}

View File

@ -452,58 +452,6 @@ func (m *MessageHandler) HandlePairInstallation(state *ReceivedMessageState, mes
return nil return nil
} }
// HandleCommunityDescription handles an community description
func (m *MessageHandler) HandleCommunityDescription(state *ReceivedMessageState, signer *ecdsa.PublicKey, description protobuf.CommunityDescription, rawPayload []byte) error {
communityResponse, err := m.communitiesManager.HandleCommunityDescriptionMessage(signer, &description, rawPayload)
if err != nil {
return err
}
community := communityResponse.Community
state.Response.AddCommunity(community)
state.Response.CommunityChanges = append(state.Response.CommunityChanges, communityResponse.Changes)
// If we haven't joined the org, nothing to do
if !community.Joined() {
return nil
}
// Update relevant chats names and add new ones
// Currently removal is not supported
chats := CreateCommunityChats(community, state.Timesource)
var chatIDs []string
for i, chat := range chats {
oldChat, ok := state.AllChats.Load(chat.ID)
if !ok {
// Beware, don't use the reference in the range (i.e chat) as it's a shallow copy
state.AllChats.Store(chat.ID, chats[i])
state.Response.AddChat(chat)
chatIDs = append(chatIDs, chat.ID)
// Update name, currently is the only field is mutable
} else if oldChat.Name != chat.Name {
oldChat.Name = chat.Name
// TODO(samyoul) remove storing of an updated reference pointer?
state.AllChats.Store(chat.ID, oldChat)
state.Response.AddChat(chat)
}
}
// Load transport filters
filters, err := m.transport.InitPublicFilters(chatIDs)
if err != nil {
return err
}
for _, filter := range filters {
state.AllFilters[filter.ChatID] = filter
}
return nil
}
// HandleCommunityInvitation handles an community invitation // HandleCommunityInvitation handles an community invitation
func (m *MessageHandler) HandleCommunityInvitation(state *ReceivedMessageState, signer *ecdsa.PublicKey, invitation protobuf.CommunityInvitation, rawPayload []byte) error { func (m *MessageHandler) HandleCommunityInvitation(state *ReceivedMessageState, signer *ecdsa.PublicKey, invitation protobuf.CommunityInvitation, rawPayload []byte) error {
if invitation.PublicKey == nil { if invitation.PublicKey == nil {

View File

@ -2327,8 +2327,6 @@ type ReceivedMessageState struct {
AllInstallations *installationMap AllInstallations *installationMap
// List of communities modified // List of communities modified
ModifiedInstallations *stringBoolMap ModifiedInstallations *stringBoolMap
// List of filters
AllFilters map[string]*transport.Filter
// Map of existing messages // Map of existing messages
ExistingMessagesMap map[string]bool ExistingMessagesMap map[string]bool
// EmojiReactions is a list of emoji reactions for the current batch // EmojiReactions is a list of emoji reactions for the current batch
@ -2447,7 +2445,6 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
ModifiedInstallations: m.modifiedInstallations, ModifiedInstallations: m.modifiedInstallations,
ExistingMessagesMap: make(map[string]bool), ExistingMessagesMap: make(map[string]bool),
EmojiReactions: make(map[string]*EmojiReaction), EmojiReactions: make(map[string]*EmojiReaction),
AllFilters: make(map[string]*transport.Filter),
GroupChatInvitations: make(map[string]*GroupChatInvitation), GroupChatInvitations: make(map[string]*GroupChatInvitation),
Response: &MessengerResponse{}, Response: &MessengerResponse{},
Timesource: m.getTimesource(), Timesource: m.getTimesource(),
@ -2794,7 +2791,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
case protobuf.CommunityDescription: case protobuf.CommunityDescription:
logger.Debug("Handling CommunityDescription") logger.Debug("Handling CommunityDescription")
err = m.handler.HandleCommunityDescription(messageState, publicKey, msg.ParsedMessage.Interface().(protobuf.CommunityDescription), msg.DecryptedPayload) err = m.handleCommunityDescription(messageState, publicKey, msg.ParsedMessage.Interface().(protobuf.CommunityDescription), msg.DecryptedPayload)
if err != nil { if err != nil {
logger.Warn("failed to handle CommunityDescription", zap.Error(err)) logger.Warn("failed to handle CommunityDescription", zap.Error(err))
allMessagesProcessed = false allMessagesProcessed = false

View File

@ -37,6 +37,18 @@ func (m *Messenger) ActiveChats() []*Chat {
return chats return chats
} }
func (m *Messenger) initChatSyncFields(chat *Chat) error {
defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod()
if err != nil {
return err
}
timestamp := uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod
chat.SyncedTo = timestamp
chat.SyncedFrom = timestamp
return nil
}
func (m *Messenger) CreatePublicChat(request *requests.CreatePublicChat) (*MessengerResponse, error) { func (m *Messenger) CreatePublicChat(request *requests.CreatePublicChat) (*MessengerResponse, error) {
if err := request.Validate(); err != nil { if err := request.Validate(); err != nil {
return nil, err return nil, err
@ -68,13 +80,9 @@ func (m *Messenger) CreatePublicChat(request *requests.CreatePublicChat) (*Messe
// We set the synced to, synced from to the default time // We set the synced to, synced from to the default time
if !willSync { if !willSync {
defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod() if err := m.initChatSyncFields(chat); err != nil {
if err != nil {
return nil, err return nil, err
} }
timestamp := uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod
chat.SyncedTo = timestamp
chat.SyncedFrom = timestamp
} }
err = m.saveChat(chat) err = m.saveChat(chat)
@ -134,13 +142,9 @@ func (m *Messenger) CreateProfileChat(request *requests.CreateProfileChat) (*Mes
// We set the synced to, synced from to the default time // We set the synced to, synced from to the default time
if !willSync { if !willSync {
defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod() if err := m.initChatSyncFields(chat); err != nil {
if err != nil {
return nil, err return nil, err
} }
timestamp := uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod
chat.SyncedTo = timestamp
chat.SyncedFrom = timestamp
} }
_, err = m.scheduleSyncFilters([]*transport.Filter{filter}) _, err = m.scheduleSyncFilters([]*transport.Filter{filter})
@ -191,13 +195,9 @@ func (m *Messenger) CreateOneToOneChat(request *requests.CreateOneToOneChat) (*M
// We set the synced to, synced from to the default time // We set the synced to, synced from to the default time
if !willSync { if !willSync {
defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod() if err := m.initChatSyncFields(chat); err != nil {
if err != nil {
return nil, err return nil, err
} }
timestamp := uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod
chat.SyncedTo = timestamp
chat.SyncedFrom = timestamp
} }
err = m.saveChat(chat) err = m.saveChat(chat)

View File

@ -690,3 +690,55 @@ func (m *Messenger) passStoredCommunityInfoToSignalHandler(communityID string) {
m.config.messengerSignalsHandler.CommunityInfoFound(community) m.config.messengerSignalsHandler.CommunityInfoFound(community)
m.forgetCommunityRequest(communityID) m.forgetCommunityRequest(communityID)
} }
// handleCommunityDescription handles an community description
func (m *Messenger) handleCommunityDescription(state *ReceivedMessageState, signer *ecdsa.PublicKey, description protobuf.CommunityDescription, rawPayload []byte) error {
communityResponse, err := m.communitiesManager.HandleCommunityDescriptionMessage(signer, &description, rawPayload)
if err != nil {
return err
}
community := communityResponse.Community
state.Response.AddCommunity(community)
state.Response.CommunityChanges = append(state.Response.CommunityChanges, communityResponse.Changes)
// If we haven't joined the org, nothing to do
if !community.Joined() {
return nil
}
// Update relevant chats names and add new ones
// Currently removal is not supported
chats := CreateCommunityChats(community, state.Timesource)
var chatIDs []string
for i, chat := range chats {
oldChat, ok := state.AllChats.Load(chat.ID)
if !ok {
// Beware, don't use the reference in the range (i.e chat) as it's a shallow copy
state.AllChats.Store(chat.ID, chats[i])
state.Response.AddChat(chat)
chatIDs = append(chatIDs, chat.ID)
// Update name, currently is the only field is mutable
} else if oldChat.Name != chat.Name {
oldChat.Name = chat.Name
// TODO(samyoul) remove storing of an updated reference pointer?
state.AllChats.Store(chat.ID, oldChat)
state.Response.AddChat(chat)
}
}
// Load transport filters
filters, err := m.transport.InitPublicFilters(chatIDs)
if err != nil {
return err
}
_, err = m.scheduleSyncFilters(filters)
if err != nil {
return err
}
return nil
}

View File

@ -167,7 +167,7 @@ func (m *Messenger) syncChat(chatID string) (*MessengerResponse, error) {
return m.syncFilters(filters) return m.syncFilters(filters)
} }
func (m *Messenger) defaultSyncPeriod() (uint32, error) { func (m *Messenger) defaultSyncPeriodFromNow() (uint32, error) {
defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod() defaultSyncPeriod, err := m.settings.GetDefaultSyncPeriod()
if err != nil { if err != nil {
return 0, err return 0, err
@ -175,9 +175,9 @@ func (m *Messenger) defaultSyncPeriod() (uint32, error) {
return uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod, nil return uint32(m.getTimesource().GetCurrentTime()/1000) - defaultSyncPeriod, nil
} }
// calculateSyncPeriod caps the sync period to the default // capToDefaultSyncPeriod caps the sync period to the default
func (m *Messenger) calculateSyncPeriod(period uint32) (uint32, error) { func (m *Messenger) capToDefaultSyncPeriod(period uint32) (uint32, error) {
d, err := m.defaultSyncPeriod() d, err := m.defaultSyncPeriodFromNow()
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -232,7 +232,7 @@ func (m *Messenger) syncFilters(filters []*transport.Filter) (*MessengerResponse
topicData, ok := topicsData[filter.Topic.String()] topicData, ok := topicsData[filter.Topic.String()]
if !ok { if !ok {
lastRequest, err := m.defaultSyncPeriod() lastRequest, err := m.defaultSyncPeriodFromNow()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -243,7 +243,7 @@ func (m *Messenger) syncFilters(filters []*transport.Filter) (*MessengerResponse
} }
batch, ok := batches[topicData.LastRequest] batch, ok := batches[topicData.LastRequest]
if !ok { if !ok {
from, err := m.calculateSyncPeriod(uint32(topicData.LastRequest)) from, err := m.capToDefaultSyncPeriod(uint32(topicData.LastRequest))
if err != nil { if err != nil {
return nil, err return nil, err
} }