aboutsummaryrefslogtreecommitdiff
path: root/internal/chat/user.go
diff options
context:
space:
mode:
author2025-12-30 19:33:39 +0300
committer2025-12-30 19:33:39 +0300
commitd317e8f6df0e0e16445db606da1d683a6b35f531 (patch)
tree4b80de04e17a137cff2dc309508b5f841f48c994 /internal/chat/user.go
downloadqchat-d317e8f6df0e0e16445db606da1d683a6b35f531.tar.gz
qchat-d317e8f6df0e0e16445db606da1d683a6b35f531.tar.bz2
qchat-d317e8f6df0e0e16445db606da1d683a6b35f531.tar.xz
qchat-d317e8f6df0e0e16445db606da1d683a6b35f531.zip
начальный коммит
Diffstat (limited to 'internal/chat/user.go')
-rw-r--r--internal/chat/user.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/chat/user.go b/internal/chat/user.go
new file mode 100644
index 0000000..e897f32
--- /dev/null
+++ b/internal/chat/user.go
@@ -0,0 +1,35 @@
+package chat
+
+import (
+ "sync"
+)
+
+type User struct {
+ Username string
+ Identify string
+ Chans map[string]*Channel
+ CurrentChan *Channel
+ Events chan any
+ mu sync.RWMutex
+}
+
+func (u *User) JoinChan(channel *Channel) {
+ u.mu.Lock()
+ defer u.mu.Unlock()
+
+ if _, ok := u.Chans[channel.Name]; ok {
+ return
+ }
+
+ u.Chans[channel.Name] = channel
+ u.CurrentChan = channel
+ channel.Join(u)
+}
+
+func (u *User) NUsername() string {
+ username := u.Username
+ identify := u.Identify
+ shortIdentify := identify[max(0, len(identify)-5):]
+
+ return username[:min(len(username), 10)] + " (" + shortIdentify + ")"
+}