-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new-links): Parse url data and display
Fixes: #10852
- Loading branch information
1 parent
cfa1965
commit bc3abdc
Showing
20 changed files
with
418 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import stint | ||
import ./io_interface | ||
|
||
import ../../../core/signals/types | ||
import ../../../core/eventemitter | ||
import ../../../../app_service/service/shared_urls/service as urls_service | ||
|
||
type | ||
Controller* = ref object of RootObj | ||
delegate: io_interface.AccessInterface | ||
events: EventEmitter | ||
sharedUrlsService: urls_service.Service | ||
|
||
proc newController*( | ||
delegate: io_interface.AccessInterface, | ||
events: EventEmitter, | ||
sharedUrlsService: urls_service.Service, | ||
): Controller = | ||
result = Controller() | ||
result.delegate = delegate | ||
result.events = events | ||
result.sharedUrlsService = sharedUrlsService | ||
|
||
proc delete*(self: Controller) = | ||
discard | ||
|
||
proc parseCommunitySharedUrl*(self: Controller, url: string): CommunityUrlDataDto = | ||
let data = self.sharedUrlsService.parseSharedUrl(url) | ||
return data.community | ||
|
||
proc parseCommunityChannelSharedUrl*(self: Controller, url: string): CommunityChannelUrlDataDto = | ||
let data = self.sharedUrlsService.parseSharedUrl(url) | ||
return data.channel | ||
|
||
proc parseContactSharedUrl*(self: Controller, url: string): ContactUrlDataDto = | ||
let data = self.sharedUrlsService.parseSharedUrl(url) | ||
return data.contact | ||
|
||
proc parseSharedUrl*(self: Controller, url: string): UrlDataDto = | ||
return self.sharedUrlsService.parseSharedUrl(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import NimQml, stint | ||
|
||
import ../../../../app_service/service/shared_urls/service as urls_service | ||
|
||
type | ||
AccessInterface* {.pure inheritable.} = ref object of RootObj | ||
|
||
method delete*(self: AccessInterface) {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method load*(self: AccessInterface) {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method viewDidLoad*(self: AccessInterface) {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method parseCommunitySharedUrl*(self: AccessInterface, url: string): string {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method parseCommunityChannelSharedUrl*(self: AccessInterface, url: string): string {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method parseContactSharedUrl*(self: AccessInterface, url: string): string {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
method parseSharedUrl*(self: AccessInterface, url: string): UrlDataDto {.base.} = | ||
raise newException(ValueError, "No implementation available") | ||
|
||
# This way (using concepts) is used only for the modules managed by AppController | ||
type | ||
DelegateInterface* = concept c | ||
c.mainDidLoad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import NimQml, sequtils, stint | ||
|
||
import io_interface, view, controller | ||
import ../io_interface as delegate_interface | ||
|
||
import ../../../../app_service/service/shared_urls/service as urls_service | ||
|
||
import ../../../global/global_singleton | ||
import ../../../core/eventemitter | ||
|
||
export io_interface | ||
|
||
type | ||
Module* = ref object of io_interface.AccessInterface | ||
delegate: delegate_interface.AccessInterface | ||
controller: Controller | ||
view: View | ||
viewVariant: QVariant | ||
moduleLoaded: bool | ||
|
||
proc newModule*( | ||
delegate: delegate_interface.AccessInterface, | ||
events: EventEmitter, | ||
sharedUrlsService: urls_service.Service, | ||
): Module = | ||
result = Module() | ||
result.delegate = delegate | ||
result.view = newView(result) | ||
result.viewVariant = newQVariant(result.view) | ||
result.controller = controller.newController( | ||
result, | ||
events, | ||
sharedUrlsService, | ||
) | ||
result.moduleLoaded = false | ||
|
||
method delete*(self: Module) = | ||
self.view.delete | ||
self.viewVariant.delete | ||
self.controller.delete | ||
|
||
method load*(self: Module) = | ||
singletonInstance.engine.setRootContextProperty("sharedUrlsModule", self.viewVariant) | ||
self.view.load() | ||
|
||
method isLoaded*(self: Module): bool = | ||
return self.moduleLoaded | ||
|
||
method viewDidLoad*(self: Module) = | ||
self.moduleLoaded = true | ||
|
||
method parseSharedUrl*(self: Module, url: string): UrlDataDto = | ||
return self.controller.parseSharedUrl(url) | ||
|
||
method parseCommunitySharedUrl*(self: Module, url: string): string = | ||
let communityData = self.controller.parseCommunitySharedUrl(url) | ||
return $communityData | ||
|
||
method parseCommunityChannelSharedUrl*(self: Module, url: string): string = | ||
let channelData = self.controller.parseCommunityChannelSharedUrl(url) | ||
return $channelData | ||
|
||
method parseContactSharedUrl*(self: Module, url: string): string = | ||
let contactData = self.controller.parseContactSharedUrl(url) | ||
return $contactData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import NimQml, json, strutils, sequtils | ||
|
||
import ./io_interface | ||
|
||
QtObject: | ||
type | ||
View* = ref object of QObject | ||
delegate: io_interface.AccessInterface | ||
|
||
proc delete*(self: View) = | ||
self.QObject.delete | ||
|
||
proc newView*(delegate: io_interface.AccessInterface): View = | ||
new(result, delete) | ||
result.QObject.setup | ||
result.delegate = delegate | ||
|
||
proc load*(self: View) = | ||
self.delegate.viewDidLoad() | ||
|
||
proc parseCommunitySharedUrl*(self: View, url: string): string {.slot.} = | ||
return self.delegate.parseCommunitySharedUrl(url) | ||
|
||
proc parseCommunityChannelSharedUrl*(self: View, url: string): string {.slot.} = | ||
return self.delegate.parseCommunityChannelSharedUrl(url) | ||
|
||
proc parseContactSharedUrl*(self: View, url: string): string {.slot.} = | ||
return self.delegate.parseContactSharedUrl(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{.used.} | ||
|
||
import json, strformat, strutils | ||
|
||
include ../../../common/json_utils | ||
|
||
type CommunityUrlDataDto* = object | ||
displayName*: string | ||
description*: string | ||
membersCount*: int | ||
color*: string | ||
tagIndices*: seq[int] | ||
communityId*: string | ||
|
||
type CommunityChannelUrlDataDto* = object | ||
emoji*: string | ||
displayName*: string | ||
description*: string | ||
color*: string | ||
uuid*: string | ||
|
||
type ContactUrlDataDto* = object | ||
displayName*: string | ||
description*: string | ||
publicKey*: string | ||
|
||
type UrlDataDto* = object | ||
community*: CommunityUrlDataDto | ||
channel*: CommunityChannelUrlDataDto | ||
contact*: ContactUrlDataDto | ||
|
||
proc toCommunityUrlDataDto*(jsonObj: JsonNode): CommunityUrlDataDto = | ||
result = CommunityUrlDataDto() | ||
discard jsonObj.getProp("displayName", result.displayName) | ||
discard jsonObj.getProp("description", result.description) | ||
discard jsonObj.getProp("membersCount", result.membersCount) | ||
discard jsonObj.getProp("color", result.color) | ||
var tagIndicesObj: JsonNode | ||
if (jsonObj.getProp("tagIndices", tagIndicesObj) and tagIndicesObj.kind == JArray): | ||
for tagIndex in tagIndicesObj: | ||
result.tagIndices.add(tagIndex.getInt) | ||
|
||
discard jsonObj.getProp("communityId", result.communityId) | ||
|
||
proc toCommunityChannelUrlDataDto*(jsonObj: JsonNode): CommunityChannelUrlDataDto = | ||
result = CommunityChannelUrlDataDto() | ||
discard jsonObj.getProp("displayName", result.displayName) | ||
discard jsonObj.getProp("description", result.description) | ||
discard jsonObj.getProp("emoji", result.emoji) | ||
discard jsonObj.getProp("color", result.color) | ||
discard jsonObj.getProp("uuid", result.uuid) | ||
|
||
proc toContactUrlDataDto*(jsonObj: JsonNode): ContactUrlDataDto = | ||
result = ContactUrlDataDto() | ||
discard jsonObj.getProp("displayName", result.displayName) | ||
discard jsonObj.getProp("description", result.description) | ||
discard jsonObj.getProp("publicKey", result.publicKey) | ||
|
||
proc toUrlDataDto*(jsonObj: JsonNode): UrlDataDto = | ||
result = UrlDataDto() | ||
|
||
var communityObj: JsonNode | ||
if (jsonObj.getProp("community", communityObj)): | ||
result.community = communityObj.toCommunityUrlDataDto() | ||
|
||
var communityChannelObj: JsonNode | ||
if (jsonObj.getProp("channel", communityChannelObj)): | ||
result.channel = communityChannelObj.toCommunityChannelUrlDataDto() | ||
|
||
var contactObj: JsonNode | ||
if (jsonObj.getProp("contact", contactObj)): | ||
result.contact = contactObj.toContactUrlDataDto() | ||
|
||
proc `$`*(communityUrlDataDto: CommunityUrlDataDto): string = | ||
var jsonObj = newJObject() | ||
jsonObj["displayName"] = %* communityUrlDataDto.displayName | ||
jsonObj["description"] = %* communityUrlDataDto.description | ||
jsonObj["membersCount"] = %* communityUrlDataDto.membersCount | ||
jsonObj["color"] = %* communityUrlDataDto.color | ||
jsonObj["communityId"] = %* communityUrlDataDto.communityId | ||
return $jsonObj | ||
|
||
proc `$`*(communityChannelUrlDataDto: CommunityChannelUrlDataDto): string = | ||
var jsonObj = newJObject() | ||
jsonObj["displayName"] = %* communityChannelUrlDataDto.displayName | ||
jsonObj["description"] = %* communityChannelUrlDataDto.description | ||
jsonObj["emoji"] = %* communityChannelUrlDataDto.emoji | ||
jsonObj["color"] = %* communityChannelUrlDataDto.color | ||
jsonObj["uuid"] = %* communityChannelUrlDataDto.uuid | ||
return $jsonObj | ||
|
||
proc `$`*(contactUrlDataDto: ContactUrlDataDto): string = | ||
var jsonObj = newJObject() | ||
jsonObj["displayName"] = %* contactUrlDataDto.displayName | ||
jsonObj["description"] = %* contactUrlDataDto.description | ||
jsonObj["publicKey"] = %* contactUrlDataDto.publicKey | ||
return $jsonObj |
Oops, something went wrong.