...
This commit is contained in:
36
examples/hero/heromodels/heromodels_chat_group.vsh
Normal file
36
examples/hero/heromodels/heromodels_chat_group.vsh
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
import freeflowuniverse.herolib.hero.heromodels
|
||||
|
||||
mut mydb := heromodels.new()!
|
||||
|
||||
// Create a new chat group
|
||||
mut chat_group := mydb.chat_group.new(
|
||||
name: 'General Discussion'
|
||||
description: 'A public channel for general discussions'
|
||||
chat_type: .public_channel
|
||||
last_activity: 0
|
||||
is_archived: false
|
||||
)!
|
||||
|
||||
// Save to database
|
||||
oid := mydb.chat_group.set(chat_group)!
|
||||
println('Created chat group with ID: ${oid}')
|
||||
|
||||
// Retrieve from database
|
||||
mut chat_group2 := mydb.chat_group.get(oid)!
|
||||
println('Retrieved chat group: ${chat_group2}')
|
||||
|
||||
// List all chat groups
|
||||
mut chat_groups := mydb.chat_group.list()!
|
||||
println('All chat groups: ${chat_groups}')
|
||||
|
||||
// Update the chat group
|
||||
chat_group2.is_archived = true
|
||||
chat_group2.last_activity = 1672531200
|
||||
mydb.chat_group.set(chat_group2)!
|
||||
|
||||
// Retrieve updated chat group
|
||||
mut chat_group3 := mydb.chat_group.get(oid)!
|
||||
println('Updated chat group: ${chat_group3}')
|
||||
51
examples/hero/heromodels/heromodels_chat_message.vsh
Normal file
51
examples/hero/heromodels/heromodels_chat_message.vsh
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.core.redisclient
|
||||
import freeflowuniverse.herolib.hero.heromodels
|
||||
|
||||
mut mydb := heromodels.new()!
|
||||
|
||||
// First create a chat group to reference
|
||||
mut chat_group := mydb.chat_group.new(
|
||||
name: 'General Discussion'
|
||||
description: 'A public channel for general discussions'
|
||||
chat_type: .public_channel
|
||||
last_activity: 0
|
||||
is_archived: false
|
||||
)!
|
||||
chat_group_id := mydb.chat_group.set(chat_group)!
|
||||
|
||||
// Create a new chat message
|
||||
mut chat_message := mydb.chat_message.new(
|
||||
name: 'Hello World Message'
|
||||
description: 'A simple hello world message'
|
||||
content: 'Hello, world!'
|
||||
chat_group_id: chat_group_id
|
||||
sender_id: 1
|
||||
parent_messages: []
|
||||
fs_files: []
|
||||
message_type: .text
|
||||
status: .sent
|
||||
reactions: []
|
||||
mentions: []
|
||||
)!
|
||||
|
||||
// Save to database
|
||||
oid := mydb.chat_message.set(chat_message)!
|
||||
println('Created chat message with ID: ${oid}')
|
||||
|
||||
// Retrieve from database
|
||||
mut chat_message2 := mydb.chat_message.get(oid)!
|
||||
println('Retrieved chat message: ${chat_message2}')
|
||||
|
||||
// List all chat messages
|
||||
mut chat_messages := mydb.chat_message.list()!
|
||||
println('All chat messages: ${chat_messages}')
|
||||
|
||||
// Update the chat message
|
||||
chat_message2.status = .read
|
||||
mydb.chat_message.set(chat_message2)!
|
||||
|
||||
// Retrieve updated chat message
|
||||
mut chat_message3 := mydb.chat_message.get(oid)!
|
||||
println('Updated chat message: ${chat_message3}')
|
||||
Reference in New Issue
Block a user