From d317e8f6df0e0e16445db606da1d683a6b35f531 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Tue, 30 Dec 2025 19:33:39 +0300 Subject: =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/chat/user.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/chat/user.go (limited to 'internal/chat/user.go') 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 + ")" +} -- cgit v1.2.3