Skip to content

Commit

Permalink
remove references from JIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfsdhgjkbmnmxc committed Apr 7, 2021
1 parent 75864e5 commit cb76984
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 36 deletions.
6 changes: 3 additions & 3 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type Chat struct {
NumCheckedItems *uint `chattype:"task" json:"num_checked_items,omitempty"`

// Assignee contact id. Tasks only
Assignee *JID `chattype:"task" json:"assignee,omitempty"`
Assignee JID `chattype:"task" json:"assignee,omitempty"`

// Task number in this team
Num uint `chattype:"task" json:"num,omitempty"`
Expand All @@ -144,7 +144,7 @@ type Chat struct {
Observers []JID `chattype:"task" json:"observers,omitempty"`

// Task creator
Owner *JID `chattype:"task" json:"owner,omitempty"`
Owner JID `chattype:"task" json:"owner,omitempty"`

// Task status. May be custom
TaskStatus string `chattype:"task" json:"task_status,omitempty"`
Expand Down Expand Up @@ -288,7 +288,7 @@ type TaskItem struct {
// Group chat membership status
type GroupMembership struct {
// Contact id
Jid *JID `json:"jid"`
Jid JID `json:"jid"`

// Status in group
Status GroupStatus `json:"status"`
Expand Down
2 changes: 1 addition & 1 deletion group_access_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package tdproto
type GroupAccessRequest struct {
Uid string `json:"uid"`
Created ISODateTimeString `json:"created"`
Subject *JID `json:"subject"`
Subject JID `json:"subject"`
}
41 changes: 29 additions & 12 deletions jid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,37 @@ import (
)

func TestNewJID(t *testing.T) {
res := new(struct {
Val JID `json:"val"`
t.Run("marshall", func(t *testing.T) {
res := new(struct {
Val JID `json:"val,omitempty"`
})

b, err := json.Marshal(res)
if err != nil {
t.Fatal(err)
}

if string(b) != "{}" {
t.Error("must be empty, got:", string(b))
}
})

data := `{"val": "t-63150419-c5c7-40fb-8aa2-ca6b613ca5a0"}`
if err := json.Unmarshal([]byte(data), res); err != nil {
t.Fatal(err)
}
t.Run("unmarshall", func(t *testing.T) {
res := new(struct {
Val JID `json:"val"`
})

if !res.Val.IsTask() {
t.Error("must be task")
}
data := `{"val": "t-63150419-c5c7-40fb-8aa2-ca6b613ca5a0"}`
if err := json.Unmarshal([]byte(data), res); err != nil {
t.Fatal(err)
}

if res.Val.Uid() != "63150419-c5c7-40fb-8aa2-ca6b613ca5a0" {
t.Error("invalid uid:", res.Val.Uid())
}
if !res.Val.IsTask() {
t.Error("must be task")
}

if res.Val.Uid() != "63150419-c5c7-40fb-8aa2-ca6b613ca5a0" {
t.Error("invalid uid:", res.Val.Uid())
}
})
}
4 changes: 2 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type MessageContent struct {
New *string `mediatype:"change" json:"new,omitempty"`

// Change actor contact id (for "change" mediatype)
Actor *JID `mediatype:"change" json:"actor,omitempty"`
Actor JID `mediatype:"change" json:"actor,omitempty"`

// Comment (for "audiomsg" mediatype)
Comment string `mediatype:"audiomsg" json:"comment,omitempty"`
Expand Down Expand Up @@ -251,7 +251,7 @@ type MessageReactionDetail struct {
Created ISODateTimeString `json:"created"`

// Reaction author
Sender *JID `json:"sender"`
Sender JID `json:"sender"`

// Reaction emoji
Name string `json:"name"`
Expand Down
4 changes: 2 additions & 2 deletions message_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ type MessagePush struct {
Team string `json:"team"`

// Sender contact id
Sender *JID `json:"sender"`
Sender JID `json:"sender"`

// Chat id
Chat *JID `json:"chat"`
Chat JID `json:"chat"`

// Message id
MessageId string `json:"message_id"`
Expand Down
2 changes: 1 addition & 1 deletion remind.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Remind struct {
Uid string `json:"uid"`

// Chat id
Chat *JID `json:"chat"`
Chat JID `json:"chat"`

// Activation time, iso
FireAt ISODateTimeString `json:"fire_at"`
Expand Down
4 changes: 2 additions & 2 deletions server_call_buzzcancel.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tdproto

func NewServerCallBuzzcancel(chat *JID, teamUid string, uid string) (r ServerCallBuzzcancel) {
func NewServerCallBuzzcancel(chat JID, teamUid string, uid string) (r ServerCallBuzzcancel) {
r.Name = r.GetName()
r.Params.Jid = *chat
r.Params.Jid = chat
r.Params.Team = teamUid
r.Params.Uid = uid
return r
Expand Down
4 changes: 2 additions & 2 deletions server_call_restart.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tdproto

func NewServerCallRestart(chat *JID, teamUid string, uid string) (r ServerCallRestart) {
func NewServerCallRestart(chat JID, teamUid string, uid string) (r ServerCallRestart) {
r.Name = r.GetName()
r.Params.Jid = *chat
r.Params.Jid = chat
r.Params.Team = teamUid
r.Params.Uid = uid
return r
Expand Down
6 changes: 3 additions & 3 deletions server_call_talking.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tdproto

func NewServerCallTalking(talking bool, chat, actor *JID) (r ServerCallTalking) {
func NewServerCallTalking(talking bool, chat, actor JID) (r ServerCallTalking) {
r.Name = r.GetName()
r.Params.Jid = *chat
r.Params.Actor = *actor
r.Params.Jid = chat
r.Params.Actor = actor
r.Params.Talking = talking
return r
}
Expand Down
6 changes: 3 additions & 3 deletions server_chat_composing.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package tdproto

func NewServerChatComposing(composing, isAudio bool, chat, actor *JID) (r ServerChatComposing) {
func NewServerChatComposing(composing, isAudio bool, chat, actor JID) (r ServerChatComposing) {
r.Name = r.GetName()
r.Params.Jid = *chat
r.Params.Actor = *actor
r.Params.Jid = chat
r.Params.Actor = actor
r.Params.Composing = composing
r.Params.IsAudio = isAudio
return r
Expand Down
6 changes: 3 additions & 3 deletions server_chat_draft.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tdproto

func NewServerChatDraft(jid *JID, draft string, draftNum int64) (r ServerChatDraft) {
func NewServerChatDraft(jid JID, draft string, draftNum int64) (r ServerChatDraft) {
r.Name = r.GetName()
r.Params.Jid = jid
r.Params.Draft = draft
Expand All @@ -18,11 +18,11 @@ func (p ServerChatDraft) GetName() string { return "server.chat.draft" }

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

// Draft text
Draft string `json:"draft"`

// Draft version
// Draft version. TODO: use gentime instead
DraftNum int64 `json:"draft_num"`
}
2 changes: 1 addition & 1 deletion team.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Team struct {
Contacts []Contact `json:"contacts,omitempty" tdproto:"readonly"`

// For single group teams, jid of chat
SingleGroup *JID `json:"single_group,omitempty" tdproto:"readonly"`
SingleGroup JID `json:"single_group,omitempty" tdproto:"readonly"`

// Color theme, if any
Theme *Theme `json:"theme,omitempty" tdproto:"readonly"`
Expand Down
2 changes: 1 addition & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type User struct {

type UserWithMe struct {
User
Inviter *JID `json:"inviter,omitempty"`
Inviter JID `json:"inviter,omitempty"`
Teams []Team `json:"teams"`
Devices []PushDevice `json:"devices"`
}

0 comments on commit cb76984

Please sign in to comment.