Exemplo n.º 1
0
func (c *IRCClient) AddChannel(name string) {
	channel := &Channel{
		info: &common.IRCChannel{
			UserId:   c.UserId,
			ServerId: c.ServerId,
			Name:     name,
			Members:  make([]string, 0),
		},
		members: make(map[string]bool),
	}

	channels := []*common.IRCChannel{channel.info}
	err := common.RedisSliceSave(fmt.Sprintf("channels:%s", c.UserId), &channels)

	if err != nil {
		log.Println("AddChannel Error: ", err)
		return
	}

	channel.joined = c.serverInfo.Active
	c.channels[strings.ToLower(name)] = channel
	if c.serverInfo.Active {
		c.conn.Join(name)
	}
}
Exemplo n.º 2
0
func (u *User) SetNotification(pushType, pushToken string, isAlert bool) (err error) {
	tokens := []string{fmt.Sprintf("%s:%s", pushType, pushToken)}
	if isAlert {
		err = common.RedisSliceSave(u.PushTokenListKey(), &tokens)
	} else {
		err = common.RedisSliceRemove(u.PushTokenListKey(), &tokens)
	}
	return
}
Exemplo n.º 3
0
func (u *User) AddServer(server *common.IRCServer) (*common.IRCServer, error) {
	server.Id = int(u.serverIdSeq.Incr())
	server.UserId = u.Id
	server.Active = false

	servers := []*common.IRCServer{server}

	err := common.RedisSliceSave(u.ServerListKey(), &servers)
	if err != nil {
		return nil, err
	}

	manager.zmq.Send <- common.MakeZmqMsg(u.Id, server.Id, common.ZmqAddServer{ServerInfo: server})

	return server, nil
}