so much work to do :c

This commit is contained in:
gitGnome
2026-04-05 22:38:02 +02:00
parent 7f54cc7a40
commit 9b57157769
6 changed files with 41 additions and 58 deletions
+10
View File
@@ -0,0 +1,10 @@
package ConnectionType
type ConnectionType uint8
const (
Stranger ConnectionType = iota
GroupFellow
Friend
GroupFriend
)
+1 -9
View File
@@ -6,8 +6,8 @@ import (
)
var (
CacheUsers = make(map[uint32]*User)
mu sync.RWMutex
CacheUsers = make(map[uint32]*User)
Groups = make(map[uint32]*Group)
)
@@ -22,14 +22,6 @@ func CacheGetUserById(id uint32) (*User, error) {
return user, nil
}
func CacheGetIdByName(name string) (uint32, error) {
user, err := CacheGetUserByName(name)
if err != nil {
return 0, err
}
return user.Id, nil
}
func CacheGetUserByName(name string) (*User, error) {
mu.RLock()
defer mu.RUnlock()
+10 -40
View File
@@ -37,7 +37,7 @@ func DbInit(ctx context.Context) {
CREATE TABLE IF NOT EXISTS user_connections (
requestor_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
recipient_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
is_accepted BOOLEAN NOT NULL DEFAULT FALSE,
state TINYINT NOT NULL DEFAULT 0
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
PRIMARY KEY (requestor_id, recipient_id)
)
@@ -46,6 +46,15 @@ func DbInit(ctx context.Context) {
panic(err)
}
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS messages (
sender_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
receiver_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
content TEXT NOT NULL,
is_group_message BOOLEAN DEFAULT FALSE
)
`)
_, err = dbConn.Exec(ctx, `
CREATE TABLE IF NOT EXISTS chat_groups (
id SERIAL PRIMARY KEY,
@@ -127,45 +136,6 @@ func DbUserGetGroups(ctx context.Context, user *User) error {
return rows.Err()
}
func DbUserGetConnections(ctx context.Context, user *User) error {
rows, err := dbConn.Query(ctx, `
SELECT
CASE WHEN requestor_id = $1 THEN recipient_id ELSE requestor_id END AS other_id,
requestor_id = $1 AS is_from_user,
is_accepted,
created_at
FROM user_connections
WHERE requestor_id = $1 OR recipient_id = $1
`, user.Id)
if err != nil {
return err
}
user.Connections = make(map[uint32]*Connection)
defer rows.Close()
for rows.Next() {
var (
otherId uint32
isFromUser bool
isAccepted bool
createdAt time.Time
)
err = rows.Scan(&otherId, &isFromUser, &isAccepted, &createdAt)
if err != nil {
return err
}
user.Connections[otherId] = &Connection{
CreatedAt: createdAt,
With: otherId,
IsFromUser: isFromUser,
IsAccepted: isAccepted,
}
}
return rows.Err()
}
func DbUserSetColor(ctx context.Context, user *User) error {
_, err := dbConn.Exec(ctx, `
UPDATE users SET color_red = $1, color_green = $2, color_blue = $3 WHERE id = $4
+4 -3
View File
@@ -1,7 +1,8 @@
package main
const (
MaxGroupsForUser uint32 = 8
MaxUsersInGroup uint32 = 12
DirectMsgMaxCache
MaxGroupsForUser uint32 = 8
MaxUsersInGroup uint32 = 12
MaxDirectMsgCache uint32 = 12
MessagesPartitions uint8 = 2
)
+12 -5
View File
@@ -19,11 +19,18 @@ type User struct {
}
type Connection struct {
CreatedAt time.Time `json:"createdAt"`
Id uint32 `json:"id"`
RequestorId uint32 `json:"requestorId"`
RecipientId uint32 `json:"recipientId"`
MessagesBuf
CreatedAt time.Time `json:"createdAt"`
MessagesBuf [MaxDirectMsgCache]*Message `json:"-"`
Id uint32 `json:"id"`
RequestorId uint32 `json:"requestorId"`
RecipientId uint32 `json:"recipientId"`
State uint8 `json:"state"`
}
type Message struct {
Content string `json:"content"`
CreatedAt time.Time `json:"createdAt"`
Sender uint32 `json:"sender"`
}
type Group struct {
+4 -1
View File
@@ -1,5 +1,8 @@
media support
chat history
media support
fix color saving to use INT (002255255035) rgba
more user customization (avatar, banner, desc)