Skip to content

Commit 4aac2e9

Browse files
committed
fix: folder generation
1 parent f0821d5 commit 4aac2e9

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ make update
1515
make all
1616
1717
# Run the Text Interface
18-
./build/tui
18+
./build/tui --name=<unique_id>
1919
```
2020

2121
## Details

examples/pingpong.nim

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import chronicles
2+
import chronos
3+
4+
import chat_sdk
5+
import content_types
6+
7+
8+
proc getContent(content: ContentFrame): string =
9+
# Skip type checks and assume its a TextFrame
10+
let m = decode(content.bytes, TextFrame).valueOr:
11+
raise newException(ValueError, fmt"Badly formed Content")
12+
return fmt"{m}"
13+
14+
proc main() {.async.} =
15+
16+
# Create Configurations
17+
var cfg_saro = DefaultConfig()
18+
var cfg_raya = DefaultConfig()
19+
20+
# Cross pollinate Peers - No Waku discovery is used in this example
21+
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
22+
cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
23+
24+
# Create Clients
25+
var saro = newClient(cfg_saro, createIdentity("Saro"))
26+
var raya = newClient(cfg_raya, createIdentity("Raya"))
27+
28+
# Wire Callbacks
29+
saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
30+
echo " Saro <------ :: " & getContent(msg)
31+
await sleepAsync(10000)
32+
discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame())
33+
)
34+
35+
saro.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
36+
echo " Saro -- Read Receipt for " & msgId
37+
)
38+
39+
40+
41+
42+
raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
43+
echo " ------> Raya :: " & getContent(msg)
44+
await sleepAsync(10000)
45+
sdiscard await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame())
46+
)
47+
48+
raya.onNewConversation(proc(convo: Conversation) {.async.} =
49+
echo " ------> Raya :: New Conversation: " & convo.id()
50+
discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame())
51+
)
52+
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
53+
echo " raya -- Read Receipt for " & msgId
54+
)
55+
56+
57+
await saro.start()
58+
await raya.start()
59+
60+
await sleepAsync(5000)
61+
62+
# Perform OOB Introduction: Raya -> Saro
63+
let raya_bundle = raya.createIntroBundle()
64+
discard await saro.newPrivateConversation(raya_bundle)
65+
66+
await sleepAsync(10000) # Run for some time
67+
68+
saro.stop()
69+
raya.stop()

examples/tui/persistence.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ proc toIdent(s: SavedConfig): Identity =
5757
proc register(name: string, multiAddr: string) {.async.} =
5858

5959
notice "Registering Account", name=name, maddr=multiAddr
60+
61+
if not dirExists(REGISTRATION_DIR):
62+
createDir(REGISTRATION_DIR)
63+
6064
try:
61-
writeFile(joinPath(".registry", fmt"{name.toLower()}.maddr"), multiAddr)
65+
writeFile(joinPath(REGISTRATION_DIR, fmt"{name.toLower()}.maddr"), multiAddr)
6266
except IOError as e:
6367
echo "Failed to write registration file: ", e.msg
6468
raise e
@@ -105,6 +109,10 @@ proc saveCfg(name:string, cfg: Config) =
105109

106110
let json = jsonutils.toJson(s)
107111

112+
113+
if not dirExists(KEY_DIR):
114+
createDir(KEY_DIR)
115+
108116
try:
109117
writeFile(joinPath(KEY_DIR, fmt"{name.toLower()}.cfg"), $json)
110118
except IOError as e:

0 commit comments

Comments
 (0)