fix: Don't try to update unknown communities (#10704)
This commit is contained in:
parent
348024c17e
commit
6ff8683338
|
@ -237,6 +237,11 @@ QtObject:
|
||||||
|
|
||||||
proc getChatIndex*(self: Service, channelGroupId, chatId: string): int =
|
proc getChatIndex*(self: Service, channelGroupId, chatId: string): int =
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
|
if not self.channelGroups.contains(channelGroupId):
|
||||||
|
warn "unknown channel group", channelGroupId
|
||||||
|
return -1
|
||||||
|
|
||||||
for chat in self.channelGroups[channelGroupId].chats:
|
for chat in self.channelGroups[channelGroupId].chats:
|
||||||
if (chat.id == chatId):
|
if (chat.id == chatId):
|
||||||
return i
|
return i
|
||||||
|
@ -247,6 +252,10 @@ QtObject:
|
||||||
if communityId == "" or categoryId == "":
|
if communityId == "" or categoryId == "":
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
if not self.channelGroups.contains(communityId):
|
||||||
|
warn "unknown community", communityId
|
||||||
|
return false
|
||||||
|
|
||||||
for chat in self.channelGroups[communityId].chats:
|
for chat in self.channelGroups[communityId].chats:
|
||||||
if chat.categoryId != categoryId:
|
if chat.categoryId != categoryId:
|
||||||
continue
|
continue
|
||||||
|
@ -259,8 +268,13 @@ QtObject:
|
||||||
if communityId == "":
|
if communityId == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.channelGroups.contains(communityId):
|
||||||
|
warn "unknown community", communityId
|
||||||
|
return
|
||||||
|
|
||||||
result.unviewedMentionsCount = 0
|
result.unviewedMentionsCount = 0
|
||||||
result.unviewedMessagesCount = 0
|
result.unviewedMessagesCount = 0
|
||||||
|
|
||||||
for chat in self.channelGroups[communityId].chats:
|
for chat in self.channelGroups[communityId].chats:
|
||||||
result.unviewedMentionsCount += chat.unviewedMentionsCount
|
result.unviewedMentionsCount += chat.unviewedMentionsCount
|
||||||
if chat.muted:
|
if chat.muted:
|
||||||
|
@ -272,6 +286,7 @@ QtObject:
|
||||||
# status-go doesn't seem to preserve categoryIDs from chat
|
# status-go doesn't seem to preserve categoryIDs from chat
|
||||||
# objects received via new messages. So we rely on what we
|
# objects received via new messages. So we rely on what we
|
||||||
# have in memory.
|
# have in memory.
|
||||||
|
|
||||||
if chat.id == "":
|
if chat.id == "":
|
||||||
return
|
return
|
||||||
var categoryId = ""
|
var categoryId = ""
|
||||||
|
@ -284,8 +299,9 @@ QtObject:
|
||||||
var channelGroupId = chat.communityId
|
var channelGroupId = chat.communityId
|
||||||
if (channelGroupId == ""):
|
if (channelGroupId == ""):
|
||||||
channelGroupId = singletonInstance.userProfile.getPubKey()
|
channelGroupId = singletonInstance.userProfile.getPubKey()
|
||||||
if (not self.channelGroups.contains(channelGroupId)):
|
|
||||||
warn "Unknown community for new channel update", channelGroupId
|
if not self.channelGroups.contains(channelGroupId):
|
||||||
|
warn "unknown community for new channel update", channelGroupId
|
||||||
return
|
return
|
||||||
|
|
||||||
let index = self.getChatIndex(channelGroupId, chat.id)
|
let index = self.getChatIndex(channelGroupId, chat.id)
|
||||||
|
@ -295,6 +311,11 @@ QtObject:
|
||||||
self.channelGroups[channelGroupId].chats[index] = self.chats[chat.id]
|
self.channelGroups[channelGroupId].chats[index] = self.chats[chat.id]
|
||||||
|
|
||||||
proc updateMissingFieldsInCommunityChat(self: Service, channelGroupId: string, newChat: ChatDto): ChatDto =
|
proc updateMissingFieldsInCommunityChat(self: Service, channelGroupId: string, newChat: ChatDto): ChatDto =
|
||||||
|
|
||||||
|
if not self.channelGroups.contains(channelGroupId):
|
||||||
|
warn "unknown channel group", channelGroupId
|
||||||
|
return
|
||||||
|
|
||||||
var chat = newChat
|
var chat = newChat
|
||||||
for previousChat in self.channelGroups[channelGroupId].chats:
|
for previousChat in self.channelGroups[channelGroupId].chats:
|
||||||
if previousChat.id != newChat.id:
|
if previousChat.id != newChat.id:
|
||||||
|
@ -308,6 +329,7 @@ QtObject:
|
||||||
|
|
||||||
# Community channel groups have less info because they come from community signals
|
# Community channel groups have less info because they come from community signals
|
||||||
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto, isCommunityChannelGroup: bool = false) =
|
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto, isCommunityChannelGroup: bool = false) =
|
||||||
|
|
||||||
var newChannelGroups = channelGroup
|
var newChannelGroups = channelGroup
|
||||||
if isCommunityChannelGroup and self.channelGroups.contains(channelGroup.id):
|
if isCommunityChannelGroup and self.channelGroups.contains(channelGroup.id):
|
||||||
# We need to update missing fields in the chats seq before saving
|
# We need to update missing fields in the chats seq before saving
|
||||||
|
@ -319,7 +341,7 @@ QtObject:
|
||||||
self.updateOrAddChat(chat)
|
self.updateOrAddChat(chat)
|
||||||
|
|
||||||
proc getChannelGroupById*(self: Service, channelGroupId: string): ChannelGroupDto =
|
proc getChannelGroupById*(self: Service, channelGroupId: string): ChannelGroupDto =
|
||||||
if (not self.channelGroups.contains(channelGroupId)):
|
if not self.channelGroups.contains(channelGroupId):
|
||||||
warn "Unknown channel group", channelGroupId
|
warn "Unknown channel group", channelGroupId
|
||||||
return
|
return
|
||||||
return self.channelGroups[channelGroupId]
|
return self.channelGroups[channelGroupId]
|
||||||
|
|
|
@ -601,7 +601,7 @@ QtObject:
|
||||||
self.events.emit(SIGNAL_COMMUNITY_KICKED, CommunityArgs(community: community))
|
self.events.emit(SIGNAL_COMMUNITY_KICKED, CommunityArgs(community: community))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Error handling community updates", msg = e.msg, communities, updatedChats, removedChats
|
error "Error handling community updates", msg = e.msg
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
self.doConnect()
|
self.doConnect()
|
||||||
|
|
Loading…
Reference in New Issue