Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. package Database
  2. import (
  3. "github.com/gofrs/uuid"
  4. "gorm.io/gorm"
  5. "gorm.io/gorm/clause"
  6. )
  7. // ConversationDetailUser all users associated with a conversation
  8. type ConversationDetailUser struct {
  9. Base
  10. ConversationDetailID uuid.UUID `gorm:"not null" json:"conversation_detail_id"`
  11. ConversationDetail ConversationDetail `gorm:"not null" json:"conversation"`
  12. UserID string `gorm:"not null" json:"user_id"` // Stored encrypted
  13. Username string `gorm:"not null" json:"username"` // Stored encrypted
  14. Admin string `gorm:"not null" json:"admin"` // Stored encrypted
  15. AssociationKey string `gorm:"not null" json:"association_key"` // Stored encrypted
  16. PublicKey string `gorm:"not null" json:"public_key"` // Stored encrypted
  17. }
  18. func GetConversationDetailUserById(id string) (ConversationDetailUser, error) {
  19. var (
  20. messageThread ConversationDetailUser
  21. err error
  22. )
  23. err = DB.Preload(clause.Associations).
  24. Where("id = ?", id).
  25. First(&messageThread).
  26. Error
  27. return messageThread, err
  28. }
  29. func (detailUser *ConversationDetailUser) CreateConversationDetailUser() error {
  30. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  31. Create(detailUser).
  32. Error
  33. }
  34. func (detailUser *ConversationDetailUser) UpdateConversationDetailUser() error {
  35. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  36. Where("id = ?", detailUser.ID).
  37. Updates(detailUser).
  38. Error
  39. }
  40. func (detailUser *ConversationDetailUser) DeleteConversationDetailUser() error {
  41. return DB.Session(&gorm.Session{FullSaveAssociations: true}).
  42. Delete(detailUser).
  43. Error
  44. }