mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-24 20:48:50 +00:00
feat(token-permissions): Add channel name to token permissin chat list model
Fixes: #11481
This commit is contained in:
parent
9b17a66935
commit
b5950b045c
@ -473,6 +473,9 @@ proc getChatDetails*(self: Controller, chatId: string): ChatDto =
|
||||
proc getChatDetailsForChatTypes*(self: Controller, types: seq[ChatType]): seq[ChatDto] =
|
||||
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 =
|
||||
return self.chatService.chatsWithCategoryHaveUnreadMessages(communityId, categoryId)
|
||||
|
||||
|
@ -278,7 +278,8 @@ proc rebuildCommunityTokenPermissionsModel(self: Module) =
|
||||
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
|
||||
|
||||
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)
|
||||
|
||||
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")
|
||||
|
||||
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.reevaluateRequiresTokenPermissionToJoin()
|
||||
@ -860,7 +862,8 @@ method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissions
|
||||
self.updateTokenPermissionModel(checkPermissionsToJoinResponse.permissions, community)
|
||||
|
||||
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.reevaluateRequiresTokenPermissionToJoin()
|
||||
|
||||
@ -1055,6 +1058,7 @@ method joinGroupChatFromInvitation*(self: Module, groupName: string, chatId: str
|
||||
|
||||
method onChatRenamed*(self: Module, chatId: string, newName: string) =
|
||||
self.view.chatsModel().renameItemById(chatId, newName)
|
||||
self.view.tokenPermissionsModel().renameChatById(chatId, newName)
|
||||
|
||||
method onGroupChatDetailsUpdated*(self: Module, chatId, newName, newColor, newImage: string) =
|
||||
self.view.chatsModel().updateNameColorIconOnItemById(chatId, newName, newColor, newImage)
|
||||
|
@ -3,8 +3,10 @@ import ./io_interface
|
||||
|
||||
import ../../../core/signals/types
|
||||
import ../../../core/eventemitter
|
||||
import ../../../../app_service/service/chat/dto/chat
|
||||
import ../../../../app_service/service/community/service as community_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/community_tokens/service as community_tokens_service
|
||||
import ../../../../app_service/service/token/service as token_service
|
||||
@ -20,6 +22,7 @@ type
|
||||
communityTokensService: community_tokens_service.Service
|
||||
networksService: networks_service.Service
|
||||
tokenService: token_service.Service
|
||||
chatService: chat_service.Service
|
||||
|
||||
proc newController*(
|
||||
delegate: io_interface.AccessInterface,
|
||||
@ -29,6 +32,7 @@ proc newController*(
|
||||
communityTokensService: community_tokens_service.Service,
|
||||
networksService: networks_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
chatService: chat_service.Service,
|
||||
): Controller =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
@ -38,6 +42,7 @@ proc newController*(
|
||||
result.communityTokensService = communityTokensService
|
||||
result.networksService = networksService
|
||||
result.tokenService = tokenService
|
||||
result.chatService = chatService
|
||||
|
||||
proc delete*(self: Controller) =
|
||||
discard
|
||||
@ -223,6 +228,9 @@ proc reorderCommunityChat*(
|
||||
chatId,
|
||||
position)
|
||||
|
||||
proc getChatDetailsByIds*(self: Controller, chatIds: seq[string]): seq[ChatDto] =
|
||||
return self.chatService.getChatsByIds(chatIds)
|
||||
|
||||
proc requestCommunityInfo*(self: Controller, communityId: string, importing: bool) =
|
||||
self.communityService.requestCommunityInfo(communityId, importing)
|
||||
|
||||
|
@ -19,6 +19,7 @@ import ../../../core/eventemitter
|
||||
import ../../../../app_service/common/types
|
||||
import ../../../../app_service/service/community/service as community_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/transaction/service as transaction_service
|
||||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
@ -59,6 +60,7 @@ proc newModule*(
|
||||
networksService: networks_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
tokensService: token_service.Service,
|
||||
chatService: chat_service.Service,
|
||||
): Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
@ -72,6 +74,7 @@ proc newModule*(
|
||||
communityTokensService,
|
||||
networksService,
|
||||
tokensService,
|
||||
chatService,
|
||||
)
|
||||
result.communityTokensModule = community_tokens_module.newCommunityTokensModule(result, events, communityTokensService, transactionService, networksService)
|
||||
result.moduleLoaded = false
|
||||
@ -180,7 +183,8 @@ proc getCuratedCommunityItem(self: Module, community: CommunityDto): CuratedComm
|
||||
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
|
||||
|
||||
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)
|
||||
|
||||
return initCuratedCommunityItem(
|
||||
|
@ -209,7 +209,7 @@ proc newModule*[T](
|
||||
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService, tokenService)
|
||||
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
|
||||
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,
|
||||
messageService)
|
||||
result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService)
|
||||
|
@ -3,17 +3,24 @@ import strformat
|
||||
type
|
||||
TokenPermissionChatListItem* = object
|
||||
key: string
|
||||
channelName: string
|
||||
|
||||
proc `$`*(self: TokenPermissionChatListItem): string =
|
||||
result = fmt"""TokenPermissionChatListItem(
|
||||
key: {self.key}
|
||||
key: {self.key},
|
||||
channelName: {self.channelName}
|
||||
]"""
|
||||
|
||||
proc initTokenPermissionChatListItem*(
|
||||
key: string
|
||||
key: string,
|
||||
channelName: string
|
||||
): TokenPermissionChatListItem =
|
||||
result.key = key
|
||||
result.channelName = channelName
|
||||
|
||||
proc getKey*(self: TokenPermissionChatListItem): string =
|
||||
return self.key
|
||||
|
||||
proc getChannelName*(self: TokenPermissionChatListItem): string =
|
||||
return self.channelName
|
||||
|
||||
|
@ -4,6 +4,7 @@ import token_permission_chat_list_item
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
Key = UserRole + 1
|
||||
ChannelName
|
||||
|
||||
QtObject:
|
||||
type TokenPermissionChatListModel* = ref object of QAbstractListModel
|
||||
@ -23,6 +24,7 @@ QtObject:
|
||||
method roleNames(self: TokenPermissionChatListModel): Table[int, string] =
|
||||
{
|
||||
ModelRole.Key.int:"key",
|
||||
ModelRole.ChannelName.int:"channelName",
|
||||
}.toTable
|
||||
|
||||
proc countChanged(self: TokenPermissionChatListModel) {.signal.}
|
||||
@ -45,6 +47,8 @@ QtObject:
|
||||
case enumRole:
|
||||
of ModelRole.Key:
|
||||
result = newQVariant(item.getKey())
|
||||
of ModelRole.ChannelName:
|
||||
result = newQVariant(item.getChannelName())
|
||||
|
||||
proc addItem*(self: TokenPermissionChatListModel, item: TokenPermissionChatListItem) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
@ -62,3 +66,11 @@ QtObject:
|
||||
|
||||
proc getItems*(self: TokenPermissionChatListModel): seq[TokenPermissionChatListItem] =
|
||||
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
|
||||
|
@ -63,7 +63,7 @@ proc getIsPrivate*(self: TokenPermissionItem): bool =
|
||||
proc getTokenCriteriaMet*(self: TokenPermissionItem): bool =
|
||||
return self.tokenCriteriaMet
|
||||
|
||||
proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto): TokenPermissionItem =
|
||||
proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto, chats: seq[ChatDto]): TokenPermissionItem =
|
||||
var tokenCriteriaItems: seq[TokenCriteriaItem] = @[]
|
||||
|
||||
for tc in tokenPermission.tokenCriteria:
|
||||
@ -80,8 +80,9 @@ proc buildTokenPermissionItem*(tokenPermission: CommunityTokenPermissionDto): To
|
||||
tokenCriteriaItems.add(tokenCriteriaItem)
|
||||
|
||||
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(
|
||||
tokenPermission.id,
|
||||
|
@ -54,6 +54,11 @@ QtObject:
|
||||
return i
|
||||
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.} =
|
||||
let idx = self.findIndexById(permissionId)
|
||||
if(idx == -1):
|
||||
|
@ -414,6 +414,9 @@ QtObject:
|
||||
|
||||
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):
|
||||
tuple[name: string, image: string, largeImage: string] =
|
||||
return self.contactService.getContactNameAndImage(chatId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user