fix(groups): Fix invitations for groups

Closes: #4767
This commit is contained in:
Boris Melnik 2022-02-17 17:13:58 +03:00
parent 0c88da4d81
commit 9a9d671014
9 changed files with 98 additions and 14 deletions

View File

@ -15,10 +15,11 @@ type
active: bool
position: int
categoryId: string
highlight: bool
proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, description: string,
`type`: int, amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
position: int, categoryId: string = "") =
position: int, categoryId: string = "", highlight: bool = false) =
self.id = id
self.name = name
self.amIChatAdmin = amIChatAdmin
@ -34,13 +35,14 @@ proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, de
self.active = active
self.position = position
self.categoryId = categoryId
self.highlight = highlight
proc initBaseItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int,
amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool,
position: int, categoryId: string = ""): BaseItem =
position: int, categoryId: string = "", highlight: bool = false): BaseItem =
result = BaseItem()
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
notificationsCount, muted, blocked, active, position, categoryId)
notificationsCount, muted, blocked, active, position, categoryId, highlight)
proc delete*(self: BaseItem) =
discard
@ -122,3 +124,9 @@ method categoryId*(self: BaseItem): string {.inline base.} =
method `categoryId=`*(self: var BaseItem, value: string) {.inline base.} =
self.categoryId = value
method highlight*(self: BaseItem): bool {.inline base.} =
self.highlight
method `highlight=`*(self: var BaseItem, value: bool) {.inline base.} =
self.highlight = value

View File

@ -94,6 +94,12 @@ method init*(self: Controller) =
var args = ContactArgs(e)
self.delegate.onContactUnblocked(args.contactId)
self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args):
var args = ChatUpdateArgsNew(e)
self.delegate.addChatIfDontExist(args.chats, false, self.events, self.settingsService, self.contactService, self.chatService,
self.communityService, self.messageService, self.gifService, self.mailserversService, setChatAsActive = false)
if (self.isCommunitySection):
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e)

View File

@ -6,10 +6,10 @@ type
subItems: SubModel
proc initItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool,
hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string): Item =
hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string, highlight: bool = false): Item =
result = Item()
result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages,
notificationsCount, muted, blocked, active, position, categoryId)
notificationsCount, muted, blocked, active, position, categoryId, highlight)
result.subItems = newSubModel()
proc delete*(self: Item) =
@ -36,6 +36,7 @@ proc `$`*(self: Item): string =
active: {self.active},
position: {self.position},
categoryId: {self.categoryId},
highlight: {self.highlight},
subItems:[
{$self.subItems}
]"""
@ -56,7 +57,8 @@ proc toJsonNode*(self: Item): JsonNode =
"blocked": self.blocked,
"active": self.active,
"position": self.position,
"categoryId": self.categoryId
"categoryId": self.categoryId,
"highlight": self.highlight
}
proc appendSubItems*(self: Item, items: seq[SubItem]) =

View File

@ -21,6 +21,7 @@ type
SubItems
IsCategory
CategoryId
Highlight
QtObject:
type
@ -85,7 +86,8 @@ QtObject:
ModelRole.Position.int:"position",
ModelRole.SubItems.int:"subItems",
ModelRole.IsCategory.int:"isCategory",
ModelRole.CategoryId.int:"categoryId"
ModelRole.CategoryId.int:"categoryId",
ModelRole.Highlight.int:"highlight"
}.toTable
method data(self: Model, index: QModelIndex, role: int): QVariant =
@ -133,6 +135,8 @@ QtObject:
result = newQVariant(item.`type` == ChatType.Unknown.int)
of ModelRole.CategoryId:
result = newQVariant(item.categoryId)
of ModelRole.Highlight:
result = newQVariant(item.highlight)
proc appendItem*(self: Model, item: Item) =
let parentModelIndex = newQModelIndex()
@ -182,6 +186,12 @@ QtObject:
return self.items[index]
proc isItemWithIdAdded*(self: Model, id: string): bool =
for it in self.items:
if(it.id == id):
return true
return false
proc getItemById*(self: Model, id: string): Item =
for it in self.items:
if(it.id == id):

View File

@ -385,7 +385,8 @@ method addNewChat*(
communityService: community_service.Service,
messageService: message_service.Service,
gifService: gif_service.Service,
mailserversService: mailservers_service.Service) =
mailserversService: mailservers_service.Service,
setChatAsActive: bool = true) =
let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0
let notificationsCount = chatDto.unviewedMentionsCount
var chatName = chatDto.name
@ -404,12 +405,13 @@ method addNewChat*(
if chatDto.categoryId == "":
let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description,
chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted,
blocked=false, active=false, position = 0, chatDto.categoryId)
blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight)
self.addSubmodule(chatDto.id, belongsToCommunity, isUsersListAvailable, events, settingsService, contactService, chatService,
communityService, messageService, gifService, mailserversService)
self.chatContentModules[chatDto.id].load()
self.view.chatsModel().appendItem(item)
# make new added chat active one
if setChatAsActive:
self.setActiveItemSubItem(item.id, "")
else:
let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId)
@ -422,6 +424,9 @@ method addNewChat*(
categoryItem.appendSubItem(channelItem)
self.setActiveItemSubItem(categoryItem.id, channelItem.id)
method doesChatExist*(self: Module, chatId: string): bool =
return self.view.chatsModel().isItemWithIdAdded(chatId)
method removeCommunityChat*(self: Module, chatId: string) =
if(not self.chatContentModules.contains(chatId)):
return
@ -691,3 +696,20 @@ method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, p
method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) =
self.view.setLoadingHistoryMessagesInProgress(isLoading)
method addChatIfDontExist*(self: Module,
chats: seq[ChatDto],
belongsToCommunity: bool,
events: EventEmitter,
settingsService: settings_service.ServiceInterface,
contactService: contact_service.Service,
chatService: chat_service.Service,
communityService: community_service.Service,
messageService: message_service.Service,
gifService: gif_service.Service,
mailserversService: mailservers_service.Service,
setChatAsActive: bool = true) =
for chatDto in chats:
if not self.doesChatExist(chatDto.id):
self.addNewChat(chatDto, belongsToCommunity, events, settingsService, contactService, chatService,
communityService, messageService, gifService, mailserversService, setChatAsActive)

View File

@ -8,7 +8,24 @@ method addNewChat*(self: AccessInterface, chatDto: ChatDto, belongsToCommunity:
settingsService: settings_service.ServiceInterface, contactService: contact_service.Service,
chatService: chat_service.Service, communityService: community_service.Service,
messageService: message_service.Service, gifService: gif_service.Service,
mailserversService: mailservers_service.Service) {.base.} =
mailserversService: mailservers_service.Service, setChatAsActive: bool = true) {.base.} =
raise newException(ValueError, "No implementation available")
method doesChatExist*(self: AccessInterface, chatId: string): bool {.base.} =
raise newException(ValueError, "No implementation available")
method addChatIfDontExist*(self: AccessInterface,
chats: seq[ChatDto],
belongsToCommunity: bool,
events: EventEmitter,
settingsService: settings_service.ServiceInterface,
contactService: contact_service.Service,
chatService: chat_service.Service,
communityService: community_service.Service,
messageService: message_service.Service,
gifService: gif_service.Service,
mailserversService: mailservers_service.Service,
setChatAsActive: bool = true) {.base.} =
raise newException(ValueError, "No implementation available")
method onNewMessagesReceived*(self: AccessInterface, chatId: string, unviewedMessagesCount: int,

View File

@ -47,6 +47,7 @@ type ChatDto* = object
canPost*: bool
position*: int
categoryId*: string
highlight*: bool
proc `$`*(self: ChatDto): string =
result = fmt"""ChatDto(
@ -72,7 +73,8 @@ proc `$`*(self: ChatDto): string =
syncedTo: {self.syncedTo},
syncedFrom: {self.syncedFrom},
categoryId: {self.categoryId},
position: {self.position}
position: {self.position},
highlight: {self.highlight}
)"""
proc toChatMember(jsonObj: JsonNode): ChatMember =
@ -103,6 +105,7 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto =
discard jsonObj.getProp("joined", result.joined)
discard jsonObj.getProp("syncedTo", result.syncedTo)
discard jsonObj.getProp("syncedFrom", result.syncedFrom)
discard jsonObj.getProp("highlight", result.highlight)
result.chatType = ChatType.Unknown
var chatTypeInt: int

View File

@ -8,6 +8,7 @@ import ../../../backend/chat as status_chat
import ../../../backend/chatCommands as status_chat_commands
import ../../../app/global/global_singleton
import ../../../app/core/eventemitter
import ../../../app/core/signals/types
import ../../../constants
import ../../common/message as message_common
@ -94,7 +95,22 @@ QtObject:
result.contactService = contactService
result.chats = initTable[string, ChatDto]()
# Forward declarations
proc updateOrAddChat*(self: Service, chat: ChatDto)
proc doConnect(self: Service) =
self.events.on(SignalType.Message.event) do(e: Args):
var receivedData = MessageSignal(e)
# Handling chat updates
if (receivedData.chats.len > 0):
for chatDto in receivedData.chats:
self.updateOrAddChat(chatDto)
self.events.emit(SIGNAL_CHAT_UPDATE, ChatUpdateArgsNew(messages: receivedData.messages, chats: receivedData.chats))
proc init*(self: Service) =
self.doConnect()
try:
let response = status_chat.getChats()

@ -1 +1 @@
Subproject commit 5780f183c7b3cf63c3abbc584daa72078241e917
Subproject commit ccfe8cc0ff7f32993f0aef996fe45fa6960b1e3e