// ProjectPostLurk: implementing Lurk interface
// Sender returns the User that casted the lurk
970416
func (lurk *ProjectPostLurk) Sender() (user *User) {
	user, _ = NewUser(lurk.From)
	return
}
560627
func (whisper *Whisper) postEvent(envelope *Envelope, isP2P bool) {
	if isP2P {
		whisper.p2pMsgQueue <- envelope
	} else {
		whisper.checkOverflow()
		whisper.messageQueue <- envelope
	}
}
420293
func (w *Worker) sendAck(evalID, token string, ack bool) {
	defer metrics.MeasureSince([]string{"nomad", "worker", "send_ack"}, time.Now())
	// Setup the request
	req := structs.EvalAckRequest{
		EvalID: evalID,
		Token:  token,
		WriteRequest: structs.WriteRequest{
			Region: w.srv.config.Region,
		},
	}
	var resp structs.GenericResponse

	// Determine if this is an Ack or Nack
	verb := "ack"
	endpoint := "Eval.Ack"
	if !ack {
		verb = "nack"
		endpoint = "Eval.Nack"
	}

	// Make the RPC call
	err := w.srv.RPC(endpoint, &req, &resp)
	if err != nil {
		w.logger.Error(fmt.Sprintf("failed to %s evaluation", verb), "eval_id", evalID, "error", err)
	} else {
		w.logger.Debug(fmt.Sprintf("%s evaluation", verb), "eval_id", evalID)
	}
}
104986
func (user *User) Lurk(post ExistingPost) (Lurk, error) {
	if post == nil {
		return nil, errors.New("Unable to lurk undefined post!")
	}

	switch post.(type) {
	case *UserPost:
		userPost := post.(*UserPost)
		lurk := UserPostLurk{From: user.ID(), Hpid: userPost.ID()}
		err := Db().Create(&lurk)
		return &lurk, err

	case *ProjectPost:
		projectPost := post.(*ProjectPost)
		lurk := ProjectPostLurk{From: user.ID(), Hpid: projectPost.ID()}
		err := Db().Create(&lurk)
		return &lurk, err
	}

	return nil, errors.New("Invalid post type " + reflect.TypeOf(post).String())
}
207178
func (p *InvitationProjector) Project(ctx context.Context, event eh.Event, entity eh.Entity) (eh.Entity, error) {
	i, ok := entity.(*Invitation)
	if !ok {
		return nil, errors.New("model is of incorrect type")
	}

	// Apply the changes for the event.
	switch event.EventType() {
	case InviteCreatedEvent:
		data, ok := event.Data().(*InviteCreatedData)
		if !ok {
			return nil, fmt.Errorf("projector: invalid event data type: %v", event.Data())
		}
		i.ID = event.AggregateID()
		i.Name = data.Name
		i.Age = data.Age

	case InviteAcceptedEvent:
		i.Status = "accepted"

	case InviteDeclinedEvent:
		i.Status = "declined"

	case InviteConfirmedEvent:
		i.Status = "confirmed"

	case InviteDeniedEvent:
		i.Status = "denied"

	default:
		return nil, errors.New("could not handle event: " + event.String())
	}

	i.Version++
	return i, nil
}
143333
func (w *filePoller) sendErr(e error, chClose <-chan struct{}) error {
	select {
	case w.errors <- e:
	case <-chClose:
		return fmt.Errorf("closed")
	}
	return nil
}
1285628
func (s *sender) sendDatagramAnticipate() (*net.UDPAddr, error) {
	err1 := s.conn.setDeadline(s.timeout)
	if err1 != nil {
		return nil, err1
	}
	var err error = nil
	ksz := uint(len(s.sendA.sends))
	knum := s.sendA.num
	if knum > ksz {
		err = fmt.Errorf("knum %v bigger than ksz %v", knum, ksz)
		return nil, err
	}

	for k := uint(0); k < knum; k++ {
		lx := s.sendA.sendslens[k]
		if lx < 4 {
			err = fmt.Errorf("lx smaller than 4")
			break
		}
		errx := s.conn.sendTo(s.sendA.sends[k][:lx], s.addr)
		if errx != nil {
			err = fmt.Errorf("k %v errx %v", k, errx.Error())
			break
		}
	}
	if err != nil {
		return nil, err
	}
	k := uint(0)
	for {
		n, addr, err := s.conn.readFrom(s.receive)
		if err != nil {
			return nil, err
		}
		if !addr.IP.Equal(s.addr.IP) || (s.tid != 0 && addr.Port != s.tid) {
			continue
		}
		p, err := parsePacket(s.receive[:n])
		if err != nil {
			continue
		}
		s.tid = addr.Port
		switch p := p.(type) {
		case pACK:
			if anticipateDebug {
				fmt.Printf(" **** pACK p.block %v  s.block %v k %v\n",
					p.block(), s.block, k)
			}
			if p.block() == s.block+uint16(k) {
				k++
				if k == knum {
					return addr, nil
				}
			}
		case pOACK:
			opts, err := unpackOACK(p)
			if s.block != 0 {
				continue
			}
			if err != nil {
				s.abort(err)
				return addr, err
			}
			for name, value := range opts {
				if name == "blksize" {
					err := s.setBlockSize(value)
					if err != nil {
						continue
					}
				}
			}
			return addr, nil
		case pERROR:
			return nil, fmt.Errorf("sending block %d: code=%d, error: %s",
				s.block, p.code(), p.message())
		}
	}
}
686327
func (pm *Pm) Sender() *User {
	user, _ := NewUser(pm.NumericSender())
	return user
}
795794
func (self *Notifications) Post(request *gottp.Request) {
	pending_item := new(db.PendingItem)
	request.ConvertArguments(pending_item)

	if request.GetArgument("topic") == nil {
		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			"Please provide topic for notification.",
		})

		return
	}

	if pending.Throttled(pending_item) {
		MSG := "Repeated Notifications are Blocked. Skipping."

		log.Println(MSG)
		request.Raise(gottp.HttpError{http.StatusBadRequest, MSG})
		return
	}

	pending_item.Topic = request.GetArgument("topic").(string)
	pending_item.IsRead = false

	pending_item.PrepareSave()

	if !utils.ValidateAndRaiseError(request, pending_item) {
		return
	}

	if !pending_item.IsValid() {
		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			"Context is required for sending notification.",
		})

		return
	}

	core.SendNotification(pending_item)
	request.Write(utils.R{StatusCode: http.StatusNoContent,
		Data: nil, Message: "true"})
	return
}
833093
func (f *Pub) SendError(err error) {
	// if err == nil { return }
	f.wg.Add(1)
	defer f.wg.Done()
	f.op(f, err, nil)
}
663686
func (ww *WidgetWatchers) PostEvent(wev EventWidget) {
	for watcher := range ww.watchers {
		// Deliver events to all listeners, ignoring return value.
		watcher.HandleEvent(wev)
	}
}
1013319
func PostingsIteratorFrom1Hit(docNum1Hit, normBits1Hit uint64,
	includeFreqNorm, includeLocs bool) (*PostingsIterator, error) {
	return &PostingsIterator{
		docNum1Hit:      docNum1Hit,
		normBits1Hit:    normBits1Hit,
		includeFreqNorm: includeFreqNorm,
		includeLocs:     includeLocs,
	}, nil
}
1283733
func newPostMemberHandler(b MemberBackend) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		req, err := decodePostMemberRequest(ctx, r)
		if err != nil {
			EncodeError(ctx, err, w)
			return
		}

		user, err := b.UserService.FindUserByID(ctx, req.MemberID)
		if err != nil {
			EncodeError(ctx, err, w)
			return
		}

		mapping := &platform.UserResourceMapping{
			ResourceID:   req.ResourceID,
			ResourceType: b.ResourceType,
			UserID:       req.MemberID,
			UserType:     b.UserType,
		}

		if err := b.UserResourceMappingService.CreateUserResourceMapping(ctx, mapping); err != nil {
			EncodeError(ctx, err, w)
			return
		}

		if err := encodeResponse(ctx, w, http.StatusCreated, newResourceUserResponse(user, b.UserType)); err != nil {
			EncodeError(ctx, err, w)
			return
		}
	}
}
476436
func PostLoginUser(w rest.ResponseWriter, r *rest.Request) {
	var recvDoc map[string]interface{}
	err := r.DecodeJsonPayload(&recvDoc)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	doc, err := api.LoginUser(variables.ServiceUserURL, variables.BackendToken, recvDoc)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusOK)
	if doc == nil {
		w.(http.ResponseWriter).Write(variables.BlankResponse)
		return
	}
	w.WriteJson(doc)
}
1200811
func PostUser(w rest.ResponseWriter, r *rest.Request) {
	var recvDoc map[string]interface{}
	id := r.PathParam("id")
	if r.Env["REMOTE_USER"].(string) != id {
		err := errors.New("Can only save your own user account")
		rest.Error(w, err.Error(), http.StatusUnauthorized)
	}
	err := r.DecodeJsonPayload(&recvDoc)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	doc, err := api.SaveUser(variables.ServiceDBURL, r.Env["JWT_RAW"].(string), id, recvDoc)
	if err != nil {
		rest.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.WriteHeader(http.StatusOK)
	if doc == nil {
		w.(http.ResponseWriter).Write(variables.BlankResponse)
		return
	}
	w.WriteJson(doc)
}
585998
func (user *User) NumericProjectFollowing() (following []uint64) {
	Db().Model(ProjectFollower{}).Where(&ProjectFollower{From: user.ID()}).Pluck(`"to"`, &following)
	return
}
251512
func (s *pcfaasController) Post() interface{} {
	var handler PcfaasPostInventoryHandler = func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens) {
		statusCode := SuccessStatus
		userInfo := GetUserInfo(tokens)
		itemID := params[InventoryItemParam]
		emails := userInfo["emails"].([]interface{})
		userEmail := emails[0].(map[string]interface{})["value"]
		lease, err := s.inventoryClient.LeaseInventoryItem(itemID, userEmail.(string), 14)
		if err != nil {
			log.Fatalln(err)
			statusCode = ServerErrorStatus
		}
		log.Println("User info ", userEmail)
		log.Println("Creating a lease for item ", itemID)
		r.JSON(statusCode, lease)
	}
	return handler
}