Skip to content

Commit

Permalink
Merge pull request #28 from tada-team/9015-call-events
Browse files Browse the repository at this point in the history
9015 fix: set omitempty
  • Loading branch information
sdfsdhgjkbmnmxc authored Jun 1, 2021
2 parents 6128862 + ba35787 commit 8d4a4da
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 69 deletions.
26 changes: 22 additions & 4 deletions call_event.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package tdproto

// Audio call information
// Call information
type CallEvent struct {
// Call start
Start *ISODateTimeString `json:"start"`
// Chat or contact id
Jid JID `json:"jid"`

// Call id
Uid string `json:"uid"`

// Call buzzing
Buzz bool `json:"buzz,omitempty"`

// Creation date, iso datetime
Created ISODateTimeString `json:"created"`

// Call start. For direct calls can be empty when buzzing
Start ISODateTimeString `json:"start,omitempty"`

// Call finish
Finish *ISODateTimeString `json:"finish"`
Finish ISODateTimeString `json:"finish,omitempty"`

// Call record enabled
Audiorecord bool `json:"audiorecord"`

// Call participants
Onliners []CallOnliner `json:"onliners,omitempty"`

// Version
Gentime int64 `json:"gentime"`

// Deprecated: use gentime or created
Timestamp int64 `json:"timestamp"`
}

// Call participant
Expand Down
4 changes: 2 additions & 2 deletions client_call_buzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ type clientCallBuzzParams struct {
// Chat or contact id
Jid JID `json:"jid"`

// List of call participants
Members []JID `json:"members"`
// List of call participants. Empty value means all participants in call
Members []JID `json:"members,omitempty"`
}
2 changes: 1 addition & 1 deletion client_call_leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type clientCallLeaveParams struct {
Jid JID `json:"jid"`

// Reason, if any
Reason string `json:"reason"`
Reason string `json:"reason,omitempty"`
}
2 changes: 1 addition & 1 deletion client_call_reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type clientCallRejectParams struct {
Jid JID `json:"jid"`

// Reason, if any
Reason string `json:"reason"`
Reason string `json:"reason,omitempty"`
}
4 changes: 2 additions & 2 deletions client_call_trickle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type clientCallTrickleParams struct {
Candidate string `json:"candidate"`

// SDP mid
SdpMid string `json:"sdp_mid"`
SdpMid string `json:"sdp_mid,omitempty"`

// SDP index
SdpMlineIndex int `json:"sdp_mline_index"`
SdpMlineIndex int `json:"sdp_mline_index,omitempty"`
}
2 changes: 1 addition & 1 deletion server_call_answer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type serverCallAnswerParams struct {
Jid JID `json:"jid"`

// List of ICE candidates (when trickle = false)
Candidates []serverCallAnswerCandidate `json:"candidates"`
Candidates []serverCallAnswerCandidate `json:"candidates,omitempty"`

// Current call participants
Onliners []CallOnliner `json:"onliners,omitempty"`
Expand Down
54 changes: 5 additions & 49 deletions server_call_state.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,15 @@
package tdproto

import "time"

func NewServerCallState(chat HasJid, startCall, finishCall *time.Time, onliners []CallOnliner, audiorecord, buzz bool, uid string, timestamp int64) (r ServerCallState) {
func NewServerCallState(callEvent CallEvent) (r ServerCallState) {
r.Name = r.GetName()
r.Params.Jid = chat.JID()
r.Params.Onliners = onliners
r.Params.Buzz = buzz
r.Params.Uid = uid
r.Params.Audiorecord = audiorecord
r.Params.Timestamp = timestamp

if startCall != nil {
r.Params.Start = NullableIsoDatetime(startCall)
} else {
r.Params.Buzz = true
}

if finishCall != nil {
r.Params.Finish = NullableIsoDatetime(startCall)
}

return r
r.Params = callEvent
return
}

// Call participant number or parameters changed
// Call information
type ServerCallState struct {
BaseEvent
Params serverCallStateParams `json:"params"`
Params CallEvent `json:"params"`
}

func (p ServerCallState) GetName() string { return "server.call.state" }

type serverCallStateParams struct {
// Chat or contact id
Jid JID `json:"jid"`

// Call id
Uid string `json:"uid"`

// Call participants
Onliners []CallOnliner `json:"onliners,omitempty"`

// Call start, if any
Start *ISODateTimeString `json:"start"`

// Call finish, if any
Finish *ISODateTimeString `json:"finish"`

// Call record enabled
Audiorecord bool `json:"audiorecord"`

// Call buzzing
Buzz bool `json:"buzz,omitempty"`

// Event start. FIXME: why not gentime?
Timestamp int64 `json:"timestamp"`
}
2 changes: 1 addition & 1 deletion server_online.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type OnlineCall struct {
Uid string `json:"uid"`

// Call start
Start *ISODateTimeString `json:"start,omitempty"`
Start ISODateTimeString `json:"start,omitempty"`

// Number participants in call
OnlineCount int `json:"online_count,omitempty"`
Expand Down
8 changes: 0 additions & 8 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ func IsoDatetime(dt time.Time) string {
return strings.Replace(s, "+0000", "Z", 1)
}

func NullableIsoDatetime(dt *time.Time) *string {
if dt == nil {
return nil
}
v := IsoDatetime(*dt)
return &v
}

func ConfirmId() string {
return randomSymbols(12, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
}
Expand Down

0 comments on commit 8d4a4da

Please sign in to comment.