From 1e08268c4ec673073a886cba9937557533a5155d Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:00:55 +0300 Subject: [PATCH 01/35] tdws --- client_call_buzz.go => tdws/client_call_buzz.go | 2 +- .../client_call_buzzcancel.go | 2 +- client_call_leave.go => tdws/client_call_leave.go | 2 +- .../client_call_muteall.go | 2 +- client_call_offer.go => tdws/client_call_offer.go | 2 +- client_call_reject.go => tdws/client_call_reject.go | 2 +- client_call_sdp.go => tdws/client_call_sdp.go | 2 +- client_call_sound.go => tdws/client_call_sound.go | 2 +- .../client_call_trickle.go | 2 +- .../client_chat_composing.go | 8 +++++--- .../client_chat_lastread.go | 2 +- client_confirm.go => tdws/client_confirm.go | 2 +- .../client_message_deleted.go | 2 +- .../client_message_updated.go | 2 +- client_ping.go => tdws/client_ping.go | 2 +- event.go => tdws/event.go | 2 +- server_call_answer.go => tdws/server_call_answer.go | 2 +- server_call_buzz.go => tdws/server_call_buzz.go | 2 +- .../server_call_buzzcancel.go | 2 +- .../server_call_checkfingerprint.go | 2 +- server_call_leave.go => tdws/server_call_leave.go | 2 +- .../server_call_muteall.go | 2 +- server_call_reject.go => tdws/server_call_reject.go | 2 +- .../server_call_restart.go | 2 +- server_call_sdp.go => tdws/server_call_sdp.go | 2 +- server_call_sound.go => tdws/server_call_sound.go | 8 +++++--- server_call_state.go => tdws/server_call_state.go | 2 +- .../server_call_talking.go | 2 +- .../server_chat_composing.go | 12 +++++++----- .../server_chat_deleted.go | 2 +- server_chat_draft.go => tdws/server_chat_draft.go | 2 +- .../server_chat_lastread.go | 2 +- .../server_chat_updated.go | 12 +++++++----- server_confirm.go => tdws/server_confirm.go | 2 +- .../server_contact_updated.go | 2 +- server_debug.go => tdws/server_debug.go | 2 +- server_login.go => tdws/server_login.go | 2 +- .../server_message_received.go | 2 +- .../server_message_updated.go | 2 +- server_online.go => tdws/server_online.go | 2 +- server_panic.go => tdws/server_panic.go | 2 +- server_processing.go => tdws/server_processing.go | 2 +- server_push.go => tdws/server_push.go | 2 +- .../server_remind_deleted.go | 2 +- .../server_remind_fired.go | 2 +- .../server_remind_updated.go | 2 +- server_roster.go => tdws/server_roster.go | 2 +- .../server_section_deleted.go | 2 +- .../server_section_updated.go | 2 +- server_tag_deleted.go => tdws/server_tag_deleted.go | 2 +- server_tag_updated.go => tdws/server_tag_updated.go | 2 +- .../server_team_counters.go | 2 +- .../server_team_deleted.go | 2 +- .../server_team_updated.go | 2 +- server_time.go => tdws/server_time.go | 2 +- server_uisettings.go => tdws/server_uisettings.go | 2 +- .../server_upload_updated.go | 2 +- server_warning.go => tdws/server_warning.go | 2 +- x.go => tdws/x.go | 2 +- 59 files changed, 79 insertions(+), 71 deletions(-) rename client_call_buzz.go => tdws/client_call_buzz.go (96%) rename client_call_buzzcancel.go => tdws/client_call_buzzcancel.go (95%) rename client_call_leave.go => tdws/client_call_leave.go (95%) rename client_call_muteall.go => tdws/client_call_muteall.go (95%) rename client_call_offer.go => tdws/client_call_offer.go (96%) rename client_call_reject.go => tdws/client_call_reject.go (95%) rename client_call_sdp.go => tdws/client_call_sdp.go (96%) rename client_call_sound.go => tdws/client_call_sound.go (95%) rename client_call_trickle.go => tdws/client_call_trickle.go (97%) rename client_chat_composing.go => tdws/client_chat_composing.go (78%) rename client_chat_lastread.go => tdws/client_chat_lastread.go (97%) rename client_confirm.go => tdws/client_confirm.go (96%) rename client_message_deleted.go => tdws/client_message_deleted.go (97%) rename client_message_updated.go => tdws/client_message_updated.go (98%) rename client_ping.go => tdws/client_ping.go (93%) rename event.go => tdws/event.go (97%) rename server_call_answer.go => tdws/server_call_answer.go (98%) rename server_call_buzz.go => tdws/server_call_buzz.go (98%) rename server_call_buzzcancel.go => tdws/server_call_buzzcancel.go (97%) rename server_call_checkfingerprint.go => tdws/server_call_checkfingerprint.go (97%) rename server_call_leave.go => tdws/server_call_leave.go (96%) rename server_call_muteall.go => tdws/server_call_muteall.go (97%) rename server_call_reject.go => tdws/server_call_reject.go (97%) rename server_call_restart.go => tdws/server_call_restart.go (97%) rename server_call_sdp.go => tdws/server_call_sdp.go (97%) rename server_call_sound.go => tdws/server_call_sound.go (72%) rename server_call_state.go => tdws/server_call_state.go (94%) rename server_call_talking.go => tdws/server_call_talking.go (97%) rename server_chat_composing.go => tdws/server_chat_composing.go (77%) rename server_chat_deleted.go => tdws/server_chat_deleted.go (97%) rename server_chat_draft.go => tdws/server_chat_draft.go (97%) rename server_chat_lastread.go => tdws/server_chat_lastread.go (97%) rename server_chat_updated.go => tdws/server_chat_updated.go (61%) rename server_confirm.go => tdws/server_confirm.go (96%) rename server_contact_updated.go => tdws/server_contact_updated.go (96%) rename server_debug.go => tdws/server_debug.go (96%) rename server_login.go => tdws/server_login.go (96%) rename server_message_received.go => tdws/server_message_received.go (98%) rename server_message_updated.go => tdws/server_message_updated.go (98%) rename server_online.go => tdws/server_online.go (98%) rename server_panic.go => tdws/server_panic.go (96%) rename server_processing.go => tdws/server_processing.go (98%) rename server_push.go => tdws/server_push.go (95%) rename server_remind_deleted.go => tdws/server_remind_deleted.go (97%) rename server_remind_fired.go => tdws/server_remind_fired.go (96%) rename server_remind_updated.go => tdws/server_remind_updated.go (96%) rename server_roster.go => tdws/server_roster.go (94%) rename server_section_deleted.go => tdws/server_section_deleted.go (97%) rename server_section_updated.go => tdws/server_section_updated.go (97%) rename server_tag_deleted.go => tdws/server_tag_deleted.go (96%) rename server_tag_updated.go => tdws/server_tag_updated.go (96%) rename server_team_counters.go => tdws/server_team_counters.go (97%) rename server_team_deleted.go => tdws/server_team_deleted.go (97%) rename server_team_updated.go => tdws/server_team_updated.go (96%) rename server_time.go => tdws/server_time.go (96%) rename server_uisettings.go => tdws/server_uisettings.go (94%) rename server_upload_updated.go => tdws/server_upload_updated.go (96%) rename server_warning.go => tdws/server_warning.go (97%) rename x.go => tdws/x.go (97%) diff --git a/client_call_buzz.go b/tdws/client_call_buzz.go similarity index 96% rename from client_call_buzz.go rename to tdws/client_call_buzz.go index 24ac226..fa26729 100644 --- a/client_call_buzz.go +++ b/tdws/client_call_buzz.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // deprecated: use http api type ClientCallBuzz struct { diff --git a/client_call_buzzcancel.go b/tdws/client_call_buzzcancel.go similarity index 95% rename from client_call_buzzcancel.go rename to tdws/client_call_buzzcancel.go index 4c63ab4..b6604f7 100644 --- a/client_call_buzzcancel.go +++ b/tdws/client_call_buzzcancel.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Call buzzing cancelled type ClientCallBuzzCancel struct { diff --git a/client_call_leave.go b/tdws/client_call_leave.go similarity index 95% rename from client_call_leave.go rename to tdws/client_call_leave.go index 459de34..96716a0 100644 --- a/client_call_leave.go +++ b/tdws/client_call_leave.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Leave call type ClientCallLeave struct { diff --git a/client_call_muteall.go b/tdws/client_call_muteall.go similarity index 95% rename from client_call_muteall.go rename to tdws/client_call_muteall.go index 37b31ce..37a7ce4 100644 --- a/client_call_muteall.go +++ b/tdws/client_call_muteall.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Mute all other call participants type ClientCallMuteAll struct { diff --git a/client_call_offer.go b/tdws/client_call_offer.go similarity index 96% rename from client_call_offer.go rename to tdws/client_call_offer.go index 29fc377..8cbc15b 100644 --- a/client_call_offer.go +++ b/tdws/client_call_offer.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Start a call type ClientCallOffer struct { diff --git a/client_call_reject.go b/tdws/client_call_reject.go similarity index 95% rename from client_call_reject.go rename to tdws/client_call_reject.go index 12b48b7..97bdf03 100644 --- a/client_call_reject.go +++ b/tdws/client_call_reject.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Reject the call type ClientCallReject struct { diff --git a/client_call_sdp.go b/tdws/client_call_sdp.go similarity index 96% rename from client_call_sdp.go rename to tdws/client_call_sdp.go index b7f2b51..59b9ffd 100644 --- a/client_call_sdp.go +++ b/tdws/client_call_sdp.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // For exchange Session Description with server when client's Local Session Description is changed type ClientCallSdp struct { diff --git a/client_call_sound.go b/tdws/client_call_sound.go similarity index 95% rename from client_call_sound.go rename to tdws/client_call_sound.go index a3a9a6f..ab7d414 100644 --- a/client_call_sound.go +++ b/tdws/client_call_sound.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Change mute state in call type ClientCallSound struct { diff --git a/client_call_trickle.go b/tdws/client_call_trickle.go similarity index 97% rename from client_call_trickle.go rename to tdws/client_call_trickle.go index f3719c4..c4a10c0 100644 --- a/client_call_trickle.go +++ b/tdws/client_call_trickle.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Send trickle candidate for webrtc connection type ClientCallTrickle struct { diff --git a/client_chat_composing.go b/tdws/client_chat_composing.go similarity index 78% rename from client_chat_composing.go rename to tdws/client_chat_composing.go index cf1e0a3..c988a5f 100644 --- a/client_chat_composing.go +++ b/tdws/client_chat_composing.go @@ -1,6 +1,8 @@ -package tdproto +package tdws -func NewClientChatComposing(jid JID, composing bool, draft *string) (r ClientChatComposing) { +import "github.com/tada-team/tdproto" + +func NewClientChatComposing(jid tdproto.JID, composing bool, draft *string) (r ClientChatComposing) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Composing = composing @@ -19,7 +21,7 @@ func (p ClientChatComposing) GetName() string { return "client.chat.composing" } // Params of the client.chat.composing event type clientChatComposingParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // true = audiomessage, false = text typing IsAudio bool `json:"is_audio,omitempty"` diff --git a/client_chat_lastread.go b/tdws/client_chat_lastread.go similarity index 97% rename from client_chat_lastread.go rename to tdws/client_chat_lastread.go index 6807076..f51085f 100644 --- a/client_chat_lastread.go +++ b/tdws/client_chat_lastread.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewClientChatLastread(jid JID, messageId *string) (r ClientChatLastread) { r.Name = r.GetName() diff --git a/client_confirm.go b/tdws/client_confirm.go similarity index 96% rename from client_confirm.go rename to tdws/client_confirm.go index 169e0a7..33791dd 100644 --- a/client_confirm.go +++ b/tdws/client_confirm.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewClientConfirm(confirmId string) (r ClientConfirm) { r.Name = r.GetName() diff --git a/client_message_deleted.go b/tdws/client_message_deleted.go similarity index 97% rename from client_message_deleted.go rename to tdws/client_message_deleted.go index 3356a0b..cc4fd4d 100644 --- a/client_message_deleted.go +++ b/tdws/client_message_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewClientMessageDeleted(messageId string) (r ClientMessageDeleted) { r.Name = r.GetName() diff --git a/client_message_updated.go b/tdws/client_message_updated.go similarity index 98% rename from client_message_updated.go rename to tdws/client_message_updated.go index e995b18..2ee21a8 100644 --- a/client_message_updated.go +++ b/tdws/client_message_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewClientMessageUpdated(p ClientMessageUpdatedParams) (r ClientMessageUpdated) { r.Name = r.GetName() diff --git a/client_ping.go b/tdws/client_ping.go similarity index 93% rename from client_ping.go rename to tdws/client_ping.go index 9c01251..9230800 100644 --- a/client_ping.go +++ b/tdws/client_ping.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewClientPing() (r ClientPing) { r.Name = r.GetName() diff --git a/event.go b/tdws/event.go similarity index 97% rename from event.go rename to tdws/event.go index 32425d0..c90e8c4 100644 --- a/event.go +++ b/tdws/event.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Base of all events type BaseEvent struct { diff --git a/server_call_answer.go b/tdws/server_call_answer.go similarity index 98% rename from server_call_answer.go rename to tdws/server_call_answer.go index 19adf03..bcd0c90 100644 --- a/server_call_answer.go +++ b/tdws/server_call_answer.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallAnswer(jid JID, sdp string, onliners []CallOnliner, uid string) (r ServerCallAnswer) { r.Name = r.GetName() diff --git a/server_call_buzz.go b/tdws/server_call_buzz.go similarity index 98% rename from server_call_buzz.go rename to tdws/server_call_buzz.go index 5ff7010..a70c92c 100644 --- a/server_call_buzz.go +++ b/tdws/server_call_buzz.go @@ -1,4 +1,4 @@ -package tdproto +package tdws import ( "time" diff --git a/server_call_buzzcancel.go b/tdws/server_call_buzzcancel.go similarity index 97% rename from server_call_buzzcancel.go rename to tdws/server_call_buzzcancel.go index ea2e6ab..946f70c 100644 --- a/server_call_buzzcancel.go +++ b/tdws/server_call_buzzcancel.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallBuzzcancel(chat JID, teamUid string, uid string) (r ServerCallBuzzcancel) { r.Name = r.GetName() diff --git a/server_call_checkfingerprint.go b/tdws/server_call_checkfingerprint.go similarity index 97% rename from server_call_checkfingerprint.go rename to tdws/server_call_checkfingerprint.go index a8cabfd..ceab8b4 100644 --- a/server_call_checkfingerprint.go +++ b/tdws/server_call_checkfingerprint.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallCheckFingerprint(fingerprint string) (r ServerCallCheckFingerprint) { r.Name = r.GetName() diff --git a/server_call_leave.go b/tdws/server_call_leave.go similarity index 96% rename from server_call_leave.go rename to tdws/server_call_leave.go index 7d22368..09fe798 100644 --- a/server_call_leave.go +++ b/tdws/server_call_leave.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallLeave(jid JID, uid string) (r ServerCallLeave) { r.Name = r.GetName() diff --git a/server_call_muteall.go b/tdws/server_call_muteall.go similarity index 97% rename from server_call_muteall.go rename to tdws/server_call_muteall.go index 383793b..4ca8da6 100644 --- a/server_call_muteall.go +++ b/tdws/server_call_muteall.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallMuteall(jid JID, muted bool) (r ServerCallMuteall) { r.Name = r.GetName() diff --git a/server_call_reject.go b/tdws/server_call_reject.go similarity index 97% rename from server_call_reject.go rename to tdws/server_call_reject.go index f5143c0..708d21b 100644 --- a/server_call_reject.go +++ b/tdws/server_call_reject.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallReject(jid JID, reason string, uid string) (r ServerCallReject) { r.Name = r.GetName() diff --git a/server_call_restart.go b/tdws/server_call_restart.go similarity index 97% rename from server_call_restart.go rename to tdws/server_call_restart.go index 5192b3a..f45d842 100644 --- a/server_call_restart.go +++ b/tdws/server_call_restart.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallRestart(chat JID, teamUid string, uid string) (r ServerCallRestart) { r.Name = r.GetName() diff --git a/server_call_sdp.go b/tdws/server_call_sdp.go similarity index 97% rename from server_call_sdp.go rename to tdws/server_call_sdp.go index 4d29189..e1608b2 100644 --- a/server_call_sdp.go +++ b/tdws/server_call_sdp.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallSdp(jid JID, uid, sdpType, sdp string) (r ServerCallSdp) { r.Name = r.GetName() diff --git a/server_call_sound.go b/tdws/server_call_sound.go similarity index 72% rename from server_call_sound.go rename to tdws/server_call_sound.go index 230e718..092c83d 100644 --- a/server_call_sound.go +++ b/tdws/server_call_sound.go @@ -1,6 +1,8 @@ -package tdproto +package tdws -func NewServerCallSound(jid JID, muted bool) (r ServerCallSound) { +import "github.com/tada-team/tdproto" + +func NewServerCallSound(jid tdproto.JID, muted bool) (r ServerCallSound) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Muted = muted @@ -18,7 +20,7 @@ func (p ServerCallSound) GetName() string { return "server.call.sound" } // Params of the server.call.sound event type ServerCallSoundParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Mute state Muted bool `json:"muted"` diff --git a/server_call_state.go b/tdws/server_call_state.go similarity index 94% rename from server_call_state.go rename to tdws/server_call_state.go index 8879a3b..df68f02 100644 --- a/server_call_state.go +++ b/tdws/server_call_state.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallState(callEvent CallEvent) (r ServerCallState) { r.Name = r.GetName() diff --git a/server_call_talking.go b/tdws/server_call_talking.go similarity index 97% rename from server_call_talking.go rename to tdws/server_call_talking.go index 5e807b6..37e373a 100644 --- a/server_call_talking.go +++ b/tdws/server_call_talking.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerCallTalking(talking bool, chat, actor JID) (r ServerCallTalking) { r.Name = r.GetName() diff --git a/server_chat_composing.go b/tdws/server_chat_composing.go similarity index 77% rename from server_chat_composing.go rename to tdws/server_chat_composing.go index 545220c..bb15b44 100644 --- a/server_chat_composing.go +++ b/tdws/server_chat_composing.go @@ -1,6 +1,8 @@ -package tdproto +package tdws -func NewServerChatComposing(composing, isAudio bool, chat, actor JID) (r ServerChatComposing) { +import "github.com/tada-team/tdproto" + +func NewServerChatComposing(composing, isAudio bool, chat, actor tdproto.JID) (r ServerChatComposing) { r.Name = r.GetName() r.Params.Jid = chat r.Params.Actor = actor @@ -20,10 +22,10 @@ func (p ServerChatComposing) GetName() string { return "server.chat.composing" } // Params of the server.chat.composing event type serverChatComposingParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Actor id - Actor JID `json:"actor"` + Actor tdproto.JID `json:"actor"` // true = start typing / audio recording, false = stop Composing bool `json:"composing"` @@ -32,5 +34,5 @@ type serverChatComposingParams struct { IsAudio bool `json:"is_audio,omitempty"` // Composing event max lifetime - ValidUntil ISODateTimeString `json:"valid_until,omitempty"` + ValidUntil tdproto.ISODateTimeString `json:"valid_until,omitempty"` } diff --git a/server_chat_deleted.go b/tdws/server_chat_deleted.go similarity index 97% rename from server_chat_deleted.go rename to tdws/server_chat_deleted.go index 2cd540d..65451eb 100644 --- a/server_chat_deleted.go +++ b/tdws/server_chat_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerChatDeleted(chat DeletedChat, teamUnread *TeamUnread, badge uint) (r ServerChatDeleted) { chat.IsArchive = true diff --git a/server_chat_draft.go b/tdws/server_chat_draft.go similarity index 97% rename from server_chat_draft.go rename to tdws/server_chat_draft.go index e3d8078..2767dfe 100644 --- a/server_chat_draft.go +++ b/tdws/server_chat_draft.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerChatDraft(jid JID, draft string, gentime int64) (r ServerChatDraft) { r.Name = r.GetName() diff --git a/server_chat_lastread.go b/tdws/server_chat_lastread.go similarity index 97% rename from server_chat_lastread.go rename to tdws/server_chat_lastread.go index aefb2b2..e992ab7 100644 --- a/server_chat_lastread.go +++ b/tdws/server_chat_lastread.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerChatLastread(counters ChatCounters, teamUnread *TeamUnread, badge uint) (r ServerChatLastread) { r.Name = r.GetName() diff --git a/server_chat_updated.go b/tdws/server_chat_updated.go similarity index 61% rename from server_chat_updated.go rename to tdws/server_chat_updated.go index 303a863..550df57 100644 --- a/server_chat_updated.go +++ b/tdws/server_chat_updated.go @@ -1,8 +1,10 @@ -package tdproto +package tdws -func NewServerChatUpdated(chat Chat, teamUnread *TeamUnread, badge uint) (r ServerChatUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerChatUpdated(chat tdproto.Chat, teamUnread *tdproto.TeamUnread, badge uint) (r ServerChatUpdated) { r.Name = r.GetName() - r.Params.Chats = []Chat{chat} + r.Params.Chats = []tdproto.Chat{chat} r.Params.TeamUnread = teamUnread r.Params.Badge = badge return r @@ -19,10 +21,10 @@ func (p ServerChatUpdated) GetName() string { return "server.chat.updated" } // Params of the server.chat.updated event type serverChatUpdatedParams struct { // Chat counters - Chats []Chat `json:"chats"` + Chats []tdproto.Chat `json:"chats"` // Current team counters - TeamUnread *TeamUnread `json:"team_unread"` + TeamUnread *tdproto.TeamUnread `json:"team_unread"` // Total number of unreads Badge uint `json:"badge"` diff --git a/server_confirm.go b/tdws/server_confirm.go similarity index 96% rename from server_confirm.go rename to tdws/server_confirm.go index 2b2c888..d7be35b 100644 --- a/server_confirm.go +++ b/tdws/server_confirm.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerConfirm(v string) (r ServerConfirm) { r.Name = r.GetName() diff --git a/server_contact_updated.go b/tdws/server_contact_updated.go similarity index 96% rename from server_contact_updated.go rename to tdws/server_contact_updated.go index 456358b..db3280d 100644 --- a/server_contact_updated.go +++ b/tdws/server_contact_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerContactUpdated(contacts ...Contact) (r ServerContactUpdated) { r.Name = r.GetName() diff --git a/server_debug.go b/tdws/server_debug.go similarity index 96% rename from server_debug.go rename to tdws/server_debug.go index 2986053..ac0c07d 100644 --- a/server_debug.go +++ b/tdws/server_debug.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerDebug(text string) (r ServerDebug) { r.Name = r.GetName() diff --git a/server_login.go b/tdws/server_login.go similarity index 96% rename from server_login.go rename to tdws/server_login.go index d2e85c2..bf8e675 100644 --- a/server_login.go +++ b/tdws/server_login.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerLogin(deviceName string) (r ServerLogin) { r.Name = r.GetName() diff --git a/server_message_received.go b/tdws/server_message_received.go similarity index 98% rename from server_message_received.go rename to tdws/server_message_received.go index febd958..cd4b200 100644 --- a/server_message_received.go +++ b/tdws/server_message_received.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // Message receiving status type ReceivedMessage struct { diff --git a/server_message_updated.go b/tdws/server_message_updated.go similarity index 98% rename from server_message_updated.go rename to tdws/server_message_updated.go index 5a7ee42..4e5f8b4 100644 --- a/server_message_updated.go +++ b/tdws/server_message_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerMessageUpdated(messages []Message, delayed bool, counters *ChatCounters, teamUnread *TeamUnread, badge *uint) (r ServerMessageUpdated) { r.Name = r.GetName() diff --git a/server_online.go b/tdws/server_online.go similarity index 98% rename from server_online.go rename to tdws/server_online.go index f582649..a0e77f5 100644 --- a/server_online.go +++ b/tdws/server_online.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerOnline(contacts []OnlineContact, calls []OnlineCall) (r ServerOnline) { r.Name = r.GetName() diff --git a/server_panic.go b/tdws/server_panic.go similarity index 96% rename from server_panic.go rename to tdws/server_panic.go index 83dabe3..b48c9f6 100644 --- a/server_panic.go +++ b/tdws/server_panic.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerPanic(code string) (r ServerPanic) { r.Name = r.GetName() diff --git a/server_processing.go b/tdws/server_processing.go similarity index 98% rename from server_processing.go rename to tdws/server_processing.go index 955581a..4370c2f 100644 --- a/server_processing.go +++ b/tdws/server_processing.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerProcessing(num, total int, action, message string, hasError bool) (r ServerProcessing) { r.Name = r.GetName() diff --git a/server_push.go b/tdws/server_push.go similarity index 95% rename from server_push.go rename to tdws/server_push.go index f070413..3c912f2 100644 --- a/server_push.go +++ b/tdws/server_push.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerMessagePush(p MessagePush) (r ServerMessagePush) { r.Name = r.GetName() diff --git a/server_remind_deleted.go b/tdws/server_remind_deleted.go similarity index 97% rename from server_remind_deleted.go rename to tdws/server_remind_deleted.go index 73b07d9..87291ef 100644 --- a/server_remind_deleted.go +++ b/tdws/server_remind_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerRemindDeleted(uid string) (r ServerRemindDeleted) { r.Name = r.GetName() diff --git a/server_remind_fired.go b/tdws/server_remind_fired.go similarity index 96% rename from server_remind_fired.go rename to tdws/server_remind_fired.go index 65f14fc..c3463fa 100644 --- a/server_remind_fired.go +++ b/tdws/server_remind_fired.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerRemindFired(remind Remind) (r ServerRemindFired) { r.Name = r.GetName() diff --git a/server_remind_updated.go b/tdws/server_remind_updated.go similarity index 96% rename from server_remind_updated.go rename to tdws/server_remind_updated.go index caf2ff3..1700d1f 100644 --- a/server_remind_updated.go +++ b/tdws/server_remind_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerRemindUpdated(reminds ...Remind) (r ServerRemindUpdated) { r.Name = r.GetName() diff --git a/server_roster.go b/tdws/server_roster.go similarity index 94% rename from server_roster.go rename to tdws/server_roster.go index 0f4e5b1..80b99e0 100644 --- a/server_roster.go +++ b/tdws/server_roster.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // deprecated func NewServerRoster(roster Roster) (r ServerRoster) { diff --git a/server_section_deleted.go b/tdws/server_section_deleted.go similarity index 97% rename from server_section_deleted.go rename to tdws/server_section_deleted.go index 99613ea..b0cd095 100644 --- a/server_section_deleted.go +++ b/tdws/server_section_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerSectionDeleted(ct ChatType, section DeletedSection) (r ServerSectionDeleted) { section.Gentime = Gentime() // XXX diff --git a/server_section_updated.go b/tdws/server_section_updated.go similarity index 97% rename from server_section_updated.go rename to tdws/server_section_updated.go index d9839ab..3e711c8 100644 --- a/server_section_updated.go +++ b/tdws/server_section_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerSectionUpdated(ct ChatType, sections ...Section) (r ServerSectionUpdated) { r.Name = r.GetName() diff --git a/server_tag_deleted.go b/tdws/server_tag_deleted.go similarity index 96% rename from server_tag_deleted.go rename to tdws/server_tag_deleted.go index 06bbc79..095387c 100644 --- a/server_tag_deleted.go +++ b/tdws/server_tag_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerTagDeleted(tags ...DeletedTag) (r ServerTagDeleted) { r.Name = r.GetName() diff --git a/server_tag_updated.go b/tdws/server_tag_updated.go similarity index 96% rename from server_tag_updated.go rename to tdws/server_tag_updated.go index bc1e5a2..21dcf1f 100644 --- a/server_tag_updated.go +++ b/tdws/server_tag_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerTagUpdated(tags ...Tag) (r ServerTagUpdated) { r.Name = r.GetName() diff --git a/server_team_counters.go b/tdws/server_team_counters.go similarity index 97% rename from server_team_counters.go rename to tdws/server_team_counters.go index 39ff1d0..be3c5a3 100644 --- a/server_team_counters.go +++ b/tdws/server_team_counters.go @@ -1,4 +1,4 @@ -package tdproto +package tdws // TODO: remove empty func NewServerTeamCounters(counters []TeamCounter, badge uint) ServerTeamCounters { diff --git a/server_team_deleted.go b/tdws/server_team_deleted.go similarity index 97% rename from server_team_deleted.go rename to tdws/server_team_deleted.go index 6ccddb2..bf655d1 100644 --- a/server_team_deleted.go +++ b/tdws/server_team_deleted.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerTeamDeleted(uid string, gentime int64) (r ServerTeamDeleted) { r.Name = r.GetName() diff --git a/server_team_updated.go b/tdws/server_team_updated.go similarity index 96% rename from server_team_updated.go rename to tdws/server_team_updated.go index f57634a..4d0518e 100644 --- a/server_team_updated.go +++ b/tdws/server_team_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerTeamUpdated(team Team) (r ServerTeamUpdated) { r.Name = r.GetName() diff --git a/server_time.go b/tdws/server_time.go similarity index 96% rename from server_time.go rename to tdws/server_time.go index 6bc91c7..f8c0b23 100644 --- a/server_time.go +++ b/tdws/server_time.go @@ -1,4 +1,4 @@ -package tdproto +package tdws import "time" diff --git a/server_uisettings.go b/tdws/server_uisettings.go similarity index 94% rename from server_uisettings.go rename to tdws/server_uisettings.go index 1fef7c2..b643f2e 100644 --- a/server_uisettings.go +++ b/tdws/server_uisettings.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerUiSettings(v *UiSettings) (r ServerUiSettings) { r.Name = r.GetName() diff --git a/server_upload_updated.go b/tdws/server_upload_updated.go similarity index 96% rename from server_upload_updated.go rename to tdws/server_upload_updated.go index acf17d2..12e3a9d 100644 --- a/server_upload_updated.go +++ b/tdws/server_upload_updated.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerUploadUpdated(uploads ...Upload) (r ServerUploadUpdated) { r.Name = r.GetName() diff --git a/server_warning.go b/tdws/server_warning.go similarity index 97% rename from server_warning.go rename to tdws/server_warning.go index 08fd949..04d4cc7 100644 --- a/server_warning.go +++ b/tdws/server_warning.go @@ -1,4 +1,4 @@ -package tdproto +package tdws func NewServerWarning(message, orig string) (r ServerWarning) { r.Name = r.GetName() diff --git a/x.go b/tdws/x.go similarity index 97% rename from x.go rename to tdws/x.go index 2d68016..0e1845b 100644 --- a/x.go +++ b/tdws/x.go @@ -1,5 +1,5 @@ // eXtra fast shortcuts -package tdproto +package tdws import "bytes" From 3a66f50e9de6c02ab2e1f33a4c1e11034e7c7662 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:06:07 +0300 Subject: [PATCH 02/35] paginated -> tdapi --- paginated.go | 39 --------------------------------------- tdapi/contact.go | 6 ++++-- tdapi/paginated.go | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 41 deletions(-) delete mode 100644 paginated.go create mode 100644 tdapi/paginated.go diff --git a/paginated.go b/paginated.go deleted file mode 100644 index 4cf7525..0000000 --- a/paginated.go +++ /dev/null @@ -1,39 +0,0 @@ -package tdproto - -// Paginated chats -type PaginatedChats struct { - Contacts []Contact `json:"contacts,omitempty"` - Objects []Chat `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Paginated messages -type PaginatedMessages struct { - Objects []Message `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Paginated contacts -type PaginatedContacts struct { - Objects []Contact `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Chat messages -type ChatMessages struct { - Messages []Message `json:"messages"` -} - -// Paginated UploadShortMessage -type PaginatedUploadShortMessages struct { - Objects []UploadShortMessage `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} diff --git a/tdapi/contact.go b/tdapi/contact.go index d48fcfe..50549fd 100644 --- a/tdapi/contact.go +++ b/tdapi/contact.go @@ -1,6 +1,8 @@ package tdapi -import "github.com/tada-team/tdproto" +import ( + "github.com/tada-team/tdproto/tdmodels" +) // Contact invite/edit form type Contact struct { @@ -35,7 +37,7 @@ type Contact struct { DebugShowActivity bool `json:"debug_show_activity"` // Status in team - Status tdproto.TeamStatus `json:"status"` + Status tdmodels.TeamStatus `json:"status"` // ContactSection uids, if any Sections []string `json:"sections"` diff --git a/tdapi/paginated.go b/tdapi/paginated.go new file mode 100644 index 0000000..70db265 --- /dev/null +++ b/tdapi/paginated.go @@ -0,0 +1,41 @@ +package tdapi + +import "github.com/tada-team/tdproto/tdmodels" + +// Paginated chats +type PaginatedChats struct { + Contacts []tdmodels.Contact `json:"contacts,omitempty"` + Objects []tdmodels.Chat `json:"objects"` + Count int `json:"count"` + Limit int `json:"limit"` + Offset int `json:"offset"` +} + +// Paginated messages +type PaginatedMessages struct { + Objects []tdmodels.Message `json:"objects"` + Count int `json:"count"` + Limit int `json:"limit"` + Offset int `json:"offset"` +} + +// Paginated contacts +type PaginatedContacts struct { + Objects []tdmodels.Contact `json:"objects"` + Count int `json:"count"` + Limit int `json:"limit"` + Offset int `json:"offset"` +} + +// Chat messages +type ChatMessages struct { + Messages []tdmodels.Message `json:"messages"` +} + +// Paginated UploadShortMessage +type PaginatedUploadShortMessages struct { + Objects []tdmodels.UploadShortMessage `json:"objects"` + Count int `json:"count"` + Limit int `json:"limit"` + Offset int `json:"offset"` +} From ffde4015683c5f76956ca4d120623a8b7df2eb37 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:15:31 +0300 Subject: [PATCH 03/35] tdmodels -> tdproto --- tdapi/contact.go | 4 ++-- tdapi/paginated.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tdapi/contact.go b/tdapi/contact.go index 50549fd..b20df96 100644 --- a/tdapi/contact.go +++ b/tdapi/contact.go @@ -1,7 +1,7 @@ package tdapi import ( - "github.com/tada-team/tdproto/tdmodels" + "github.com/tada-team/tdproto" ) // Contact invite/edit form @@ -37,7 +37,7 @@ type Contact struct { DebugShowActivity bool `json:"debug_show_activity"` // Status in team - Status tdmodels.TeamStatus `json:"status"` + Status tdproto.TeamStatus `json:"status"` // ContactSection uids, if any Sections []string `json:"sections"` diff --git a/tdapi/paginated.go b/tdapi/paginated.go index 70db265..7ef65aa 100644 --- a/tdapi/paginated.go +++ b/tdapi/paginated.go @@ -1,11 +1,11 @@ package tdapi -import "github.com/tada-team/tdproto/tdmodels" +import "github.com/tada-team/tdproto" // Paginated chats type PaginatedChats struct { - Contacts []tdmodels.Contact `json:"contacts,omitempty"` - Objects []tdmodels.Chat `json:"objects"` + Contacts []tdproto.Contact `json:"contacts,omitempty"` + Objects []tdproto.Chat `json:"objects"` Count int `json:"count"` Limit int `json:"limit"` Offset int `json:"offset"` @@ -13,7 +13,7 @@ type PaginatedChats struct { // Paginated messages type PaginatedMessages struct { - Objects []tdmodels.Message `json:"objects"` + Objects []tdproto.Message `json:"objects"` Count int `json:"count"` Limit int `json:"limit"` Offset int `json:"offset"` @@ -21,7 +21,7 @@ type PaginatedMessages struct { // Paginated contacts type PaginatedContacts struct { - Objects []tdmodels.Contact `json:"objects"` + Objects []tdproto.Contact `json:"objects"` Count int `json:"count"` Limit int `json:"limit"` Offset int `json:"offset"` @@ -29,12 +29,12 @@ type PaginatedContacts struct { // Chat messages type ChatMessages struct { - Messages []tdmodels.Message `json:"messages"` + Messages []tdproto.Message `json:"messages"` } // Paginated UploadShortMessage type PaginatedUploadShortMessages struct { - Objects []tdmodels.UploadShortMessage `json:"objects"` + Objects []tdproto.UploadShortMessage `json:"objects"` Count int `json:"count"` Limit int `json:"limit"` Offset int `json:"offset"` From d76d4d96a87a009ea13fe7f7796677e2a722a544 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:33:10 +0300 Subject: [PATCH 04/35] imports fix --- chat.go | 4 ++-- tdapi/chats.go | 1 + tdapi/contact.go | 4 +--- tdapi/emoji.go | 4 +++- tdapi/main.go | 16 ---------------- tdapi/releases.go | 10 +++++++++- tdapi/sms_code.go | 14 +++++++++++--- tdapi/task.go | 2 +- tdapi/team.go | 1 + tdapi/timezones.go | 3 ++- tdws/client_call_buzz.go | 7 ++++--- tdws/client_call_buzzcancel.go | 4 +++- tdws/client_call_leave.go | 4 +++- tdws/client_call_muteall.go | 4 +++- tdws/client_call_offer.go | 4 +++- tdws/client_call_reject.go | 4 +++- tdws/client_call_sdp.go | 6 ++++-- tdws/client_call_sound.go | 4 +++- tdws/client_call_trickle.go | 4 +++- tdws/client_chat_lastread.go | 6 ++++-- tdws/client_message_updated.go | 6 ++++-- tdws/confirm_id.go | 29 +++++++++++++++++++++++++++++ tdws/server_call_answer.go | 10 ++++++---- tdws/server_call_buzz.go | 14 ++++++++------ tdws/server_call_buzzcancel.go | 6 ++++-- tdws/server_call_leave.go | 6 ++++-- tdws/server_call_muteall.go | 6 ++++-- tdws/server_call_reject.go | 6 ++++-- tdws/server_call_restart.go | 6 ++++-- tdws/server_call_sdp.go | 8 +++++--- tdws/server_call_state.go | 6 ++++-- tdws/server_call_talking.go | 8 +++++--- tdws/server_chat_deleted.go | 12 +++++++----- tdws/server_chat_draft.go | 6 ++++-- tdws/server_chat_lastread.go | 10 ++++++---- tdws/server_contact_updated.go | 6 ++++-- tdws/server_message_received.go | 4 +++- tdws/server_message_updated.go | 12 +++++++----- tdws/server_online.go | 8 +++++--- tdws/server_push.go | 6 ++++-- tdws/server_remind_deleted.go | 6 ++++-- tdws/server_remind_fired.go | 8 +++++--- tdws/server_remind_updated.go | 6 ++++-- tdws/server_roster.go | 16 ---------------- tdws/server_section_deleted.go | 12 +++++++----- tdws/server_section_updated.go | 10 ++++++---- tdws/server_tag_deleted.go | 6 ++++-- tdws/server_tag_updated.go | 6 ++++-- tdws/server_team_counters.go | 6 ++++-- tdws/server_team_deleted.go | 6 ++++-- tdws/server_team_updated.go | 8 +++++--- tdws/server_time.go | 10 +++++++--- tdws/server_uisettings.go | 6 ++++-- tdws/server_upload_updated.go | 6 ++++-- utils.go | 23 ----------------------- 55 files changed, 247 insertions(+), 169 deletions(-) delete mode 100644 tdapi/main.go create mode 100644 tdws/confirm_id.go delete mode 100644 tdws/server_roster.go diff --git a/chat.go b/chat.go index fb9cf02..86b7cfa 100644 --- a/chat.go +++ b/chat.go @@ -12,7 +12,7 @@ type ChatShort struct { DisplayName string `json:"display_name"` // Icon data - Icons *IconData `json:"icons"` + Icons IconData `json:"icons"` } // Minimal chat representation for deletion @@ -51,7 +51,7 @@ type Chat struct { DisplayName string `json:"display_name"` // Icons info - Icons *IconData `json:"icons"` + Icons IconData `json:"icons"` // Include unread messages to counters CountersEnabled bool `json:"counters_enabled,omitempty"` diff --git a/tdapi/chats.go b/tdapi/chats.go index afb6c92..b69bb7d 100644 --- a/tdapi/chats.go +++ b/tdapi/chats.go @@ -1,5 +1,6 @@ package tdapi +// Chat filter type ChatFilter struct { UserParams Paginator diff --git a/tdapi/contact.go b/tdapi/contact.go index b20df96..8523586 100644 --- a/tdapi/contact.go +++ b/tdapi/contact.go @@ -1,8 +1,6 @@ package tdapi -import ( - "github.com/tada-team/tdproto" -) +import "github.com/tada-team/tdproto" // Contact invite/edit form type Contact struct { diff --git a/tdapi/emoji.go b/tdapi/emoji.go index a8299ac..ea7b2db 100644 --- a/tdapi/emoji.go +++ b/tdapi/emoji.go @@ -2,6 +2,8 @@ package tdapi import "github.com/tada-team/tdproto" -type EmojiResp struct { +// Emoji response +type Emoji struct { + // Emoji list All []tdproto.Emoji `json:"all"` } diff --git a/tdapi/main.go b/tdapi/main.go deleted file mode 100644 index 0083e04..0000000 --- a/tdapi/main.go +++ /dev/null @@ -1,16 +0,0 @@ -package tdapi - -type PathSpec struct { - Input interface{} - Output interface{} -} - -var Paths = make(map[string]PathSpec) - -func registerPath(path string, spec PathSpec) { - - if _, ok := Paths[path]; ok { - panic("path already registered") - } - Paths[path] = spec -} diff --git a/tdapi/releases.go b/tdapi/releases.go index 6827b21..8b4f28f 100644 --- a/tdapi/releases.go +++ b/tdapi/releases.go @@ -2,9 +2,17 @@ package tdapi import "github.com/tada-team/tdproto" -type ReleasesResp struct { +// Releases response +type Releases struct { + // Android dist Android []tdproto.Dist `json:"android,omitempty"` + + // Linux dist Linux []tdproto.Dist `json:"linux,omitempty"` + + // macOS dist Mac []tdproto.Dist `json:"mac,omitempty"` + + // Windows dist Win []tdproto.Dist `json:"win,omitempty"` } diff --git a/tdapi/sms_code.go b/tdapi/sms_code.go index b1193d1..e566a67 100644 --- a/tdapi/sms_code.go +++ b/tdapi/sms_code.go @@ -2,9 +2,17 @@ package tdapi import "github.com/tada-team/tdproto" +// Sms code response type SmsCode struct { - Phone string `json:"phone"` + // Phone number + Phone string `json:"phone"` + + // Code expiration date CodeValidUntil tdproto.ISODateTimeString `json:"code_valid_until"` - NextCodeAt tdproto.ISODateTimeString `json:"next_code_at"` - CodeLength int `json:"code_length"` + + // Next code date + NextCodeAt tdproto.ISODateTimeString `json:"next_code_at"` + + // Code length, symbols + CodeLength int `json:"code_length"` } diff --git a/tdapi/task.go b/tdapi/task.go index 272d117..96667d6 100644 --- a/tdapi/task.go +++ b/tdapi/task.go @@ -2,7 +2,7 @@ package tdapi import "github.com/tada-team/tdproto" -// Task +// Task response type Task struct { // Custom task color CustomColorIndex *uint16 `json:"custom_color_index,omitempty"` diff --git a/tdapi/team.go b/tdapi/team.go index 9317db8..868fad9 100644 --- a/tdapi/team.go +++ b/tdapi/team.go @@ -2,6 +2,7 @@ package tdapi import "github.com/tada-team/tdproto" +// Team response type Team struct { // Team name Name string `json:"name"` diff --git a/tdapi/timezones.go b/tdapi/timezones.go index fc0f319..adf6fd2 100644 --- a/tdapi/timezones.go +++ b/tdapi/timezones.go @@ -1,5 +1,6 @@ package tdapi -type TimezonesResp struct { +// Timezones response +type Timezones struct { Timezones []string `json:"timezones"` } diff --git a/tdws/client_call_buzz.go b/tdws/client_call_buzz.go index fa26729..4a30917 100644 --- a/tdws/client_call_buzz.go +++ b/tdws/client_call_buzz.go @@ -1,6 +1,7 @@ package tdws -// deprecated: use http api +import "github.com/tada-team/tdproto" + type ClientCallBuzz struct { BaseEvent Params clientCallBuzzParams `json:"params"` @@ -11,8 +12,8 @@ func (p ClientCallBuzz) GetName() string { return "client.call.buzz" } // Call buzzing type clientCallBuzzParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // List of call participants. Empty value means all participants in call - Members []JID `json:"members,omitempty"` + Members []tdproto.JID `json:"members,omitempty"` } diff --git a/tdws/client_call_buzzcancel.go b/tdws/client_call_buzzcancel.go index b6604f7..5c979c3 100644 --- a/tdws/client_call_buzzcancel.go +++ b/tdws/client_call_buzzcancel.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Call buzzing cancelled type ClientCallBuzzCancel struct { BaseEvent @@ -11,5 +13,5 @@ func (p ClientCallBuzzCancel) GetName() string { return "client.call.buzzcancel" // Params of the client.call.buzzcancel event type clientCallBuzzCancelParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` } diff --git a/tdws/client_call_leave.go b/tdws/client_call_leave.go index 96716a0..5765341 100644 --- a/tdws/client_call_leave.go +++ b/tdws/client_call_leave.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Leave call type ClientCallLeave struct { BaseEvent @@ -11,7 +13,7 @@ func (p ClientCallLeave) GetName() string { return "client.call.leave" } // Params of the client.call.leave event type clientCallLeaveParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Reason, if any Reason string `json:"reason,omitempty"` diff --git a/tdws/client_call_muteall.go b/tdws/client_call_muteall.go index 37a7ce4..1602f81 100644 --- a/tdws/client_call_muteall.go +++ b/tdws/client_call_muteall.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Mute all other call participants type ClientCallMuteAll struct { BaseEvent @@ -11,5 +13,5 @@ func (p ClientCallMuteAll) GetName() string { return "client.call.muteall" } // Params of the client.call.muteall event type clientCallMuteAllParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` } diff --git a/tdws/client_call_offer.go b/tdws/client_call_offer.go index 8cbc15b..1bd2866 100644 --- a/tdws/client_call_offer.go +++ b/tdws/client_call_offer.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Start a call type ClientCallOffer struct { BaseEvent @@ -11,7 +13,7 @@ func (p ClientCallOffer) GetName() string { return "client.call.offer" } // Params of the client.call.offer event type clientCallOfferParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Mute state Muted bool `json:"muted"` diff --git a/tdws/client_call_reject.go b/tdws/client_call_reject.go index 97bdf03..bb2d5b8 100644 --- a/tdws/client_call_reject.go +++ b/tdws/client_call_reject.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Reject the call type ClientCallReject struct { BaseEvent @@ -11,7 +13,7 @@ func (p ClientCallReject) GetName() string { return "client.call.reject" } // Params of the client.call.reject event type clientCallRejectParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Reason, if any Reason string `json:"reason,omitempty"` diff --git a/tdws/client_call_sdp.go b/tdws/client_call_sdp.go index 59b9ffd..ab09f6d 100644 --- a/tdws/client_call_sdp.go +++ b/tdws/client_call_sdp.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // For exchange Session Description with server when client's Local Session Description is changed type ClientCallSdp struct { BaseEvent @@ -11,11 +13,11 @@ func (p ClientCallSdp) GetName() string { return "client.call.sdp" } // Params of the client.call.sdp event type clientCallSdpParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call id Uid string `json:"uid"` // SDP data - JSEP JSEP `json:"jsep"` + JSEP tdproto.JSEP `json:"jsep"` } diff --git a/tdws/client_call_sound.go b/tdws/client_call_sound.go index ab7d414..9c1964d 100644 --- a/tdws/client_call_sound.go +++ b/tdws/client_call_sound.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Change mute state in call type ClientCallSound struct { BaseEvent @@ -11,7 +13,7 @@ func (p ClientCallSound) GetName() string { return "client.call.sound" } // Params of the client.call.sound event type clientCallSoundParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Mute state Muted bool `json:"muted"` diff --git a/tdws/client_call_trickle.go b/tdws/client_call_trickle.go index c4a10c0..19eb016 100644 --- a/tdws/client_call_trickle.go +++ b/tdws/client_call_trickle.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + // Send trickle candidate for webrtc connection type ClientCallTrickle struct { BaseEvent @@ -11,7 +13,7 @@ func (p ClientCallTrickle) GetName() string { return "client.call.trickle" } // Params of client.call.trickle event type clientCallTrickleParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Trickle candidate Candidate string `json:"candidate"` diff --git a/tdws/client_chat_lastread.go b/tdws/client_chat_lastread.go index f51085f..736829a 100644 --- a/tdws/client_chat_lastread.go +++ b/tdws/client_chat_lastread.go @@ -1,6 +1,8 @@ package tdws -func NewClientChatLastread(jid JID, messageId *string) (r ClientChatLastread) { +import "github.com/tada-team/tdproto" + +func NewClientChatLastread(jid tdproto.JID, messageId *string) (r ClientChatLastread) { r.Name = r.GetName() r.ConfirmId = ConfirmId() r.Params.Jid = jid @@ -19,7 +21,7 @@ func (p ClientChatLastread) GetName() string { return "client.chat.lastread" } // Params of the client.chat.lastread event type clientChatLastreadParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Last read message id. Omitted = last message in chat LastReadMessageId *string `json:"last_read_message_id,omitempty"` diff --git a/tdws/client_message_updated.go b/tdws/client_message_updated.go index 2ee21a8..b548619 100644 --- a/tdws/client_message_updated.go +++ b/tdws/client_message_updated.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + func NewClientMessageUpdated(p ClientMessageUpdatedParams) (r ClientMessageUpdated) { r.Name = r.GetName() r.ConfirmId = ConfirmId() @@ -18,10 +20,10 @@ func (p ClientMessageUpdated) GetName() string { return "client.message.updated" // Params of the client.message.updated event type ClientMessageUpdatedParams struct { // Chat, task or contact jid. Required. - To JID `json:"to"` + To tdproto.JID `json:"to"` // Message content. Required. - Content MessageContent `json:"content"` + Content tdproto.MessageContent `json:"content"` // Uid created by client. Recommended. MessageId string `json:"message_id,omitempty"` diff --git a/tdws/confirm_id.go b/tdws/confirm_id.go new file mode 100644 index 0000000..f400541 --- /dev/null +++ b/tdws/confirm_id.go @@ -0,0 +1,29 @@ +package tdws + +import ( + "crypto/rand" + "log" +) + +func ConfirmId() string { + return randomSymbols(12, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") +} + +func randomSymbols(n int, letters string) string { + bytes, err := randomBytes(n) + if err != nil { + log.Panicln("random bytes fail:", err) + } + for i, b := range bytes { + bytes[i] = letters[b%byte(len(letters))] + } + return string(bytes) +} + +func randomBytes(n int) ([]byte, error) { + b := make([]byte, n) + if _, err := rand.Read(b); err != nil { + return nil, err + } + return b, nil +} diff --git a/tdws/server_call_answer.go b/tdws/server_call_answer.go index bcd0c90..9236a05 100644 --- a/tdws/server_call_answer.go +++ b/tdws/server_call_answer.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallAnswer(jid JID, sdp string, onliners []CallOnliner, uid string) (r ServerCallAnswer) { +import "github.com/tada-team/tdproto" + +func NewServerCallAnswer(jid tdproto.JID, sdp string, onliners []tdproto.CallOnliner, uid string) (r ServerCallAnswer) { r.Name = r.GetName() r.Params.Jid = jid r.Params.JSEP.Type = "answer" @@ -21,16 +23,16 @@ func (p ServerCallAnswer) GetName() string { return "server.call.answer" } // Params of the server.call.answer event type serverCallAnswerParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // List of ICE candidates (when trickle = false) Candidates []serverCallAnswerCandidate `json:"candidates,omitempty"` // Current call participants - Onliners []CallOnliner `json:"onliners,omitempty"` + Onliners []tdproto.CallOnliner `json:"onliners,omitempty"` // SDP data - JSEP JSEP `json:"jsep"` + JSEP tdproto.JSEP `json:"jsep"` // Call id Uid string `json:"uid"` diff --git a/tdws/server_call_buzz.go b/tdws/server_call_buzz.go index a70c92c..6fb1e7d 100644 --- a/tdws/server_call_buzz.go +++ b/tdws/server_call_buzz.go @@ -2,9 +2,11 @@ package tdws import ( "time" + + "github.com/tada-team/tdproto" ) -func NewServerCallBuzz(teamShort TeamShort, chatShort ChatShort, actorShort ContactShort, uid string, timeout time.Duration) (r ServerCallBuzz) { +func NewServerCallBuzz(teamShort tdproto.TeamShort, chatShort tdproto.ChatShort, actorShort tdproto.ContactShort, uid string, timeout time.Duration) (r ServerCallBuzz) { r.Name = r.GetName() r.Params.TeamShort = teamShort r.Params.ChatShort = chatShort @@ -29,22 +31,22 @@ func (p ServerCallBuzz) GetName() string { return "server.call.buzz" } // Params of the server.call.buzz event type serverCallBuzzParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Chat icons - Icons *IconData `json:"icons"` + Icons tdproto.IconData `json:"icons"` // Chat title DisplayName string `json:"display_name"` // Short team information - TeamShort TeamShort `json:"teaminfo"` + TeamShort tdproto.TeamShort `json:"teaminfo"` // Short chat information - ChatShort ChatShort `json:"chat"` + ChatShort tdproto.ChatShort `json:"chat"` // Short call creator information - ActorShort ContactShort `json:"actor"` + ActorShort tdproto.ContactShort `json:"actor"` // Call id Uid string `json:"uid"` diff --git a/tdws/server_call_buzzcancel.go b/tdws/server_call_buzzcancel.go index 946f70c..e27f9f5 100644 --- a/tdws/server_call_buzzcancel.go +++ b/tdws/server_call_buzzcancel.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallBuzzcancel(chat JID, teamUid string, uid string) (r ServerCallBuzzcancel) { +import "github.com/tada-team/tdproto" + +func NewServerCallBuzzcancel(chat tdproto.JID, teamUid string, uid string) (r ServerCallBuzzcancel) { r.Name = r.GetName() r.Params.Jid = chat r.Params.Team = teamUid @@ -19,7 +21,7 @@ func (p ServerCallBuzzcancel) GetName() string { return "server.call.buzzcancel" // Params of the server.call.buzzcancel event type serverCallBuzzcancelParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Team id Team string `json:"team"` diff --git a/tdws/server_call_leave.go b/tdws/server_call_leave.go index 09fe798..491c967 100644 --- a/tdws/server_call_leave.go +++ b/tdws/server_call_leave.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallLeave(jid JID, uid string) (r ServerCallLeave) { +import "github.com/tada-team/tdproto" + +func NewServerCallLeave(jid tdproto.JID, uid string) (r ServerCallLeave) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Uid = uid @@ -18,7 +20,7 @@ func (p ServerCallLeave) GetName() string { return "server.call.leave" } // Params of the server.call.leave event type serverCallLeaveParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call uid Uid string `json:"uid"` diff --git a/tdws/server_call_muteall.go b/tdws/server_call_muteall.go index 4ca8da6..31e5a3c 100644 --- a/tdws/server_call_muteall.go +++ b/tdws/server_call_muteall.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallMuteall(jid JID, muted bool) (r ServerCallMuteall) { +import "github.com/tada-team/tdproto" + +func NewServerCallMuteall(jid tdproto.JID, muted bool) (r ServerCallMuteall) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Muted = muted @@ -18,7 +20,7 @@ func (p ServerCallMuteall) GetName() string { return "server.call.muteall" } // Params of the server.call.muteall event type serverCallMuteallParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Mute state Muted bool `json:"muted"` diff --git a/tdws/server_call_reject.go b/tdws/server_call_reject.go index 708d21b..201e742 100644 --- a/tdws/server_call_reject.go +++ b/tdws/server_call_reject.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallReject(jid JID, reason string, uid string) (r ServerCallReject) { +import "github.com/tada-team/tdproto" + +func NewServerCallReject(jid tdproto.JID, reason string, uid string) (r ServerCallReject) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Reason = reason @@ -19,7 +21,7 @@ func (p ServerCallReject) GetName() string { return "server.call.reject" } // Params of the server.call.reject event type serverCallRejectParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call id Uid string `json:"uid"` diff --git a/tdws/server_call_restart.go b/tdws/server_call_restart.go index f45d842..5636af5 100644 --- a/tdws/server_call_restart.go +++ b/tdws/server_call_restart.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallRestart(chat JID, teamUid string, uid string) (r ServerCallRestart) { +import "github.com/tada-team/tdproto" + +func NewServerCallRestart(chat tdproto.JID, teamUid string, uid string) (r ServerCallRestart) { r.Name = r.GetName() r.Params.Jid = chat r.Params.Team = teamUid @@ -19,7 +21,7 @@ func (p ServerCallRestart) GetName() string { return "server.call.restart" } // Params of the server.call.restart event type serverCallRestartParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call id Uid string `json:"uid"` diff --git a/tdws/server_call_sdp.go b/tdws/server_call_sdp.go index e1608b2..8398e21 100644 --- a/tdws/server_call_sdp.go +++ b/tdws/server_call_sdp.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallSdp(jid JID, uid, sdpType, sdp string) (r ServerCallSdp) { +import "github.com/tada-team/tdproto" + +func NewServerCallSdp(jid tdproto.JID, uid, sdpType, sdp string) (r ServerCallSdp) { r.Name = r.GetName() r.Params.Jid = jid r.Params.JSEP.Type = sdpType @@ -20,11 +22,11 @@ func (p ServerCallSdp) GetName() string { return "server.call.sdp" } // Params of the server.call.sdp event type serverCallSdpParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call id Uid string `json:"uid"` // SDP data - JSEP JSEP `json:"jsep"` + JSEP tdproto.JSEP `json:"jsep"` } diff --git a/tdws/server_call_state.go b/tdws/server_call_state.go index df68f02..19ba735 100644 --- a/tdws/server_call_state.go +++ b/tdws/server_call_state.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallState(callEvent CallEvent) (r ServerCallState) { +import "github.com/tada-team/tdproto" + +func NewServerCallState(callEvent tdproto.CallEvent) (r ServerCallState) { r.Name = r.GetName() r.Params = callEvent return @@ -9,7 +11,7 @@ func NewServerCallState(callEvent CallEvent) (r ServerCallState) { // Call information type ServerCallState struct { BaseEvent - Params CallEvent `json:"params"` + Params tdproto.CallEvent `json:"params"` } func (p ServerCallState) GetName() string { return "server.call.state" } diff --git a/tdws/server_call_talking.go b/tdws/server_call_talking.go index 37e373a..76b0ed0 100644 --- a/tdws/server_call_talking.go +++ b/tdws/server_call_talking.go @@ -1,6 +1,8 @@ package tdws -func NewServerCallTalking(talking bool, chat, actor JID) (r ServerCallTalking) { +import "github.com/tada-team/tdproto" + +func NewServerCallTalking(talking bool, chat, actor tdproto.JID) (r ServerCallTalking) { r.Name = r.GetName() r.Params.Jid = chat r.Params.Actor = actor @@ -19,10 +21,10 @@ func (p ServerCallTalking) GetName() string { return "server.call.talking" } // Params of the server.call.talking event type serverCallTalkingParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Actor id - Actor JID `json:"actor"` + Actor tdproto.JID `json:"actor"` // Is talking Talking bool `json:"talking"` diff --git a/tdws/server_chat_deleted.go b/tdws/server_chat_deleted.go index 65451eb..8f5e2ce 100644 --- a/tdws/server_chat_deleted.go +++ b/tdws/server_chat_deleted.go @@ -1,11 +1,13 @@ package tdws -func NewServerChatDeleted(chat DeletedChat, teamUnread *TeamUnread, badge uint) (r ServerChatDeleted) { +import "github.com/tada-team/tdproto" + +func NewServerChatDeleted(chat tdproto.DeletedChat, teamUnread *tdproto.TeamUnread, badge uint) (r ServerChatDeleted) { chat.IsArchive = true - chat.Gentime = Gentime() + chat.Gentime = tdproto.Gentime() r.Name = r.GetName() - r.Params.Chats = []DeletedChat{chat} + r.Params.Chats = []tdproto.DeletedChat{chat} r.Params.TeamUnread = teamUnread r.Params.Badge = badge return r @@ -22,10 +24,10 @@ func (p ServerChatDeleted) GetName() string { return "server.chat.deleted" } // Params of the server.chat.deleted event type serverChatDeletedParams struct { // List of deleted chats - Chats []DeletedChat `json:"chats"` + Chats []tdproto.DeletedChat `json:"chats"` // Current team counters - TeamUnread *TeamUnread `json:"team_unread"` + TeamUnread *tdproto.TeamUnread `json:"team_unread"` // Total number of unreads Badge uint `json:"badge"` diff --git a/tdws/server_chat_draft.go b/tdws/server_chat_draft.go index 2767dfe..d784ad4 100644 --- a/tdws/server_chat_draft.go +++ b/tdws/server_chat_draft.go @@ -1,6 +1,8 @@ package tdws -func NewServerChatDraft(jid JID, draft string, gentime int64) (r ServerChatDraft) { +import "github.com/tada-team/tdproto" + +func NewServerChatDraft(jid tdproto.JID, draft string, gentime int64) (r ServerChatDraft) { r.Name = r.GetName() r.Params.Jid = jid r.Params.Draft = draft @@ -19,7 +21,7 @@ func (p ServerChatDraft) GetName() string { return "server.chat.draft" } // Params of the server.chat.draft event type serverChatDraftParams struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Draft text Draft string `json:"draft"` diff --git a/tdws/server_chat_lastread.go b/tdws/server_chat_lastread.go index e992ab7..493fe6f 100644 --- a/tdws/server_chat_lastread.go +++ b/tdws/server_chat_lastread.go @@ -1,8 +1,10 @@ package tdws -func NewServerChatLastread(counters ChatCounters, teamUnread *TeamUnread, badge uint) (r ServerChatLastread) { +import "github.com/tada-team/tdproto" + +func NewServerChatLastread(counters tdproto.ChatCounters, teamUnread *tdproto.TeamUnread, badge uint) (r ServerChatLastread) { r.Name = r.GetName() - r.Params.Chats = []ChatCounters{counters} + r.Params.Chats = []tdproto.ChatCounters{counters} r.Params.TeamUnread = teamUnread r.Params.Badge = badge return r @@ -19,10 +21,10 @@ func (p ServerChatLastread) GetName() string { return "server.chat.lastread" } // Params of the server.chat.lastread event type serverChatLastreadParams struct { // Chat counters - Chats []ChatCounters `json:"chats"` + Chats []tdproto.ChatCounters `json:"chats"` // Current team counters - TeamUnread *TeamUnread `json:"team_unread"` + TeamUnread *tdproto.TeamUnread `json:"team_unread"` // Total number of unreads Badge uint `json:"badge"` diff --git a/tdws/server_contact_updated.go b/tdws/server_contact_updated.go index db3280d..e2ea6cf 100644 --- a/tdws/server_contact_updated.go +++ b/tdws/server_contact_updated.go @@ -1,6 +1,8 @@ package tdws -func NewServerContactUpdated(contacts ...Contact) (r ServerContactUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerContactUpdated(contacts ...tdproto.Contact) (r ServerContactUpdated) { r.Name = r.GetName() r.Params.Contacts = contacts return r @@ -17,5 +19,5 @@ func (p ServerContactUpdated) GetName() string { return "server.contact.updated" // Params of the server.contact.updated event type serverContactUpdatedParams struct { // Contact info - Contacts []Contact `json:"contacts"` + Contacts []tdproto.Contact `json:"contacts"` } diff --git a/tdws/server_message_received.go b/tdws/server_message_received.go index cd4b200..5bf10d3 100644 --- a/tdws/server_message_received.go +++ b/tdws/server_message_received.go @@ -1,9 +1,11 @@ package tdws +import "github.com/tada-team/tdproto" + // Message receiving status type ReceivedMessage struct { // Chat or contact id - Chat JID `json:"chat"` + Chat tdproto.JID `json:"chat"` // Message id MessageId string `json:"message_id"` diff --git a/tdws/server_message_updated.go b/tdws/server_message_updated.go index 4e5f8b4..c1342ec 100644 --- a/tdws/server_message_updated.go +++ b/tdws/server_message_updated.go @@ -1,12 +1,14 @@ package tdws -func NewServerMessageUpdated(messages []Message, delayed bool, counters *ChatCounters, teamUnread *TeamUnread, badge *uint) (r ServerMessageUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerMessageUpdated(messages []tdproto.Message, delayed bool, counters *tdproto.ChatCounters, teamUnread *tdproto.TeamUnread, badge *uint) (r ServerMessageUpdated) { r.Name = r.GetName() r.ConfirmId = ConfirmId() r.Params.Messages = messages r.Params.Delayed = delayed - r.Params.ChatCounters = make([]ChatCounters, 0) + r.Params.ChatCounters = make([]tdproto.ChatCounters, 0) if counters != nil { r.Params.ChatCounters = append(r.Params.ChatCounters, *counters) } @@ -33,16 +35,16 @@ func (p ServerMessageUpdated) GetName() string { return "server.message.updated" // Params of the server.message.updated event type serverMessageUpdatedParams struct { // Messages data - Messages []Message `json:"messages"` + Messages []tdproto.Message `json:"messages"` // true = silently message update, false = new message Delayed bool `json:"delayed"` // Chat counters - ChatCounters []ChatCounters `json:"chat_counters"` + ChatCounters []tdproto.ChatCounters `json:"chat_counters"` // Current team counters - TeamUnread *TeamUnread `json:"team_unread"` + TeamUnread *tdproto.TeamUnread `json:"team_unread"` // Total number of unreads, if changed Badge *uint `json:"badge"` diff --git a/tdws/server_online.go b/tdws/server_online.go index a0e77f5..4723fda 100644 --- a/tdws/server_online.go +++ b/tdws/server_online.go @@ -1,5 +1,7 @@ package tdws +import "github.com/tada-team/tdproto" + func NewServerOnline(contacts []OnlineContact, calls []OnlineCall) (r ServerOnline) { r.Name = r.GetName() r.Params.Contacts = contacts @@ -27,7 +29,7 @@ type serverOnlineParams struct { // Contact online status type OnlineContact struct { // Contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Is away from keyboard Afk bool `json:"afk,omitempty"` @@ -39,13 +41,13 @@ type OnlineContact struct { // Active call status type OnlineCall struct { // Chat or contact id - Jid JID `json:"jid"` + Jid tdproto.JID `json:"jid"` // Call id Uid string `json:"uid"` // Call start - Start ISODateTimeString `json:"start,omitempty"` + Start tdproto.ISODateTimeString `json:"start,omitempty"` // Number participants in call OnlineCount int `json:"online_count,omitempty"` diff --git a/tdws/server_push.go b/tdws/server_push.go index 3c912f2..5aab8fd 100644 --- a/tdws/server_push.go +++ b/tdws/server_push.go @@ -1,6 +1,8 @@ package tdws -func NewServerMessagePush(p MessagePush) (r ServerMessagePush) { +import "github.com/tada-team/tdproto" + +func NewServerMessagePush(p tdproto.MessagePush) (r ServerMessagePush) { r.Name = r.GetName() r.Params = p return r @@ -9,7 +11,7 @@ func NewServerMessagePush(p MessagePush) (r ServerMessagePush) { // Push replacement for desktop application type ServerMessagePush struct { BaseEvent - Params MessagePush `json:"params"` + Params tdproto.MessagePush `json:"params"` } func (p ServerMessagePush) GetName() string { return "server.message.push" } diff --git a/tdws/server_remind_deleted.go b/tdws/server_remind_deleted.go index 87291ef..9c10637 100644 --- a/tdws/server_remind_deleted.go +++ b/tdws/server_remind_deleted.go @@ -1,8 +1,10 @@ package tdws +import "github.com/tada-team/tdproto" + func NewServerRemindDeleted(uid string) (r ServerRemindDeleted) { r.Name = r.GetName() - r.Params.Remind = []DeletedRemind{ + r.Params.Remind = []tdproto.DeletedRemind{ {Uid: uid}, } return r @@ -19,5 +21,5 @@ func (p ServerRemindDeleted) GetName() string { return "server.remind.deleted" } // Params of the server.remind.deleted event type serverRemindDeletedParams struct { // Remind information - Remind []DeletedRemind `json:"reminds"` + Remind []tdproto.DeletedRemind `json:"reminds"` } diff --git a/tdws/server_remind_fired.go b/tdws/server_remind_fired.go index c3463fa..c4fd7c1 100644 --- a/tdws/server_remind_fired.go +++ b/tdws/server_remind_fired.go @@ -1,8 +1,10 @@ package tdws -func NewServerRemindFired(remind Remind) (r ServerRemindFired) { +import "github.com/tada-team/tdproto" + +func NewServerRemindFired(remind tdproto.Remind) (r ServerRemindFired) { r.Name = r.GetName() - r.Params.Reminds = []Remind{remind} + r.Params.Reminds = []tdproto.Remind{remind} return r } @@ -17,5 +19,5 @@ func (p ServerRemindFired) GetName() string { return "server.remind.fired" } // Params of the server.remind.fired event type serverRemindFiredParams struct { // Remind information - Reminds []Remind `json:"reminds"` + Reminds []tdproto.Remind `json:"reminds"` } diff --git a/tdws/server_remind_updated.go b/tdws/server_remind_updated.go index 1700d1f..ea22074 100644 --- a/tdws/server_remind_updated.go +++ b/tdws/server_remind_updated.go @@ -1,6 +1,8 @@ package tdws -func NewServerRemindUpdated(reminds ...Remind) (r ServerRemindUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerRemindUpdated(reminds ...tdproto.Remind) (r ServerRemindUpdated) { r.Name = r.GetName() r.Params.Reminds = reminds return r @@ -17,5 +19,5 @@ func (p ServerRemindUpdated) GetName() string { return "server.remind.updated" } // Params of the server.remind.updated event type serverRemindUpdatedParams struct { // Remind information - Reminds []Remind `json:"reminds"` + Reminds []tdproto.Remind `json:"reminds"` } diff --git a/tdws/server_roster.go b/tdws/server_roster.go deleted file mode 100644 index 80b99e0..0000000 --- a/tdws/server_roster.go +++ /dev/null @@ -1,16 +0,0 @@ -package tdws - -// deprecated -func NewServerRoster(roster Roster) (r ServerRoster) { - r.Name = r.GetName() - r.Params = roster - return r -} - -// deprecated -type ServerRoster struct { - BaseEvent - Params Roster `json:"params"` -} - -func (p ServerRoster) GetName() string { return "server.roster" } diff --git a/tdws/server_section_deleted.go b/tdws/server_section_deleted.go index b0cd095..5868c94 100644 --- a/tdws/server_section_deleted.go +++ b/tdws/server_section_deleted.go @@ -1,12 +1,14 @@ package tdws -func NewServerSectionDeleted(ct ChatType, section DeletedSection) (r ServerSectionDeleted) { - section.Gentime = Gentime() // XXX +import "github.com/tada-team/tdproto" + +func NewServerSectionDeleted(ct tdproto.ChatType, section tdproto.DeletedSection) (r ServerSectionDeleted) { + section.Gentime = tdproto.Gentime() // XXX r.Name = r.GetName() r.Params.ChatType = ct r.Params.Gentime = section.Gentime - r.Params.Sections = []DeletedSection{section} + r.Params.Sections = []tdproto.DeletedSection{section} return r } @@ -21,10 +23,10 @@ func (p ServerSectionDeleted) GetName() string { return "server.section.deleted" // Params of the server.section.deleted event type serverSectionDeletedParams struct { // Chat type - ChatType ChatType `json:"chat_type"` + ChatType tdproto.ChatType `json:"chat_type"` // Section/project info - Sections []DeletedSection `json:"sections"` + Sections []tdproto.DeletedSection `json:"sections"` // Deprecated Gentime int64 `json:"gentime"` diff --git a/tdws/server_section_updated.go b/tdws/server_section_updated.go index 3e711c8..73092ca 100644 --- a/tdws/server_section_updated.go +++ b/tdws/server_section_updated.go @@ -1,9 +1,11 @@ package tdws -func NewServerSectionUpdated(ct ChatType, sections ...Section) (r ServerSectionUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerSectionUpdated(ct tdproto.ChatType, sections ...tdproto.Section) (r ServerSectionUpdated) { r.Name = r.GetName() r.Params.ChatType = ct - r.Params.Gentime = Gentime() // XXX + r.Params.Gentime = tdproto.Gentime() // XXX r.Params.Sections = sections return r } @@ -19,10 +21,10 @@ func (p ServerSectionUpdated) GetName() string { return "server.section.updated" // Params of the server.section.updated event type serverSectionUpdatedParams struct { // Chat type - ChatType ChatType `json:"chat_type"` + ChatType tdproto.ChatType `json:"chat_type"` // Section/project info - Sections []Section `json:"sections"` + Sections []tdproto.Section `json:"sections"` // deprecated Gentime int64 `json:"gentime"` diff --git a/tdws/server_tag_deleted.go b/tdws/server_tag_deleted.go index 095387c..3da6461 100644 --- a/tdws/server_tag_deleted.go +++ b/tdws/server_tag_deleted.go @@ -1,6 +1,8 @@ package tdws -func NewServerTagDeleted(tags ...DeletedTag) (r ServerTagDeleted) { +import "github.com/tada-team/tdproto" + +func NewServerTagDeleted(tags ...tdproto.DeletedTag) (r ServerTagDeleted) { r.Name = r.GetName() r.Params.Tags = tags return r @@ -17,5 +19,5 @@ func (p ServerTagDeleted) GetName() string { return "server.tag.deleted" } // Params of the server.tag.deleted event type serverTagDeletedParams struct { // Tags info - Tags []DeletedTag `json:"tags"` + Tags []tdproto.DeletedTag `json:"tags"` } diff --git a/tdws/server_tag_updated.go b/tdws/server_tag_updated.go index 21dcf1f..2321e3b 100644 --- a/tdws/server_tag_updated.go +++ b/tdws/server_tag_updated.go @@ -1,6 +1,8 @@ package tdws -func NewServerTagUpdated(tags ...Tag) (r ServerTagUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerTagUpdated(tags ...tdproto.Tag) (r ServerTagUpdated) { r.Name = r.GetName() r.Params.Tags = tags return r @@ -17,5 +19,5 @@ func (p ServerTagUpdated) GetName() string { return "server.tag.updated" } // Params of the server.tag.updated event type serverTagUpdatedParams struct { // Tags info - Tags []Tag `json:"tags"` + Tags []tdproto.Tag `json:"tags"` } diff --git a/tdws/server_team_counters.go b/tdws/server_team_counters.go index be3c5a3..584fb50 100644 --- a/tdws/server_team_counters.go +++ b/tdws/server_team_counters.go @@ -1,7 +1,9 @@ package tdws +import "github.com/tada-team/tdproto" + // TODO: remove empty -func NewServerTeamCounters(counters []TeamCounter, badge uint) ServerTeamCounters { +func NewServerTeamCounters(counters []tdproto.TeamCounter, badge uint) ServerTeamCounters { r := ServerTeamCounters{} r.Name = r.GetName() r.Params.Teams = counters @@ -20,7 +22,7 @@ func (p ServerTeamCounters) GetName() string { return "server.team.counters" } // Params of the server.team.counters event type serverTeamCountersParams struct { // Counters - Teams []TeamCounter `json:"teams"` + Teams []tdproto.TeamCounter `json:"teams"` // Total number of unreads Badge uint `json:"badge"` diff --git a/tdws/server_team_deleted.go b/tdws/server_team_deleted.go index bf655d1..df4999d 100644 --- a/tdws/server_team_deleted.go +++ b/tdws/server_team_deleted.go @@ -1,8 +1,10 @@ package tdws +import "github.com/tada-team/tdproto" + func NewServerTeamDeleted(uid string, gentime int64) (r ServerTeamDeleted) { r.Name = r.GetName() - r.Params.Teams = []DeletedTeam{{ + r.Params.Teams = []tdproto.DeletedTeam{{ Uid: uid, IsArchive: true, Gentime: gentime, @@ -21,5 +23,5 @@ func (p ServerTeamDeleted) GetName() string { return "server.team.deleted" } // Params of the server.team.deleted event type serverTeamDeletedParams struct { // Teams info - Teams []DeletedTeam `json:"teams"` + Teams []tdproto.DeletedTeam `json:"teams"` } diff --git a/tdws/server_team_updated.go b/tdws/server_team_updated.go index 4d0518e..8e7339b 100644 --- a/tdws/server_team_updated.go +++ b/tdws/server_team_updated.go @@ -1,8 +1,10 @@ package tdws -func NewServerTeamUpdated(team Team) (r ServerTeamUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerTeamUpdated(team tdproto.Team) (r ServerTeamUpdated) { r.Name = r.GetName() - r.Params.Teams = []Team{team} + r.Params.Teams = []tdproto.Team{team} return r } @@ -16,5 +18,5 @@ func (p ServerTeamUpdated) GetName() string { return "server.team.updated" } // Params of the server.team.updated event type serverTeamUpdatedParams struct { - Teams []Team `json:"teams"` + Teams []tdproto.Team `json:"teams"` } diff --git a/tdws/server_time.go b/tdws/server_time.go index f8c0b23..4e7e836 100644 --- a/tdws/server_time.go +++ b/tdws/server_time.go @@ -1,10 +1,14 @@ package tdws -import "time" +import ( + "time" + + "github.com/tada-team/tdproto" +) func NewServerTime() (r ServerTime) { r.Name = r.GetName() - r.Params.Time = IsoDatetime(time.Now()) + r.Params.Time = tdproto.IsoDatetime(time.Now()) return r } @@ -19,5 +23,5 @@ func (p ServerTime) GetName() string { return "server.time" } // Params of the server.time event type serverTimeParams struct { // Current time - Time ISODateTimeString `json:"time"` + Time tdproto.ISODateTimeString `json:"time"` } diff --git a/tdws/server_uisettings.go b/tdws/server_uisettings.go index b643f2e..7d52680 100644 --- a/tdws/server_uisettings.go +++ b/tdws/server_uisettings.go @@ -1,6 +1,8 @@ package tdws -func NewServerUiSettings(v *UiSettings) (r ServerUiSettings) { +import "github.com/tada-team/tdproto" + +func NewServerUiSettings(v *tdproto.UiSettings) (r ServerUiSettings) { r.Name = r.GetName() r.Params = v return r @@ -9,7 +11,7 @@ func NewServerUiSettings(v *UiSettings) (r ServerUiSettings) { // Part of UI settings changed type ServerUiSettings struct { BaseEvent - Params *UiSettings `json:"params"` + Params *tdproto.UiSettings `json:"params"` } func (p ServerUiSettings) GetName() string { return "server.uisettings" } diff --git a/tdws/server_upload_updated.go b/tdws/server_upload_updated.go index 12e3a9d..cc4f4e1 100644 --- a/tdws/server_upload_updated.go +++ b/tdws/server_upload_updated.go @@ -1,6 +1,8 @@ package tdws -func NewServerUploadUpdated(uploads ...Upload) (r ServerUploadUpdated) { +import "github.com/tada-team/tdproto" + +func NewServerUploadUpdated(uploads ...tdproto.Upload) (r ServerUploadUpdated) { r.Name = r.GetName() r.Params.Uploads = uploads return r @@ -17,5 +19,5 @@ func (p ServerUploadUpdated) GetName() string { return "server.upload.updated" } // Params of the server.upload.updated event type serverUploadUpdatedParams struct { // Uploads data - Uploads []Upload `json:"uploads"` + Uploads []tdproto.Upload `json:"uploads"` } diff --git a/utils.go b/utils.go index 0f487af..c4b2120 100644 --- a/utils.go +++ b/utils.go @@ -32,26 +32,3 @@ func IsoDatetime(dt time.Time) string { s := dt.UTC().Format("2006-01-02T15:04:05.000000-0700") return strings.Replace(s, "+0000", "Z", 1) } - -func ConfirmId() string { - return randomSymbols(12, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") -} - -func randomSymbols(n int, letters string) string { - bytes, err := randomBytes(n) - if err != nil { - log.Panicln("random bytes fail:", err) - } - for i, b := range bytes { - bytes[i] = letters[b%byte(len(letters))] - } - return string(bytes) -} - -func randomBytes(n int) ([]byte, error) { - b := make([]byte, n) - if _, err := rand.Read(b); err != nil { - return nil, err - } - return b, nil -} From cba1ed962dd0b39092459531a57ed189d0a1e5b0 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:36:55 +0300 Subject: [PATCH 05/35] changelog --- CHANGELOG | 5 +++++ contact.go | 4 ++-- tdapi/Readme.md | 1 + tdmarkup/Readme.md | 1 + tdws/Readme.md | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tdapi/Readme.md create mode 100644 tdmarkup/Readme.md create mode 100644 tdws/Readme.md diff --git a/CHANGELOG b/CHANGELOG index 1b4a50e..c9e66b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v2.0.0 + - websocket events moved to tdws package + - removed deprecated server.roster event + - not nullable IconData + v1.34.1 - tdapi.MyReactions - tdapi.DevicePing diff --git a/contact.go b/contact.go index e3a62c2..a9e8581 100644 --- a/contact.go +++ b/contact.go @@ -18,7 +18,7 @@ type Contact struct { ContactPhone string `json:"contact_phone"` // Icons data - Icons *IconData `json:"icons"` + Icons IconData `json:"icons"` // Role in this team Role string `json:"role"` @@ -204,5 +204,5 @@ type ContactShort struct { ShortName string `json:"short_name"` // Icons data - Icons *IconData `json:"icons"` + Icons IconData `json:"icons"` } diff --git a/tdapi/Readme.md b/tdapi/Readme.md new file mode 100644 index 0000000..ce555c0 --- /dev/null +++ b/tdapi/Readme.md @@ -0,0 +1 @@ +HTTP API structures diff --git a/tdmarkup/Readme.md b/tdmarkup/Readme.md new file mode 100644 index 0000000..fad0058 --- /dev/null +++ b/tdmarkup/Readme.md @@ -0,0 +1 @@ +Messages markup. diff --git a/tdws/Readme.md b/tdws/Readme.md new file mode 100644 index 0000000..d639157 --- /dev/null +++ b/tdws/Readme.md @@ -0,0 +1 @@ +Websocket events. From 0b89ec5ec988d2c6640541ca95d50fc706c34bb3 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 29 Jun 2021 23:40:37 +0300 Subject: [PATCH 06/35] typo fixed --- CHANGELOG | 5 +++-- codegen/api_paths/chat_paths.go | 12 ++++++------ codegen/api_paths/group_paths.go | 6 +++--- codegen/api_paths/misc.go | 10 +++++----- codegen/api_paths/paths_types.go | 6 +++--- codegen/api_paths/task.go | 8 ++++---- codegen/api_paths/team_paths.go | 26 +++++++++++++------------- codegen/openapi/converters.go | 2 +- codegen/sphinx/paths_doc/main.go | 10 +++++----- tdapi/contact.go | 2 +- 10 files changed, 44 insertions(+), 43 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c9e66b6..3a1a917 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ v2.0.0 - websocket events moved to tdws package - - removed deprecated server.roster event - - not nullable IconData + - PaginatedXXX structs moved to tdapi + - IconData now always not nullable + - server.roster event removed v1.34.1 - tdapi.MyReactions diff --git a/codegen/api_paths/chat_paths.go b/codegen/api_paths/chat_paths.go index c79e3c2..89eafba 100644 --- a/codegen/api_paths/chat_paths.go +++ b/codegen/api_paths/chat_paths.go @@ -8,12 +8,12 @@ var ChatPaths = []PathSpec{ { Path: "/api/v4/teams/{team_id}/chats/{chat_id}", Get: &OperationSpec{ - Responce: tdproto.Chat{}, + Response: tdproto.Chat{}, Description: "Get the chat information.", }, Put: &OperationSpec{ Request: tdproto.Chat{}, - Responce: tdproto.Chat{}, + Response: tdproto.Chat{}, Description: "Change chat settings.", }, }, @@ -28,11 +28,11 @@ var ChatPaths = []PathSpec{ Path: "/api/v4/teams/{team_id}/chats/{chat_id}/messages/{message_id}", Post: &OperationSpec{ Request: tdproto.Message{}, - Responce: tdproto.Message{}, + Response: tdproto.Message{}, Description: "Edit message.", }, Delete: &OperationSpec{ - Responce: tdproto.Message{}, + Response: tdproto.Message{}, Description: "Delete message.", }, }, @@ -47,11 +47,11 @@ var ChatPaths = []PathSpec{ Path: "/api/v4/teams/{team_id}/chats/{contact_id}/messages/{message_id}", Post: &OperationSpec{ Request: tdproto.Message{}, - Responce: tdproto.Message{}, + Response: tdproto.Message{}, Description: "Edit message in direct chat.", }, Delete: &OperationSpec{ - Responce: tdproto.Message{}, + Response: tdproto.Message{}, Description: "Delete message in direct chat.", }, }, diff --git a/codegen/api_paths/group_paths.go b/codegen/api_paths/group_paths.go index f31eb78..9d1cb12 100644 --- a/codegen/api_paths/group_paths.go +++ b/codegen/api_paths/group_paths.go @@ -6,7 +6,7 @@ var GroupPaths = []PathSpec{ { Path: "/api/v4/teams/{team_id}/groups", Get: &OperationSpec{ - Responce: []tdproto.Chat{}, + Response: []tdproto.Chat{}, Description: "Get all groups in the team.", }, Delete: &OperationSpec{ @@ -16,14 +16,14 @@ var GroupPaths = []PathSpec{ { Path: "/api/v4/teams/{team_id}/groups/{group_id}/members", Get: &OperationSpec{ - Responce: []tdproto.GroupMembership{}, + Response: []tdproto.GroupMembership{}, Description: "Get the list of group members.", }, }, { Path: "/api/v4/teams/{team_id}/groups/{group_id}/members/{contact_id}", Delete: &OperationSpec{ - Responce: tdproto.GroupMembership{}, + Response: tdproto.GroupMembership{}, Description: "Remove member from the group.", }, }, diff --git a/codegen/api_paths/misc.go b/codegen/api_paths/misc.go index 75314f3..6461170 100644 --- a/codegen/api_paths/misc.go +++ b/codegen/api_paths/misc.go @@ -6,25 +6,25 @@ var MiscPaths = []PathSpec{ { Path: "/api/v4/addr", Get: &OperationSpec{ - Responce: "", + Response: "", Description: "Returns client address for debuging purposes.", - ResponceDescription: "Address of the server.", + ResponseDescription: "Address of the server.", SecurityIsOptional: true, }, }, { Path: "/api/v4/ping", Get: &OperationSpec{ - Responce: "", + Response: "", Description: "Ping the server.", - ResponceDescription: "Set to ``\"pong\"``.", + ResponseDescription: "Set to ``\"pong\"``.", SecurityIsOptional: true, }, }, { Path: "/features.json", Get: &OperationSpec{ - Responce: tdproto.Features{}, + Response: tdproto.Features{}, Description: "Get the server features information.", SecurityIsOptional: true, }, diff --git a/codegen/api_paths/paths_types.go b/codegen/api_paths/paths_types.go index 0b5ad2f..1680e24 100644 --- a/codegen/api_paths/paths_types.go +++ b/codegen/api_paths/paths_types.go @@ -2,9 +2,9 @@ package api_paths type OperationSpec struct { Request interface{} - Responce interface{} + Response interface{} Description interface{} - ResponceDescription string + ResponseDescription string RequestDescription string SecurityIsOptional bool } @@ -29,6 +29,6 @@ var PathTitles = map[string]string{ "group": "Group related paths", "team": "Team related paths", "chat": "Chat related paths", - "misc": "Miscelaneos paths", + "misc": "Miscellaneous paths", "task": "Task related paths", } diff --git a/codegen/api_paths/task.go b/codegen/api_paths/task.go index 54fde35..d9039c1 100644 --- a/codegen/api_paths/task.go +++ b/codegen/api_paths/task.go @@ -9,23 +9,23 @@ var TaskPaths = []PathSpec{ Path: "/api/v4/teams/{team_id}/tasks", Post: &OperationSpec{ Request: tdapi.Task{}, - Responce: tdapi.Task{}, + Response: tdapi.Task{}, Description: "Create new task", }, }, { Path: "/api/v4/teams/{team_id}/tasks/{task_id}", Get: &OperationSpec{ - Responce: tdapi.Task{}, + Response: tdapi.Task{}, Description: "Get task", }, Post: &OperationSpec{ Request: tdapi.Task{}, - Responce: tdapi.Task{}, + Response: tdapi.Task{}, Description: "Update task", }, Delete: &OperationSpec{ - Responce: tdapi.Task{}, + Response: tdapi.Task{}, Description: "Delete task", }, }, diff --git a/codegen/api_paths/team_paths.go b/codegen/api_paths/team_paths.go index 27eab60..820a63e 100644 --- a/codegen/api_paths/team_paths.go +++ b/codegen/api_paths/team_paths.go @@ -6,59 +6,59 @@ var TeamPaths = []PathSpec{ { Path: "/api/v4/teams", Get: &OperationSpec{ - Responce: []tdproto.Team{}, + Response: []tdproto.Team{}, Description: "Get the list of teams on the server.", }, }, { Path: "/api/v4/teams/{team_id}", Get: &OperationSpec{ - Responce: tdproto.Team{}, + Response: tdproto.Team{}, Description: "Get team info.", }, Put: &OperationSpec{ Request: tdproto.Team{}, - Responce: tdproto.Team{}, + Response: tdproto.Team{}, Description: []string{"Update team settings.", "Must have admin rights."}, RequestDescription: ":ref:`tdproto-Team` object with updated fields.", - ResponceDescription: "Updated :ref:`tdproto-Team` object of the team.", + ResponseDescription: "Updated :ref:`tdproto-Team` object of the team.", }, Delete: &OperationSpec{ - Responce: tdproto.Team{}, - ResponceDescription: ":ref:`tdproto-Team` object of deleted team.", + Response: tdproto.Team{}, + ResponseDescription: ":ref:`tdproto-Team` object of deleted team.", Description: []string{"Delete the team.", "Must have admin rights."}, }, }, { Path: "/api/v4/teams/{team_id}/chats", Get: &OperationSpec{ - Responce: []tdproto.Chat{}, + Response: []tdproto.Chat{}, Description: "Get the list of chats in the team.", }, }, { Path: "/api/v4/teams/{team_id}/contacts", Get: &OperationSpec{ - Responce: []tdproto.Contact{}, + Response: []tdproto.Contact{}, Description: "Get the list of contacts of the team.", }, }, { Path: "/api/v4/teams/{team_id}/contacts/{contact_id}", Get: &OperationSpec{ - Responce: tdproto.Contact{}, + Response: tdproto.Contact{}, Description: "Get contact details.", }, Post: &OperationSpec{ Request: tdproto.Contact{}, - Responce: tdproto.Contact{}, + Response: tdproto.Contact{}, Description: "Update contact details.", - ResponceDescription: "Updated :ref:`tdproto-Contact` object.", + ResponseDescription: "Updated :ref:`tdproto-Contact` object.", }, Delete: &OperationSpec{ - Responce: tdproto.Contact{}, + Response: tdproto.Contact{}, Description: []string{"Remove contact from the team.", "Must have admin rights."}, - ResponceDescription: "Removed :ref:`tdproto-Contact` object.", + ResponseDescription: "Removed :ref:`tdproto-Contact` object.", }, }, } diff --git a/codegen/openapi/converters.go b/codegen/openapi/converters.go index 9b6e941..d85dea2 100644 --- a/codegen/openapi/converters.go +++ b/codegen/openapi/converters.go @@ -231,7 +231,7 @@ func getDescription(method api_paths.OperationSpec) string { func convertPathSpecMethod(method api_paths.OperationSpec, operation **openApiOperation) error { getRepsonce := openApiResponse{} - err := interfaceToOaContents(method.Responce, &getRepsonce.Content, true) + err := interfaceToOaContents(method.Response, &getRepsonce.Content, true) if err != nil { return err } diff --git a/codegen/sphinx/paths_doc/main.go b/codegen/sphinx/paths_doc/main.go index 45404c3..3a8efee 100644 --- a/codegen/sphinx/paths_doc/main.go +++ b/codegen/sphinx/paths_doc/main.go @@ -110,12 +110,12 @@ func generateSpecRst(path string, spec api_paths.OperationSpec, method string) e var resultObjectName string var resultKind reflect.Kind - if spec.Responce != nil { - resultKind = reflect.TypeOf(spec.Responce).Kind() + if spec.Response != nil { + resultKind = reflect.TypeOf(spec.Response).Kind() if resultKind == reflect.Slice { - resultObjectName = reflect.TypeOf(spec.Responce).Elem().Name() + resultObjectName = reflect.TypeOf(spec.Response).Elem().Name() } else { - resultObjectName = reflect.TypeOf(spec.Responce).Name() + resultObjectName = reflect.TypeOf(spec.Response).Name() } } @@ -146,7 +146,7 @@ func generateSpecRst(path string, spec api_paths.OperationSpec, method string) e Description: description, RequestDescription: spec.RequestDescription, RequestObjectName: requestObjectName, - ResultDescription: spec.ResponceDescription, + ResultDescription: spec.ResponseDescription, ResultObjectName: resultObjectName, ResultKind: resultKind, }) diff --git a/tdapi/contact.go b/tdapi/contact.go index 8523586..d48fcfe 100644 --- a/tdapi/contact.go +++ b/tdapi/contact.go @@ -1,6 +1,6 @@ package tdapi -import "github.com/tada-team/tdproto" +import "github.com/tada-team/tdproto" // Contact invite/edit form type Contact struct { From bca779c1bbb2d79d62d485aacf77aa94d7c1f312 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Wed, 30 Jun 2021 02:54:45 +0300 Subject: [PATCH 07/35] tdws -> tdevents --- CHANGELOG | 2 +- {tdws => tdevents}/Readme.md | 0 {tdws => tdevents}/client_call_buzz.go | 2 +- {tdws => tdevents}/client_call_buzzcancel.go | 2 +- {tdws => tdevents}/client_call_leave.go | 2 +- {tdws => tdevents}/client_call_muteall.go | 2 +- {tdws => tdevents}/client_call_offer.go | 2 +- {tdws => tdevents}/client_call_reject.go | 2 +- {tdws => tdevents}/client_call_sdp.go | 2 +- {tdws => tdevents}/client_call_sound.go | 2 +- {tdws => tdevents}/client_call_trickle.go | 2 +- {tdws => tdevents}/client_chat_composing.go | 2 +- {tdws => tdevents}/client_chat_lastread.go | 2 +- {tdws => tdevents}/client_confirm.go | 2 +- {tdws => tdevents}/client_message_deleted.go | 2 +- {tdws => tdevents}/client_message_updated.go | 2 +- {tdws => tdevents}/client_ping.go | 2 +- {tdws => tdevents}/confirm_id.go | 2 +- {tdws => tdevents}/event.go | 2 +- {tdws => tdevents}/server_call_answer.go | 2 +- {tdws => tdevents}/server_call_buzz.go | 2 +- {tdws => tdevents}/server_call_buzzcancel.go | 2 +- {tdws => tdevents}/server_call_checkfingerprint.go | 2 +- {tdws => tdevents}/server_call_leave.go | 2 +- {tdws => tdevents}/server_call_muteall.go | 2 +- {tdws => tdevents}/server_call_reject.go | 2 +- {tdws => tdevents}/server_call_restart.go | 2 +- {tdws => tdevents}/server_call_sdp.go | 2 +- {tdws => tdevents}/server_call_sound.go | 2 +- {tdws => tdevents}/server_call_state.go | 2 +- {tdws => tdevents}/server_call_talking.go | 2 +- {tdws => tdevents}/server_chat_composing.go | 2 +- {tdws => tdevents}/server_chat_deleted.go | 2 +- {tdws => tdevents}/server_chat_draft.go | 2 +- {tdws => tdevents}/server_chat_lastread.go | 2 +- {tdws => tdevents}/server_chat_updated.go | 2 +- {tdws => tdevents}/server_confirm.go | 2 +- {tdws => tdevents}/server_contact_updated.go | 2 +- {tdws => tdevents}/server_debug.go | 2 +- {tdws => tdevents}/server_login.go | 2 +- {tdws => tdevents}/server_message_received.go | 2 +- {tdws => tdevents}/server_message_updated.go | 2 +- {tdws => tdevents}/server_online.go | 2 +- {tdws => tdevents}/server_panic.go | 2 +- {tdws => tdevents}/server_processing.go | 2 +- {tdws => tdevents}/server_push.go | 2 +- {tdws => tdevents}/server_remind_deleted.go | 2 +- {tdws => tdevents}/server_remind_fired.go | 2 +- {tdws => tdevents}/server_remind_updated.go | 2 +- {tdws => tdevents}/server_section_deleted.go | 2 +- {tdws => tdevents}/server_section_updated.go | 2 +- {tdws => tdevents}/server_tag_deleted.go | 2 +- {tdws => tdevents}/server_tag_updated.go | 2 +- {tdws => tdevents}/server_team_counters.go | 2 +- {tdws => tdevents}/server_team_deleted.go | 2 +- {tdws => tdevents}/server_team_updated.go | 2 +- {tdws => tdevents}/server_time.go | 2 +- {tdws => tdevents}/server_uisettings.go | 2 +- {tdws => tdevents}/server_upload_updated.go | 2 +- {tdws => tdevents}/server_warning.go | 2 +- {tdws => tdevents}/x.go | 2 +- 61 files changed, 60 insertions(+), 60 deletions(-) rename {tdws => tdevents}/Readme.md (100%) rename {tdws => tdevents}/client_call_buzz.go (96%) rename {tdws => tdevents}/client_call_buzzcancel.go (95%) rename {tdws => tdevents}/client_call_leave.go (96%) rename {tdws => tdevents}/client_call_muteall.go (95%) rename {tdws => tdevents}/client_call_offer.go (96%) rename {tdws => tdevents}/client_call_reject.go (96%) rename {tdws => tdevents}/client_call_sdp.go (96%) rename {tdws => tdevents}/client_call_sound.go (96%) rename {tdws => tdevents}/client_call_trickle.go (97%) rename {tdws => tdevents}/client_chat_composing.go (98%) rename {tdws => tdevents}/client_chat_lastread.go (97%) rename {tdws => tdevents}/client_confirm.go (96%) rename {tdws => tdevents}/client_message_deleted.go (96%) rename {tdws => tdevents}/client_message_updated.go (98%) rename {tdws => tdevents}/client_ping.go (93%) rename {tdws => tdevents}/confirm_id.go (96%) rename {tdws => tdevents}/event.go (97%) rename {tdws => tdevents}/server_call_answer.go (98%) rename {tdws => tdevents}/server_call_buzz.go (98%) rename {tdws => tdevents}/server_call_buzzcancel.go (97%) rename {tdws => tdevents}/server_call_checkfingerprint.go (96%) rename {tdws => tdevents}/server_call_leave.go (97%) rename {tdws => tdevents}/server_call_muteall.go (97%) rename {tdws => tdevents}/server_call_reject.go (97%) rename {tdws => tdevents}/server_call_restart.go (97%) rename {tdws => tdevents}/server_call_sdp.go (97%) rename {tdws => tdevents}/server_call_sound.go (97%) rename {tdws => tdevents}/server_call_state.go (95%) rename {tdws => tdevents}/server_call_talking.go (97%) rename {tdws => tdevents}/server_chat_composing.go (98%) rename {tdws => tdevents}/server_chat_deleted.go (98%) rename {tdws => tdevents}/server_chat_draft.go (97%) rename {tdws => tdevents}/server_chat_lastread.go (97%) rename {tdws => tdevents}/server_chat_updated.go (97%) rename {tdws => tdevents}/server_confirm.go (96%) rename {tdws => tdevents}/server_contact_updated.go (97%) rename {tdws => tdevents}/server_debug.go (95%) rename {tdws => tdevents}/server_login.go (96%) rename {tdws => tdevents}/server_message_received.go (98%) rename {tdws => tdevents}/server_message_updated.go (98%) rename {tdws => tdevents}/server_online.go (98%) rename {tdws => tdevents}/server_panic.go (96%) rename {tdws => tdevents}/server_processing.go (97%) rename {tdws => tdevents}/server_push.go (95%) rename {tdws => tdevents}/server_remind_deleted.go (97%) rename {tdws => tdevents}/server_remind_fired.go (96%) rename {tdws => tdevents}/server_remind_updated.go (97%) rename {tdws => tdevents}/server_section_deleted.go (98%) rename {tdws => tdevents}/server_section_updated.go (97%) rename {tdws => tdevents}/server_tag_deleted.go (96%) rename {tdws => tdevents}/server_tag_updated.go (96%) rename {tdws => tdevents}/server_team_counters.go (97%) rename {tdws => tdevents}/server_team_deleted.go (97%) rename {tdws => tdevents}/server_team_updated.go (96%) rename {tdws => tdevents}/server_time.go (96%) rename {tdws => tdevents}/server_uisettings.go (95%) rename {tdws => tdevents}/server_upload_updated.go (96%) rename {tdws => tdevents}/server_warning.go (96%) rename {tdws => tdevents}/x.go (97%) diff --git a/CHANGELOG b/CHANGELOG index 3a1a917..f608f12 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ v2.0.0 - - websocket events moved to tdws package + - websocket events moved to tdevents package - PaginatedXXX structs moved to tdapi - IconData now always not nullable - server.roster event removed diff --git a/tdws/Readme.md b/tdevents/Readme.md similarity index 100% rename from tdws/Readme.md rename to tdevents/Readme.md diff --git a/tdws/client_call_buzz.go b/tdevents/client_call_buzz.go similarity index 96% rename from tdws/client_call_buzz.go rename to tdevents/client_call_buzz.go index 4a30917..7b0be1e 100644 --- a/tdws/client_call_buzz.go +++ b/tdevents/client_call_buzz.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_buzzcancel.go b/tdevents/client_call_buzzcancel.go similarity index 95% rename from tdws/client_call_buzzcancel.go rename to tdevents/client_call_buzzcancel.go index 5c979c3..1af8859 100644 --- a/tdws/client_call_buzzcancel.go +++ b/tdevents/client_call_buzzcancel.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_leave.go b/tdevents/client_call_leave.go similarity index 96% rename from tdws/client_call_leave.go rename to tdevents/client_call_leave.go index 5765341..8927b44 100644 --- a/tdws/client_call_leave.go +++ b/tdevents/client_call_leave.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_muteall.go b/tdevents/client_call_muteall.go similarity index 95% rename from tdws/client_call_muteall.go rename to tdevents/client_call_muteall.go index 1602f81..7163205 100644 --- a/tdws/client_call_muteall.go +++ b/tdevents/client_call_muteall.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_offer.go b/tdevents/client_call_offer.go similarity index 96% rename from tdws/client_call_offer.go rename to tdevents/client_call_offer.go index 1bd2866..84d7404 100644 --- a/tdws/client_call_offer.go +++ b/tdevents/client_call_offer.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_reject.go b/tdevents/client_call_reject.go similarity index 96% rename from tdws/client_call_reject.go rename to tdevents/client_call_reject.go index bb2d5b8..fc167e1 100644 --- a/tdws/client_call_reject.go +++ b/tdevents/client_call_reject.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_sdp.go b/tdevents/client_call_sdp.go similarity index 96% rename from tdws/client_call_sdp.go rename to tdevents/client_call_sdp.go index ab09f6d..180d16a 100644 --- a/tdws/client_call_sdp.go +++ b/tdevents/client_call_sdp.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_sound.go b/tdevents/client_call_sound.go similarity index 96% rename from tdws/client_call_sound.go rename to tdevents/client_call_sound.go index 9c1964d..007b666 100644 --- a/tdws/client_call_sound.go +++ b/tdevents/client_call_sound.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_call_trickle.go b/tdevents/client_call_trickle.go similarity index 97% rename from tdws/client_call_trickle.go rename to tdevents/client_call_trickle.go index 19eb016..9feccbc 100644 --- a/tdws/client_call_trickle.go +++ b/tdevents/client_call_trickle.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_chat_composing.go b/tdevents/client_chat_composing.go similarity index 98% rename from tdws/client_chat_composing.go rename to tdevents/client_chat_composing.go index c988a5f..829f159 100644 --- a/tdws/client_chat_composing.go +++ b/tdevents/client_chat_composing.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_chat_lastread.go b/tdevents/client_chat_lastread.go similarity index 97% rename from tdws/client_chat_lastread.go rename to tdevents/client_chat_lastread.go index 736829a..7647e29 100644 --- a/tdws/client_chat_lastread.go +++ b/tdevents/client_chat_lastread.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_confirm.go b/tdevents/client_confirm.go similarity index 96% rename from tdws/client_confirm.go rename to tdevents/client_confirm.go index 33791dd..105e456 100644 --- a/tdws/client_confirm.go +++ b/tdevents/client_confirm.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewClientConfirm(confirmId string) (r ClientConfirm) { r.Name = r.GetName() diff --git a/tdws/client_message_deleted.go b/tdevents/client_message_deleted.go similarity index 96% rename from tdws/client_message_deleted.go rename to tdevents/client_message_deleted.go index cc4fd4d..4657bd6 100644 --- a/tdws/client_message_deleted.go +++ b/tdevents/client_message_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewClientMessageDeleted(messageId string) (r ClientMessageDeleted) { r.Name = r.GetName() diff --git a/tdws/client_message_updated.go b/tdevents/client_message_updated.go similarity index 98% rename from tdws/client_message_updated.go rename to tdevents/client_message_updated.go index b548619..95f0026 100644 --- a/tdws/client_message_updated.go +++ b/tdevents/client_message_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/client_ping.go b/tdevents/client_ping.go similarity index 93% rename from tdws/client_ping.go rename to tdevents/client_ping.go index 9230800..9e5fa84 100644 --- a/tdws/client_ping.go +++ b/tdevents/client_ping.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewClientPing() (r ClientPing) { r.Name = r.GetName() diff --git a/tdws/confirm_id.go b/tdevents/confirm_id.go similarity index 96% rename from tdws/confirm_id.go rename to tdevents/confirm_id.go index f400541..e4822ad 100644 --- a/tdws/confirm_id.go +++ b/tdevents/confirm_id.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import ( "crypto/rand" diff --git a/tdws/event.go b/tdevents/event.go similarity index 97% rename from tdws/event.go rename to tdevents/event.go index c90e8c4..05b4639 100644 --- a/tdws/event.go +++ b/tdevents/event.go @@ -1,4 +1,4 @@ -package tdws +package tdevents // Base of all events type BaseEvent struct { diff --git a/tdws/server_call_answer.go b/tdevents/server_call_answer.go similarity index 98% rename from tdws/server_call_answer.go rename to tdevents/server_call_answer.go index 9236a05..ed39e61 100644 --- a/tdws/server_call_answer.go +++ b/tdevents/server_call_answer.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_buzz.go b/tdevents/server_call_buzz.go similarity index 98% rename from tdws/server_call_buzz.go rename to tdevents/server_call_buzz.go index 6fb1e7d..5525a7e 100644 --- a/tdws/server_call_buzz.go +++ b/tdevents/server_call_buzz.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import ( "time" diff --git a/tdws/server_call_buzzcancel.go b/tdevents/server_call_buzzcancel.go similarity index 97% rename from tdws/server_call_buzzcancel.go rename to tdevents/server_call_buzzcancel.go index e27f9f5..ed6fbbb 100644 --- a/tdws/server_call_buzzcancel.go +++ b/tdevents/server_call_buzzcancel.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_checkfingerprint.go b/tdevents/server_call_checkfingerprint.go similarity index 96% rename from tdws/server_call_checkfingerprint.go rename to tdevents/server_call_checkfingerprint.go index ceab8b4..93a74e1 100644 --- a/tdws/server_call_checkfingerprint.go +++ b/tdevents/server_call_checkfingerprint.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerCallCheckFingerprint(fingerprint string) (r ServerCallCheckFingerprint) { r.Name = r.GetName() diff --git a/tdws/server_call_leave.go b/tdevents/server_call_leave.go similarity index 97% rename from tdws/server_call_leave.go rename to tdevents/server_call_leave.go index 491c967..94c2896 100644 --- a/tdws/server_call_leave.go +++ b/tdevents/server_call_leave.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_muteall.go b/tdevents/server_call_muteall.go similarity index 97% rename from tdws/server_call_muteall.go rename to tdevents/server_call_muteall.go index 31e5a3c..2f938e7 100644 --- a/tdws/server_call_muteall.go +++ b/tdevents/server_call_muteall.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_reject.go b/tdevents/server_call_reject.go similarity index 97% rename from tdws/server_call_reject.go rename to tdevents/server_call_reject.go index 201e742..f62dbcc 100644 --- a/tdws/server_call_reject.go +++ b/tdevents/server_call_reject.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_restart.go b/tdevents/server_call_restart.go similarity index 97% rename from tdws/server_call_restart.go rename to tdevents/server_call_restart.go index 5636af5..32e1b5f 100644 --- a/tdws/server_call_restart.go +++ b/tdevents/server_call_restart.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_sdp.go b/tdevents/server_call_sdp.go similarity index 97% rename from tdws/server_call_sdp.go rename to tdevents/server_call_sdp.go index 8398e21..294366a 100644 --- a/tdws/server_call_sdp.go +++ b/tdevents/server_call_sdp.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_sound.go b/tdevents/server_call_sound.go similarity index 97% rename from tdws/server_call_sound.go rename to tdevents/server_call_sound.go index 092c83d..e5c48a1 100644 --- a/tdws/server_call_sound.go +++ b/tdevents/server_call_sound.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_state.go b/tdevents/server_call_state.go similarity index 95% rename from tdws/server_call_state.go rename to tdevents/server_call_state.go index 19ba735..f7823d1 100644 --- a/tdws/server_call_state.go +++ b/tdevents/server_call_state.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_call_talking.go b/tdevents/server_call_talking.go similarity index 97% rename from tdws/server_call_talking.go rename to tdevents/server_call_talking.go index 76b0ed0..362eb6e 100644 --- a/tdws/server_call_talking.go +++ b/tdevents/server_call_talking.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_chat_composing.go b/tdevents/server_chat_composing.go similarity index 98% rename from tdws/server_chat_composing.go rename to tdevents/server_chat_composing.go index bb15b44..f249794 100644 --- a/tdws/server_chat_composing.go +++ b/tdevents/server_chat_composing.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_chat_deleted.go b/tdevents/server_chat_deleted.go similarity index 98% rename from tdws/server_chat_deleted.go rename to tdevents/server_chat_deleted.go index 8f5e2ce..a421633 100644 --- a/tdws/server_chat_deleted.go +++ b/tdevents/server_chat_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_chat_draft.go b/tdevents/server_chat_draft.go similarity index 97% rename from tdws/server_chat_draft.go rename to tdevents/server_chat_draft.go index d784ad4..318e546 100644 --- a/tdws/server_chat_draft.go +++ b/tdevents/server_chat_draft.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_chat_lastread.go b/tdevents/server_chat_lastread.go similarity index 97% rename from tdws/server_chat_lastread.go rename to tdevents/server_chat_lastread.go index 493fe6f..08a930d 100644 --- a/tdws/server_chat_lastread.go +++ b/tdevents/server_chat_lastread.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_chat_updated.go b/tdevents/server_chat_updated.go similarity index 97% rename from tdws/server_chat_updated.go rename to tdevents/server_chat_updated.go index 550df57..b9ca472 100644 --- a/tdws/server_chat_updated.go +++ b/tdevents/server_chat_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_confirm.go b/tdevents/server_confirm.go similarity index 96% rename from tdws/server_confirm.go rename to tdevents/server_confirm.go index d7be35b..7b91ea2 100644 --- a/tdws/server_confirm.go +++ b/tdevents/server_confirm.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerConfirm(v string) (r ServerConfirm) { r.Name = r.GetName() diff --git a/tdws/server_contact_updated.go b/tdevents/server_contact_updated.go similarity index 97% rename from tdws/server_contact_updated.go rename to tdevents/server_contact_updated.go index e2ea6cf..1790483 100644 --- a/tdws/server_contact_updated.go +++ b/tdevents/server_contact_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_debug.go b/tdevents/server_debug.go similarity index 95% rename from tdws/server_debug.go rename to tdevents/server_debug.go index ac0c07d..1c9d35d 100644 --- a/tdws/server_debug.go +++ b/tdevents/server_debug.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerDebug(text string) (r ServerDebug) { r.Name = r.GetName() diff --git a/tdws/server_login.go b/tdevents/server_login.go similarity index 96% rename from tdws/server_login.go rename to tdevents/server_login.go index bf8e675..01862cf 100644 --- a/tdws/server_login.go +++ b/tdevents/server_login.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerLogin(deviceName string) (r ServerLogin) { r.Name = r.GetName() diff --git a/tdws/server_message_received.go b/tdevents/server_message_received.go similarity index 98% rename from tdws/server_message_received.go rename to tdevents/server_message_received.go index 5bf10d3..8e2a60b 100644 --- a/tdws/server_message_received.go +++ b/tdevents/server_message_received.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_message_updated.go b/tdevents/server_message_updated.go similarity index 98% rename from tdws/server_message_updated.go rename to tdevents/server_message_updated.go index c1342ec..9b2dbf8 100644 --- a/tdws/server_message_updated.go +++ b/tdevents/server_message_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_online.go b/tdevents/server_online.go similarity index 98% rename from tdws/server_online.go rename to tdevents/server_online.go index 4723fda..0e9dcb4 100644 --- a/tdws/server_online.go +++ b/tdevents/server_online.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_panic.go b/tdevents/server_panic.go similarity index 96% rename from tdws/server_panic.go rename to tdevents/server_panic.go index b48c9f6..34c5a34 100644 --- a/tdws/server_panic.go +++ b/tdevents/server_panic.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerPanic(code string) (r ServerPanic) { r.Name = r.GetName() diff --git a/tdws/server_processing.go b/tdevents/server_processing.go similarity index 97% rename from tdws/server_processing.go rename to tdevents/server_processing.go index 4370c2f..959d4b6 100644 --- a/tdws/server_processing.go +++ b/tdevents/server_processing.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerProcessing(num, total int, action, message string, hasError bool) (r ServerProcessing) { r.Name = r.GetName() diff --git a/tdws/server_push.go b/tdevents/server_push.go similarity index 95% rename from tdws/server_push.go rename to tdevents/server_push.go index 5aab8fd..399e7e6 100644 --- a/tdws/server_push.go +++ b/tdevents/server_push.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_remind_deleted.go b/tdevents/server_remind_deleted.go similarity index 97% rename from tdws/server_remind_deleted.go rename to tdevents/server_remind_deleted.go index 9c10637..e346999 100644 --- a/tdws/server_remind_deleted.go +++ b/tdevents/server_remind_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_remind_fired.go b/tdevents/server_remind_fired.go similarity index 96% rename from tdws/server_remind_fired.go rename to tdevents/server_remind_fired.go index c4fd7c1..3db0306 100644 --- a/tdws/server_remind_fired.go +++ b/tdevents/server_remind_fired.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_remind_updated.go b/tdevents/server_remind_updated.go similarity index 97% rename from tdws/server_remind_updated.go rename to tdevents/server_remind_updated.go index ea22074..b6b70f1 100644 --- a/tdws/server_remind_updated.go +++ b/tdevents/server_remind_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_section_deleted.go b/tdevents/server_section_deleted.go similarity index 98% rename from tdws/server_section_deleted.go rename to tdevents/server_section_deleted.go index 5868c94..12769e7 100644 --- a/tdws/server_section_deleted.go +++ b/tdevents/server_section_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_section_updated.go b/tdevents/server_section_updated.go similarity index 97% rename from tdws/server_section_updated.go rename to tdevents/server_section_updated.go index 73092ca..911627f 100644 --- a/tdws/server_section_updated.go +++ b/tdevents/server_section_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_tag_deleted.go b/tdevents/server_tag_deleted.go similarity index 96% rename from tdws/server_tag_deleted.go rename to tdevents/server_tag_deleted.go index 3da6461..9456a32 100644 --- a/tdws/server_tag_deleted.go +++ b/tdevents/server_tag_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_tag_updated.go b/tdevents/server_tag_updated.go similarity index 96% rename from tdws/server_tag_updated.go rename to tdevents/server_tag_updated.go index 2321e3b..25c6675 100644 --- a/tdws/server_tag_updated.go +++ b/tdevents/server_tag_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_team_counters.go b/tdevents/server_team_counters.go similarity index 97% rename from tdws/server_team_counters.go rename to tdevents/server_team_counters.go index 584fb50..08d10cc 100644 --- a/tdws/server_team_counters.go +++ b/tdevents/server_team_counters.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_team_deleted.go b/tdevents/server_team_deleted.go similarity index 97% rename from tdws/server_team_deleted.go rename to tdevents/server_team_deleted.go index df4999d..f236d3a 100644 --- a/tdws/server_team_deleted.go +++ b/tdevents/server_team_deleted.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_team_updated.go b/tdevents/server_team_updated.go similarity index 96% rename from tdws/server_team_updated.go rename to tdevents/server_team_updated.go index 8e7339b..f1d0f56 100644 --- a/tdws/server_team_updated.go +++ b/tdevents/server_team_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_time.go b/tdevents/server_time.go similarity index 96% rename from tdws/server_time.go rename to tdevents/server_time.go index 4e7e836..62c6f81 100644 --- a/tdws/server_time.go +++ b/tdevents/server_time.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import ( "time" diff --git a/tdws/server_uisettings.go b/tdevents/server_uisettings.go similarity index 95% rename from tdws/server_uisettings.go rename to tdevents/server_uisettings.go index 7d52680..22c29a5 100644 --- a/tdws/server_uisettings.go +++ b/tdevents/server_uisettings.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_upload_updated.go b/tdevents/server_upload_updated.go similarity index 96% rename from tdws/server_upload_updated.go rename to tdevents/server_upload_updated.go index cc4f4e1..be97f10 100644 --- a/tdws/server_upload_updated.go +++ b/tdevents/server_upload_updated.go @@ -1,4 +1,4 @@ -package tdws +package tdevents import "github.com/tada-team/tdproto" diff --git a/tdws/server_warning.go b/tdevents/server_warning.go similarity index 96% rename from tdws/server_warning.go rename to tdevents/server_warning.go index 04d4cc7..b2d0357 100644 --- a/tdws/server_warning.go +++ b/tdevents/server_warning.go @@ -1,4 +1,4 @@ -package tdws +package tdevents func NewServerWarning(message, orig string) (r ServerWarning) { r.Name = r.GetName() diff --git a/tdws/x.go b/tdevents/x.go similarity index 97% rename from tdws/x.go rename to tdevents/x.go index 0e1845b..cd86c64 100644 --- a/tdws/x.go +++ b/tdevents/x.go @@ -1,5 +1,5 @@ // eXtra fast shortcuts -package tdws +package tdevents import "bytes" From c289f9844d983acd781430238eef7b6150c38262 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Wed, 30 Jun 2021 03:04:42 +0300 Subject: [PATCH 08/35] remove paginated prefix --- tdapi/chats.go | 20 ++++++++++++++++++++ tdapi/contact.go | 15 +++++++++++++++ tdapi/hotmessages.go | 15 --------------- tdapi/message.go | 41 ++++++++++++++++++++++++++++++++++++----- tdapi/mixins.go | 14 ++++++++++---- tdapi/paginated.go | 41 ----------------------------------------- tdapi/upload.go | 16 ++++++++++++++++ 7 files changed, 97 insertions(+), 65 deletions(-) delete mode 100644 tdapi/hotmessages.go delete mode 100644 tdapi/paginated.go diff --git a/tdapi/chats.go b/tdapi/chats.go index b69bb7d..cc5e711 100644 --- a/tdapi/chats.go +++ b/tdapi/chats.go @@ -1,5 +1,25 @@ package tdapi +import "github.com/tada-team/tdproto" + +// Chats response +type Chats struct { + // Chat list + Objects []tdproto.Chat `json:"objects"` + + // Contacts used in chats + Contacts []tdproto.Contact `json:"contacts,omitempty"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} + // Chat filter type ChatFilter struct { UserParams diff --git a/tdapi/contact.go b/tdapi/contact.go index d48fcfe..dd2a075 100644 --- a/tdapi/contact.go +++ b/tdapi/contact.go @@ -2,6 +2,21 @@ package tdapi import "github.com/tada-team/tdproto" +// Paginated contacts +type Contacts struct { + // Contacts list + Objects []tdproto.Contact `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} + // Contact invite/edit form type Contact struct { // User uid (for invitation from other team) diff --git a/tdapi/hotmessages.go b/tdapi/hotmessages.go deleted file mode 100644 index 82eeebe..0000000 --- a/tdapi/hotmessages.go +++ /dev/null @@ -1,15 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// All-in-one response with all messages info for fast chat rendering -type Hotmessages struct { - // chat information - Chat tdproto.Chat `json:"chat"` - - // Messages list - Messages []tdproto.Message `json:"messages"` - - // Contacts list - Contacts []tdproto.Contact `json:"contacts"` -} diff --git a/tdapi/message.go b/tdapi/message.go index b1a1edf..06843da 100644 --- a/tdapi/message.go +++ b/tdapi/message.go @@ -2,6 +2,40 @@ package tdapi import "github.com/tada-team/tdproto" +// Messages response +type Messages struct { + // Message list + Objects []tdproto.Message `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} + +// Chat messages +type ChatMessages struct { + // Message list + Messages []tdproto.Message `json:"messages"` +} + +// All-in-one response with all messages info for fast chat rendering +type Hotmessages struct { + // chat information + Chat tdproto.Chat `json:"chat"` + + // Messages list + Messages []tdproto.Message `json:"messages"` + + // Contacts list + Contacts []tdproto.Contact `json:"contacts"` +} + +// Message filter type MessageFilter struct { UserParams Paginator @@ -61,6 +95,7 @@ type MessageFilter struct { Around string `schema:"around"` } +// Update message form type MessageUpdate struct { // Important flag. Not required. Default: false Important bool `json:"important,omitempty"` @@ -72,6 +107,7 @@ type MessageUpdate struct { SendAt string `json:"send_at,omitempty"` } +// Update message response type Message struct { // Message type Type tdproto.Mediatype `json:"type"` @@ -99,8 +135,3 @@ type MessageMarkup struct { // Deprecated: use markup instead Links tdproto.MessageLinks `json:"links"` } - -// file upload: -//
-// -//
diff --git a/tdapi/mixins.go b/tdapi/mixins.go index d4de080..d957c4c 100644 --- a/tdapi/mixins.go +++ b/tdapi/mixins.go @@ -1,11 +1,17 @@ package tdapi type Paginator struct { - Limit int `schema:"limit"` - Offset int `schema:"offset"` + // Limit + Limit int `json:"limit,omitempty"` + + // Offset + Offset int `json:"offset,omitempty"` } type UserParams struct { - Lang string `schema:"lang"` - Timezone string `schema:"timezone"` + // Language code + Lang string `schema:"lang,omitempty"` + + // Timezone + Timezone string `schema:"timezone,omitempty"` } diff --git a/tdapi/paginated.go b/tdapi/paginated.go deleted file mode 100644 index 7ef65aa..0000000 --- a/tdapi/paginated.go +++ /dev/null @@ -1,41 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Paginated chats -type PaginatedChats struct { - Contacts []tdproto.Contact `json:"contacts,omitempty"` - Objects []tdproto.Chat `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Paginated messages -type PaginatedMessages struct { - Objects []tdproto.Message `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Paginated contacts -type PaginatedContacts struct { - Objects []tdproto.Contact `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} - -// Chat messages -type ChatMessages struct { - Messages []tdproto.Message `json:"messages"` -} - -// Paginated UploadShortMessage -type PaginatedUploadShortMessages struct { - Objects []tdproto.UploadShortMessage `json:"objects"` - Count int `json:"count"` - Limit int `json:"limit"` - Offset int `json:"offset"` -} diff --git a/tdapi/upload.go b/tdapi/upload.go index b9df4f1..ccb29df 100644 --- a/tdapi/upload.go +++ b/tdapi/upload.go @@ -2,6 +2,7 @@ package tdapi import "github.com/tada-team/tdproto" +// Uploads filter type UploadFilter struct { Paginator @@ -20,3 +21,18 @@ type UploadFilter struct { // ?text=substr Text string `schema:"text"` } + +// Upload + ShortMessage objects +type UploadShortMessages struct { + // Upload + ShortMessage objects list + Objects []tdproto.UploadShortMessage `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} From f5b1d1fc595bff48539af04c6eb8bb2c823c4040 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Wed, 30 Jun 2021 04:53:47 +0300 Subject: [PATCH 09/35] imports fix --- utils.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils.go b/utils.go index c4b2120..0c0e032 100644 --- a/utils.go +++ b/utils.go @@ -1,8 +1,6 @@ package tdproto import ( - "crypto/rand" - "log" "path/filepath" "runtime" "strings" From a3fcb2287a22cf4eba4b849779106e0e179939dd Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Wed, 30 Jun 2021 20:50:55 +0300 Subject: [PATCH 10/35] tdforms / tdquery / tdresp --- tdapi/message.go | 137 -------------------- tdapi/task.go | 130 ------------------- tdapi/{ => tdforms}/color_rule.go | 2 +- tdapi/{ => tdforms}/contact.go | 17 +-- tdapi/{device.go => tdforms/device_ping.go} | 2 +- tdapi/tdforms/draft.go | 7 + tdapi/{ => tdforms}/group.go | 8 +- tdapi/{ => tdforms}/integration.go | 3 +- tdapi/tdforms/message_creation.go | 23 ++++ tdapi/tdforms/message_update.go | 13 ++ tdapi/tdforms/task.go | 57 ++++++++ tdapi/{ => tdforms}/team.go | 12 +- tdapi/{ => tdquery}/chats.go | 24 +--- tdapi/tdquery/messages.go | 63 +++++++++ tdapi/{ => tdquery}/mixins.go | 2 +- tdapi/tdquery/tasks.go | 67 ++++++++++ tdapi/tdquery/uploads.go | 23 ++++ tdapi/{ => tdresp}/background_action.go | 2 +- tdapi/tdresp/chat_messages.go | 9 ++ tdapi/tdresp/chats.go | 21 +++ tdapi/tdresp/contacts.go | 18 +++ tdapi/{ => tdresp}/draft.go | 4 +- tdapi/{ => tdresp}/emoji.go | 2 +- tdapi/tdresp/group_members.go | 9 ++ tdapi/tdresp/hotmessages.go | 15 +++ tdapi/tdresp/message_markup.go | 12 ++ tdapi/tdresp/messages.go | 19 +++ tdapi/{ => tdresp}/my_reactions.go | 2 +- tdapi/{ => tdresp}/releases.go | 8 +- tdapi/{ => tdresp}/sms_code.go | 2 +- tdapi/tdresp/task_colors.go | 10 ++ tdapi/tdresp/team_prejoin_info.go | 9 ++ tdapi/{ => tdresp}/timezones.go | 3 +- tdapi/tdresp/upload_short_messages.go | 18 +++ tdapi/upload.go | 38 ------ 35 files changed, 416 insertions(+), 375 deletions(-) delete mode 100644 tdapi/message.go delete mode 100644 tdapi/task.go rename tdapi/{ => tdforms}/color_rule.go (98%) rename tdapi/{ => tdforms}/contact.go (91%) rename tdapi/{device.go => tdforms/device_ping.go} (87%) create mode 100644 tdapi/tdforms/draft.go rename tdapi/{ => tdforms}/group.go (86%) rename tdapi/{ => tdforms}/integration.go (92%) create mode 100644 tdapi/tdforms/message_creation.go create mode 100644 tdapi/tdforms/message_update.go create mode 100644 tdapi/tdforms/task.go rename tdapi/{ => tdforms}/team.go (82%) rename tdapi/{ => tdquery}/chats.go (74%) create mode 100644 tdapi/tdquery/messages.go rename tdapi/{ => tdquery}/mixins.go (94%) create mode 100644 tdapi/tdquery/tasks.go create mode 100644 tdapi/tdquery/uploads.go rename tdapi/{ => tdresp}/background_action.go (90%) create mode 100644 tdapi/tdresp/chat_messages.go create mode 100644 tdapi/tdresp/chats.go create mode 100644 tdapi/tdresp/contacts.go rename tdapi/{ => tdresp}/draft.go (91%) rename tdapi/{ => tdresp}/emoji.go (89%) create mode 100644 tdapi/tdresp/group_members.go create mode 100644 tdapi/tdresp/hotmessages.go create mode 100644 tdapi/tdresp/message_markup.go create mode 100644 tdapi/tdresp/messages.go rename tdapi/{ => tdresp}/my_reactions.go (94%) rename tdapi/{ => tdresp}/releases.go (56%) rename tdapi/{ => tdresp}/sms_code.go (96%) create mode 100644 tdapi/tdresp/task_colors.go create mode 100644 tdapi/tdresp/team_prejoin_info.go rename tdapi/{ => tdresp}/timezones.go (72%) create mode 100644 tdapi/tdresp/upload_short_messages.go delete mode 100644 tdapi/upload.go diff --git a/tdapi/message.go b/tdapi/message.go deleted file mode 100644 index 06843da..0000000 --- a/tdapi/message.go +++ /dev/null @@ -1,137 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Messages response -type Messages struct { - // Message list - Objects []tdproto.Message `json:"objects"` - - // Count - Count int `json:"count"` - - // Limit - Limit int `json:"limit"` - - // Offset - Offset int `json:"offset"` -} - -// Chat messages -type ChatMessages struct { - // Message list - Messages []tdproto.Message `json:"messages"` -} - -// All-in-one response with all messages info for fast chat rendering -type Hotmessages struct { - // chat information - Chat tdproto.Chat `json:"chat"` - - // Messages list - Messages []tdproto.Message `json:"messages"` - - // Contacts list - Contacts []tdproto.Contact `json:"contacts"` -} - -// Message filter -type MessageFilter struct { - UserParams - Paginator - - // ?chat=jid,jid - Chat string `schema:"chat"` - - // ?chat_type=task,group,direct|any (default: any) - ChatType string `schema:"chat_type"` - - // ?sender=jid,jid - Sender string `schema:"sender"` - - // ?has_upload=true|false|any (default: any) - HasUpload string `schema:"has_upload"` - - // ?text=substr - Text string `schema:"text"` - - // ?type=image,video,plain,file - Type tdproto.Mediatype `schema:"type"` - - // ?important=true|any - Important string `schema:"important"` - - // ?date_from=dt (include) - DateFrom string `schema:"date_from"` - - // ?date_to=dt - DateTo string `schema:"date_to"` - - // ?include_deleted=true|false (default: false) - IncludeDeleted string `schema:"include_deleted"` - - // ?gentime_from= - GentimeFrom string `schema:"gentime_from"` - - // ?exact=msgId - Exact string `schema:"exact"` - - // ?unread=(true|false) - Unread string `schema:"unread"` - - // ?old_from=msgId (exclude msgId) - OldFrom string `schema:"old_from"` - - // ?new_from=msgId (exclude msgId) - NewFrom string `schema:"new_from"` - - // ?old_from_inc=msgId (include msgId) - OldFromInc string `schema:"old_from_inc"` - - // ?new_from_inc=msgId (include msgId) - NewFromInc string `schema:"new_from_inc"` - - // ?around=msgId (include msgId) - Around string `schema:"around"` -} - -// Update message form -type MessageUpdate struct { - // Important flag. Not required. Default: false - Important bool `json:"important,omitempty"` - - // Disable links preview generation. Not required. Default: false - Nopreview bool `json:"nopreview,omitempty"` - - // Draft message, send later - SendAt string `json:"send_at,omitempty"` -} - -// Update message response -type Message struct { - // Message type - Type tdproto.Mediatype `json:"type"` - - // Message text - Text string `json:"text"` - - // Message id - MessageUid string `json:"message_id,omitempty"` - - // Message attachments - Uploads []string `json:"uploads,omitempty"` - - // Backward compatibility mode - OldStyleAttachment bool `json:"old_style_attachment,omitempty"` - - MessageUpdate -} - -// Message markup with checked links -type MessageMarkup struct { - // Message markup - Markup []tdproto.MarkupEntity `json:"markup"` - - // Deprecated: use markup instead - Links tdproto.MessageLinks `json:"links"` -} diff --git a/tdapi/task.go b/tdapi/task.go deleted file mode 100644 index 96667d6..0000000 --- a/tdapi/task.go +++ /dev/null @@ -1,130 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Task response -type Task struct { - // Custom task color - CustomColorIndex *uint16 `json:"custom_color_index,omitempty"` - - // Task description - Description string `json:"description,omitempty"` - - // Task tags - Tags []string `json:"tags,omitempty"` - - // Task section UID - SectionUid string `json:"section,omitempty"` - - // User who follow the task - Observers []tdproto.JID `json:"observers,omitempty"` // TODO: rename to "followers" - - // Items of the task - Items []string `json:"items,omitempty"` - - // User who was assigned the task - Assignee tdproto.JID `json:"assignee,omitempty"` - - // Deadline time, if any - Deadline tdproto.ISODateTimeString `json:"deadline,omitempty"` - - // Is task public - Public bool `json:"public,omitempty"` - - // Fire a reminder at this time - RemindAt tdproto.ISODateTimeString `json:"remind_at,omitempty"` - - // Task status - TaskStatus string `json:"task_status,omitempty"` - - // Task importance - Importance *int `json:"importance,omitempty"` - - // Task urgency - Urgency *int `json:"urgency,omitempty"` - - // Task complexity - Complexity *int `json:"complexity,omitempty"` - - // Time spent - SpentTime *int `json:"spent_time,omitempty"` - - // Linked messages - LinkedMessages []string `json:"linked_messages,omitempty"` // TODO: Message object - - // Task uploads - Uploads []string `json:"uploads,omitempty"` -} - -// Query parameters for listing messages -type TaskFilter struct { - UserParams - Paginator - - //* ?sort = [ "created" | "-created" | "last_message" | "-last_message" | "deadline" | "-deadline" ] - Sort string `schema:"sort"` - - //* ?task_status = new,done | new | any - TaskStatus string `schema:"task_status"` - - //* ?exclude_task_status = new,done | new | any - ExcludeTaskStatus string `schema:"exclude_task_status"` - - //* ?num=num1,num2,num3... - Num string `schema:"num"` - - //* ?observer=jid,jid // TODO: rename to ?follower= - Observer string `schema:"observer"` - - //* ?member=jid,jid - Member string `schema:"member"` - - //* ?assignee=jid,jid - Assignee string `schema:"assignee"` - - //* ?owner=jid,jid - Owner string `schema:"owner"` - - //* ?section=[ uid,uid... | "-" ] - Section string `schema:"section"` // TODO: rename to ?project= - - //* ?tag=[ tag,tag,tag... | "-" ] - Tag string `schema:"tag"` - - //* ?q= - Q string `schema:"q"` - - //* ?public=true|false - Public string `schema:"public"` - - //* ?deadline_gte= - DeadlineGTE string `schema:"deadline_gte"` - - //* ?deadline_lte= - DeadlineLTE string `schema:"deadline_lte"` - - //* ?done_gte= - DoneGTE string `schema:"done_gte"` - - //* ?done_lte= - DoneLTE string `schema:"done_lte"` - - //* ?created_gte= - CreatedGTE string `schema:"created_gte"` - - //* ?created_lte= - CreatedLTE string `schema:"created_lte"` - - //* ?short=true|false - Short string `schema:"short"` - - // gentime great than group/chat - GentimeGT int64 `schema:"gentime_gt"` -} - -// Task cards colors -type TaskColors struct { - // Color list - Colors []tdproto.TaskColor `json:"colors"` -} - diff --git a/tdapi/color_rule.go b/tdapi/tdforms/color_rule.go similarity index 98% rename from tdapi/color_rule.go rename to tdapi/tdforms/color_rule.go index 39b2406..ba68729 100644 --- a/tdapi/color_rule.go +++ b/tdapi/tdforms/color_rule.go @@ -1,4 +1,4 @@ -package tdapi +package tdforms // Task color rule form type ColorRule struct { diff --git a/tdapi/contact.go b/tdapi/tdforms/contact.go similarity index 91% rename from tdapi/contact.go rename to tdapi/tdforms/contact.go index dd2a075..18e6e85 100644 --- a/tdapi/contact.go +++ b/tdapi/tdforms/contact.go @@ -1,22 +1,7 @@ -package tdapi +package tdforms import "github.com/tada-team/tdproto" -// Paginated contacts -type Contacts struct { - // Contacts list - Objects []tdproto.Contact `json:"objects"` - - // Count - Count int `json:"count"` - - // Limit - Limit int `json:"limit"` - - // Offset - Offset int `json:"offset"` -} - // Contact invite/edit form type Contact struct { // User uid (for invitation from other team) diff --git a/tdapi/device.go b/tdapi/tdforms/device_ping.go similarity index 87% rename from tdapi/device.go rename to tdapi/tdforms/device_ping.go index 5769dd3..dfdc659 100644 --- a/tdapi/device.go +++ b/tdapi/tdforms/device_ping.go @@ -1,4 +1,4 @@ -package tdapi +package tdforms // Device ping response type DevicePing struct { diff --git a/tdapi/tdforms/draft.go b/tdapi/tdforms/draft.go new file mode 100644 index 0000000..a3a0f14 --- /dev/null +++ b/tdapi/tdforms/draft.go @@ -0,0 +1,7 @@ +package tdforms + +// Draft form +type Draft struct { + // Draft content + DraftContent string `json:"draft"` +} diff --git a/tdapi/group.go b/tdapi/tdforms/group.go similarity index 86% rename from tdapi/group.go rename to tdapi/tdforms/group.go index 595cc47..9ace064 100644 --- a/tdapi/group.go +++ b/tdapi/tdforms/group.go @@ -1,13 +1,7 @@ -package tdapi +package tdforms import "github.com/tada-team/tdproto" -// Group members -type GroupMembers struct { - // Group members lust - Members []tdproto.GroupMembership `json:"members"` -} - // Group form type Group struct { // Group title diff --git a/tdapi/integration.go b/tdapi/tdforms/integration.go similarity index 92% rename from tdapi/integration.go rename to tdapi/tdforms/integration.go index a7ff85d..9446010 100644 --- a/tdapi/integration.go +++ b/tdapi/tdforms/integration.go @@ -1,7 +1,8 @@ -package tdapi +package tdforms import "github.com/tada-team/tdproto" +// Integration type Integration struct { // Enabled Enabled bool `json:"enabled"` diff --git a/tdapi/tdforms/message_creation.go b/tdapi/tdforms/message_creation.go new file mode 100644 index 0000000..6f73b45 --- /dev/null +++ b/tdapi/tdforms/message_creation.go @@ -0,0 +1,23 @@ +package tdforms + +import "github.com/tada-team/tdproto" + +// Message creation form +type MessageCreation struct { + // Message type + Type tdproto.Mediatype `json:"type"` + + // Message text + Text string `json:"text"` + + // Message id + MessageUid string `json:"message_id,omitempty"` + + // Message attachments + Uploads []string `json:"uploads,omitempty"` + + // Backward compatibility mode + OldStyleAttachment bool `json:"old_style_attachment,omitempty"` + + MessageUpdate +} diff --git a/tdapi/tdforms/message_update.go b/tdapi/tdforms/message_update.go new file mode 100644 index 0000000..a01d551 --- /dev/null +++ b/tdapi/tdforms/message_update.go @@ -0,0 +1,13 @@ +package tdforms + +// Update message form +type MessageUpdate struct { + // Important flag. Not required. Default: false + Important bool `json:"important,omitempty"` + + // Disable links preview generation. Not required. Default: false + Nopreview bool `json:"nopreview,omitempty"` + + // Draft message, send later + SendAt string `json:"send_at,omitempty"` +} diff --git a/tdapi/tdforms/task.go b/tdapi/tdforms/task.go new file mode 100644 index 0000000..0666b4e --- /dev/null +++ b/tdapi/tdforms/task.go @@ -0,0 +1,57 @@ +package tdforms + +import "github.com/tada-team/tdproto" + +// Task form +type Task struct { + // Custom task color + CustomColorIndex *uint16 `json:"custom_color_index,omitempty"` + + // Task description + Description string `json:"description,omitempty"` + + // Task tags + Tags []string `json:"tags,omitempty"` + + // Task section UID + SectionUid string `json:"section,omitempty"` + + // User who follow the task + Observers []tdproto.JID `json:"observers,omitempty"` // TODO: rename to "followers" + + // Items of the task + Items []string `json:"items,omitempty"` + + // User who was assigned the task + Assignee tdproto.JID `json:"assignee,omitempty"` + + // Deadline time, if any + Deadline tdproto.ISODateTimeString `json:"deadline,omitempty"` + + // Is task public + Public bool `json:"public,omitempty"` + + // Fire a reminder at this time + RemindAt tdproto.ISODateTimeString `json:"remind_at,omitempty"` + + // Task status + TaskStatus string `json:"task_status,omitempty"` + + // Task importance + Importance *int `json:"importance,omitempty"` + + // Task urgency + Urgency *int `json:"urgency,omitempty"` + + // Task complexity + Complexity *int `json:"complexity,omitempty"` + + // Time spent + SpentTime *int `json:"spent_time,omitempty"` + + // Linked messages + LinkedMessages []string `json:"linked_messages,omitempty"` // TODO: Message object + + // Task uploads + Uploads []string `json:"uploads,omitempty"` +} diff --git a/tdapi/team.go b/tdapi/tdforms/team.go similarity index 82% rename from tdapi/team.go rename to tdapi/tdforms/team.go index 868fad9..9166cdd 100644 --- a/tdapi/team.go +++ b/tdapi/tdforms/team.go @@ -1,8 +1,6 @@ -package tdapi +package tdforms -import "github.com/tada-team/tdproto" - -// Team response +// Team form type Team struct { // Team name Name string `json:"name"` @@ -37,9 +35,3 @@ type Team struct { // Team pinned Pinned bool `json:"pinned,omitempty"` } - -// Invitation information -type TeamPrejoinInfo struct { - // Short team information - Team tdproto.TeamShort `json:"team"` -} diff --git a/tdapi/chats.go b/tdapi/tdquery/chats.go similarity index 74% rename from tdapi/chats.go rename to tdapi/tdquery/chats.go index cc5e711..586f7bf 100644 --- a/tdapi/chats.go +++ b/tdapi/tdquery/chats.go @@ -1,27 +1,7 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Chats response -type Chats struct { - // Chat list - Objects []tdproto.Chat `json:"objects"` - - // Contacts used in chats - Contacts []tdproto.Contact `json:"contacts,omitempty"` - - // Count - Count int `json:"count"` - - // Limit - Limit int `json:"limit"` - - // Offset - Offset int `json:"offset"` -} +package tdquery // Chat filter -type ChatFilter struct { +type Chats struct { UserParams Paginator diff --git a/tdapi/tdquery/messages.go b/tdapi/tdquery/messages.go new file mode 100644 index 0000000..a01aa75 --- /dev/null +++ b/tdapi/tdquery/messages.go @@ -0,0 +1,63 @@ +package tdquery + +import "github.com/tada-team/tdproto" + +// Message filter +type Messages struct { + UserParams + Paginator + + // ?chat=jid,jid + Chat string `schema:"chat"` + + // ?chat_type=task,group,direct|any (default: any) + ChatType string `schema:"chat_type"` + + // ?sender=jid,jid + Sender string `schema:"sender"` + + // ?has_upload=true|false|any (default: any) + HasUpload string `schema:"has_upload"` + + // ?text=substr + Text string `schema:"text"` + + // ?type=image,video,plain,file + Type tdproto.Mediatype `schema:"type"` + + // ?important=true|any + Important string `schema:"important"` + + // ?date_from=dt (include) + DateFrom string `schema:"date_from"` + + // ?date_to=dt + DateTo string `schema:"date_to"` + + // ?include_deleted=true|false (default: false) + IncludeDeleted string `schema:"include_deleted"` + + // ?gentime_from= + GentimeFrom string `schema:"gentime_from"` + + // ?exact=msgId + Exact string `schema:"exact"` + + // ?unread=(true|false) + Unread string `schema:"unread"` + + // ?old_from=msgId (exclude msgId) + OldFrom string `schema:"old_from"` + + // ?new_from=msgId (exclude msgId) + NewFrom string `schema:"new_from"` + + // ?old_from_inc=msgId (include msgId) + OldFromInc string `schema:"old_from_inc"` + + // ?new_from_inc=msgId (include msgId) + NewFromInc string `schema:"new_from_inc"` + + // ?around=msgId (include msgId) + Around string `schema:"around"` +} diff --git a/tdapi/mixins.go b/tdapi/tdquery/mixins.go similarity index 94% rename from tdapi/mixins.go rename to tdapi/tdquery/mixins.go index d957c4c..1dbafa9 100644 --- a/tdapi/mixins.go +++ b/tdapi/tdquery/mixins.go @@ -1,4 +1,4 @@ -package tdapi +package tdquery type Paginator struct { // Limit diff --git a/tdapi/tdquery/tasks.go b/tdapi/tdquery/tasks.go new file mode 100644 index 0000000..c2a4664 --- /dev/null +++ b/tdapi/tdquery/tasks.go @@ -0,0 +1,67 @@ +package tdquery + +// Query parameters for listing messages +type Tasks struct { + UserParams + Paginator + + //* ?sort = [ "created" | "-created" | "last_message" | "-last_message" | "deadline" | "-deadline" ] + Sort string `schema:"sort"` + + //* ?task_status = new,done | new | any + TaskStatus string `schema:"task_status"` + + //* ?exclude_task_status = new,done | new | any + ExcludeTaskStatus string `schema:"exclude_task_status"` + + //* ?num=num1,num2,num3... + Num string `schema:"num"` + + //* ?observer=jid,jid // TODO: rename to ?follower= + Observer string `schema:"observer"` + + //* ?member=jid,jid + Member string `schema:"member"` + + //* ?assignee=jid,jid + Assignee string `schema:"assignee"` + + //* ?owner=jid,jid + Owner string `schema:"owner"` + + //* ?section=[ uid,uid... | "-" ] + Section string `schema:"section"` // TODO: rename to ?project= + + //* ?tag=[ tag,tag,tag... | "-" ] + Tag string `schema:"tag"` + + //* ?q= + Q string `schema:"q"` + + //* ?public=true|false + Public string `schema:"public"` + + //* ?deadline_gte= + DeadlineGTE string `schema:"deadline_gte"` + + //* ?deadline_lte= + DeadlineLTE string `schema:"deadline_lte"` + + //* ?done_gte= + DoneGTE string `schema:"done_gte"` + + //* ?done_lte= + DoneLTE string `schema:"done_lte"` + + //* ?created_gte= + CreatedGTE string `schema:"created_gte"` + + //* ?created_lte= + CreatedLTE string `schema:"created_lte"` + + //* ?short=true|false + Short string `schema:"short"` + + // gentime great than group/chat + GentimeGT int64 `schema:"gentime_gt"` +} diff --git a/tdapi/tdquery/uploads.go b/tdapi/tdquery/uploads.go new file mode 100644 index 0000000..6d39515 --- /dev/null +++ b/tdapi/tdquery/uploads.go @@ -0,0 +1,23 @@ +package tdquery + +import "github.com/tada-team/tdproto" + +// Uploads filter +type Uploads struct { + Paginator + + // Comma separated chat jids + Chat string `schema:"chat"` + + // Comma separated sender jids + Sender string `schema:"sender"` + + // Content type + ContentType string `schema:"content_type"` + + // Comma separated Mediatypes + Type tdproto.Mediatype `schema:"type"` + + // Search string + Text string `schema:"text"` +} diff --git a/tdapi/background_action.go b/tdapi/tdresp/background_action.go similarity index 90% rename from tdapi/background_action.go rename to tdapi/tdresp/background_action.go index 2f8eff1..09a945d 100644 --- a/tdapi/background_action.go +++ b/tdapi/tdresp/background_action.go @@ -1,4 +1,4 @@ -package tdapi +package tdresp // Background action (for example: Excel import) information type BackgroundAction struct { diff --git a/tdapi/tdresp/chat_messages.go b/tdapi/tdresp/chat_messages.go new file mode 100644 index 0000000..5f41919 --- /dev/null +++ b/tdapi/tdresp/chat_messages.go @@ -0,0 +1,9 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Chat messages +type ChatMessages struct { + // Message list + Messages []tdproto.Message `json:"messages"` +} diff --git a/tdapi/tdresp/chats.go b/tdapi/tdresp/chats.go new file mode 100644 index 0000000..4e84121 --- /dev/null +++ b/tdapi/tdresp/chats.go @@ -0,0 +1,21 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Chats response +type Chats struct { + // Chat list + Objects []tdproto.Chat `json:"objects"` + + // Contacts used in chats + Contacts []tdproto.Contact `json:"contacts,omitempty"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} diff --git a/tdapi/tdresp/contacts.go b/tdapi/tdresp/contacts.go new file mode 100644 index 0000000..d063eee --- /dev/null +++ b/tdapi/tdresp/contacts.go @@ -0,0 +1,18 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Paginated contacts +type Contacts struct { + // Contacts list + Objects []tdproto.Contact `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} diff --git a/tdapi/draft.go b/tdapi/tdresp/draft.go similarity index 91% rename from tdapi/draft.go rename to tdapi/tdresp/draft.go index dbc78e0..131ec2d 100644 --- a/tdapi/draft.go +++ b/tdapi/tdresp/draft.go @@ -1,8 +1,8 @@ -package tdapi +package tdresp import "github.com/tada-team/tdproto" -// Draft form and response +// Draft response type Draft struct { // Draft content Draft string `json:"draft"` diff --git a/tdapi/emoji.go b/tdapi/tdresp/emoji.go similarity index 89% rename from tdapi/emoji.go rename to tdapi/tdresp/emoji.go index ea7b2db..f8c314b 100644 --- a/tdapi/emoji.go +++ b/tdapi/tdresp/emoji.go @@ -1,4 +1,4 @@ -package tdapi +package tdresp import "github.com/tada-team/tdproto" diff --git a/tdapi/tdresp/group_members.go b/tdapi/tdresp/group_members.go new file mode 100644 index 0000000..dc54a8f --- /dev/null +++ b/tdapi/tdresp/group_members.go @@ -0,0 +1,9 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Group members +type GroupMembers struct { + // Group members lust + Members []tdproto.GroupMembership `json:"members"` +} diff --git a/tdapi/tdresp/hotmessages.go b/tdapi/tdresp/hotmessages.go new file mode 100644 index 0000000..f238100 --- /dev/null +++ b/tdapi/tdresp/hotmessages.go @@ -0,0 +1,15 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// All-in-one response with all messages info for fast chat rendering +type Hotmessages struct { + // chat information + Chat tdproto.Chat `json:"chat"` + + // Messages list + Messages []tdproto.Message `json:"messages"` + + // Contacts list + Contacts []tdproto.Contact `json:"contacts"` +} diff --git a/tdapi/tdresp/message_markup.go b/tdapi/tdresp/message_markup.go new file mode 100644 index 0000000..1dec3bd --- /dev/null +++ b/tdapi/tdresp/message_markup.go @@ -0,0 +1,12 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Message markup with checked links +type MessageMarkup struct { + // Message markup + Markup []tdproto.MarkupEntity `json:"markup"` + + // Deprecated: use markup instead + Links tdproto.MessageLinks `json:"links"` +} diff --git a/tdapi/tdresp/messages.go b/tdapi/tdresp/messages.go new file mode 100644 index 0000000..cf21431 --- /dev/null +++ b/tdapi/tdresp/messages.go @@ -0,0 +1,19 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Messages response +type Messages struct { + // Message list + Objects []tdproto.Message `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} + diff --git a/tdapi/my_reactions.go b/tdapi/tdresp/my_reactions.go similarity index 94% rename from tdapi/my_reactions.go rename to tdapi/tdresp/my_reactions.go index 7cc203f..b0a3518 100644 --- a/tdapi/my_reactions.go +++ b/tdapi/tdresp/my_reactions.go @@ -1,4 +1,4 @@ -package tdapi +package tdresp import "github.com/tada-team/tdproto" diff --git a/tdapi/releases.go b/tdapi/tdresp/releases.go similarity index 56% rename from tdapi/releases.go rename to tdapi/tdresp/releases.go index 8b4f28f..9131bb6 100644 --- a/tdapi/releases.go +++ b/tdapi/tdresp/releases.go @@ -1,4 +1,4 @@ -package tdapi +package tdresp import "github.com/tada-team/tdproto" @@ -8,11 +8,11 @@ type Releases struct { Android []tdproto.Dist `json:"android,omitempty"` // Linux dist - Linux []tdproto.Dist `json:"linux,omitempty"` + Linux []tdproto.Dist `json:"linux,omitempty"` // macOS dist - Mac []tdproto.Dist `json:"mac,omitempty"` + Mac []tdproto.Dist `json:"mac,omitempty"` // Windows dist - Win []tdproto.Dist `json:"win,omitempty"` + Win []tdproto.Dist `json:"win,omitempty"` } diff --git a/tdapi/sms_code.go b/tdapi/tdresp/sms_code.go similarity index 96% rename from tdapi/sms_code.go rename to tdapi/tdresp/sms_code.go index e566a67..e0cb319 100644 --- a/tdapi/sms_code.go +++ b/tdapi/tdresp/sms_code.go @@ -1,4 +1,4 @@ -package tdapi +package tdresp import "github.com/tada-team/tdproto" diff --git a/tdapi/tdresp/task_colors.go b/tdapi/tdresp/task_colors.go new file mode 100644 index 0000000..d7fa87b --- /dev/null +++ b/tdapi/tdresp/task_colors.go @@ -0,0 +1,10 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Task cards colors +type TaskColors struct { + // Color list + Colors []tdproto.TaskColor `json:"colors"` +} + diff --git a/tdapi/tdresp/team_prejoin_info.go b/tdapi/tdresp/team_prejoin_info.go new file mode 100644 index 0000000..4b098ae --- /dev/null +++ b/tdapi/tdresp/team_prejoin_info.go @@ -0,0 +1,9 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Invitation information +type TeamPrejoinInfo struct { + // Short team information + Team tdproto.TeamShort `json:"team"` +} diff --git a/tdapi/timezones.go b/tdapi/tdresp/timezones.go similarity index 72% rename from tdapi/timezones.go rename to tdapi/tdresp/timezones.go index adf6fd2..c41d9df 100644 --- a/tdapi/timezones.go +++ b/tdapi/tdresp/timezones.go @@ -1,6 +1,7 @@ -package tdapi +package tdresp // Timezones response type Timezones struct { + // Timezones list Timezones []string `json:"timezones"` } diff --git a/tdapi/tdresp/upload_short_messages.go b/tdapi/tdresp/upload_short_messages.go new file mode 100644 index 0000000..9634b19 --- /dev/null +++ b/tdapi/tdresp/upload_short_messages.go @@ -0,0 +1,18 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +// Upload + ShortMessage objects +type UploadShortMessages struct { + // Upload + ShortMessage objects list + Objects []tdproto.UploadShortMessage `json:"objects"` + + // Count + Count int `json:"count"` + + // Limit + Limit int `json:"limit"` + + // Offset + Offset int `json:"offset"` +} diff --git a/tdapi/upload.go b/tdapi/upload.go deleted file mode 100644 index ccb29df..0000000 --- a/tdapi/upload.go +++ /dev/null @@ -1,38 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Uploads filter -type UploadFilter struct { - Paginator - - // ?chat=jid,jid - Chat string `schema:"chat"` - - // ?sender=jid,jid - Sender string `schema:"sender"` - - // ?content_type=image/jpeg - ContentType string `schema:"content_type"` - - // ?type=file,image,audio,video - Type tdproto.Mediatype `schema:"type"` - - // ?text=substr - Text string `schema:"text"` -} - -// Upload + ShortMessage objects -type UploadShortMessages struct { - // Upload + ShortMessage objects list - Objects []tdproto.UploadShortMessage `json:"objects"` - - // Count - Count int `json:"count"` - - // Limit - Limit int `json:"limit"` - - // Offset - Offset int `json:"offset"` -} From de2a5fc6881ed517fccb3f653972ba2a86824157 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Fri, 23 Jul 2021 15:02:50 +0300 Subject: [PATCH 11/35] tdapi/tdforms -> tdforms --- {tdapi/tdforms => tdforms}/color_rule.go | 0 {tdapi/tdforms => tdforms}/contact.go | 0 {tdapi/tdforms => tdforms}/device_ping.go | 0 {tdapi/tdforms => tdforms}/draft.go | 0 {tdapi/tdforms => tdforms}/group.go | 0 {tdapi/tdforms => tdforms}/integration.go | 0 {tdapi/tdforms => tdforms}/message_creation.go | 0 {tdapi/tdforms => tdforms}/message_update.go | 0 {tdapi/tdforms => tdforms}/task.go | 0 {tdapi/tdforms => tdforms}/team.go | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {tdapi/tdforms => tdforms}/color_rule.go (100%) rename {tdapi/tdforms => tdforms}/contact.go (100%) rename {tdapi/tdforms => tdforms}/device_ping.go (100%) rename {tdapi/tdforms => tdforms}/draft.go (100%) rename {tdapi/tdforms => tdforms}/group.go (100%) rename {tdapi/tdforms => tdforms}/integration.go (100%) rename {tdapi/tdforms => tdforms}/message_creation.go (100%) rename {tdapi/tdforms => tdforms}/message_update.go (100%) rename {tdapi/tdforms => tdforms}/task.go (100%) rename {tdapi/tdforms => tdforms}/team.go (100%) diff --git a/tdapi/tdforms/color_rule.go b/tdforms/color_rule.go similarity index 100% rename from tdapi/tdforms/color_rule.go rename to tdforms/color_rule.go diff --git a/tdapi/tdforms/contact.go b/tdforms/contact.go similarity index 100% rename from tdapi/tdforms/contact.go rename to tdforms/contact.go diff --git a/tdapi/tdforms/device_ping.go b/tdforms/device_ping.go similarity index 100% rename from tdapi/tdforms/device_ping.go rename to tdforms/device_ping.go diff --git a/tdapi/tdforms/draft.go b/tdforms/draft.go similarity index 100% rename from tdapi/tdforms/draft.go rename to tdforms/draft.go diff --git a/tdapi/tdforms/group.go b/tdforms/group.go similarity index 100% rename from tdapi/tdforms/group.go rename to tdforms/group.go diff --git a/tdapi/tdforms/integration.go b/tdforms/integration.go similarity index 100% rename from tdapi/tdforms/integration.go rename to tdforms/integration.go diff --git a/tdapi/tdforms/message_creation.go b/tdforms/message_creation.go similarity index 100% rename from tdapi/tdforms/message_creation.go rename to tdforms/message_creation.go diff --git a/tdapi/tdforms/message_update.go b/tdforms/message_update.go similarity index 100% rename from tdapi/tdforms/message_update.go rename to tdforms/message_update.go diff --git a/tdapi/tdforms/task.go b/tdforms/task.go similarity index 100% rename from tdapi/tdforms/task.go rename to tdforms/task.go diff --git a/tdapi/tdforms/team.go b/tdforms/team.go similarity index 100% rename from tdapi/tdforms/team.go rename to tdforms/team.go From 38d3e5661c30194298027fd9d95cfb3642c358f9 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Fri, 23 Jul 2021 15:04:19 +0300 Subject: [PATCH 12/35] tdapi/tdresp -> tdresp --- tdforms/Readme.md | 1 + tdresp/Readme.md | 1 + {tdapi/tdresp => tdresp}/background_action.go | 0 {tdapi/tdresp => tdresp}/chat_messages.go | 0 {tdapi/tdresp => tdresp}/chats.go | 0 {tdapi/tdresp => tdresp}/contacts.go | 0 {tdapi/tdresp => tdresp}/draft.go | 0 {tdapi/tdresp => tdresp}/emoji.go | 0 {tdapi/tdresp => tdresp}/group_members.go | 0 {tdapi/tdresp => tdresp}/hotmessages.go | 0 {tdapi/tdresp => tdresp}/message_markup.go | 0 {tdapi/tdresp => tdresp}/messages.go | 0 {tdapi/tdresp => tdresp}/my_reactions.go | 0 {tdapi/tdresp => tdresp}/releases.go | 0 {tdapi/tdresp => tdresp}/sms_code.go | 0 {tdapi/tdresp => tdresp}/task_colors.go | 0 {tdapi/tdresp => tdresp}/team_prejoin_info.go | 0 {tdapi/tdresp => tdresp}/timezones.go | 0 {tdapi/tdresp => tdresp}/upload_short_messages.go | 0 19 files changed, 2 insertions(+) create mode 100644 tdforms/Readme.md create mode 100644 tdresp/Readme.md rename {tdapi/tdresp => tdresp}/background_action.go (100%) rename {tdapi/tdresp => tdresp}/chat_messages.go (100%) rename {tdapi/tdresp => tdresp}/chats.go (100%) rename {tdapi/tdresp => tdresp}/contacts.go (100%) rename {tdapi/tdresp => tdresp}/draft.go (100%) rename {tdapi/tdresp => tdresp}/emoji.go (100%) rename {tdapi/tdresp => tdresp}/group_members.go (100%) rename {tdapi/tdresp => tdresp}/hotmessages.go (100%) rename {tdapi/tdresp => tdresp}/message_markup.go (100%) rename {tdapi/tdresp => tdresp}/messages.go (100%) rename {tdapi/tdresp => tdresp}/my_reactions.go (100%) rename {tdapi/tdresp => tdresp}/releases.go (100%) rename {tdapi/tdresp => tdresp}/sms_code.go (100%) rename {tdapi/tdresp => tdresp}/task_colors.go (100%) rename {tdapi/tdresp => tdresp}/team_prejoin_info.go (100%) rename {tdapi/tdresp => tdresp}/timezones.go (100%) rename {tdapi/tdresp => tdresp}/upload_short_messages.go (100%) diff --git a/tdforms/Readme.md b/tdforms/Readme.md new file mode 100644 index 0000000..0990c06 --- /dev/null +++ b/tdforms/Readme.md @@ -0,0 +1 @@ +HTTP API forms diff --git a/tdresp/Readme.md b/tdresp/Readme.md new file mode 100644 index 0000000..19c86ec --- /dev/null +++ b/tdresp/Readme.md @@ -0,0 +1 @@ +HTTP API responses diff --git a/tdapi/tdresp/background_action.go b/tdresp/background_action.go similarity index 100% rename from tdapi/tdresp/background_action.go rename to tdresp/background_action.go diff --git a/tdapi/tdresp/chat_messages.go b/tdresp/chat_messages.go similarity index 100% rename from tdapi/tdresp/chat_messages.go rename to tdresp/chat_messages.go diff --git a/tdapi/tdresp/chats.go b/tdresp/chats.go similarity index 100% rename from tdapi/tdresp/chats.go rename to tdresp/chats.go diff --git a/tdapi/tdresp/contacts.go b/tdresp/contacts.go similarity index 100% rename from tdapi/tdresp/contacts.go rename to tdresp/contacts.go diff --git a/tdapi/tdresp/draft.go b/tdresp/draft.go similarity index 100% rename from tdapi/tdresp/draft.go rename to tdresp/draft.go diff --git a/tdapi/tdresp/emoji.go b/tdresp/emoji.go similarity index 100% rename from tdapi/tdresp/emoji.go rename to tdresp/emoji.go diff --git a/tdapi/tdresp/group_members.go b/tdresp/group_members.go similarity index 100% rename from tdapi/tdresp/group_members.go rename to tdresp/group_members.go diff --git a/tdapi/tdresp/hotmessages.go b/tdresp/hotmessages.go similarity index 100% rename from tdapi/tdresp/hotmessages.go rename to tdresp/hotmessages.go diff --git a/tdapi/tdresp/message_markup.go b/tdresp/message_markup.go similarity index 100% rename from tdapi/tdresp/message_markup.go rename to tdresp/message_markup.go diff --git a/tdapi/tdresp/messages.go b/tdresp/messages.go similarity index 100% rename from tdapi/tdresp/messages.go rename to tdresp/messages.go diff --git a/tdapi/tdresp/my_reactions.go b/tdresp/my_reactions.go similarity index 100% rename from tdapi/tdresp/my_reactions.go rename to tdresp/my_reactions.go diff --git a/tdapi/tdresp/releases.go b/tdresp/releases.go similarity index 100% rename from tdapi/tdresp/releases.go rename to tdresp/releases.go diff --git a/tdapi/tdresp/sms_code.go b/tdresp/sms_code.go similarity index 100% rename from tdapi/tdresp/sms_code.go rename to tdresp/sms_code.go diff --git a/tdapi/tdresp/task_colors.go b/tdresp/task_colors.go similarity index 100% rename from tdapi/tdresp/task_colors.go rename to tdresp/task_colors.go diff --git a/tdapi/tdresp/team_prejoin_info.go b/tdresp/team_prejoin_info.go similarity index 100% rename from tdapi/tdresp/team_prejoin_info.go rename to tdresp/team_prejoin_info.go diff --git a/tdapi/tdresp/timezones.go b/tdresp/timezones.go similarity index 100% rename from tdapi/tdresp/timezones.go rename to tdresp/timezones.go diff --git a/tdapi/tdresp/upload_short_messages.go b/tdresp/upload_short_messages.go similarity index 100% rename from tdapi/tdresp/upload_short_messages.go rename to tdresp/upload_short_messages.go From b37363dec22722f70a5146028a7b0f7752a7a20f Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Fri, 23 Jul 2021 15:06:08 +0300 Subject: [PATCH 13/35] tdapi/tdquery -> tdquery --- tdforms/Readme.md | 2 +- tdmocks/Readme.md | 1 + tdquery/Readme.md | 1 + {tdapi/tdquery => tdquery}/chats.go | 0 {tdapi/tdquery => tdquery}/messages.go | 0 {tdapi/tdquery => tdquery}/mixins.go | 0 {tdapi/tdquery => tdquery}/tasks.go | 0 {tdapi/tdquery => tdquery}/uploads.go | 0 tdresp/Readme.md | 2 +- 9 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tdmocks/Readme.md create mode 100644 tdquery/Readme.md rename {tdapi/tdquery => tdquery}/chats.go (100%) rename {tdapi/tdquery => tdquery}/messages.go (100%) rename {tdapi/tdquery => tdquery}/mixins.go (100%) rename {tdapi/tdquery => tdquery}/tasks.go (100%) rename {tdapi/tdquery => tdquery}/uploads.go (100%) diff --git a/tdforms/Readme.md b/tdforms/Readme.md index 0990c06..081887b 100644 --- a/tdforms/Readme.md +++ b/tdforms/Readme.md @@ -1 +1 @@ -HTTP API forms +HTTP API forms. diff --git a/tdmocks/Readme.md b/tdmocks/Readme.md new file mode 100644 index 0000000..4e850eb --- /dev/null +++ b/tdmocks/Readme.md @@ -0,0 +1 @@ +Mock objects collection. diff --git a/tdquery/Readme.md b/tdquery/Readme.md new file mode 100644 index 0000000..cba4e24 --- /dev/null +++ b/tdquery/Readme.md @@ -0,0 +1 @@ +HTTP API filters. diff --git a/tdapi/tdquery/chats.go b/tdquery/chats.go similarity index 100% rename from tdapi/tdquery/chats.go rename to tdquery/chats.go diff --git a/tdapi/tdquery/messages.go b/tdquery/messages.go similarity index 100% rename from tdapi/tdquery/messages.go rename to tdquery/messages.go diff --git a/tdapi/tdquery/mixins.go b/tdquery/mixins.go similarity index 100% rename from tdapi/tdquery/mixins.go rename to tdquery/mixins.go diff --git a/tdapi/tdquery/tasks.go b/tdquery/tasks.go similarity index 100% rename from tdapi/tdquery/tasks.go rename to tdquery/tasks.go diff --git a/tdapi/tdquery/uploads.go b/tdquery/uploads.go similarity index 100% rename from tdapi/tdquery/uploads.go rename to tdquery/uploads.go diff --git a/tdresp/Readme.md b/tdresp/Readme.md index 19c86ec..f2769d2 100644 --- a/tdresp/Readme.md +++ b/tdresp/Readme.md @@ -1 +1 @@ -HTTP API responses +HTTP API responses. From 61c0e80a13688c663b9323f1476db89f20d8afe1 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Fri, 23 Jul 2021 15:13:26 +0300 Subject: [PATCH 14/35] tdapi remove --- 2fa.go | 9 +++ tdapi/Readme.md | 1 - tdapi/auth.go | 105 --------------------------------- tdapi/resp.go | 27 --------- tdforms/2fa.go | 68 +++++++++++++++++++++ {tdapi => tdforms}/calls.go | 2 +- tdresp/2fa.go | 31 ++++++++++ tdapi/err.go => tdresp/base.go | 28 ++++++++- 8 files changed, 136 insertions(+), 135 deletions(-) create mode 100644 2fa.go delete mode 100644 tdapi/Readme.md delete mode 100644 tdapi/auth.go delete mode 100644 tdapi/resp.go create mode 100644 tdforms/2fa.go rename {tdapi => tdforms}/calls.go (98%) create mode 100644 tdresp/2fa.go rename tdapi/err.go => tdresp/base.go (58%) diff --git a/2fa.go b/2fa.go new file mode 100644 index 0000000..1690e0e --- /dev/null +++ b/2fa.go @@ -0,0 +1,9 @@ +package tdproto + +// RecoveryStatus: +const ( + Unknown2fa = "unknown" + Unconfirmed2fa = "unconfirmed" + Confirmed2fa = "confirmed" + Declined2fa = "declined" +) diff --git a/tdapi/Readme.md b/tdapi/Readme.md deleted file mode 100644 index ce555c0..0000000 --- a/tdapi/Readme.md +++ /dev/null @@ -1 +0,0 @@ -HTTP API structures diff --git a/tdapi/auth.go b/tdapi/auth.go deleted file mode 100644 index dfe59f0..0000000 --- a/tdapi/auth.go +++ /dev/null @@ -1,105 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// RecoveryStatus: -const ( - Unknown2fa = "unknown" - Unconfirmed2fa = "unconfirmed" - Confirmed2fa = "confirmed" - Declined2fa = "declined" -) - -type Auth struct { - Token string `json:"token,omitempty"` - Me tdproto.UserWithMe `json:"me"` - Required2fa bool `json:"required2fa"` - Recovery2fa bool `json:"recovery2fa"` - Method2fa string `json:"method2fa"` -} - -type Auth2faSettingsResponse struct { - Enabled bool `json:"enabled"` - RecoveryStatus string `json:"recovery_status"` -} - -type Auth2faMailRecovery struct { - CodeValidUntil tdproto.ISODateTimeString `json:"code_valid_until"` - NextCodeAt tdproto.ISODateTimeString `json:"next_code_at"` - CodeLength int `json:"code_length"` - Email string `json:"email"` -} - -type Auth2faSettingsMailValidation struct { - Enabled bool `json:"enabled"` - RecoveryStatus string `json:"recovery_status"` - CodeValidUntil tdproto.ISODateTimeString `json:"code_valid_until"` - NextCodeAt string `json:"next_code_at"` - CodeLength int `json:"code_length"` -} - -type basicPasswordUpdate struct { - NewPassword string `json:"new_password"` - NewPasswordRepeat string `json:"new_password_repeat"` - Hint string `json:"hint"` -} - -type basicToken struct { - Token string `json:"token"` -} - -type basicPassword struct { - Password string `json:"password"` -} - -type basicEmail struct { - Email string `json:"email"` -} - -type basicCode struct { - Code string `json:"code"` -} - -type Auth2faForm struct { - basicToken - basicPassword -} - -type Create2faPasswordForm struct { - basicPasswordUpdate -} - -type Update2faPasswordForm struct { - basicPasswordUpdate - basicPassword -} - -type Internal2faPasswordForm struct { - basicPassword -} - -type SendMail2faConfirmForm struct { - basicPassword - basicEmail -} - -type ConfirmMail2faForm struct { - basicPassword - basicCode - basicEmail -} - -type AuthToken2faForm struct { - basicToken -} - -type AuthCheckCode2faForm struct { - basicToken - basicCode -} - -type AuthPasswordRecovery2faForm struct { - basicPasswordUpdate - basicToken - basicCode -} diff --git a/tdapi/resp.go b/tdapi/resp.go deleted file mode 100644 index 151feea..0000000 --- a/tdapi/resp.go +++ /dev/null @@ -1,27 +0,0 @@ -package tdapi - -import "github.com/tada-team/tdproto" - -// Server response -type Resp struct { - // Request status - Ok bool `json:"ok"` - - // Result only if ok is true) - Result interface{} `json:"result,omitempty"` - - // Error (only if ok is false) - Error Err `json:"error,omitempty"` - - // Error (only if ok is false and Error is 'InvalidData') - Details map[string]string `json:"details,omitempty"` - - // Reason (only if ok is false and Error is `AccessDenied`) - Reason string `json:"reason,omitempty"` - - // Reason markup (only if ok is false and Error is `AccessDenied`) - Markup []tdproto.MarkupEntity `json:"markup,omitempty"` - - // Server side work time - DebugTime string `json:"_time,omitempty"` -} diff --git a/tdforms/2fa.go b/tdforms/2fa.go new file mode 100644 index 0000000..dc8e42a --- /dev/null +++ b/tdforms/2fa.go @@ -0,0 +1,68 @@ +package tdforms + + +type basicPasswordUpdate struct { + NewPassword string `json:"new_password"` + NewPasswordRepeat string `json:"new_password_repeat"` + Hint string `json:"hint"` +} + +type basicToken struct { + Token string `json:"token"` +} + +type basicPassword struct { + Password string `json:"password"` +} + +type basicEmail struct { + Email string `json:"email"` +} + +type basicCode struct { + Code string `json:"code"` +} + +type Auth2faForm struct { + basicToken + basicPassword +} + +type Create2faPasswordForm struct { + basicPasswordUpdate +} + +type Update2faPasswordForm struct { + basicPasswordUpdate + basicPassword +} + +type Internal2faPasswordForm struct { + basicPassword +} + +type SendMail2faConfirmForm struct { + basicPassword + basicEmail +} + +type ConfirmMail2faForm struct { + basicPassword + basicCode + basicEmail +} + +type AuthToken2faForm struct { + basicToken +} + +type AuthCheckCode2faForm struct { + basicToken + basicCode +} + +type AuthPasswordRecovery2faForm struct { + basicPasswordUpdate + basicToken + basicCode +} diff --git a/tdapi/calls.go b/tdforms/calls.go similarity index 98% rename from tdapi/calls.go rename to tdforms/calls.go index f1bb812..6e265bc 100644 --- a/tdapi/calls.go +++ b/tdforms/calls.go @@ -1,4 +1,4 @@ -package tdapi +package tdforms import "github.com/tada-team/tdproto" diff --git a/tdresp/2fa.go b/tdresp/2fa.go new file mode 100644 index 0000000..18f8d15 --- /dev/null +++ b/tdresp/2fa.go @@ -0,0 +1,31 @@ +package tdresp + +import "github.com/tada-team/tdproto" + +type Auth struct { + Token string `json:"token,omitempty"` + Me tdproto.UserWithMe `json:"me"` + Required2fa bool `json:"required2fa"` + Recovery2fa bool `json:"recovery2fa"` + Method2fa string `json:"method2fa"` +} + +type Auth2faMailRecovery struct { + CodeValidUntil tdproto.ISODateTimeString `json:"code_valid_until"` + NextCodeAt tdproto.ISODateTimeString `json:"next_code_at"` + CodeLength int `json:"code_length"` + Email string `json:"email"` +} + +type Auth2faSettingsResponse struct { + Enabled bool `json:"enabled"` + RecoveryStatus string `json:"recovery_status"` +} + +type Auth2faSettingsMailValidation struct { + Enabled bool `json:"enabled"` + RecoveryStatus string `json:"recovery_status"` + CodeValidUntil tdproto.ISODateTimeString `json:"code_valid_until"` + NextCodeAt string `json:"next_code_at"` + CodeLength int `json:"code_length"` +} diff --git a/tdapi/err.go b/tdresp/base.go similarity index 58% rename from tdapi/err.go rename to tdresp/base.go index 151584d..44c35a3 100644 --- a/tdapi/err.go +++ b/tdresp/base.go @@ -1,4 +1,30 @@ -package tdapi +package tdresp + +import "github.com/tada-team/tdproto" + +// Server response +type Resp struct { + // Request status + Ok bool `json:"ok"` + + // Result only if ok is true) + Result interface{} `json:"result,omitempty"` + + // Error (only if ok is false) + Error Err `json:"error,omitempty"` + + // Error (only if ok is false and Error is 'InvalidData') + Details map[string]string `json:"details,omitempty"` + + // Reason (only if ok is false and Error is `AccessDenied`) + Reason string `json:"reason,omitempty"` + + // Reason markup (only if ok is false and Error is `AccessDenied`) + Markup []tdproto.MarkupEntity `json:"markup,omitempty"` + + // Server side work time + DebugTime string `json:"_time,omitempty"` +} type Err string From e7cb4bef0e6411ed96e96e40b39db9a2e7bcca7f Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Wed, 28 Jul 2021 16:48:49 +0300 Subject: [PATCH 15/35] icons fix --- tdmocks/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdmocks/main.go b/tdmocks/main.go index b8775f0..daf91bc 100644 --- a/tdmocks/main.go +++ b/tdmocks/main.go @@ -37,7 +37,7 @@ var Alice = tdproto.Contact{ ShortName: "Alice S.", ContactEmail: "alice@example.com", ContactPhone: "+7 (555) 000-00-01", - Icons: &StubIcons, + Icons: StubIcons, Role: "manager", Mood: "🤦", TeamStatus: tdproto.TeamMember, From 5840349dddee00175e4c067bddeb71a9a1359f51 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 9 Aug 2021 13:32:01 +0300 Subject: [PATCH 16/35] Moved client activity to tdevents --- client_activity.go => tdevents/client_activity.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename client_activity.go => tdevents/client_activity.go (96%) diff --git a/client_activity.go b/tdevents/client_activity.go similarity index 96% rename from client_activity.go rename to tdevents/client_activity.go index 8b206a8..63f0a8e 100644 --- a/client_activity.go +++ b/tdevents/client_activity.go @@ -1,4 +1,4 @@ -package tdproto +package tdevents func NewClientActivity(afk bool) (r ClientActivity) { r.Name = r.GetName() From 052d81ab69a2b3dbcbe846b7193dd2b3a43f61e8 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 9 Aug 2021 13:32:32 +0300 Subject: [PATCH 17/35] api_paths: Use tdquery package for HTTP Queries --- codegen/api_paths/task.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/codegen/api_paths/task.go b/codegen/api_paths/task.go index 81ae388..0c56dfb 100644 --- a/codegen/api_paths/task.go +++ b/codegen/api_paths/task.go @@ -1,36 +1,37 @@ package api_paths import ( - "github.com/tada-team/tdproto/tdapi" + "github.com/tada-team/tdproto/tdforms" + "github.com/tada-team/tdproto/tdquery" ) var TaskPaths = []PathSpec{ { Path: "/api/v4/teams/{team_id}/tasks", Post: &OperationSpec{ - Request: tdapi.Task{}, - Response: tdapi.Task{}, + Request: tdforms.Task{}, + Response: tdforms.Task{}, Description: "Create new task", }, Get: &OperationSpec{ - QueryStruct: tdapi.TaskFilter{}, - Response: []tdapi.Task{}, + QueryStruct: tdquery.Tasks{}, + Response: []tdforms.Task{}, Description: "Get the list of tasks", }, }, { Path: "/api/v4/teams/{team_id}/tasks/{task_id}", Get: &OperationSpec{ - Response: tdapi.Task{}, + Response: tdforms.Task{}, Description: "Get task", }, Post: &OperationSpec{ - Request: tdapi.Task{}, - Response: tdapi.Task{}, + Request: tdforms.Task{}, + Response: tdforms.Task{}, Description: "Update task", }, Delete: &OperationSpec{ - Response: tdapi.Task{}, + Response: tdforms.Task{}, Description: "Delete task", }, }, From 949ab099bfbc8d678e86f73c96cc074f6854054f Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 9 Aug 2021 13:32:55 +0300 Subject: [PATCH 18/35] codegen: Removed all cherry picking code --- codegen/inspect.go | 103 --------------------------------------------- 1 file changed, 103 deletions(-) diff --git a/codegen/inspect.go b/codegen/inspect.go index b80ba1c..7fa9401 100644 --- a/codegen/inspect.go +++ b/codegen/inspect.go @@ -186,107 +186,9 @@ func ParseTdproto() (infoToFill *TdProto, err error) { return nil, err } - tdapiFileSet := token.NewFileSet() - tdapiNameToAstMap, err := extractTdapiAst(tdapiFileSet) - if err != nil { - return nil, err - } - - tdFormsPackage := new(TdPackage) - tdFormsPackage.TdEvents = make(map[string]string) - tdFormsPackage.TdStructs = make(map[string]TdStruct) - tdFormsPackage.TdTypes = make(map[string]TdType) - tdFormsPackage.TdMapTypes = make(map[string]TdMapType) - - infoToFill.TdForms = tdFormsPackage - - err = parseTdprotoAst(tdapiNameToAstMap["tdapi"], tdFormsPackage, - &map[string]string{ - "task": "", - "my_reactions": "", - "resp": "", - "err": "", - }, - ) - if err != nil { - return nil, err - } - - // Cherry picking - // Task - err = cherryPickStruct(tdModelsPackage, tdFormsPackage, "Task") - if err != nil { - return nil, err - } - // TaskFilter query - err = cherryPickQuery(tdModelsPackage, tdFormsPackage, "TaskFilter") - if err != nil { - return nil, err - } - // MyReactions - err = cherryPickStruct(tdModelsPackage, tdFormsPackage, "MyReactions") - if err != nil { - return nil, err - } - - // Resp - err = cherryPickStruct(tdModelsPackage, tdFormsPackage, "Resp") - if err != nil { - return nil, err - } - - // Err - err = cherryPickTypeAlias(tdModelsPackage, tdFormsPackage, "Err") - if err != nil { - return nil, err - } - return infoToFill, nil } -func cherryPickTypeAlias(tdproto *TdPackage, tdapi *TdPackage, name string) error { - - pickObject, ok := tdapi.TdTypes[name] - if !ok { - return fmt.Errorf("failed to cherry pick query %s", name) - } - tdproto.TdTypes[name] = pickObject - - return nil -} - -func cherryPickQuery(tdproto *TdPackage, tdapi *TdPackage, name string) error { - - pickObject, ok := tdapi.TdStructs[name] - if !ok { - return fmt.Errorf("failed to cherry pick query %s", name) - } - - var newQuery TdQuery - - newQuery.Help = pickObject.Help - newQuery.ParamsNamesAndHelp = make(map[string]string) - newQuery.Name = name - for _, field := range pickObject.Fields { - newQuery.ParamsNamesAndHelp[field.SchemaName] = field.Help - } - - tdproto.TdQueries[name] = newQuery - - return nil -} - -func cherryPickStruct(tdproto *TdPackage, tdapi *TdPackage, name string) error { - - pickObject, ok := tdapi.TdStructs[name] - if !ok { - return fmt.Errorf("failed to cherry pick struct %s", name) - } - tdproto.TdStructs[name] = pickObject - - return nil -} - func parseTdprotoAst(packageAst *ast.Package, infoToFill *TdPackage, fileFilter *map[string]string) error { for fileName, fileAst := range packageAst.Files { @@ -719,11 +621,6 @@ func extractTdprotoAst(fileSet *token.FileSet) (map[string]*ast.Package, error) return parser.ParseDir(fileSet, tdProtoPath, nil, parser.ParseComments) } -func extractTdapiAst(fileSet *token.FileSet) (map[string]*ast.Package, error) { - tdProtoPath := tdproto.SourceDir() - return parser.ParseDir(fileSet, path.Join(tdProtoPath, "tdapi"), nil, parser.ParseComments) -} - func cleanHelp(s string) string { return strings.TrimSuffix(strings.TrimSpace(strings.Join(strings.Fields(s), " ")), ".") } From b576f70a1eba51e04ed54e215505c943458eb0aa Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 10 Aug 2021 19:57:16 +0300 Subject: [PATCH 19/35] spelling fixes --- codegen/inspect.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/codegen/inspect.go b/codegen/inspect.go index 81456fd..ba3e06a 100644 --- a/codegen/inspect.go +++ b/codegen/inspect.go @@ -79,12 +79,12 @@ type TdMapType struct { } type TdPackage struct { - TdStructs map[string]TdStruct - TdTypes map[string]TdType - TdEvents map[string]string - TdMapTypes map[string]TdMapType - TdConsts []TdConstFields - TdQueries map[string]TdQuery + TdStructs map[string]TdStruct + TdTypes map[string]TdType + TdEvents map[string]string + TdMapTypes map[string]TdMapType + TdConstants []TdConstFields + TdQueries map[string]TdQuery } type TdProto struct { @@ -100,7 +100,7 @@ type TdEnum struct { func (i TdPackage) GetEnums() []TdEnum { constMap := make(map[string][]string) - for _, aConst := range i.TdConsts { + for _, aConst := range i.TdConstants { constType := aConst.Type constValue := aConst.Value @@ -145,7 +145,7 @@ func (tds TdStruct) GetStructAnonymousStructs(tdInfo *TdPackage) []TdStruct { anonymousStructs[i] = tdInfo.TdStructs[anonymousStructName] } - // TODO: Deep copy Fields and AnonnymousFields + // TODO: Deep copy Fields and AnonymousFields return anonymousStructs } @@ -250,12 +250,12 @@ func parseFunctionDeclaration(infoToFill *TdPackage, functionDeclaration *ast.Fu } returnStatementAst := functionDeclaration.Body.List[0].(*ast.ReturnStmt) - returnStatemetExpression, ok := returnStatementAst.Results[0].(*ast.BasicLit) + returnStatementExpression, ok := returnStatementAst.Results[0].(*ast.BasicLit) if !ok { return nil } - eventName := strings.Trim(returnStatemetExpression.Value, "\"") + eventName := strings.Trim(returnStatementExpression.Value, "\"") typeIdent := functionDeclaration.Recv.List[0].Type.(*ast.Ident) typeEventBelongsTo := typeIdent.Obj.Name @@ -573,7 +573,7 @@ func parseConstDeclaration(infoToFill *TdPackage, genDeclaration *ast.GenDecl) e return fmt.Errorf("could not extract constant value %+v", valueSpec.Values[0]) } - infoToFill.TdConsts = append(infoToFill.TdConsts, TdConstFields{ + infoToFill.TdConstants = append(infoToFill.TdConstants, TdConstFields{ Name: constName, Type: constTypeName, Value: constValue.Value, @@ -608,8 +608,8 @@ func parseStarAst(starAst *ast.StarExpr) (string, error) { } func parseSelectorAst(selectorNode *ast.SelectorExpr) string { - expresionIdent := selectorNode.X.(*ast.Ident) - expressionStr := expresionIdent.Name + expressionIdent := selectorNode.X.(*ast.Ident) + expressionStr := expressionIdent.Name if expressionStr == "tdproto" { // HACK: when tdapi references tdproto return selectorNode.Sel.Name } From 2c715fa55ada014c4a925bec20e2a1ef1cad6152 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 10 Aug 2021 20:03:45 +0300 Subject: [PATCH 20/35] writeFileFromTemplate debug --- codegen/dart/main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/codegen/dart/main.go b/codegen/dart/main.go index aabf3be..c1789d9 100644 --- a/codegen/dart/main.go +++ b/codegen/dart/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "log" "os" "path" "strings" @@ -128,7 +129,6 @@ func lowercaseFirstOrAll(input string) string { } func writeFileFromTemplate(fileName string, template *template.Template, data interface{}, useExclusive bool) error { - fileFlags := os.O_WRONLY | os.O_CREATE if useExclusive { fileFlags |= os.O_EXCL @@ -149,6 +149,13 @@ func writeFileFromTemplate(fileName string, template *template.Template, data in return err } + b, err := os.ReadFile(fileName) + if err != nil { + return err + } + + log.Printf("writeFileFromTemplate:\n%s\n---", string(b)) + return nil } From 1b16b8f942af9268a61ce710b3d312395012f023 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 10 Aug 2021 20:18:50 +0300 Subject: [PATCH 21/35] debug --- codegen/dart/main.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/codegen/dart/main.go b/codegen/dart/main.go index c1789d9..2587aa1 100644 --- a/codegen/dart/main.go +++ b/codegen/dart/main.go @@ -81,11 +81,14 @@ export 'src/interfaces/i_response.dart'; export 'src/interfaces/i_websocket_event.dart'; // Generated enums: -{{range $value := .GeneratedEnums}}export '{{$value}}'; -{{end}} +{{ range $value := .GeneratedEnums -}} + export '{{ $value }}'; +{{ end }} // Generated models: -{{range $value := .GeneratedModels}}export '{{$value}}'; -{{end}} +{{ range $value := .GeneratedModels -}} + // export '{{ $value }}'; + export '{{ $value }}'; +{{ end }} `)) type DartLibInfo struct { From 758630e19866666a77bdf9fec853fe47922c3c29 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 10 Aug 2021 20:31:46 +0300 Subject: [PATCH 22/35] debug --- codegen/dart/main.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/codegen/dart/main.go b/codegen/dart/main.go index 2587aa1..5410268 100644 --- a/codegen/dart/main.go +++ b/codegen/dart/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "flag" "fmt" "log" @@ -13,9 +14,11 @@ import ( "github.com/tada-team/tdproto/codegen" ) -const libPathPrefix = "./lib/" -const enumsPathPrefix = "./src/enums" -const modelsPathPrefix = "./src/models" +const ( + libPathPrefix = "./lib/" + enumsPathPrefix = "./src/enums" + modelsPathPrefix = "./src/models" +) var dartTypeMap = map[string]string{ "string": "String", @@ -131,23 +134,14 @@ func lowercaseFirstOrAll(input string) string { return strings.ToLower(input) } -func writeFileFromTemplate(fileName string, template *template.Template, data interface{}, useExclusive bool) error { - fileFlags := os.O_WRONLY | os.O_CREATE - if useExclusive { - fileFlags |= os.O_EXCL - } - - file, err := os.OpenFile(fileName, fileFlags, 0o640) - if err != nil { - return err - } - - err = template.Execute(file, data) +func renderToFile(fileName string, template *template.Template, data interface{}) error { + var buf bytes.Buffer + err := template.Execute(&buf, data) if err != nil { return err } - err = file.Close() + err = os.WriteFile(fileName, buf.Bytes(), 0640) if err != nil { return err } @@ -170,7 +164,7 @@ func generateDart(tdprotoInfo *codegen.TdPackage, baseLibPath string) error { enumFilePath := path.Join(enumsPathPrefix, fmt.Sprintf("%s.dart", enumFileName)) libInfo.GeneratedEnums = append(libInfo.GeneratedEnums, enumFilePath) - err := writeFileFromTemplate(path.Join(baseLibPath, enumFilePath), dartEnumTemplate, tdEnum, true) + err := renderToFile(path.Join(baseLibPath, enumFilePath), dartEnumTemplate, tdEnum) if err != nil { return err } @@ -189,13 +183,13 @@ func generateDart(tdprotoInfo *codegen.TdPackage, baseLibPath string) error { return nil } - err = writeFileFromTemplate(path.Join(baseLibPath, dartClassFilePath), dartClassTemplate, dartClass, true) + err = renderToFile(path.Join(baseLibPath, dartClassFilePath), dartClassTemplate, dartClass) if err != nil { return err } } - err := writeFileFromTemplate(path.Join(baseLibPath, "./tdproto_dart.dart"), dartLibTemplate, libInfo, false) + err := renderToFile(path.Join(baseLibPath, "./tdproto_dart.dart"), dartLibTemplate, libInfo) if err != nil { return err } @@ -308,7 +302,7 @@ func main() { flag.Parse() var dartLibPath string - switch len_args := len(flag.Args()); len_args { + switch lenArgs := len(flag.Args()); lenArgs { case 0: newTempDir, err := os.MkdirTemp("", "tdproto_dart") if err != nil { @@ -319,7 +313,7 @@ func main() { case 1: dartLibPath = flag.Arg(0) default: - panic(fmt.Errorf("expected zero or one argument got %d", len_args)) + panic(fmt.Errorf("expected zero or one argument got %d", lenArgs)) } err = createDirectoryStructure(dartLibPath) From e018f14105e2fcaf0e4e50273b1d3b5c4d458893 Mon Sep 17 00:00:00 2001 From: Maxim Oransky Date: Tue, 10 Aug 2021 20:36:28 +0300 Subject: [PATCH 23/35] remove debug --- codegen/dart/main.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/codegen/dart/main.go b/codegen/dart/main.go index 5410268..bf36e08 100644 --- a/codegen/dart/main.go +++ b/codegen/dart/main.go @@ -4,7 +4,6 @@ import ( "bytes" "flag" "fmt" - "log" "os" "path" "strings" @@ -84,14 +83,11 @@ export 'src/interfaces/i_response.dart'; export 'src/interfaces/i_websocket_event.dart'; // Generated enums: -{{ range $value := .GeneratedEnums -}} - export '{{ $value }}'; -{{ end }} +{{range $value := .GeneratedEnums}}export '{{$value}}'; +{{end}} // Generated models: -{{ range $value := .GeneratedModels -}} - // export '{{ $value }}'; - export '{{ $value }}'; -{{ end }} +{{range $value := .GeneratedModels}}export '{{$value}}'; +{{end}} `)) type DartLibInfo struct { @@ -120,7 +116,6 @@ func snakeCaseOrLower(input string) string { return codegen.ToSnakeCase(input) } } - return strings.ToLower(input) } @@ -130,7 +125,6 @@ func lowercaseFirstOrAll(input string) string { return codegen.LowercaseFirstLetter(input) } } - return strings.ToLower(input) } @@ -146,13 +140,6 @@ func renderToFile(fileName string, template *template.Template, data interface{} return err } - b, err := os.ReadFile(fileName) - if err != nil { - return err - } - - log.Printf("writeFileFromTemplate:\n%s\n---", string(b)) - return nil } @@ -292,9 +279,7 @@ func createDirectoryStructure(basePath string) error { } func main() { - tdprotoInfo, err := codegen.ParseTdproto() - if err != nil { panic(err) } @@ -325,5 +310,4 @@ func main() { if err != nil { panic(err) } - } From f02f7bb931b09784f822cbc5b465fe6ba1830f3b Mon Sep 17 00:00:00 2001 From: igo95862 Date: Wed, 11 Aug 2021 10:38:26 +0300 Subject: [PATCH 24/35] dart: Try using exclusive on all files --- codegen/dart/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/codegen/dart/main.go b/codegen/dart/main.go index bf36e08..11c1324 100644 --- a/codegen/dart/main.go +++ b/codegen/dart/main.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "flag" "fmt" "os" @@ -129,13 +128,19 @@ func lowercaseFirstOrAll(input string) string { } func renderToFile(fileName string, template *template.Template, data interface{}) error { - var buf bytes.Buffer - err := template.Execute(&buf, data) + fileFlags := os.O_WRONLY | os.O_CREATE | os.O_EXCL + + file, err := os.OpenFile(fileName, fileFlags, 0o640) + if err != nil { + return err + } + + err = template.Execute(file, data) if err != nil { return err } - err = os.WriteFile(fileName, buf.Bytes(), 0640) + err = file.Close() if err != nil { return err } From 57d6fad1c7df63282c61afd66132e66e4f89f0d0 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Thu, 12 Aug 2021 14:05:15 +0300 Subject: [PATCH 25/35] codegen: Parse tdforms, tdevents and tdquery --- codegen/inspect.go | 67 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/codegen/inspect.go b/codegen/inspect.go index ba3e06a..f745b10 100644 --- a/codegen/inspect.go +++ b/codegen/inspect.go @@ -90,6 +90,8 @@ type TdPackage struct { type TdProto struct { TdForms *TdPackage TdModels *TdPackage + TdEvents *TdPackage + TdQuery *TdPackage } type TdEnum struct { @@ -164,31 +166,52 @@ func (tds TdStruct) GetAllJsonFields(tdInfo *TdPackage) []TdStructField { func ParseTdproto() (infoToFill *TdProto, err error) { infoToFill = new(TdProto) - tdprotoFileSet := token.NewFileSet() + allPackages := make(map[string]*ast.Package) + err = extractTdprotoAst(&allPackages) + if err != nil { + return infoToFill, err + } - tdModelsPackage := new(TdPackage) - tdModelsPackage.TdEvents = make(map[string]string) - tdModelsPackage.TdStructs = make(map[string]TdStruct) - tdModelsPackage.TdTypes = make(map[string]TdType) - tdModelsPackage.TdMapTypes = make(map[string]TdMapType) - tdModelsPackage.TdQueries = make(map[string]TdQuery) + err = createTdProtoPackage(&infoToFill.TdModels, "tdproto", allPackages) + if err != nil { + return infoToFill, err + } - infoToFill.TdModels = tdModelsPackage + err = createTdProtoPackage(&infoToFill.TdForms, "tdforms", allPackages) + if err != nil { + return infoToFill, err + } - tdprotoNameToAstMap, err := extractTdprotoAst(tdprotoFileSet) + err = createTdProtoPackage(&infoToFill.TdEvents, "tdevents", allPackages) if err != nil { - return nil, err + return infoToFill, err } - tdprotoAst := tdprotoNameToAstMap["tdproto"] - err = parseTdprotoAst(tdprotoAst, tdModelsPackage, nil) + err = createTdProtoPackage(&infoToFill.TdQuery, "tdquery", allPackages) if err != nil { - return nil, err + return infoToFill, err } return infoToFill, nil } +func createTdProtoPackage(packageSlot **TdPackage, packageName string, allPackagesAst map[string]*ast.Package) error { + *packageSlot = new(TdPackage) + (*packageSlot).TdEvents = make(map[string]string) + (*packageSlot).TdStructs = make(map[string]TdStruct) + (*packageSlot).TdTypes = make(map[string]TdType) + (*packageSlot).TdMapTypes = make(map[string]TdMapType) + (*packageSlot).TdQueries = make(map[string]TdQuery) + + tdprotoAst := allPackagesAst[packageName] + err := parseTdprotoAst(tdprotoAst, *packageSlot, nil) + if err != nil { + return err + } + + return nil +} + func parseTdprotoAst(packageAst *ast.Package, infoToFill *TdPackage, fileFilter *map[string]string) error { for fileName, fileAst := range packageAst.Files { @@ -616,9 +639,23 @@ func parseSelectorAst(selectorNode *ast.SelectorExpr) string { return expressionStr + "." + selectorNode.Sel.Name } -func extractTdprotoAst(fileSet *token.FileSet) (map[string]*ast.Package, error) { +func extractTdprotoAst(packages *map[string]*ast.Package) error { + tdProtoPath := tdproto.SourceDir() - return parser.ParseDir(fileSet, tdProtoPath, nil, parser.ParseComments) + + for _, packageName := range []string{"", "tdforms", "tdevents", "tdquery"} { + fileSet := token.NewFileSet() + pkgs, err := parser.ParseDir(fileSet, path.Join(tdProtoPath, packageName), nil, parser.ParseComments) + if err != nil { + return err + } + + for key, value := range pkgs { + (*packages)[key] = value + } + } + + return nil } func cleanHelp(s string) string { From 95c8ce7b02b85af063ca04a809fac3d7d1547351 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Wed, 18 Aug 2021 16:24:23 +0300 Subject: [PATCH 26/35] sphinx: Add tdforms structures to data index --- codegen/sphinx/json_index/main.go | 116 ++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 23 deletions(-) diff --git a/codegen/sphinx/json_index/main.go b/codegen/sphinx/json_index/main.go index 4a6f3a0..824fa54 100644 --- a/codegen/sphinx/json_index/main.go +++ b/codegen/sphinx/json_index/main.go @@ -17,7 +17,12 @@ func main() { panic(err) } - err = generateRstJson(tdprotoInfo.TdModels) + err = generateRstJson(tdprotoInfo.TdModels, "tdmodels") + if err != nil { + panic(err) + } + + err = generateRstJson(tdprotoInfo.TdForms, "tdforms") if err != nil { panic(err) } @@ -55,12 +60,23 @@ func (r rstJsonField) GetModifiers() string { type rstJsonStruct struct { codegen.TdStruct - Fields []rstJsonField + Fields []rstJsonField + TdPackage string +} + +type rstEnum struct { + codegen.TdEnum + TdPackage string +} + +type rstType struct { + codegen.TdType + TdPackage string } var jsonTemplate = template.Must(template.New("rstJson").Parse(` .. tdproto:struct:: {{.TdStruct.Name}} - :tdpackage: tdmodels + :tdpackage: {{.TdPackage}} {{.TdStruct.Help}} {{range $field := .Fields}} @@ -69,7 +85,7 @@ var jsonTemplate = template.Must(template.New("rstJson").Parse(` var enumTemplate = template.Must(template.New("rstEnum").Parse(` .. tdproto:enum:: {{.Name}} - :tdpackage: tdmodels + :tdpackage: {{.TdPackage}} **Possible values**: {{range $value := .Values}} @@ -79,7 +95,7 @@ var enumTemplate = template.Must(template.New("rstEnum").Parse(` var typeAliasTemplate = template.Must(template.New("rstType").Parse(` .. tdproto:type:: {{.Name}} - :tdpackage: tdmodels + :tdpackage: {{.TdPackage}} {{if .Help}} {{.Help}} @@ -109,46 +125,60 @@ func isEventStruct(structName string, tdprotoInfo *codegen.TdPackage) bool { return isEvent } -func generateRstJson(tdprotoInfo *codegen.TdPackage) error { +func generateEnumsRst(enumsList []codegen.TdEnum, tdPackageName string, enumedTypeAliases *map[string]string) error { - enumedTypeAliases := make(map[string]string) + fmt.Fprintf(os.Stdout, "\n%s enums index\n============================\n", tdPackageName) - fmt.Fprintln(os.Stdout, "\nEnums index\n============================") - enumsList := tdprotoInfo.GetEnums() sort.Slice(enumsList, func(i, j int) bool { return strings.ToLower(enumsList[i].Name) < strings.ToLower(enumsList[j].Name) }) for _, enum := range enumsList { - err := enumTemplate.Execute(os.Stdout, enum) + err := enumTemplate.Execute(os.Stdout, rstEnum{ + TdEnum: enum, + TdPackage: tdPackageName, + }) if err != nil { return err } - enumedTypeAliases[enum.Name] = "" + (*enumedTypeAliases)[enum.Name] = "" } - fmt.Fprintln(os.Stdout, "\nType aliases\n============================") + return nil +} + +func generateTypeAliasesRst(tdPackage *codegen.TdPackage, tdPackageName string, enumedTypeAliases *map[string]string) error { + + fmt.Fprintf(os.Stdout, "\n%s type aliases\n============================\n", tdPackageName) var typesList []codegen.TdType - for _, someType := range tdprotoInfo.TdTypes { + for _, someType := range tdPackage.TdTypes { typesList = append(typesList, someType) } sort.Slice(typesList, func(i, j int) bool { return strings.ToLower(typesList[i].Name) < strings.ToLower(typesList[j].Name) }) for _, typeAlias := range typesList { - _, isEnumed := enumedTypeAliases[typeAlias.Name] + _, isEnumed := (*enumedTypeAliases)[typeAlias.Name] if isEnumed { continue } - err := typeAliasTemplate.Execute(os.Stdout, typeAlias) + err := typeAliasTemplate.Execute(os.Stdout, rstType{ + TdType: typeAlias, + TdPackage: tdPackageName, + }) if err != nil { return err } } + return nil +} + +func generateStructsRst(tdPackage *codegen.TdPackage, tdPackageName string, enumedTypeAliases *map[string]string) error { + var jsonObjects []rstJsonStruct - for _, tdStruct := range tdprotoInfo.TdStructs { + for _, tdStruct := range tdPackage.TdStructs { if tdStruct.Help == "" { // Do not print structures without help continue @@ -159,21 +189,22 @@ func generateRstJson(tdprotoInfo *codegen.TdPackage) error { continue } - if isEventStruct(tdStruct.Name, tdprotoInfo) { + if isEventStruct(tdStruct.Name, tdPackage) { continue } - if tdStruct.IsEventParams(tdprotoInfo) { + if tdStruct.IsEventParams(tdPackage) { continue } newRstJson := rstJsonStruct{ - TdStruct: tdStruct, + TdStruct: tdStruct, + TdPackage: tdPackageName, } fieldMissingHelp := false - for _, field := range tdStruct.GetAllJsonFields(tdprotoInfo) { + for _, field := range tdStruct.GetAllJsonFields(tdPackage) { if field.IsNotSerialized { continue } @@ -215,7 +246,7 @@ func generateRstJson(tdprotoInfo *codegen.TdPackage) error { return strings.ToLower(jsonObjects[i].Name) < strings.ToLower(jsonObjects[j].Name) }) - fmt.Fprintln(os.Stdout, "\nJSON objects index\n============================") + fmt.Fprintf(os.Stdout, "\n%s JSON objects index\n============================\n", tdPackageName) for _, object := range jsonObjects { err := jsonTemplate.Execute(os.Stdout, object) @@ -224,9 +255,13 @@ func generateRstJson(tdprotoInfo *codegen.TdPackage) error { } } - fmt.Fprintln(os.Stdout, "\nHTTP Queries\n============================") + return nil +} + +func generateQueryRst(tdPackage *codegen.TdPackage, tdPackageName string) error { + fmt.Fprintf(os.Stdout, "\n%s HTTP Queries\n============================\n", tdPackageName) - for _, query := range tdprotoInfo.TdQueries { + for _, query := range tdPackage.TdQueries { err := httpQueryTemplate.Execute(os.Stdout, query) if err != nil { return err @@ -235,3 +270,38 @@ func generateRstJson(tdprotoInfo *codegen.TdPackage) error { return nil } + +func generateRstJson(tdPackage *codegen.TdPackage, tdPackageName string) error { + + enumedTypeAliases := make(map[string]string) + enumsList := tdPackage.GetEnums() + + if len(enumsList) > 0 { + err := generateEnumsRst(enumsList, tdPackageName, &enumedTypeAliases) + if err != nil { + return err + } + } + + if len(tdPackage.TdTypes) > 0 { + err := generateTypeAliasesRst(tdPackage, tdPackageName, &enumedTypeAliases) + if err != nil { + return err + } + } + if len(tdPackage.TdStructs) > 0 { + err := generateStructsRst(tdPackage, tdPackageName, &enumedTypeAliases) + if err != nil { + return err + } + } + + if len(tdPackage.TdQueries) > 0 { + err := generateQueryRst(tdPackage, tdPackageName) + if err != nil { + return err + } + } + + return nil +} From f4ae90e08088256177831b86acd3f98cdf967be4 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Fri, 20 Aug 2021 15:25:50 +0300 Subject: [PATCH 27/35] codegen: Add package name to all elements of td package --- codegen/inspect.go | 47 +++++++++++++++++++------------ codegen/sphinx/json_index/main.go | 20 +++++-------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/codegen/inspect.go b/codegen/inspect.go index f745b10..0b0e073 100644 --- a/codegen/inspect.go +++ b/codegen/inspect.go @@ -60,14 +60,16 @@ type TdStruct struct { ReadOnly bool AnonymousFields []string FileName string + PackageName string } type TdType struct { - Name string - Help string - IsArray bool - BaseType string - Filename string + Name string + Help string + IsArray bool + BaseType string + Filename string + PackageName string } type TdMapType struct { @@ -76,6 +78,7 @@ type TdMapType struct { KeyTypeStr string ValueTypeStr string Filename string + PackageName string } type TdPackage struct { @@ -85,6 +88,7 @@ type TdPackage struct { TdMapTypes map[string]TdMapType TdConstants []TdConstFields TdQueries map[string]TdQuery + Name string } type TdProto struct { @@ -95,8 +99,9 @@ type TdProto struct { } type TdEnum struct { - Name string - Values []string + Name string + Values []string + PackageName string } func (i TdPackage) GetEnums() []TdEnum { @@ -114,8 +119,9 @@ func (i TdPackage) GetEnums() []TdEnum { for key, value := range constMap { listOfEnums = append(listOfEnums, TdEnum{ - Name: key, - Values: value, + Name: key, + Values: value, + PackageName: i.Name, }) } @@ -202,6 +208,7 @@ func createTdProtoPackage(packageSlot **TdPackage, packageName string, allPackag (*packageSlot).TdTypes = make(map[string]TdType) (*packageSlot).TdMapTypes = make(map[string]TdMapType) (*packageSlot).TdQueries = make(map[string]TdQuery) + (*packageSlot).Name = packageName tdprotoAst := allPackagesAst[packageName] err := parseTdprotoAst(tdprotoAst, *packageSlot, nil) @@ -356,6 +363,7 @@ func parseMapTypeDeclaration(infoToFill *TdPackage, declarationSpec *ast.TypeSpe ValueTypeStr: valueTypeStr, Help: helpString, Filename: fileName, + PackageName: infoToFill.Name, } return nil @@ -366,11 +374,12 @@ func parseArrayTypeDefinition(infoToFill *TdPackage, declarationSpec *ast.TypeSp arrayExpressionAst := arrayAst.Elt.(*ast.Ident) arrayTypeStr := arrayExpressionAst.Name infoToFill.TdTypes[typeName] = TdType{ - Name: typeName, - BaseType: arrayTypeStr, - IsArray: true, - Help: helpString, - Filename: fileName, + Name: typeName, + BaseType: arrayTypeStr, + IsArray: true, + Help: helpString, + Filename: fileName, + PackageName: infoToFill.Name, } return nil } @@ -378,10 +387,11 @@ func parseArrayTypeDefinition(infoToFill *TdPackage, declarationSpec *ast.TypeSp func parseTypeDefinition(infoToFill *TdPackage, declarationSpec *ast.TypeSpec, typeIndent *ast.Ident, helpString string, fileName string) error { typeName := declarationSpec.Name.Name infoToFill.TdTypes[typeName] = TdType{ - Name: typeName, - BaseType: typeIndent.Name, - Help: helpString, - Filename: fileName, + Name: typeName, + BaseType: typeIndent.Name, + Help: helpString, + Filename: fileName, + PackageName: infoToFill.Name, } return nil } @@ -562,6 +572,7 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS Fields: fieldsList, AnonymousFields: anonymousFieldsList, FileName: fileName, + PackageName: infoToFill.Name, } return nil diff --git a/codegen/sphinx/json_index/main.go b/codegen/sphinx/json_index/main.go index 824fa54..7e8b317 100644 --- a/codegen/sphinx/json_index/main.go +++ b/codegen/sphinx/json_index/main.go @@ -60,23 +60,20 @@ func (r rstJsonField) GetModifiers() string { type rstJsonStruct struct { codegen.TdStruct - Fields []rstJsonField - TdPackage string + Fields []rstJsonField } type rstEnum struct { codegen.TdEnum - TdPackage string } type rstType struct { codegen.TdType - TdPackage string } var jsonTemplate = template.Must(template.New("rstJson").Parse(` .. tdproto:struct:: {{.TdStruct.Name}} - :tdpackage: {{.TdPackage}} + :tdpackage: {{.PackageName}} {{.TdStruct.Help}} {{range $field := .Fields}} @@ -85,7 +82,7 @@ var jsonTemplate = template.Must(template.New("rstJson").Parse(` var enumTemplate = template.Must(template.New("rstEnum").Parse(` .. tdproto:enum:: {{.Name}} - :tdpackage: {{.TdPackage}} + :tdpackage: {{.PackageName}} **Possible values**: {{range $value := .Values}} @@ -95,7 +92,7 @@ var enumTemplate = template.Must(template.New("rstEnum").Parse(` var typeAliasTemplate = template.Must(template.New("rstType").Parse(` .. tdproto:type:: {{.Name}} - :tdpackage: {{.TdPackage}} + :tdpackage: {{.PackageName}} {{if .Help}} {{.Help}} @@ -134,8 +131,7 @@ func generateEnumsRst(enumsList []codegen.TdEnum, tdPackageName string, enumedTy }) for _, enum := range enumsList { err := enumTemplate.Execute(os.Stdout, rstEnum{ - TdEnum: enum, - TdPackage: tdPackageName, + TdEnum: enum, }) if err != nil { return err @@ -163,8 +159,7 @@ func generateTypeAliasesRst(tdPackage *codegen.TdPackage, tdPackageName string, } err := typeAliasTemplate.Execute(os.Stdout, rstType{ - TdType: typeAlias, - TdPackage: tdPackageName, + TdType: typeAlias, }) if err != nil { return err @@ -198,8 +193,7 @@ func generateStructsRst(tdPackage *codegen.TdPackage, tdPackageName string, enum } newRstJson := rstJsonStruct{ - TdStruct: tdStruct, - TdPackage: tdPackageName, + TdStruct: tdStruct, } fieldMissingHelp := false From c31ac965336a71135ac70b0ac737fd8ae6f84632 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 23 Aug 2021 16:54:39 +0300 Subject: [PATCH 28/35] codegen: Started with adding package names to fields --- codegen/inspect.go | 60 +++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/codegen/inspect.go b/codegen/inspect.go index 0b0e073..b75a92d 100644 --- a/codegen/inspect.go +++ b/codegen/inspect.go @@ -51,6 +51,7 @@ type TdStructField struct { IsList bool IsOmitEmpty bool IsNotSerialized bool + PackageName string } type TdStruct struct { @@ -346,13 +347,15 @@ func parseTypeDeclaration(infoToFill *TdPackage, genDeclaration *ast.GenDecl, de func parseMapTypeDeclaration(infoToFill *TdPackage, declarationSpec *ast.TypeSpec, mapAst *ast.MapType, helpString string, fileName string) error { typeName := declarationSpec.Name.Name + var keyPackageName, keyTypeStr string - keyTypeStr, err := parseExprToString(mapAst.Key) + err := parseExprToString(mapAst.Key, &keyPackageName, &keyTypeStr) if err != nil { return err } - valueTypeStr, err := parseExprToString(mapAst.Value) + var valuePackageName, valueTypeStr string + err = parseExprToString(mapAst.Value, &valuePackageName, &valueTypeStr) if err != nil { return err } @@ -484,6 +487,7 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS isList := false isPointer := false fieldTypeStr := "" + fieldPackageName := "" keyTypeStr := "" switch fieldTypeAst := field.Type.(type) { @@ -498,7 +502,7 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS case *ast.InterfaceType: fieldTypeStr = "interface{}" case *ast.SelectorExpr: - fieldTypeStr = parseSelectorAst(arrayTypeAst) + fieldPackageName, fieldTypeStr = parseSelectorAst(arrayTypeAst) default: return fmt.Errorf("unknown array type %#v", arrayTypeAst) } @@ -519,22 +523,22 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS // TODO: Implement pointers to maps continue case *ast.SelectorExpr: - fieldTypeStr = parseSelectorAst(pointedType) + fieldPackageName, fieldTypeStr = parseSelectorAst(pointedType) default: return fmt.Errorf("unknown pointer field of %s type %#v", structName, pointedType) } case *ast.SelectorExpr: - fieldTypeStr = parseSelectorAst(fieldTypeAst) + fieldPackageName, fieldTypeStr = parseSelectorAst(fieldTypeAst) case *ast.InterfaceType: fieldTypeStr = "interface{}" case *ast.MapType: var err error - keyTypeStr, err = parseExprToString(fieldTypeAst.Key) + err = parseExprToString(fieldTypeAst.Key, &fieldPackageName, &fieldTypeStr) if err != nil { return err } - fieldTypeStr, err = parseExprToString(fieldTypeAst.Value) + err = parseExprToString(fieldTypeAst.Value, &fieldPackageName, &fieldTypeStr) if err != nil { return err } @@ -549,6 +553,10 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS _, isPrimitive := GolangPrimitiveTypes[fieldTypeStr] + if fieldPackageName == "" && !isPrimitive { + fieldPackageName = infoToFill.Name + } + fieldsList = append(fieldsList, TdStructField{ Name: fieldName, IsReadOnly: isReadOnly, @@ -562,6 +570,7 @@ func parseStructDefinitionInfo(infoToFill *TdPackage, declarationSpec *ast.TypeS IsPrimitive: isPrimitive, IsNotSerialized: isNotSerialized, Help: fieldDoc, + PackageName: fieldPackageName, }) } @@ -618,36 +627,43 @@ func parseConstDeclaration(infoToFill *TdPackage, genDeclaration *ast.GenDecl) e return nil } -func parseExprToString(expr interface{}) (string, error) { +func parseExprToString(expr interface{}, packageName *string, expression *string) error { switch exprType := expr.(type) { case *ast.SelectorExpr: - return parseSelectorAst(exprType), nil + (*packageName), (*expression) = parseSelectorAst(exprType) + return nil case *ast.Ident: - return exprType.Name, nil + *packageName = "" + *expression = exprType.Name + return nil case *ast.InterfaceType: - return "interface{}", nil + *packageName = "" + *expression = "interface{}" + return nil case *ast.StarExpr: - return parseStarAst(exprType) + err := parseStarAst(exprType, packageName, expression) + if err != nil { + return err + } + return nil } - return "", fmt.Errorf("cannot parse expression %#v", expr) + return fmt.Errorf("cannot parse expression %#v", expr) } -func parseStarAst(starAst *ast.StarExpr) (string, error) { - pointedType, err := parseExprToString(starAst.X) +func parseStarAst(starAst *ast.StarExpr, packageName *string, expression *string) error { + err := parseExprToString(starAst.X, packageName, expression) if err != nil { - return "", err + return err } - return pointedType, nil + return nil } -func parseSelectorAst(selectorNode *ast.SelectorExpr) string { +func parseSelectorAst(selectorNode *ast.SelectorExpr) (string, string) { expressionIdent := selectorNode.X.(*ast.Ident) expressionStr := expressionIdent.Name - if expressionStr == "tdproto" { // HACK: when tdapi references tdproto - return selectorNode.Sel.Name - } - return expressionStr + "." + selectorNode.Sel.Name + + return expressionStr, selectorNode.Sel.Name } func extractTdprotoAst(packages *map[string]*ast.Package) error { From e0f8a0234a2f383ee9b1cc92ec83d7b79baaa92d Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 23 Aug 2021 17:36:31 +0300 Subject: [PATCH 29/35] sphinx: Updated events documentation to v2 --- codegen/sphinx/events/main.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/codegen/sphinx/events/main.go b/codegen/sphinx/events/main.go index 5fe67d1..3971fb7 100644 --- a/codegen/sphinx/events/main.go +++ b/codegen/sphinx/events/main.go @@ -16,7 +16,7 @@ func main() { panic(err) } - clientEvents, serverEvents, err := generateRstServerEvents(tdprotoInfo.TdModels) + clientEvents, serverEvents, err := generateRstServerEvents(tdprotoInfo) if err != nil { panic(err) } @@ -39,17 +39,16 @@ type rstEvent struct { Fields []rstEventField } -func generateRstServerEvents(tdprotoInfo *codegen.TdPackage) (clientEvents []rstEvent, serverEvents []rstEvent, err error) { - for eventStructName, eventStr := range tdprotoInfo.TdEvents { +func generateRstServerEvents(tdprotoInfo *codegen.TdProto) (clientEvents []rstEvent, serverEvents []rstEvent, err error) { + for eventStructName, eventStr := range tdprotoInfo.TdEvents.TdEvents { eventExample, ok := eventExampleStr[eventStr] if !ok { eventExample = "" } - originalStruct, ok := tdprotoInfo.TdStructs[eventStructName] + originalStruct, ok := tdprotoInfo.TdEvents.TdStructs[eventStructName] if !ok { - fmt.Fprintf(os.Stderr, "Failed to find struct %s of event %s.\n", eventStructName, eventStr) - continue + return clientEvents, serverEvents, fmt.Errorf("failed to find struct %s of event %s", eventStructName, eventStr) } eventExampleFormatted := strings.ReplaceAll(eventExample, "\n", "\n ") @@ -64,16 +63,26 @@ func generateRstServerEvents(tdprotoInfo *codegen.TdPackage) (clientEvents []rst var paramsStruct codegen.TdStruct for _, originalField := range originalStruct.Fields { - if originalField.Name == "Params" { - paramsStruct, ok = tdprotoInfo.TdStructs[originalField.TypeStr] - if !ok { - fmt.Fprintf(os.Stderr, "Failed to find parameter type %s of event %s.\n", originalField.TypeStr, eventStructName) - continue - } + if originalField.Name != "Params" { + continue } + switch originalField.PackageName { + case "tdevents": + paramsStruct, ok = tdprotoInfo.TdEvents.TdStructs[originalField.TypeStr] + case "tdproto": + paramsStruct, ok = tdprotoInfo.TdModels.TdStructs[originalField.TypeStr] + default: + ok = false + } + + if !ok { + fmt.Fprintf(os.Stderr, "Failed to find struct %s of event %s.\n", eventStructName, eventStr) + continue + } + } - for _, paramField := range paramsStruct.GetAllJsonFields(tdprotoInfo) { + for _, paramField := range paramsStruct.GetAllJsonFields(tdprotoInfo.TdEvents) { fieldHelp := paramField.Help if fieldHelp == "" { fieldHelp = "DOCUMENTATION MISSING" From 11d0b307865cb67f05d1211ce9aa4d96b6fc8ae7 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Tue, 24 Aug 2021 16:45:01 +0300 Subject: [PATCH 30/35] typescript: Try fix for typescript generation --- codegen/typescript/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/typescript/main.go b/codegen/typescript/main.go index bc8d679..ac1fe7a 100644 --- a/codegen/typescript/main.go +++ b/codegen/typescript/main.go @@ -29,7 +29,7 @@ var tsTypesMap = map[string]string{ "bool": "boolean", "interface{}": "any", "ISODateTimeString": "string", - "time.Time": "string", + "Time": "string", "UiSettings": "UiSettings", } From ab7005a4094a7dfcca49ada63b14ddca04c4dfc5 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Wed, 25 Aug 2021 17:31:57 +0300 Subject: [PATCH 31/35] codegen: Started with inspect rework --- codegen/inspect2.go | 141 ++++++++++++++++++++++++++++++++++++++++ codegen/inspect_test.go | 11 +++- 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 codegen/inspect2.go diff --git a/codegen/inspect2.go b/codegen/inspect2.go new file mode 100644 index 0000000..5126ee4 --- /dev/null +++ b/codegen/inspect2.go @@ -0,0 +1,141 @@ +package codegen + +import ( + "fmt" + "go/ast" + "go/token" + "path" + "reflect" + "strings" +) + +type TdElement struct { + TypeName string + TypeKind reflect.Kind + PackageName string + FileName string + Help string +} + +type TdConstant struct { + TdElement + ConstValue string +} + +type TdPackage2 map[string]interface{} +type TdProto2 map[string]TdPackage2 + +func ParseTdproto2(infoToFill *TdProto2) error { + + allPackages := make(map[string]*ast.Package) + err := extractTdprotoAst(&allPackages) + if err != nil { + return err + } + + for packageName, packageAst := range allPackages { + newPackageMap := make(TdPackage2) + (*infoToFill)[packageName] = newPackageMap + err := parseAst(packageName, &newPackageMap, packageAst) + if err != nil { + return err + } + } + + return nil +} + +func parseAst(packageName string, packageMap *TdPackage2, packageAst *ast.Package) error { + for fileName, fileAst := range packageAst.Files { + + basePath := path.Base(fileName) + basePathNoExt := strings.TrimRight(basePath, path.Ext(basePath)) + + err := parseFileAst(packageMap, basePathNoExt, fileAst) + if err != nil { + return err + } + } + + return nil +} + +func parseFileAst(packageMap *TdPackage2, fileName string, fileAst *ast.File) error { + for _, declaration := range fileAst.Decls { + switch declarationType := declaration.(type) { + case *ast.GenDecl: + err := parseGenericDeclaration(packageMap, fileName, declarationType) + if err != nil { + return err + } + + } + + } + + return nil +} + +func parseGenericDeclaration(packageMap *TdPackage2, fileName string, genDeclaration *ast.GenDecl) error { + switch genDeclaration.Tok { + case token.CONST: + return parseConstDeclaration2(packageMap, fileName, genDeclaration) + case token.TYPE: + for _, aSpec := range genDeclaration.Specs { + aTypeSpec := aSpec.(*ast.TypeSpec) + err := parseTypeDeclaration2(packageMap, genDeclaration, aTypeSpec, fileName) + if err != nil { + return err + } + } + } + + return nil +} + +func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclaration *ast.GenDecl) error { + for _, spec := range genDeclaration.Specs { + valueSpec, ok := spec.(*ast.ValueSpec) + if !ok { + return fmt.Errorf("expected const spec got %+v", spec) + } + + if len(valueSpec.Names) != 1 { + return fmt.Errorf("expected one constant name got %+v", valueSpec.Names) + } + + constName := valueSpec.Names[0].Name + + constTypeName := fmt.Sprintf("%s", valueSpec.Type) + if constTypeName == "" || valueSpec.Type == nil { + errorLogger.Printf("WARN: const has no typeName %s", constName) + continue + } + + if len(valueSpec.Values) != 1 { + return fmt.Errorf("expected one constant value got %+v", valueSpec.Values) + } + + constValue, ok := valueSpec.Values[0].(*ast.BasicLit) + if !ok { + return fmt.Errorf("could not extract constant value %+v", valueSpec.Values[0]) + } + + (*packageMap)[constName] = TdConstant{ + ConstValue: constValue.Value, + TdElement: TdElement{ + FileName: fileName, + TypeKind: reflect.String, + Help: cleanHelp(valueSpec.Doc.Text()), + }, + } + + } + + return nil +} + +func parseTypeDeclaration2(packageMap *TdPackage2, genDeclaration *ast.GenDecl, declarationSpec *ast.TypeSpec, fileName string) error { + + return nil +} diff --git a/codegen/inspect_test.go b/codegen/inspect_test.go index 641f08c..fdff711 100644 --- a/codegen/inspect_test.go +++ b/codegen/inspect_test.go @@ -7,7 +7,16 @@ import ( func TestParsing(t *testing.T) { _, err := ParseTdproto() if err != nil { - t.Error(err) + t.Fatal(err) + } +} + +func TestParsing2(t *testing.T) { + tdproto := make(TdProto2) + + err := ParseTdproto2(&tdproto) + if err != nil { + t.Fatal(err) } } From 9885543d279c5698a5085c79cbb7e9ab9833baff Mon Sep 17 00:00:00 2001 From: igo95862 Date: Thu, 26 Aug 2021 17:50:33 +0300 Subject: [PATCH 32/35] codegen: inspect2 added array and type parsing --- codegen/inspect2.go | 85 ++++++++++++++++++++++++++++++++++++++--- codegen/inspect_test.go | 7 ---- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/codegen/inspect2.go b/codegen/inspect2.go index 5126ee4..c395145 100644 --- a/codegen/inspect2.go +++ b/codegen/inspect2.go @@ -9,6 +9,8 @@ import ( "strings" ) +const StringTypeName = "string" + type TdElement struct { TypeName string TypeKind reflect.Kind @@ -22,6 +24,11 @@ type TdConstant struct { ConstValue string } +type TdType2 struct { + TdElement + BaseTypeName string +} + type TdPackage2 map[string]interface{} type TdProto2 map[string]TdPackage2 @@ -105,27 +112,39 @@ func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclarat } constName := valueSpec.Names[0].Name + constTypeKind := reflect.String constTypeName := fmt.Sprintf("%s", valueSpec.Type) if constTypeName == "" || valueSpec.Type == nil { - errorLogger.Printf("WARN: const has no typeName %s", constName) - continue + constTypeName = StringTypeName } if len(valueSpec.Values) != 1 { return fmt.Errorf("expected one constant value got %+v", valueSpec.Values) } - constValue, ok := valueSpec.Values[0].(*ast.BasicLit) + var constValue string + + switch constExpr := valueSpec.Values[0]; constExpr.(type) { + case *ast.BasicLit: + constValue = constExpr.(*ast.BasicLit).Value + case *ast.CallExpr: + callExpr := constExpr.(*ast.CallExpr) + constTypeName = callExpr.Fun.(*ast.Ident).Name + constValue = callExpr.Fun.(*ast.Ident).Obj.Kind.String() + constTypeKind = reflect.Int + } + if !ok { return fmt.Errorf("could not extract constant value %+v", valueSpec.Values[0]) } (*packageMap)[constName] = TdConstant{ - ConstValue: constValue.Value, + ConstValue: constValue, TdElement: TdElement{ + TypeName: constTypeName, FileName: fileName, - TypeKind: reflect.String, + TypeKind: constTypeKind, Help: cleanHelp(valueSpec.Doc.Text()), }, } @@ -137,5 +156,61 @@ func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclarat func parseTypeDeclaration2(packageMap *TdPackage2, genDeclaration *ast.GenDecl, declarationSpec *ast.TypeSpec, fileName string) error { + helpString := cleanHelp(genDeclaration.Doc.Text()) + + switch typeAst := declarationSpec.Type.(type) { + case *ast.Ident: + err := parseTypeDefinition2(packageMap, declarationSpec, typeAst, helpString, fileName) + if err != nil { + return err + } + case *ast.StructType: + + case *ast.ArrayType: + err := parseArrayDefinition2(packageMap, declarationSpec, typeAst, helpString, fileName) + if err != nil { + return err + } + case *ast.MapType: + + default: + errorLogger.Printf("WARN: Not implemented type declaration %#v", typeAst) + } + + return nil +} + +func parseTypeDefinition2(packageMap *TdPackage2, declarationSpec *ast.TypeSpec, typeIndent *ast.Ident, helpString string, fileName string) error { + + typeName := declarationSpec.Name.Name + + (*packageMap)[typeName] = TdType2{ + TdElement: TdElement{ + TypeName: typeName, + Help: helpString, + FileName: fileName, + TypeKind: reflect.String, + }, + BaseTypeName: typeIndent.Name, + } + + return nil +} + +func parseArrayDefinition2(packageMap *TdPackage2, declarationSpec *ast.TypeSpec, arrayAst *ast.ArrayType, helpString string, fileName string) error { + typeName := declarationSpec.Name.Name + arrayExpressionAst := arrayAst.Elt.(*ast.Ident) + arrayTypeStr := arrayExpressionAst.Name + + (*packageMap)[typeName] = TdType2{ + TdElement: TdElement{ + TypeName: typeName, + Help: helpString, + FileName: fileName, + TypeKind: reflect.Array, + }, + BaseTypeName: arrayTypeStr, + } + return nil } diff --git a/codegen/inspect_test.go b/codegen/inspect_test.go index fdff711..f13b1cf 100644 --- a/codegen/inspect_test.go +++ b/codegen/inspect_test.go @@ -4,13 +4,6 @@ import ( "testing" ) -func TestParsing(t *testing.T) { - _, err := ParseTdproto() - if err != nil { - t.Fatal(err) - } -} - func TestParsing2(t *testing.T) { tdproto := make(TdProto2) From 8aa42e4041a7ca65307c7eb3e9f8d8de85f07022 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Fri, 27 Aug 2021 15:45:26 +0300 Subject: [PATCH 33/35] codegen: Added map type parsing to inspect2 --- codegen/inspect2.go | 129 +++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 38 deletions(-) diff --git a/codegen/inspect2.go b/codegen/inspect2.go index c395145..0ed8e06 100644 --- a/codegen/inspect2.go +++ b/codegen/inspect2.go @@ -5,15 +5,12 @@ import ( "go/ast" "go/token" "path" - "reflect" "strings" ) const StringTypeName = "string" type TdElement struct { - TypeName string - TypeKind reflect.Kind PackageName string FileName string Help string @@ -22,16 +19,36 @@ type TdElement struct { type TdConstant struct { TdElement ConstValue string + TypeName string } type TdType2 struct { TdElement - BaseTypeName string + TypeName string +} + +type TdTypeArray struct { + TdElement + TypeName string +} + +type TdTypeMap struct { + TdElement + KeyTypeStr string + KeyTypePackage string + ValueTypeStr string + ValueTypePackage string } type TdPackage2 map[string]interface{} type TdProto2 map[string]TdPackage2 +type ParserState struct { + CurrentFile string + CurrentPackageName string + CurrentPackageMap *TdPackage2 +} + func ParseTdproto2(infoToFill *TdProto2) error { allPackages := make(map[string]*ast.Package) @@ -58,7 +75,11 @@ func parseAst(packageName string, packageMap *TdPackage2, packageAst *ast.Packag basePath := path.Base(fileName) basePathNoExt := strings.TrimRight(basePath, path.Ext(basePath)) - err := parseFileAst(packageMap, basePathNoExt, fileAst) + err := parseFileAst(ParserState{ + CurrentFile: basePathNoExt, + CurrentPackageName: packageName, + CurrentPackageMap: packageMap, + }, fileAst) if err != nil { return err } @@ -67,11 +88,11 @@ func parseAst(packageName string, packageMap *TdPackage2, packageAst *ast.Packag return nil } -func parseFileAst(packageMap *TdPackage2, fileName string, fileAst *ast.File) error { +func parseFileAst(parser ParserState, fileAst *ast.File) error { for _, declaration := range fileAst.Decls { switch declarationType := declaration.(type) { case *ast.GenDecl: - err := parseGenericDeclaration(packageMap, fileName, declarationType) + err := parseGenericDeclaration(parser, declarationType) if err != nil { return err } @@ -83,14 +104,14 @@ func parseFileAst(packageMap *TdPackage2, fileName string, fileAst *ast.File) er return nil } -func parseGenericDeclaration(packageMap *TdPackage2, fileName string, genDeclaration *ast.GenDecl) error { +func parseGenericDeclaration(parser ParserState, genDeclaration *ast.GenDecl) error { switch genDeclaration.Tok { case token.CONST: - return parseConstDeclaration2(packageMap, fileName, genDeclaration) + return parseConstDeclaration2(parser, genDeclaration) case token.TYPE: for _, aSpec := range genDeclaration.Specs { aTypeSpec := aSpec.(*ast.TypeSpec) - err := parseTypeDeclaration2(packageMap, genDeclaration, aTypeSpec, fileName) + err := parseTypeDeclaration2(parser, genDeclaration, aTypeSpec) if err != nil { return err } @@ -100,7 +121,7 @@ func parseGenericDeclaration(packageMap *TdPackage2, fileName string, genDeclara return nil } -func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclaration *ast.GenDecl) error { +func parseConstDeclaration2(parser ParserState, genDeclaration *ast.GenDecl) error { for _, spec := range genDeclaration.Specs { valueSpec, ok := spec.(*ast.ValueSpec) if !ok { @@ -112,7 +133,6 @@ func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclarat } constName := valueSpec.Names[0].Name - constTypeKind := reflect.String constTypeName := fmt.Sprintf("%s", valueSpec.Type) if constTypeName == "" || valueSpec.Type == nil { @@ -132,21 +152,20 @@ func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclarat callExpr := constExpr.(*ast.CallExpr) constTypeName = callExpr.Fun.(*ast.Ident).Name constValue = callExpr.Fun.(*ast.Ident).Obj.Kind.String() - constTypeKind = reflect.Int } if !ok { return fmt.Errorf("could not extract constant value %+v", valueSpec.Values[0]) } - (*packageMap)[constName] = TdConstant{ - ConstValue: constValue, + (*parser.CurrentPackageMap)[constName] = TdConstant{ TdElement: TdElement{ - TypeName: constTypeName, - FileName: fileName, - TypeKind: constTypeKind, - Help: cleanHelp(valueSpec.Doc.Text()), + PackageName: parser.CurrentPackageName, + FileName: parser.CurrentFile, + Help: cleanHelp(valueSpec.Doc.Text()), }, + ConstValue: constValue, + TypeName: constTypeName, } } @@ -154,62 +173,96 @@ func parseConstDeclaration2(packageMap *TdPackage2, fileName string, genDeclarat return nil } -func parseTypeDeclaration2(packageMap *TdPackage2, genDeclaration *ast.GenDecl, declarationSpec *ast.TypeSpec, fileName string) error { +func parseTypeDeclaration2(parser ParserState, genDeclaration *ast.GenDecl, declarationSpec *ast.TypeSpec) error { helpString := cleanHelp(genDeclaration.Doc.Text()) switch typeAst := declarationSpec.Type.(type) { case *ast.Ident: - err := parseTypeDefinition2(packageMap, declarationSpec, typeAst, helpString, fileName) + err := parseTypeDefinition2(parser, declarationSpec, typeAst, helpString) if err != nil { return err } case *ast.StructType: case *ast.ArrayType: - err := parseArrayDefinition2(packageMap, declarationSpec, typeAst, helpString, fileName) + err := parseArrayDefinition2(parser, declarationSpec, typeAst, helpString) if err != nil { return err } case *ast.MapType: - + err := parseMapTypeDefinition(parser, declarationSpec, typeAst, helpString) + if err != nil { + return nil + } default: - errorLogger.Printf("WARN: Not implemented type declaration %#v", typeAst) + errorLogger.Printf("WARN: Not implemented type declaration %#v in file %s", typeAst, parser.CurrentFile) } return nil } -func parseTypeDefinition2(packageMap *TdPackage2, declarationSpec *ast.TypeSpec, typeIndent *ast.Ident, helpString string, fileName string) error { +func parseTypeDefinition2(parser ParserState, declarationSpec *ast.TypeSpec, typeIndent *ast.Ident, helpString string) error { typeName := declarationSpec.Name.Name - (*packageMap)[typeName] = TdType2{ + (*parser.CurrentPackageMap)[typeName] = TdType2{ TdElement: TdElement{ - TypeName: typeName, - Help: helpString, - FileName: fileName, - TypeKind: reflect.String, + + Help: helpString, + FileName: parser.CurrentFile, + PackageName: parser.CurrentPackageName, }, - BaseTypeName: typeIndent.Name, + TypeName: typeIndent.Name, } return nil } -func parseArrayDefinition2(packageMap *TdPackage2, declarationSpec *ast.TypeSpec, arrayAst *ast.ArrayType, helpString string, fileName string) error { +func parseArrayDefinition2(parser ParserState, declarationSpec *ast.TypeSpec, arrayAst *ast.ArrayType, helpString string) error { typeName := declarationSpec.Name.Name arrayExpressionAst := arrayAst.Elt.(*ast.Ident) arrayTypeStr := arrayExpressionAst.Name - (*packageMap)[typeName] = TdType2{ + (*parser.CurrentPackageMap)[typeName] = TdType2{ TdElement: TdElement{ - TypeName: typeName, - Help: helpString, - FileName: fileName, - TypeKind: reflect.Array, + + Help: helpString, + FileName: parser.CurrentFile, + PackageName: parser.CurrentPackageName, + }, + TypeName: arrayTypeStr, + } + + return nil +} + +func parseMapTypeDefinition(parser ParserState, declarationSpec *ast.TypeSpec, mapAst *ast.MapType, helpString string) error { + typeName := declarationSpec.Name.Name + var keyPackageName, keyTypeStr string + + err := parseExprToString(mapAst.Key, &keyPackageName, &keyTypeStr) + if err != nil { + return err + } + + var valuePackageName, valueTypeStr string + err = parseExprToString(mapAst.Value, &valuePackageName, &valueTypeStr) + if err != nil { + return err + } + + (*parser.CurrentPackageMap)[typeName] = TdTypeMap{ + TdElement: TdElement{ + + Help: helpString, + FileName: parser.CurrentFile, + PackageName: parser.CurrentPackageName, }, - BaseTypeName: arrayTypeStr, + KeyTypeStr: keyTypeStr, + KeyTypePackage: keyPackageName, + ValueTypeStr: valueTypeStr, + ValueTypePackage: valuePackageName, } return nil From 6ce4b8cc3ed7cbfd18f626bac890dc8791405fd6 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Mon, 30 Aug 2021 16:48:32 +0300 Subject: [PATCH 34/35] codegen: Added basic struct parsing to inspect2 --- codegen/inspect2.go | 213 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 1 deletion(-) diff --git a/codegen/inspect2.go b/codegen/inspect2.go index 0ed8e06..016c584 100644 --- a/codegen/inspect2.go +++ b/codegen/inspect2.go @@ -5,6 +5,7 @@ import ( "go/ast" "go/token" "path" + "reflect" "strings" ) @@ -40,6 +41,26 @@ type TdTypeMap struct { ValueTypePackage string } +type TdStruct2 struct { + TdElement + Fields []TdStructField2 + AnonymousFields []string + TypeName string +} + +type TdStructField2 struct { + TdElement + FieldName string + TypeName string + JsonName string + SchemaName string + IsPrimitive bool + IsReadOnly bool + IsPointer bool + IsOmitEmpty bool + IsNotSerialized bool +} + type TdPackage2 map[string]interface{} type TdProto2 map[string]TdPackage2 @@ -184,7 +205,10 @@ func parseTypeDeclaration2(parser ParserState, genDeclaration *ast.GenDecl, decl return err } case *ast.StructType: - + err := parseStructDefinition(parser, declarationSpec, typeAst, helpString) + if err != nil { + return err + } case *ast.ArrayType: err := parseArrayDefinition2(parser, declarationSpec, typeAst, helpString) if err != nil { @@ -267,3 +291,190 @@ func parseMapTypeDefinition(parser ParserState, declarationSpec *ast.TypeSpec, m return nil } + +func parseStructDefinition(parser ParserState, declarationSpec *ast.TypeSpec, structInfo *ast.StructType, helpString string) error { + structName := declarationSpec.Name.Name + + if helpString == "" { + errorLogger.Printf("WARN: TdStruct %s missing a doc string in file %s", structName, parser.CurrentFile) + } + + if strings.HasPrefix(strings.ToLower(helpString), "deprecated") { + return nil + } + + var fieldsList []TdStructField2 + var anonymousFieldsList []string + + for _, field := range structInfo.Fields.List { + switch len(field.Names) { + case 0: + anonymousIdent := field.Type.(*ast.Ident) + anonymousFieldName := anonymousIdent.Name + anonymousFieldsList = append(anonymousFieldsList, anonymousFieldName) + continue + case 1: + default: + return fmt.Errorf("unexpected struct %s field name amount of %d", structName, len(field.Names)) + } + + fieldName := field.Names[0].Name + isOmitEmpty := false + isReadOnly := false + isNotSerialized := false + jsonName := fieldName + fieldDoc := cleanHelp(field.Doc.Text()) + var schemaName string + + if field.Tag != nil { + structTags := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) + + var jsonTags []string + if jsonTagsStr, ok := structTags.Lookup("json"); ok { + jsonTags = strings.Split(jsonTagsStr, ",") + } + + for i, aTag := range jsonTags { + if i == 0 { + if aTag == "-" { + isNotSerialized = true + } + + jsonName = aTag + } else { + if aTag == "omitempty" { + isOmitEmpty = true + } else { + return fmt.Errorf("unknown json tag %s", aTag) + } + } + } + + var tdprotoTags []string + tdprotoTagsStr, ok := structTags.Lookup("tdproto") + if ok { + tdprotoTags = strings.Split(tdprotoTagsStr, ",") + } + + for _, aTag := range tdprotoTags { + if aTag == "readonly" { + isReadOnly = true + } else { + return fmt.Errorf("unknown tdproto tag %s", aTag) + } + } + + var schemaTags []string + schemaTagsStr, ok := structTags.Lookup("schema") + if ok { + schemaTags = strings.Split(schemaTagsStr, ",") + } + + for _, sTag := range schemaTags { + schemaName = sTag + } + } + + // isList := false + isPointer := false + fieldTypeStr := "" + fieldPackageName := "" + // keyTypeStr := "" + + switch fieldTypeAst := field.Type.(type) { + case *ast.Ident: + fieldTypeStr = fieldTypeAst.Name + case *ast.ArrayType: + // isList = true + + switch arrayTypeAst := fieldTypeAst.Elt.(type) { + case *ast.Ident: + fieldTypeStr = arrayTypeAst.Name + case *ast.InterfaceType: + fieldTypeStr = "interface{}" + case *ast.SelectorExpr: + fieldPackageName, fieldTypeStr = parseSelectorAst(arrayTypeAst) + default: + return fmt.Errorf("unknown array type %#v", arrayTypeAst) + } + + case *ast.StarExpr: + isPointer = true + + switch pointedType := fieldTypeAst.X.(type) { + case *ast.Ident: + fieldTypeStr = pointedType.Name + case *ast.ArrayType: + // isList = true + + arrayExprAst := pointedType.Elt.(*ast.Ident) + + fieldTypeStr = arrayExprAst.Name + case *ast.MapType: + // TODO: Implement pointers to maps + continue + case *ast.SelectorExpr: + fieldPackageName, fieldTypeStr = parseSelectorAst(pointedType) + default: + return fmt.Errorf("unknown pointer field of %s type %#v", structName, pointedType) + } + + case *ast.SelectorExpr: + fieldPackageName, fieldTypeStr = parseSelectorAst(fieldTypeAst) + case *ast.InterfaceType: + fieldTypeStr = "interface{}" + case *ast.MapType: + var err error + err = parseExprToString(fieldTypeAst.Key, &fieldPackageName, &fieldTypeStr) + if err != nil { + return err + } + err = parseExprToString(fieldTypeAst.Value, &fieldPackageName, &fieldTypeStr) + if err != nil { + return err + } + default: + return fmt.Errorf("unknown field of %s type %#v", structName, fieldTypeAst) + } + + if fieldTypeStr == "" { + return fmt.Errorf("empty field name %s of %s", structName, fieldName) + + } + + _, isPrimitive := GolangPrimitiveTypes[fieldTypeStr] + + if fieldPackageName == "" && !isPrimitive { + fieldPackageName = parser.CurrentPackageName + } + + fieldsList = append(fieldsList, TdStructField2{ + TdElement: TdElement{ + Help: fieldDoc, + PackageName: fieldPackageName, + FileName: parser.CurrentFile, + }, + FieldName: fieldName, + IsReadOnly: isReadOnly, + IsOmitEmpty: isOmitEmpty, + JsonName: jsonName, + SchemaName: schemaName, + IsPointer: isPointer, + IsPrimitive: isPrimitive, + IsNotSerialized: isNotSerialized, + }) + } + + (*parser.CurrentPackageMap)[structName] = TdStruct2{ + TdElement: TdElement{ + Help: helpString, + PackageName: parser.CurrentPackageName, + FileName: parser.CurrentFile, + }, + TypeName: structName, + Fields: fieldsList, + AnonymousFields: anonymousFieldsList, + } + + return nil +} From 391465257d890d0901285f8771aeb8fb724631d6 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Tue, 31 Aug 2021 17:36:52 +0300 Subject: [PATCH 35/35] codegen: Special structs to indicate the primitive or refrence --- codegen/inspect2.go | 73 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/codegen/inspect2.go b/codegen/inspect2.go index 016c584..ad729f1 100644 --- a/codegen/inspect2.go +++ b/codegen/inspect2.go @@ -11,6 +11,19 @@ import ( const StringTypeName = "string" +var golangePrimitiveToKind = map[string]reflect.Kind{ + "string": reflect.String, +} + +type TdPrimitive struct { + PrimitiveType reflect.Kind +} + +type TdRefrence struct { + Package string + Name string +} + type TdElement struct { PackageName string FileName string @@ -20,17 +33,17 @@ type TdElement struct { type TdConstant struct { TdElement ConstValue string - TypeName string + ConstType interface{} } type TdType2 struct { TdElement - TypeName string + Type interface{} } type TdTypeArray struct { TdElement - TypeName string + ArrayType interface{} } type TdTypeMap struct { @@ -153,11 +166,13 @@ func parseConstDeclaration2(parser ParserState, genDeclaration *ast.GenDecl) err return fmt.Errorf("expected one constant name got %+v", valueSpec.Names) } + var constKind reflect.Kind + constName := valueSpec.Names[0].Name constTypeName := fmt.Sprintf("%s", valueSpec.Type) if constTypeName == "" || valueSpec.Type == nil { - constTypeName = StringTypeName + constKind = reflect.String } if len(valueSpec.Values) != 1 { @@ -179,6 +194,19 @@ func parseConstDeclaration2(parser ParserState, genDeclaration *ast.GenDecl) err return fmt.Errorf("could not extract constant value %+v", valueSpec.Values[0]) } + var constType interface{} + + if constKind != 0 { + constType = TdPrimitive{ + PrimitiveType: constKind, + } + } else { + constType = TdRefrence{ + Package: parser.CurrentPackageName, + Name: constTypeName, + } + } + (*parser.CurrentPackageMap)[constName] = TdConstant{ TdElement: TdElement{ PackageName: parser.CurrentPackageName, @@ -186,7 +214,7 @@ func parseConstDeclaration2(parser ParserState, genDeclaration *ast.GenDecl) err Help: cleanHelp(valueSpec.Doc.Text()), }, ConstValue: constValue, - TypeName: constTypeName, + ConstType: constType, } } @@ -229,6 +257,21 @@ func parseTypeDeclaration2(parser ParserState, genDeclaration *ast.GenDecl, decl func parseTypeDefinition2(parser ParserState, declarationSpec *ast.TypeSpec, typeIndent *ast.Ident, helpString string) error { typeName := declarationSpec.Name.Name + typeTypeName := typeIndent.Name + + typeKind, isPrimitive := golangePrimitiveToKind[typeTypeName] + + var typeType interface{} + if isPrimitive { + typeType = TdPrimitive{ + PrimitiveType: typeKind, + } + } else { + typeType = TdRefrence{ + Package: parser.CurrentPackageName, + Name: typeTypeName, + } + } (*parser.CurrentPackageMap)[typeName] = TdType2{ TdElement: TdElement{ @@ -237,7 +280,7 @@ func parseTypeDefinition2(parser ParserState, declarationSpec *ast.TypeSpec, typ FileName: parser.CurrentFile, PackageName: parser.CurrentPackageName, }, - TypeName: typeIndent.Name, + Type: typeType, } return nil @@ -248,14 +291,28 @@ func parseArrayDefinition2(parser ParserState, declarationSpec *ast.TypeSpec, ar arrayExpressionAst := arrayAst.Elt.(*ast.Ident) arrayTypeStr := arrayExpressionAst.Name - (*parser.CurrentPackageMap)[typeName] = TdType2{ + typeKind, isPrimitive := golangePrimitiveToKind[arrayTypeStr] + + var arrayType interface{} + if isPrimitive { + arrayType = TdPrimitive{ + PrimitiveType: typeKind, + } + } else { + arrayType = TdRefrence{ + Package: parser.CurrentPackageName, + Name: arrayTypeStr, + } + } + + (*parser.CurrentPackageMap)[typeName] = TdTypeArray{ TdElement: TdElement{ Help: helpString, FileName: parser.CurrentFile, PackageName: parser.CurrentPackageName, }, - TypeName: arrayTypeStr, + ArrayType: arrayType, } return nil