Exemple #1
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
}
Exemple #2
0
func (c *IRCClient) DelChannel(name string) {
	channel, ok := c.GetChannel(name)
	if !ok {
		log.Println("DelChannel Error: Channel does not exist", name)
		return
	}
	if channel.info.Joined {
		log.Println("DelChannel Error: Cannot delete joined channel", name)
		return
	}
	delete(c.channels, strings.ToLower(name))

	channels := []*common.IRCChannel{channel.info}
	if err := common.RedisSliceRemove(fmt.Sprintf("channels:%s", c.UserId), &channels); err != nil {
		log.Println("DelChannel Error: Redis Remove Error:", err)
		return
	}

	zmqMgr.Send <- c.MakeZmqMsg(common.ZmqDelChannel{Channel: "-" + name})

}
Exemple #3
0
func (m *PushManager) SendGCM(userId string, pushTokens []string, payload *Packet) {
	c := gcm.New(common.Config.GCMAPIKey)
	msg := gcm.NewMessage(pushTokens...)
	switch body := payload.body.(type) {
	case SendPushLog:
		msg.CollapseKey = fmt.Sprintf("%d:%s", body.Log.ServerId, body.Log.Channel)
	}

	var err error
	if payload.RawData == nil {
		payload.RawData, err = json.Marshal(payload.body)
		if err != nil {
			log.Println("SendGCM Error: ", err)
			return
		}
	}

	msg.SetPayload("type", payload.Cmd)
	msg.SetPayload("data", string(payload.RawData))
	resp, err2 := c.Send(msg)
	if err2 != nil {
		log.Println("SendGCM Error: ", err2)
	}
	log.Printf("%+v", resp)
	var removeTokens []string
	for i, result := range resp.Results {
		switch result.Error {
		case "NotRegistered":
			removeTokens = append(removeTokens, "gcm:"+pushTokens[i])
		}
	}
	if removeTokens != nil {
		err = common.RedisSliceRemove(m.PushTokenListKey(userId), &removeTokens)
		if err != nil {
			log.Println("SendGCM - RemoveTokens Error: ", err2)
		}
	}
}