// Run implements runnable interface func (job *pullPresenceJob) Run() { presence := job.presence presence.LastSeen = time.Now() if !presence.Writing { // Send online status var interested []models.Friend log.Printf("Awaiting for [FriendID = %d] list", presence.DigitsID) err := mangos.FindAll(constants.CFriends, bson.M{"friend_id": presence.DigitsID}, &interested) if err != nil { log.Printf("Could not list [FriendID = %d]:%s", presence.DigitsID, err) return } for _, friend := range interested { client := binds.Get(friend.DigitsID) if client != nil { client.Send(presence) log.Printf("Sent presence from %d to %d", presence.DigitsID, friend.DigitsID) } } return } // Send writing status client := binds.Get(presence.FriendID) if client != nil { client.Send(presence) log.Printf("Sent writing presence from %d to %d", presence.DigitsID, presence.FriendID) } }
// List writes a list of groups available for the current session func List(c *echo.Context) (int, interface{}) { digitsID, ok := c.Get("digitsID").(int64) if !ok { return msg.Forbidden("session required") } // List all groups where digitID is member of var groups = make([]models.Group, 0) err := mangos.FindAll(constants.CGroups, bson.M{"members": digitsID}, &groups) if err != nil { return msg.InternalError(err) } return msg.Ok(groups) }
// List inserts a new friendship in database func List(c *echo.Context) (int, interface{}) { digitsID, ok := c.Get("digitsID").(int64) if !ok { return msg.Forbidden("session required") } // Find all user friends var friends = make([]models.Friend, 0) err := mangos.FindAll(constants.CFriends, bson.M{"digits_id": digitsID}, &friends) if err != nil { return msg.InternalError(err) } return msg.Ok(friends) }