Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pkg/sendMessage/service/send_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type MediaStruct struct {
FormatJid *bool `json:"formatJid,omitempty"`
Quoted QuotedStruct `json:"quoted"`
ForwardingScore *uint32 `json:"forwardingScore,omitempty"`
ViewOnce bool `json:"viewOnce"`
}

type PollStruct struct {
Expand Down Expand Up @@ -1186,6 +1187,24 @@ func (s *sendService) sendMediaFileWithRetry(data *MediaStruct, fileData []byte,
return nil, errors.New("invalid media type")
}

// view-once: when requested, flag the media so it disappears after the recipient opens it
// once (image, video and voice/PTV support it; documents do not). Additive — without the
// flag the media is a normal message, exactly as before.
if data.ViewOnce {
if media.ImageMessage != nil {
media.ImageMessage.ViewOnce = proto.Bool(true)
}
if media.VideoMessage != nil {
media.VideoMessage.ViewOnce = proto.Bool(true)
}
if media.AudioMessage != nil {
media.AudioMessage.ViewOnce = proto.Bool(true)
}
if media.PtvMessage != nil {
media.PtvMessage.ViewOnce = proto.Bool(true)
}
}

message, err := s.SendMessage(instance, media, mediaType, &SendDataStruct{
Id: data.Id,
Number: data.Number,
Expand Down Expand Up @@ -1490,6 +1509,24 @@ func (s *sendService) sendMediaUrlWithRetry(data *MediaStruct, instance *instanc
return nil, errors.New("invalid media type")
}

// view-once: when requested, flag the media so it disappears after the recipient opens it
// once (image, video and voice/PTV support it; documents do not). Additive — without the
// flag the media is a normal message, exactly as before.
if data.ViewOnce {
if media.ImageMessage != nil {
media.ImageMessage.ViewOnce = proto.Bool(true)
}
if media.VideoMessage != nil {
media.VideoMessage.ViewOnce = proto.Bool(true)
}
if media.AudioMessage != nil {
media.AudioMessage.ViewOnce = proto.Bool(true)
}
if media.PtvMessage != nil {
media.PtvMessage.ViewOnce = proto.Bool(true)
}
}

messageStart := time.Now()
message, err := s.SendMessage(instance, media, mediaType, &SendDataStruct{
Id: data.Id,
Expand Down