Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/entities/message_thread.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/entities/message_thread.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway@6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/entities/message_thread.go
-
curl -L -o message_thread.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/6917738ca6db1603dee9e07994b4e42d5e1ae9b2/api/pkg/entities/message_thread.go
2.4 kB
| package entities | |
| import ( | |
| "time" | |
| "github.com/google/uuid" | |
| ) | |
| // MessageThread represents a message thread between 2 phone numbers | |
| type MessageThread struct { | |
| ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703ca"` | |
| Owner string `json:"owner" gorm:"uniqueIndex:idx_message_threads_user_owner_contact,priority:2" example:"+18005550199"` | |
| Contact string `json:"contact" gorm:"uniqueIndex:idx_message_threads_user_owner_contact,priority:3" example:"+18005550100"` | |
| IsArchived bool `json:"is_archived" example:"false"` | |
| UnreadCount uint `json:"unread_count" gorm:"not null;default:0" example:"0"` | |
| UserID UserID `json:"user_id" gorm:"uniqueIndex:idx_message_threads_user_owner_contact,priority:1" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"` | |
| Color string `json:"color" example:"indigo"` | |
| Status MessageStatus `json:"status" example:"PENDING"` | |
| LastMessageContent *string `json:"last_message_content" example:"This is a sample message content"` | |
| LastMessageID *uuid.UUID `json:"last_message_id" example:"32343a19-da5e-4b1b-a767-3298a73703ca"` | |
| CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:09.527976+03:00"` | |
| UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:09.527976+03:00"` | |
| OrderTimestamp time.Time `json:"order_timestamp" example:"2022-06-05T14:26:09.527976+03:00"` | |
| // ContactDetails is resolved at read time and never persisted. | |
| ContactDetails *Contact `json:"contact_details,omitempty" gorm:"-"` | |
| } | |
| // Update a message thread after a message event | |
| func (thread *MessageThread) Update(timestamp time.Time, messageID uuid.UUID, content string, status MessageStatus) *MessageThread { | |
| thread.OrderTimestamp = timestamp | |
| thread.LastMessageID = &messageID | |
| thread.Status = status | |
| thread.LastMessageContent = &content | |
| return thread | |
| } | |
| // UpdateArchive sets a message thread as archived | |
| func (thread *MessageThread) UpdateArchive(isArchived bool) *MessageThread { | |
| thread.IsArchived = isArchived | |
| return thread | |
| } | |
| // HasLastMessage checks the last message in a thread by ID | |
| func (thread *MessageThread) HasLastMessage(id uuid.UUID) bool { | |
| if thread.LastMessageID == nil { | |
| return false | |
| } | |
| return *thread.LastMessageID == id | |
| } | |