Example #1
0
func RoomsIndex(c *gin.Context) {
	user, err := GetUserFromContext(c)
	if err != nil {
		c.Fail(500, err)
	}

	rooms, err := models.FindRooms(user.TeamId)
	if err != nil {
		c.Fail(500, err)
	}

	memberships, err := models.FindRoomMemberships(user.Id)
	if err != nil {
		c.Fail(500, err)
	}

	unread, err := models.UnreadRooms(user.Id)
	if err != nil {
		c.Fail(500, err)
	}

	c.JSON(200, gin.H{
		"rooms":        rooms,
		"memberships":  memberships,
		"unread_rooms": unread,
	})
}
// A helper function to join all rooms the user is a member of.
func joinRoomMemberships(userId string, so socketio.Socket) error {
	ms, err := models.FindRoomMemberships(userId)
	for _, m := range ms {
		if err != nil {
			return err
		}
		err = so.Join(m)
	}
	return err
}