|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 | 7 | "time"
|
| 8 | + |
| 9 | + "github.com/gofrs/uuid/v5" |
8 | 10 | )
|
9 | 11 |
|
10 | 12 | type ParticipantSessionView struct {
|
@@ -40,16 +42,27 @@ func CreateContactConversation(ctx context.Context, participantID string, user *
|
40 | 42 | UserId: participantID,
|
41 | 43 | },
|
42 | 44 | }
|
43 |
| - return CreateConversation(ctx, "CONTACT", UniqueConversationId(participantID, user.UserId), "", "", participants, user) |
| 45 | + return createConversation(ctx, "CONTACT", UniqueConversationId(participantID, user.UserId), "", "", participants, "", user) |
| 46 | +} |
| 47 | + |
| 48 | +func CreateGroupConversation(ctx context.Context, name, announcement string, participants []Participant, user *SafeUser) (*Conversation, error) { |
| 49 | + pids := make([]string, len(participants)) |
| 50 | + for i, p := range participants { |
| 51 | + pids[i] = p.UserId |
| 52 | + } |
| 53 | + randomId := uuid.Must(uuid.NewV4()).String() |
| 54 | + conversationId := GroupConversationId(user.UserId, name, pids, randomId) |
| 55 | + return createConversation(ctx, "GROUP", conversationId, name, announcement, participants, randomId, user) |
44 | 56 | }
|
45 | 57 |
|
46 |
| -func CreateConversation(ctx context.Context, category, conversationId string, name, announcement string, participants []Participant, user *SafeUser) (*Conversation, error) { |
| 58 | +func createConversation(ctx context.Context, category, conversationId string, name, announcement string, participants []Participant, randomId string, user *SafeUser) (*Conversation, error) { |
47 | 59 | params, err := json.Marshal(map[string]any{
|
48 | 60 | "category": category,
|
49 | 61 | "conversation_id": conversationId,
|
50 | 62 | "name": name,
|
51 | 63 | "announcement": announcement,
|
52 | 64 | "participants": participants,
|
| 65 | + "random_id": randomId, |
53 | 66 | })
|
54 | 67 | if err != nil {
|
55 | 68 | return nil, err
|
|
0 commit comments