(req RuntimeSendRequest)
| 753 | } |
| 754 | |
| 755 | func (m *Manager) prepareRuntimeSend(req RuntimeSendRequest) (SendResult, error) { |
| 756 | if m == nil || m.router == nil { |
| 757 | return SendResult{}, errors.New("network: manager router is required") |
| 758 | } |
| 759 | now := m.now().UTC() |
| 760 | workspaceID := strings.TrimSpace(req.WorkspaceID) |
| 761 | if err := ValidateWorkspaceID(workspaceID); err != nil { |
| 762 | return SendResult{}, err |
| 763 | } |
| 764 | channel := strings.TrimSpace(req.Channel) |
| 765 | if err := ValidateChannel(channel); err != nil { |
| 766 | return SendResult{}, err |
| 767 | } |
| 768 | id := normalizeOptionalIdentifier(req.ID) |
| 769 | if id == nil { |
| 770 | id = ptrString(store.NewID("msg")) |
| 771 | } |
| 772 | envelope := Envelope{ |
| 773 | Protocol: ProtocolV0, |
| 774 | ID: *id, |
| 775 | WorkspaceID: workspaceID, |
| 776 | Kind: Kind(strings.TrimSpace(string(req.Kind))), |
| 777 | Channel: channel, |
| 778 | Surface: normalizeOptionalSurface(req.Surface), |
| 779 | ThreadID: normalizeOptionalIdentifier(req.ThreadID), |
| 780 | DirectID: normalizeOptionalIdentifier(req.DirectID), |
| 781 | From: RuntimePeerID, |
| 782 | To: normalizeOptionalIdentifier(req.To), |
| 783 | Mentions: normalizeEnvelopeMentions(req.Mentions), |
| 784 | WorkID: normalizeOptionalIdentifier(req.WorkID), |
| 785 | ReplyTo: normalizeOptionalIdentifier(req.ReplyTo), |
| 786 | TraceID: normalizeOptionalIdentifier(req.TraceID), |
| 787 | CausationID: normalizeOptionalIdentifier(req.CausationID), |
| 788 | TS: now.Unix(), |
| 789 | ExpiresAt: cloneInt64Ptr(req.ExpiresAt), |
| 790 | Body: cloneRawMessage(req.Body), |
| 791 | Ext: cloneExtensionMap(req.Ext), |
| 792 | } |
| 793 | if isConversationKind(envelope.Kind) && |
| 794 | envelope.Surface != nil && |
| 795 | *envelope.Surface == SurfaceDirect && |
| 796 | envelope.To != nil { |
| 797 | directID, _, _, err := DirectRoomIdentity(envelope.WorkspaceID, channel, envelope.From, *envelope.To) |
| 798 | if err != nil { |
| 799 | return SendResult{}, err |
| 800 | } |
| 801 | envelope.DirectID = ptrString(directID) |
| 802 | } |
| 803 | if envelope.IsDirected() && !m.peers.HasPresence(envelope.WorkspaceID, envelope.Channel, *envelope.To, now) { |
| 804 | return SendResult{}, fmt.Errorf( |
| 805 | "%w: peer_id=%q channel=%q", |
| 806 | ErrTargetPeerNotFound, |
| 807 | *envelope.To, |
| 808 | envelope.Channel, |
| 809 | ) |
| 810 | } |
| 811 | if err := ValidateEnvelope(envelope, ValidateOptions{Now: now, MaxReplayAge: m.router.maxReplayAge}); err != nil { |
| 812 | return SendResult{}, err |
no test coverage detected