Skip to content

Commit

Permalink
chore: refactor after review
Browse files Browse the repository at this point in the history
  • Loading branch information
mprakhov committed Oct 31, 2023
1 parent da0cbd0 commit 8d89f10
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 79 deletions.
8 changes: 4 additions & 4 deletions src/app/modules/main/chat_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ proc init*(self: Controller) =
if args.communityId == self.sectionId:
self.delegate.setPermissionsToJoinCheckOngoing(false)

self.events.on(SIGNAL_CONTROL_NODE_OFFLINE) do(e: Args):
self.events.on(SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN) do(e: Args):
let args = CommunityIdArgs(e)
if args.communityId == self.sectionId:
self.delegate.onControlNodeOffline()
self.delegate.onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin()

self.events.on(SignalType.Wallet.event, proc(e: Args) =
var data = WalletSignal(e)
Expand Down Expand Up @@ -683,5 +683,5 @@ proc collectCommunityMetricsMessagesTimestamps*(self: Controller, intervals: str
proc collectCommunityMetricsMessagesCount*(self: Controller, intervals: string) =
self.communityService.collectCommunityMetricsMessagesCount(self.getMySectionId(), intervals)

proc isCommunityRequestAwaitingAddress*(self: Controller, communityId: string): bool =
self.communityService.isCommunityRequestAwaitingAddress(communityId)
proc waitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Controller, communityId: string): bool =
self.communityService.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(communityId)
2 changes: 1 addition & 1 deletion src/app/modules/main/chat_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -406,5 +406,5 @@ method setChannelsPermissionsCheckOngoing*(self: AccessInterface, value: bool) {
method getChannelsPermissionsCheckOngoing*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method onControlNodeOffline*(self: AccessInterface) {.base.} =
method onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
10 changes: 5 additions & 5 deletions src/app/modules/main/chat_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ method onChatsLoaded*(
else:
let community = self.controller.getMyCommunity()
self.view.setAmIMember(community.joined)
self.view.setIsControlNodeOffline(self.controller.isCommunityRequestAwaitingAddress(community.id))
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(self.controller.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(community.id))
self.initCommunityTokenPermissionsModel(channelGroup)
self.onCommunityCheckAllChannelsPermissionsResponse(channelGroup.channelPermissions)
self.controller.asyncCheckPermissionsToJoin()
Expand Down Expand Up @@ -891,11 +891,11 @@ method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, checkAllCha
method onKickedFromCommunity*(self: Module) =
self.view.setAmIMember(false)
let communityId = self.controller.getMySectionId()
self.view.setIsControlNodeOffline(self.controller.isCommunityRequestAwaitingAddress(communityId))
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(self.controller.waitingOnNewCommunityOwnerToConfirmRequestToRejoin(communityId))

method onJoinedCommunity*(self: Module) =
self.view.setAmIMember(true)
self.view.setIsControlNodeOffline(false)
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(false)

method onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
self.updateBadgeNotifications(chat, hasUnreadMessages=false, unviewedMentionsCount=0)
Expand Down Expand Up @@ -1347,5 +1347,5 @@ method setChannelsPermissionsCheckOngoing*(self: Module, value: bool) =
if self.view.chatsModel().getItemPermissionsRequired(chatId):
cModule.setPermissionsCheckOngoing(true)

method onControlNodeOffline*(self: Module) =
self.view.setIsControlNodeOffline(true)
method onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Module) =
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(true)
25 changes: 12 additions & 13 deletions src/app/modules/main/chat_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ QtObject:
chatsLoaded: bool
communityMetrics: string # NOTE: later this should be replaced with QAbstractListModel-based model
permissionsCheckOngoing: bool
isControlNodeOffline: bool
isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin: bool

proc delete*(self: View) =
self.model.delete
Expand Down Expand Up @@ -68,7 +68,7 @@ QtObject:
result.requiresTokenPermissionToJoin = false
result.chatsLoaded = false
result.communityMetrics = "[]"
result.isControlNodeOffline = false
result.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin = false

proc load*(self: View) =
self.delegate.viewDidLoad()
Expand Down Expand Up @@ -391,7 +391,6 @@ QtObject:
proc amIMemberChanged*(self: View) {.signal.}

proc setAmIMember*(self: View, value: bool) =
writeStackTrace()
if (value == self.amIMember):
return
self.amIMember = value
Expand Down Expand Up @@ -450,17 +449,17 @@ QtObject:
self.permissionsCheckOngoing = value
self.permissionsCheckOngoingChanged()

proc getIsControlNodeOffline*(self: View): bool {.slot.} =
return self.isControlNodeOffline
proc getWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: View): bool {.slot.} =
return self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin

proc isControlNodeOfflineChanged*(self: View) {.signal.}
proc isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged*(self: View) {.signal.}

proc setIsControlNodeOffline*(self: View, value: bool) =
if (value == self.isControlNodeOffline):
proc setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: View, value: bool) =
if (value == self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin):
return
self.isControlNodeOffline = value
self.isControlNodeOfflineChanged()
self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin = value
self.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged()

QtProperty[bool] isControlNodeOffline:
read = getIsControlNodeOffline
notify = isControlNodeOfflineChanged
QtProperty[bool] isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin:
read = getWaitingOnNewCommunityOwnerToConfirmRequestToRejoin
notify = isWaitingOnNewCommunityOwnerToConfirmRequestToRejoinChanged
4 changes: 2 additions & 2 deletions src/app_service/service/community/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const asyncLoadCommunitiesDataTask: Task = proc(argEncoded: string) {.gcsafe, ni
let responseCommunities = status_go.getAllCommunities()
let responseSettings = status_go.getCommunitiesSettings()
let responseMyPendingRequestsToJoin = status_go.myPendingRequestsToJoin()
let responseMyAwaitingRequestsToJoin = status_go.myAwaitingRequestsToJoin()
let responseMyAwaitingAddressesRequestsToJoin = status_go.myAwaitingAddressesRequestsToJoin()

arg.finish(%* {
"tags": responseTags,
"communities": responseCommunities,
"settings": responseSettings,
"myPendingRequestsToJoin": responseMyPendingRequestsToJoin,
"myAwaitingRequestsToJoin": responseMyAwaitingRequestsToJoin,
"myAwaitingAddressesRequestsToJoin": responseMyAwaitingAddressesRequestsToJoin,
"error": "",
})
except Exception as e:
Expand Down
24 changes: 12 additions & 12 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const SIGNAL_COMMUNITY_MEMBERS_CHANGED* = "communityMembersChanged"
const SIGNAL_COMMUNITY_KICKED* = "communityKicked"
const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity"
const SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED* = "requestToJoinCommunityCanceled"
const SIGNAL_CONTROL_NODE_OFFLINE* = "controlNodeOffline"
const SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN* = "waitingOnNewCommunityOwnerToConfirmRequestToRejoin"
const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound"
const SIGNAL_CURATED_COMMUNITIES_UPDATED* = "curatedCommunitiesUpdated"
const SIGNAL_COMMUNITY_MUTED* = "communityMuted"
Expand Down Expand Up @@ -233,7 +233,7 @@ QtObject:
historyArchiveDownloadTaskCommunityIds*: HashSet[string]
requestedCommunityIds*: HashSet[string]
communityMetrics: Table[string, CommunityMetricsDto]
myAwaitingRequestsToJoin: Table[string, CommunityMembershipRequestDto]
myAwaitingAddressesRequestsToJoin: Table[string, CommunityMembershipRequestDto]

# Forward declaration
proc asyncLoadCuratedCommunities*(self: Service)
Expand Down Expand Up @@ -331,7 +331,7 @@ QtObject:
self.updateMembershipRequestToNewState(membershipRequest.communityId, membershipRequest.id, community,
requestToJoinState)
if requestToJoinState == RequestToJoinType.AwaitingAddress:
self.events.emit(SIGNAL_CONTROL_NODE_OFFLINE, CommunityIdArgs(communityId: membershipRequest.communityId))
self.events.emit(SIGNAL_WAITING_ON_NEW_COMMUNITY_OWNER_TO_CONFIRM_REQUEST_TO_REJOIN, CommunityIdArgs(communityId: membershipRequest.communityId))
except Exception as e:
error "Unknown request", msg = e.msg

Expand Down Expand Up @@ -665,8 +665,8 @@ QtObject:

# If the community was not joined before but is now, we signal it
if(not wasJoined and community.joined and community.isMember):
if community.id in self.myAwaitingRequestsToJoin:
self.myAwaitingRequestsToJoin.del(community.id)
if community.id in self.myAwaitingAddressesRequestsToJoin:
self.myAwaitingAddressesRequestsToJoin.del(community.id)

self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false))

Expand Down Expand Up @@ -726,12 +726,12 @@ QtObject:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)

let myAwaitingRequestResponse = responseObj["myAwaitingRequestsToJoin"]
let myAwaitingRequestResponse = responseObj["myAwaitingAddressesRequestsToJoin"]

if myAwaitingRequestResponse{"result"}.kind != JNull:
for jsonCommunityReqest in myAwaitingRequestResponse["result"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myAwaitingRequestsToJoin[communityRequest.communityId] = communityRequest
self.myAwaitingAddressesRequestsToJoin[communityRequest.communityId] = communityRequest

self.events.emit(SIGNAL_COMMUNITY_DATA_LOADED, Args())
except Exception as e:
Expand Down Expand Up @@ -1830,9 +1830,9 @@ QtObject:

# If the state is no longer pending, delete the request
community.pendingRequestsToJoin.delete(indexPending)
# Delete if control node changed status for awaiting request to join
if communityId in self.myAwaitingRequestsToJoin:
self.myAwaitingRequestsToJoin.del(communityId)
# Delete if control node changed status for awaiting addresses request to join
if communityId in self.myAwaitingAddressesRequestsToJoin:
self.myAwaitingAddressesRequestsToJoin.del(communityId)

else:
community.pendingRequestsToJoin[indexPending].state = newState.int
Expand Down Expand Up @@ -2004,8 +2004,8 @@ QtObject:
return true
return false

proc isCommunityRequestAwaitingAddress*(self: Service, communityId: string): bool {.slot.} =
return communityId in self.myAwaitingRequestsToJoin
proc waitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Service, communityId: string): bool {.slot.} =
return communityId in self.myAwaitingAddressesRequestsToJoin

proc requestExtractDiscordChannelsAndCategories*(self: Service, filesToImport: seq[string]) =
try:
Expand Down
16 changes: 8 additions & 8 deletions src/backend/communities.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export response_type

proc getCommunityTags*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("communityTags".prefix)

proc muteCategory*(communityId: string, categoryId: string, interval: int): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("muteCommunityCategory".prefix, %* [
{
Expand Down Expand Up @@ -82,7 +82,7 @@ proc reevaluateCommunityMembersPermissions*(
result = callPrivateRPC("reevaluateCommunityMembersPermissions".prefix, %*[{
"communityId": communityId
}])

proc checkCommunityChannelPermissions*(communityId: string, chatId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("checkCommunityChannelPermissions".prefix, %*[{
"communityId": communityId,
Expand All @@ -98,8 +98,8 @@ proc checkAllCommunityChannelsPermissions*(communityId: string, addresses: seq[s
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myPendingRequestsToJoin".prefix)

proc myAwaitingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myAwaitingRequestsToJoin".prefix)
proc myAwaitingAddressesRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myAwaitingAddressesRequestsToJoin".prefix)

proc myCanceledRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myCanceledRequestsToJoin".prefix)
Expand Down Expand Up @@ -258,7 +258,7 @@ proc deleteCommunityTokenPermission*(communityId: string, permissionId: string):
"communityId": communityId,
"permissionId": permissionId
}])

proc requestCancelDiscordCommunityImport*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("requestCancelDiscordCommunityImport".prefix, %*[communityId])

Expand Down Expand Up @@ -426,9 +426,9 @@ proc unbanUserFromCommunity*(communityId: string, pubKey: string): RpcResponse[J
}])

proc setCommunityMuted*(communityId: string, mutedType: int): RpcResponse[JsonNode] {.raises: [Exception].} =
return callPrivateRPC("setCommunityMuted".prefix, %*[{
"communityId": communityId,
"mutedType": mutedType
return callPrivateRPC("setCommunityMuted".prefix, %*[{
"communityId": communityId,
"mutedType": mutedType
}])

proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string], inviteMessage: string): RpcResponse[JsonNode] {.raises: [Exception].} =
Expand Down
22 changes: 4 additions & 18 deletions ui/app/AppLayouts/Chat/ChatLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ StackLayout {

sourceComponent: {
if (chatItem.isCommunity() && !chatItem.amIMember) {
if (chatItem.isControlNodeOffline) {
return controlNodeOffline
if (chatItem.isWaitingOnNewCommunityOwnerToConfirmRequestToRejoin) {
return controlNodeOfflineComponent
} else if (chatItem.requiresTokenPermissionToJoin) {
return joinCommunityViewComponent
}
Expand Down Expand Up @@ -336,35 +336,21 @@ StackLayout {
}

Component {
id: controlNodeOffline
id: controlNodeOfflineComponent
ControlNodeOfflineCommunityView {
id: joinCommunityView
id: controlNodeOfflineView
readonly property var communityData: sectionItemModel
readonly property string communityId: communityData.id
name: communityData.name
communityDesc: communityData.description
color: communityData.color
image: communityData.image
membersCount: communityData.members.count
joinCommunity: true
amISectionAdmin: communityData.memberRole === Constants.memberRole.owner ||
communityData.memberRole === Constants.memberRole.admin ||
communityData.memberRole === Constants.memberRole.tokenMaster
communityItemsModel: root.rootStore.communityItemsModel
notificationCount: activityCenterStore.unreadNotificationsCount
hasUnseenNotifications: activityCenterStore.hasUnseenNotifications
openCreateChat: rootStore.openCreateChat
onNotificationButtonClicked: Global.openActivityCenterPopup()
onAdHocChatButtonClicked: rootStore.openCloseCreateChatView()

Connections {
target: root.rootStore.communitiesModuleInst
function onCommunityAccessRequested(communityId: string) {
if (communityId === joinCommunityView.communityId) {
joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityId)
}
}
}
}
}
// End of components related to transfer community ownership flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ ColumnLayout {
text: root.listUsersText
font.pixelSize: 13
}

StatusBaseText {
text: qsTr("joined the channel")
font.pixelSize: 13
color: Theme.palette.baseColor1
}
}

ListView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ StatusSectionLayout {
id: root

// General properties:
property bool amISectionAdmin: false
property bool openCreateChat: false
property string name
property string communityDesc
property color color
property string channelName
property string channelDesc
property bool joinCommunity: true // Otherwise it means join channel action

// Blur view properties:
property int membersCount
Expand All @@ -37,7 +34,6 @@ StatusSectionLayout {
property string listUsersText
property var messagesModel

signal infoButtonClicked
signal adHocChatButtonClicked


Expand All @@ -48,7 +44,6 @@ StatusSectionLayout {
}

headerContent: JoinCommunityHeaderPanel {
joinCommunity: root.joinCommunity
color: root.color
name: root.name
channelName: root.channelName
Expand All @@ -66,16 +61,15 @@ StatusSectionLayout {
membersCount: root.membersCount
image: root.image
color: root.color
amISectionAdmin: root.amISectionAdmin
openCreateChat: root.openCreateChat
onInfoButtonClicked: if(root.amISectionAdmin) root.infoButtonClicked()
amISectionAdmin: false
openCreateChat: false
onAdHocChatButtonClicked: root.adHocChatButtonClicked()
}

ColumnLayout {
Layout.fillWidth: true
Layout.margins: Style.current.halfPadding
layer.enabled: root.joinCommunity
layer.enabled: true
layer.effect: fastBlur

Repeater {
Expand Down
2 changes: 1 addition & 1 deletion vendor/status-go
Submodule status-go updated 56 files
+386 −296 appdatabase/migrations/bindata.go
+223 −174 appdatabase/migrationsprevnodecfg/bindata.go
+19 −21 mailserver/migrations/bindata.go
+58 −50 multiaccounts/migrations/bindata.go
+1 −0 protocol/activity_center.go
+18 −20 protocol/anonmetrics/migrations/migrations.go
+9 −0 protocol/common/message_sender.go
+79 −0 protocol/common/message_sender_test.go
+17 −0 protocol/common/raw_messages_persistence.go
+37 −4 protocol/communities/community.go
+1 −1 protocol/communities/community_test.go
+83 −19 protocol/communities/manager.go
+5 −5 protocol/communities/manager_test.go
+83 −11 protocol/communities/persistence.go
+4 −1 protocol/communities/persistence_test.go
+1 −0 protocol/communities/request_to_join.go
+8 −0 protocol/communities_messenger_helpers_test.go
+270 −23 protocol/communities_messenger_signers_test.go
+87 −72 protocol/encryption/migrations/migrations.go
+475 −840 protocol/encryption/protocol_message.pb.go
+0 −6 protocol/messenger.go
+87 −8 protocol/messenger_communities.go
+4 −0 protocol/messenger_handler.go
+7 −12 protocol/messenger_response.go
+471 −342 protocol/migrations/migrations.go
+1 −0 protocol/migrations/sqlite/1698746210_add_signature_to_revealed_addresses.up.sql
+58 −0 protocol/persistence_test.go
+110 −204 protocol/protobuf/anon_metrics.pb.go
+304 −482 protocol/protobuf/application_metadata_message.pb.go
+189 −344 protocol/protobuf/chat_identity.pb.go
+1,069 −1,766 protocol/protobuf/chat_message.pb.go
+283 −478 protocol/protobuf/command.pb.go
+1,144 −1,974 protocol/protobuf/communities.pb.go
+107 −222 protocol/protobuf/community_privileged_user_sync_message.pb.go
+68 −138 protocol/protobuf/community_shard_key.pb.go
+416 −758 protocol/protobuf/community_update.pb.go
+191 −337 protocol/protobuf/contact.pb.go
+163 −298 protocol/protobuf/contact_verification.pb.go
+108 −206 protocol/protobuf/emoji_reaction.pb.go
+92 −203 protocol/protobuf/enums.pb.go
+88 −180 protocol/protobuf/group_chat_invitation.pb.go
+171 −298 protocol/protobuf/membership_update_message.pb.go
+2,241 −3,691 protocol/protobuf/pairing.pb.go
+69 −139 protocol/protobuf/pin_message.pb.go
+549 −989 protocol/protobuf/push_notifications.pb.go
+56 −120 protocol/protobuf/shard.pb.go
+89 −180 protocol/protobuf/status_update.pb.go
+157 −254 protocol/protobuf/sync_settings.pb.go
+203 −348 protocol/protobuf/url_data.pb.go
+35 −33 protocol/pushnotificationclient/migrations/migrations.go
+26 −26 protocol/pushnotificationserver/migrations/migrations.go
+31 −30 protocol/transport/migrations/migrations.go
+9 −0 services/ext/api.go
+94 −78 static/bindata.go
+19 −21 t/bindata.go
+50 −44 walletdatabase/migrations/bindata.go

0 comments on commit 8d89f10

Please sign in to comment.