| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package server
- import (
- "errors"
- "sync"
- "time"
- "github.com/mkaminski/goaim/oscar"
- )
- var ErrSignedOff = errors.New("user signed off")
- type ChatRoom struct {
- CreateTime time.Time
- DetailLevel uint8
- Exchange uint16
- Cookie string
- InstanceNumber uint16
- Name string
- SessionManager
- }
- func (c ChatRoom) TLVList() []oscar.TLV {
- return []oscar.TLV{
- oscar.NewTLV(0x00c9, uint16(15)),
- oscar.NewTLV(0x00ca, uint32(c.CreateTime.Unix())),
- oscar.NewTLV(0x00d1, uint16(1024)),
- oscar.NewTLV(0x00d2, uint16(100)),
- oscar.NewTLV(0x00d5, uint8(2)),
- oscar.NewTLV(0x006a, c.Name),
- oscar.NewTLV(0x00d3, c.Name),
- }
- }
- type ChatRegistry struct {
- store map[string]ChatRoom
- mapMutex sync.RWMutex
- }
- func NewChatRegistry() *ChatRegistry {
- return &ChatRegistry{
- store: make(map[string]ChatRoom),
- }
- }
- func (c *ChatRegistry) Register(room ChatRoom) {
- c.mapMutex.Lock()
- defer c.mapMutex.Unlock()
- c.store[room.Cookie] = room
- }
- func (c *ChatRegistry) Retrieve(chatID string) (ChatRoom, error) {
- c.mapMutex.RLock()
- defer c.mapMutex.RUnlock()
- sm, found := c.store[chatID]
- if !found {
- return sm, errors.New("unable to find session manager for chat")
- }
- return sm, nil
- }
- func (c *ChatRegistry) MaybeRemoveRoom(chatID string) {
- c.mapMutex.Lock()
- defer c.mapMutex.Unlock()
- room, found := c.store[chatID]
- if found && room.Empty() {
- delete(c.store, chatID)
- }
- }
|