...
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
module heromodels
|
||||
|
||||
import time
|
||||
import crypto.blake3
|
||||
import json
|
||||
|
||||
// ChatGroup represents a chat channel or conversation
|
||||
@[heap]
|
||||
pub struct ChatGroup {
|
||||
pub mut:
|
||||
chat_type ChatType
|
||||
messages []u32 // IDs of chat messages
|
||||
created_at i64
|
||||
updated_at i64
|
||||
last_activity i64
|
||||
is_archived bool
|
||||
tags []string
|
||||
}
|
||||
|
||||
pub enum ChatType {
|
||||
public_channel
|
||||
private_channel
|
||||
direct_message
|
||||
group_message
|
||||
}
|
||||
|
||||
pub fn (mut c ChatGroup) calculate_id() {
|
||||
content := json.encode(ChatGroupContent{
|
||||
name: c.name
|
||||
description: c.description
|
||||
group_id: c.group_id
|
||||
chat_type: c.chat_type
|
||||
is_archived: c.is_archived
|
||||
tags: c.tags
|
||||
})
|
||||
hash := blake3.sum256(content.bytes())
|
||||
c.id = hash.hex()[..48]
|
||||
}
|
||||
|
||||
struct ChatGroupContent {
|
||||
name string
|
||||
description string
|
||||
group_id string
|
||||
chat_type ChatType
|
||||
is_archived bool
|
||||
tags []string
|
||||
}
|
||||
|
||||
pub fn new_chat_group(name string, group_id string, chat_type ChatType) ChatGroup {
|
||||
mut chat_group := ChatGroup{
|
||||
name: name
|
||||
group_id: group_id
|
||||
chat_type: chat_type
|
||||
created_at: time.now().unix()
|
||||
updated_at: time.now().unix()
|
||||
last_activity: time.now().unix()
|
||||
}
|
||||
chat_group.calculate_id()
|
||||
return chat_group
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
module heromodels
|
||||
|
||||
import time
|
||||
import crypto.blake3
|
||||
import json
|
||||
|
||||
// ChatMessage represents a message in a chat group
|
||||
@[heap]
|
||||
pub struct ChatMessage {
|
||||
pub mut:
|
||||
id string // blake192 hash
|
||||
content string
|
||||
chat_group_id string // Associated chat group
|
||||
sender_id string // User ID of sender
|
||||
parent_messages []MessageLink // Referenced/replied messages
|
||||
fs_files []string // IDs of linked files
|
||||
message_type MessageType
|
||||
status MessageStatus
|
||||
created_at i64
|
||||
updated_at i64
|
||||
edited_at i64
|
||||
deleted_at i64
|
||||
reactions []MessageReaction
|
||||
mentions []string // User IDs mentioned in message
|
||||
tags []string
|
||||
}
|
||||
|
||||
pub struct MessageLink {
|
||||
pub mut:
|
||||
message_id string
|
||||
link_type MessageLinkType
|
||||
}
|
||||
|
||||
pub enum MessageLinkType {
|
||||
reply
|
||||
reference
|
||||
forward
|
||||
quote
|
||||
}
|
||||
|
||||
pub enum MessageType {
|
||||
text
|
||||
image
|
||||
file
|
||||
voice
|
||||
video
|
||||
system
|
||||
announcement
|
||||
}
|
||||
|
||||
pub enum MessageStatus {
|
||||
sent
|
||||
delivered
|
||||
read
|
||||
failed
|
||||
deleted
|
||||
}
|
||||
|
||||
pub struct MessageReaction {
|
||||
pub mut:
|
||||
user_id string
|
||||
emoji string
|
||||
timestamp i64
|
||||
}
|
||||
|
||||
pub fn (mut m ChatMessage) calculate_id() {
|
||||
content := json.encode(MessageContent{
|
||||
content: m.content
|
||||
chat_group_id: m.chat_group_id
|
||||
sender_id: m.sender_id
|
||||
parent_messages: m.parent_messages
|
||||
fs_files: m.fs_files
|
||||
message_type: m.message_type
|
||||
mentions: m.mentions
|
||||
tags: m.tags
|
||||
})
|
||||
hash := blake3.sum256(content.bytes())
|
||||
m.id = hash.hex()[..48]
|
||||
}
|
||||
|
||||
struct MessageContent {
|
||||
content string
|
||||
chat_group_id string
|
||||
sender_id string
|
||||
parent_messages []MessageLink
|
||||
fs_files []string
|
||||
message_type MessageType
|
||||
mentions []string
|
||||
tags []string
|
||||
}
|
||||
|
||||
pub fn new_chat_message(content string, chat_group_id string, sender_id string) ChatMessage {
|
||||
mut message := ChatMessage{
|
||||
content: content
|
||||
chat_group_id: chat_group_id
|
||||
sender_id: sender_id
|
||||
message_type: .text
|
||||
status: .sent
|
||||
created_at: time.now().unix()
|
||||
updated_at: time.now().unix()
|
||||
}
|
||||
message.calculate_id()
|
||||
return message
|
||||
}
|
||||
25
lib/hero/heromodels/chat_group.v
Normal file
25
lib/hero/heromodels/chat_group.v
Normal file
@@ -0,0 +1,25 @@
|
||||
module heromodels
|
||||
|
||||
import time
|
||||
import crypto.blake3
|
||||
import json
|
||||
|
||||
// ChatGroup represents a chat channel or conversation
|
||||
@[heap]
|
||||
pub struct ChatGroup {
|
||||
pub mut:
|
||||
chat_type ChatType
|
||||
messages []u32 // IDs of chat messages
|
||||
created_at i64
|
||||
updated_at i64
|
||||
last_activity i64
|
||||
is_archived bool
|
||||
tags []string
|
||||
}
|
||||
|
||||
pub enum ChatType {
|
||||
public_channel
|
||||
private_channel
|
||||
direct_message
|
||||
group_message
|
||||
}
|
||||
58
lib/hero/heromodels/chat_message.v
Normal file
58
lib/hero/heromodels/chat_message.v
Normal file
@@ -0,0 +1,58 @@
|
||||
module heromodels
|
||||
|
||||
import time
|
||||
import crypto.blake3
|
||||
import json
|
||||
|
||||
// ChatMessage represents a message in a chat group
|
||||
@[heap]
|
||||
pub struct ChatMessage {
|
||||
pub mut:
|
||||
content string
|
||||
chat_group_id u32 // Associated chat group
|
||||
sender_id u32 // User ID of sender
|
||||
parent_messages []MessageLink // Referenced/replied messages
|
||||
fs_files []u32 // IDs of linked files
|
||||
message_type MessageType
|
||||
status MessageStatus
|
||||
reactions []MessageReaction
|
||||
mentions []u32 // User IDs mentioned in message
|
||||
}
|
||||
|
||||
pub struct MessageLink {
|
||||
pub mut:
|
||||
message_id u32
|
||||
link_type MessageLinkType
|
||||
}
|
||||
|
||||
pub enum MessageLinkType {
|
||||
reply
|
||||
reference
|
||||
forward
|
||||
quote
|
||||
}
|
||||
|
||||
pub enum MessageType {
|
||||
text
|
||||
image
|
||||
file
|
||||
voice
|
||||
video
|
||||
system
|
||||
announcement
|
||||
}
|
||||
|
||||
pub enum MessageStatus {
|
||||
sent
|
||||
delivered
|
||||
read
|
||||
failed
|
||||
deleted
|
||||
}
|
||||
|
||||
pub struct MessageReaction {
|
||||
pub mut:
|
||||
user_id u32
|
||||
emoji string
|
||||
timestamp i64
|
||||
}
|
||||
@@ -138,6 +138,41 @@ pub fn (mut self DBProjectIssue) new(args ProjectIssueArg) !ProjectIssue {
|
||||
children: args.children
|
||||
}
|
||||
|
||||
// Validate that project_id exists
|
||||
mut db_project := DBProject{
|
||||
db: self.db
|
||||
}
|
||||
if !db_project.exist(args.project_id)! {
|
||||
return error('Project with ID ${args.project_id} does not exist')
|
||||
}
|
||||
|
||||
// Get the project to validate swimlane and milestone
|
||||
project_obj := db_project.get(args.project_id)!
|
||||
|
||||
// Validate swimlane exists in the project
|
||||
swimlane_exists := false
|
||||
for swimlane in project_obj.swimlanes {
|
||||
if swimlane.name == o.swimlane {
|
||||
swimlane_exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !swimlane_exists {
|
||||
return error('Swimlane "${args.swimlane}" does not exist in project "${project_obj.name}"')
|
||||
}
|
||||
|
||||
// Validate milestone exists in the project
|
||||
milestone_exists := false
|
||||
for milestone in project_obj.milestones {
|
||||
if milestone.name == o.milestone {
|
||||
milestone_exists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !milestone_exists {
|
||||
return error('Milestone "${args.milestone}" does not exist in project "${project_obj.name}"')
|
||||
}
|
||||
|
||||
// Set base fields
|
||||
o.name = args.name
|
||||
o.description = args.description
|
||||
|
||||
Reference in New Issue
Block a user