// List all notifications
968326
func (self *Notifications) Get(request *gottp.Request) {
	var args struct {
		Organization string `json:"org"`
		AppName      string `json:"app_name"`
		User         string `json:"user" required:"true"`
	}

	request.ConvertArguments(&args)
	paginator := request.GetPaginator()

	all, err := sentApi.GetAll(paginator, args.User, args.AppName, args.Organization)

	if err != nil {
		if err != mgo.ErrNotFound {
			log.Println(err)
			request.Raise(gottp.HttpError{
				http.StatusInternalServerError,
				"Unable to fetch data, Please try again later.",
			})

		} else {
			request.Raise(gottp.HttpError{
				http.StatusNotFound,
				"Not Found.",
			})
		}
		return
	}

	request.Write(all)
	return
}
956506
func (c Client) GetNotifications() (n []contract.Notification, err error) {
	conn := c.Pool.Get()
	defer conn.Close()

	objects, err := getObjectsByRange(conn, db.Notification, 0, -1)
	if err != nil {
		return nil, err
	}

	n, err = unmarshalNotifications(objects)
	if err != nil {
		return n, err
	}

	return n, nil
}
837392
func (maildir *Maildir) List(start, limit int) (*data.Messages, error) {
	log.Println("Listing messages in", maildir.Path)
	messages := make([]data.Message, 0)

	dir, err := os.Open(maildir.Path)
	if err != nil {
		return nil, err
	}
	defer dir.Close()

	n, err := dir.Readdir(0)
	if err != nil {
		return nil, err
	}

	for _, fileinfo := range n {
		b, err := ioutil.ReadFile(filepath.Join(maildir.Path, fileinfo.Name()))
		if err != nil {
			return nil, err
		}
		msg := data.FromBytes(b)
		// FIXME domain
		m := *msg.Parse("mailhog.example")
		m.ID = data.MessageID(fileinfo.Name())
		m.Created = fileinfo.ModTime()
		messages = append(messages, m)
	}

	log.Printf("Found %d messages", len(messages))
	msgs := data.Messages(messages)
	return &msgs, nil
}
111689
func List(c *client.Client, results int) (api.Apps, int, error) {
	body, count, err := c.LimitedRequest("/v1/apps/", results)

	if err != nil {
		return []api.App{}, -1, err
	}

	var apps []api.App
	if err = json.Unmarshal([]byte(body), &apps); err != nil {
		return []api.App{}, -1, err
	}

	return apps, count, nil
}
1230030
func (e *ListTrackersEngine) List() []libkb.Tracker {
	if e.trackers == nil {
		return []libkb.Tracker{}
	}
	return e.trackers.Trackers
}
188304
func (api UsersAPI) GetNotifications(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]

	type NotificationList struct {
		Approvals               []invitations.JoinOrganizationInvitation `json:"approvals"`
		ContractRequests        []contractdb.ContractSigningRequest      `json:"contractRequests"`
		Invitations             []invitations.JoinOrganizationInvitation `json:"invitations"`
		MissingScopes           []organizationDb.MissingScope            `json:"missingscopes"`
		OrganizationInvitations []invitations.JoinOrganizationInvitation `json:"organizationinvitations"`
	}
	var notifications NotificationList

	invitationMgr := invitations.NewInvitationManager(r)
	valMgr := validationdb.NewManager(r)

	userOrgRequests, err := invitationMgr.FilterByUser(username, "pending")
	if handleServerError(w, "getting invitations by user", err) {
		return
	}

	// Add the invites for the users verified phone numbers. This is required if the invite
	// was added before the phone number was verified, and no invite sms was send
	validatedPhonenumbers, err := valMgr.GetByUsernameValidatedPhonenumbers(username)
	if handleServerError(w, "getting verified phone numbers", err) {
		return
	}
	for _, number := range validatedPhonenumbers {
		phonenumberRequests, err := invitationMgr.FilterByPhonenumber(number.Phonenumber, "pending")
		if handleServerError(w, "getting invitations by user for phonenumber", err) {
			return
		}
		userOrgRequests = append(userOrgRequests, phonenumberRequests...)
	}

	// Add the invites for the users verified email addresses. This is required if the invite
	// was added before the email address was verified, and no invite email was send
	validatedEmailaddresses, err := valMgr.GetByUsernameValidatedEmailAddress(username)
	if handleServerError(w, "getting verified email addresses", err) {
		return
	}
	for _, email := range validatedEmailaddresses {
		emailRequests, err := invitationMgr.FilterByEmail(email.EmailAddress, "pending")
		if handleServerError(w, "getting invitations by user for email", err) {
			return
		}
		for _, emailRequest := range emailRequests {
			alreadyFound := false
			for _, inv := range userOrgRequests {
				if inv.Organization == emailRequest.Organization {
					alreadyFound = true
					break
				}
			}
			if !alreadyFound {
				userOrgRequests = append(userOrgRequests, emailRequest)
			}
		}
	}

	// Add the invites for the organizations where this user is an owner
	orgMgr := organizationDb.NewManager(r)

	orgs, err := orgMgr.AllByUser(username)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	var ownedOrgs []string

	for _, org := range orgs {
		if exists(username, org.Owners) {
			ownedOrgs = append(ownedOrgs, org.Globalid)
		}
	}

	orgInvites := make([]invitations.JoinOrganizationInvitation, 0)

	for _, org := range ownedOrgs {
		invites, err := invitationMgr.GetOpenOrganizationInvites(org)
		if err != nil {
			log.Error("Error while loading all invites where the organization ", org, " is invited")
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		orgInvites = append(orgInvites, invites...)
	}

	notifications.Invitations = userOrgRequests
	notifications.OrganizationInvitations = orgInvites
	// TODO: Get Approvals and Contract requests
	notifications.Approvals = []invitations.JoinOrganizationInvitation{}
	notifications.ContractRequests = []contractdb.ContractSigningRequest{}
	extraOrganizations := []string{}
	for _, invitation := range notifications.Invitations {
		extraOrganizations = append(extraOrganizations, invitation.Organization)
	}
	err, notifications.MissingScopes = getMissingScopesForOrganizations(r, username, extraOrganizations)
	if handleServerError(w, "getting missing scopes", err) {
		return
	}
	w.Header().Set("Content-type", "application/json")
	json.NewEncoder(w).Encode(&notifications)
}
1196114
func (mattermost *MattermostNotifier) Notify(messages Messages) bool {
	if !mattermost.Init() {
		return false
	}

	if mattermost.Detailed {
		return mattermost.notifyDetailed(messages)
	}

	return mattermost.notifySimple(messages)
}
143280
func (b *BlockChain) sendNotification(typ NotificationType, data interface{}) {
	// Generate and send the notification.
	n := Notification{Type: typ, Data: data}
	b.notificationsLock.RLock()
	for _, callback := range b.notifications {
		callback(&n)
	}
	b.notificationsLock.RUnlock()
}
1179826
func List(c *messagebird.Client, msgListParams *ListParams) (*MessageList, error) {
	messageList := &MessageList{}
	params, err := paramsForMessageList(msgListParams)
	if err != nil {
		return messageList, err
	}

	if err := c.Request(messageList, http.MethodGet, path+"?"+params.Encode(), nil); err != nil {
		return nil, err
	}

	return messageList, nil
}
309963
func (s *GroupsService) List() *GroupsListCall {
	var call GroupsListCall
	call.service = s
	return &call
}
1362318
func (rs *REST) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {
	servers := rs.GetServersToValidate()

	wait := sync.WaitGroup{}
	wait.Add(len(servers))
	statuses := make(chan api.ComponentStatus, len(servers))
	for k, v := range servers {
		go func(name string, server *Server) {
			defer wait.Done()
			status := rs.getComponentStatus(name, server)
			statuses <- *status
		}(k, v)
	}
	wait.Wait()
	close(statuses)

	reply := []api.ComponentStatus{}
	for status := range statuses {
		reply = append(reply, status)
	}
	return &api.ComponentStatusList{Items: reply}, nil
}
425795
func (s *AssessmentRun) SetNotifications(v []*AssessmentRunNotification) *AssessmentRun {
	s.Notifications = v
	return s
}
145568
func Notify(ctx context.Context, subj, msg string) error {
	if os.Getenv("GOPASS_NO_NOTIFY") != "" || !ctxutil.IsNotifications(ctx) {
		return nil
	}
	conn, err := dbus.SessionBus()
	if err != nil {
		return err
	}

	obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
	call := obj.Call("org.freedesktop.Notifications.Notify", 0, "gopass", uint32(0), iconURI(), subj, msg, []string{}, map[string]dbus.Variant{}, int32(5000))
	if call.Err != nil {
		return err
	}

	return nil
}
515701
func (pn *peernet) notifyAll(notification func(f inet.Notifiee)) {
	pn.notifmu.Lock()
	var wg sync.WaitGroup
	for n := range pn.notifs {
		// make sure we dont block
		// and they dont block each other.
		wg.Add(1)
		go func(n inet.Notifiee) {
			defer wg.Done()
			notification(n)
		}(n)
	}
	wg.Wait()
	pn.notifmu.Unlock()
}
1258022
func (cli *OpsGenieHeartbeatClient) List(req heartbeat.ListHeartbeatsRequest) (*heartbeat.ListHeartbeatsResponse, error) {
	req.APIKey = cli.apiKey
	resp, err := cli.sendRequest(cli.buildGetRequest(listHeartbeatURL, req))

	if resp == nil {
		return nil, err
	}
	defer resp.Body.Close()

	var listHeartbeatsResp heartbeat.ListHeartbeatsResponse
	if err = resp.Body.FromJsonTo(&listHeartbeatsResp); err != nil {
		message := "Server response can not be parsed, " + err.Error()
		logging.Logger().Warn(message)
		return nil, errors.New(message)
	}

	return &listHeartbeatsResp, nil
}
744395
func (s *NotificationServer) TransactionNotifications() TransactionNotificationsClient {
	c := make(chan *TransactionNotifications)
	s.mu.Lock()
	s.transactions = append(s.transactions, c)
	s.mu.Unlock()
	return TransactionNotificationsClient{
		C:      c,
		server: s,
	}
}
397806
func (n *Notifier) Notify(eventType EventType, message string, increment bool) {
	notif := &notification{
		Type:      eventType,
		Message:   message,
		Increment: increment,
	}

	if increment {
		n.Lock()
		n.current++
		n.Unlock()
	}

	n.RLock()
	current := n.current
	total := n.total
	n.RUnlock()

	if current > total {
		panic(fmt.Sprintf(
			"notifications exceed maximum %d/%d", current, total))
	}

	select {
	case n.notifications <- notif:
		return
	case <-n.observerClosed:
		return
	case <-n.ctxDone:
		return
	}
}