feat(token-permissions): Add channel name to token permissin chat list model

Fixes: #11481
This commit is contained in:
Boris Melnik 2023-07-19 16:48:37 +03:00
parent 9b17a66935
commit b5950b045c
10 changed files with 57 additions and 10 deletions

View File

@ -473,6 +473,9 @@ proc getChatDetails*(self: Controller, chatId: string): ChatDto =
proc getChatDetailsForChatTypes*(self: Controller, types: seq[ChatType]): seq[ChatDto] = proc getChatDetailsForChatTypes*(self: Controller, types: seq[ChatType]): seq[ChatDto] =
return self.chatService.getChatsOfChatTypes(types) return self.chatService.getChatsOfChatTypes(types)
proc getChatDetailsByIds*(self: Controller, chatIds: seq[string]): seq[ChatDto] =
return self.chatService.getChatsByIds(chatIds)
proc chatsWithCategoryHaveUnreadMessages*(self: Controller, communityId: string, categoryId: string): bool = proc chatsWithCategoryHaveUnreadMessages*(self: Controller, communityId: string, categoryId: string): bool =
return self.chatService.chatsWithCategoryHaveUnreadMessages(communityId, categoryId) return self.chatService.chatsWithCategoryHaveUnreadMessages(communityId, categoryId)

View File

@ -278,7 +278,8 @@ proc rebuildCommunityTokenPermissionsModel(self: Module) =
var tokenPermissionsItems: seq[TokenPermissionItem] = @[] var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
for id, tokenPermission in community.tokenPermissions: for id, tokenPermission in community.tokenPermissions:
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission) let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
tokenPermissionsItems.add(tokenPermissionItem) tokenPermissionsItems.add(tokenPermissionItem)
let memberPermissions = filter(tokenPermissionsItems, tokenPermissionsItem => let memberPermissions = filter(tokenPermissionsItems, tokenPermissionsItem =>
@ -780,7 +781,8 @@ method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, per
singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed") singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed")
method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission) let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
self.view.tokenPermissionsModel.addItem(tokenPermissionItem) self.view.tokenPermissionsModel.addItem(tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin() self.reevaluateRequiresTokenPermissionToJoin()
@ -860,7 +862,8 @@ method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissions
self.updateTokenPermissionModel(checkPermissionsToJoinResponse.permissions, community) self.updateTokenPermissionModel(checkPermissionsToJoinResponse.permissions, community)
method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission) let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
self.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem) self.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin() self.reevaluateRequiresTokenPermissionToJoin()
@ -1055,6 +1058,7 @@ method joinGroupChatFromInvitation*(self: Module, groupName: string, chatId: str
method onChatRenamed*(self: Module, chatId: string, newName: string) = method onChatRenamed*(self: Module, chatId: string, newName: string) =
self.view.chatsModel().renameItemById(chatId, newName) self.view.chatsModel().renameItemById(chatId, newName)
self.view.tokenPermissionsModel().renameChatById(chatId, newName)
method onGroupChatDetailsUpdated*(self: Module, chatId, newName, newColor, newImage: string) = method onGroupChatDetailsUpdated*(self: Module, chatId, newName, newColor, newImage: string) =
self.view.chatsModel().updateNameColorIconOnItemById(chatId, newName, newColor, newImage) self.view.chatsModel().updateNameColorIconOnItemById(chatId, newName, newColor, newImage)

View File

@ -3,8 +3,10 @@ import ./io_interface
import ../../../core/signals/types import ../../../core/signals/types
import ../../../core/eventemitter import ../../../core/eventemitter
import ../../../../app_service/service/chat/dto/chat
import ../../../../app_service/service/community/service as community_service import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/contacts/service as contacts_service import ../../../../app_service/service/contacts/service as contacts_service
import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/network/service as networks_service import ../../../../app_service/service/network/service as networks_service
import ../../../../app_service/service/community_tokens/service as community_tokens_service import ../../../../app_service/service/community_tokens/service as community_tokens_service
import ../../../../app_service/service/token/service as token_service import ../../../../app_service/service/token/service as token_service
@ -20,6 +22,7 @@ type
communityTokensService: community_tokens_service.Service communityTokensService: community_tokens_service.Service
networksService: networks_service.Service networksService: networks_service.Service
tokenService: token_service.Service tokenService: token_service.Service
chatService: chat_service.Service
proc newController*( proc newController*(
delegate: io_interface.AccessInterface, delegate: io_interface.AccessInterface,
@ -29,6 +32,7 @@ proc newController*(
communityTokensService: community_tokens_service.Service, communityTokensService: community_tokens_service.Service,
networksService: networks_service.Service, networksService: networks_service.Service,
tokenService: token_service.Service, tokenService: token_service.Service,
chatService: chat_service.Service,
): Controller = ): Controller =
result = Controller() result = Controller()
result.delegate = delegate result.delegate = delegate
@ -38,6 +42,7 @@ proc newController*(
result.communityTokensService = communityTokensService result.communityTokensService = communityTokensService
result.networksService = networksService result.networksService = networksService
result.tokenService = tokenService result.tokenService = tokenService
result.chatService = chatService
proc delete*(self: Controller) = proc delete*(self: Controller) =
discard discard
@ -223,6 +228,9 @@ proc reorderCommunityChat*(
chatId, chatId,
position) position)
proc getChatDetailsByIds*(self: Controller, chatIds: seq[string]): seq[ChatDto] =
return self.chatService.getChatsByIds(chatIds)
proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) = proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) =
self.communityService.requestCommunityInfo(communityId, importing) self.communityService.requestCommunityInfo(communityId, importing)

View File

@ -19,6 +19,7 @@ import ../../../core/eventemitter
import ../../../../app_service/common/types import ../../../../app_service/common/types
import ../../../../app_service/service/community/service as community_service import ../../../../app_service/service/community/service as community_service
import ../../../../app_service/service/contacts/service as contacts_service import ../../../../app_service/service/contacts/service as contacts_service
import ../../../../app_service/service/chat/service as chat_service
import ../../../../app_service/service/network/service as networks_service import ../../../../app_service/service/network/service as networks_service
import ../../../../app_service/service/transaction/service as transaction_service import ../../../../app_service/service/transaction/service as transaction_service
import ../../../../app_service/service/community_tokens/service as community_tokens_service import ../../../../app_service/service/community_tokens/service as community_tokens_service
@ -59,6 +60,7 @@ proc newModule*(
networksService: networks_service.Service, networksService: networks_service.Service,
transactionService: transaction_service.Service, transactionService: transaction_service.Service,
tokensService: token_service.Service, tokensService: token_service.Service,
chatService: chat_service.Service,
): Module = ): Module =
result = Module() result = Module()
result.delegate = delegate result.delegate = delegate
@ -72,6 +74,7 @@ proc newModule*(
communityTokensService, communityTokensService,
networksService, networksService,
tokensService, tokensService,
chatService,
) )
result.communityTokensModule = community_tokens_module.newCommunityTokensModule(result, events, communityTokensService, transactionService, networksService) result.communityTokensModule = community_tokens_module.newCommunityTokensModule(result, events, communityTokensService, transactionService, networksService)
result.moduleLoaded = false result.moduleLoaded = false
@ -180,7 +183,8 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
var tokenPermissionsItems: seq[TokenPermissionItem] = @[] var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
for id, tokenPermission in community.tokenPermissions: for id, tokenPermission in community.tokenPermissions:
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission) let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
tokenPermissionsItems.add(tokenPermissionItem) tokenPermissionsItems.add(tokenPermissionItem)
return initCuratedCommunityItem( return initCuratedCommunityItem(

View File

@ -209,7 +209,7 @@ proc newModule*[T](
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService, tokenService) result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService, tokenService)
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService, result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
messageService, chatService, communityService) messageService, chatService, communityService)
result.communitiesModule = communities_module.newModule(result, events, communityService, contactsService, communityTokensService, networkService, transactionService, tokenService) result.communitiesModule = communities_module.newModule(result, events, communityService, contactsService, communityTokensService, networkService, transactionService, tokenService, chatService)
result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService, result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService,
messageService) messageService)
result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService) result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService)

View File

@ -3,17 +3,24 @@ import strformat
type type
TokenPermissionChatListItem* = object TokenPermissionChatListItem* = object
key: string key: string
channelName: string
proc `$`*(self: TokenPermissionChatListItem): string = proc `$`*(self: TokenPermissionChatListItem): string =
result = fmt"""TokenPermissionChatListItem( result = fmt"""TokenPermissionChatListItem(
key: {self.key} key: {self.key},
channelName: {self.channelName}
]""" ]"""
proc initTokenPermissionChatListItem*( proc initTokenPermissionChatListItem*(
key: string key: string,
channelName: string
): TokenPermissionChatListItem = ): TokenPermissionChatListItem =
result.key = key result.key = key
result.channelName = channelName
proc getKey*(self: TokenPermissionChatListItem): string = proc getKey*(self: TokenPermissionChatListItem): string =
return self.key return self.key
proc getChannelName*(self: TokenPermissionChatListItem): string =
return self.channelName

View File

@ -4,6 +4,7 @@ import token_permission_chat_list_item
type type
ModelRole {.pure.} = enum ModelRole {.pure.} = enum
Key = UserRole + 1 Key = UserRole + 1
ChannelName
QtObject: QtObject:
type TokenPermissionChatListModel* = ref object of QAbstractListModel type TokenPermissionChatListModel* = ref object of QAbstractListModel
@ -23,6 +24,7 @@ QtObject:
method roleNames(self: TokenPermissionChatListModel): Table[int, string] = method roleNames(self: TokenPermissionChatListModel): Table[int, string] =
{ {
ModelRole.Key.int:"key", ModelRole.Key.int:"key",
ModelRole.ChannelName.int:"channelName",
}.toTable }.toTable
proc countChanged(self: TokenPermissionChatListModel) {.signal.} proc countChanged(self: TokenPermissionChatListModel) {.signal.}
@ -45,6 +47,8 @@ QtObject:
case enumRole: case enumRole:
of ModelRole.Key: of ModelRole.Key:
result = newQVariant(item.getKey()) result = newQVariant(item.getKey())
of ModelRole.ChannelName:
result = newQVariant(item.getChannelName())
proc addItem*(self: TokenPermissionChatListModel, item: TokenPermissionChatListItem) = proc addItem*(self: TokenPermissionChatListModel, item: TokenPermissionChatListItem) =
let parentModelIndex = newQModelIndex() let parentModelIndex = newQModelIndex()
@ -62,3 +66,11 @@ QtObject:
proc getItems*(self: TokenPermissionChatListModel): seq[TokenPermissionChatListItem] = proc getItems*(self: TokenPermissionChatListModel): seq[TokenPermissionChatListItem] =
return self.items return self.items
proc renameChatById*(self: TokenPermissionChatListModel, chatId: string, newName: string) =
for i in 0 ..< self.items.len:
if self.items[i].getKey() == chatId:
self.items[i] = initTokenPermissionChatListItem(chatId, newName)
let index = self.createIndex(i, 0, nil)
self.dataChanged(index, index, @[ModelRole.ChannelName.int])
return

View File

@ -63,7 +63,7 @@ proc getIsPrivate*(self: TokenPermissionItem): bool =
proc getTokenCriteriaMet*(self: TokenPermissionItem): bool = proc getTokenCriteriaMet*(self: TokenPermissionItem): bool =
return self.tokenCriteriaMet return self.tokenCriteriaMet
proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto): TokenPermissionItem = proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto, chats: seq[ChatDto]): TokenPermissionItem =
var tokenCriteriaItems: seq[TokenCriteriaItem] = @[] var tokenCriteriaItems: seq[TokenCriteriaItem] = @[]
for tc in tokenPermission.tokenCriteria: for tc in tokenPermission.tokenCriteria:
@ -80,8 +80,9 @@ proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto): To
tokenCriteriaItems.add(tokenCriteriaItem) tokenCriteriaItems.add(tokenCriteriaItem)
var tokenPermissionChatListItems: seq[TokenPermissionChatListItem] = @[] var tokenPermissionChatListItems: seq[TokenPermissionChatListItem] = @[]
for chatID in tokenPermission.chatIDs:
tokenPermissionChatListItems.add(initTokenPermissionChatListItem(chatID)) for chat in chats:
tokenPermissionChatListItems.add(initTokenPermissionChatListItem(chat.id, chat.name))
let tokenPermissionItem = initTokenPermissionItem( let tokenPermissionItem = initTokenPermissionItem(
tokenPermission.id, tokenPermission.id,

View File

@ -54,6 +54,11 @@ QtObject:
return i return i
return -1 return -1
proc renameChatById*(self: TokenPermissionsModel, chatId: string, newName: string) =
for i in 0 ..< self.items.len:
let item = self.items[i]
item.getChatList().renameChatById(chatId, newName)
proc belongsToChat*(self: TokenPermissionsModel, permissionId: string, chatId: string): bool {.slot.} = proc belongsToChat*(self: TokenPermissionsModel, permissionId: string, chatId: string): bool {.slot.} =
let idx = self.findIndexById(permissionId) let idx = self.findIndexById(permissionId)
if(idx == -1): if(idx == -1):

View File

@ -414,6 +414,9 @@ QtObject:
return self.chats[chatId] return self.chats[chatId]
proc getChatsByIds*(self: Service, chatIds: seq[string]): seq[ChatDto] =
return self.getAllChats().filterIt(it.id in chatIds)
proc getOneToOneChatNameAndImage*(self: Service, chatId: string): proc getOneToOneChatNameAndImage*(self: Service, chatId: string):
tuple[name: string, image: string, largeImage: string] = tuple[name: string, image: string, largeImage: string] =
return self.contactService.getContactNameAndImage(chatId) return self.contactService.getContactNameAndImage(chatId)