From a7eace96c3d75aad0e36018c6b40a9b119dfa843 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 14 Jul 2025 16:49:37 +0300 Subject: [PATCH 1/3] [IMSERVER-20667] add methods for threads and chats --- bot.go | 30 ++- button_easyjson.go | 4 +- chat.go | 20 ++ chat_easyjson.go | 2 +- client.go | 102 ++++++++ file_easyjson.go | 2 +- message.go | 8 + message_easyjson.go | 123 ++++++++- types.go | 31 ++- types_easyjson.go | 622 ++++++++++++++++++++++++++++++++++---------- 10 files changed, 785 insertions(+), 159 deletions(-) diff --git a/bot.go b/bot.go index 0971743..f148d76 100644 --- a/bot.go +++ b/bot.go @@ -28,6 +28,24 @@ type Bot struct { Info *BotInfo } +// AutosubscribeToThreads toggles thread auto-subscription behaviour for the specified chat. +// enable – turn the feature on/off. +// withExisting – if true, the bot will also subscribe to already existing threads. +func (b *Bot) AutosubscribeToThreads(chatID string, enable, withExisting bool) error { + return b.client.AutosubscribeToThreads(chatID, enable, withExisting) +} + +// AddThread adds a new thread to the specified chat and returns the thread ID. +func (b *Bot) AddThread(chatID, msgID string) (*Thread, error) { + return b.client.AddThread(chatID, msgID) +} + +// GetThreadSubscribers gets the subscribers list for a thread. +// Either cursor or pageSize must be provided. +func (b *Bot) GetThreadSubscribers(threadID string, cursor string, pageSize int) (*ThreadSubscribers, error) { + return b.client.GetThreadSubscribers(threadID, cursor, pageSize) +} + // GetInfo returns information about bot: // id, name, about, avatar func (b *Bot) GetInfo() (*BotInfo, error) { @@ -80,7 +98,17 @@ func (b *Bot) UnblockChatUser(chatID, userID string) error { return b.client.UnblockChatUser(chatID, userID) } -// ResolveChatJoinRequests sends a decision to accept/decline user join to chat +// DeleteChatMembers removes multiple members from chat +func (b *Bot) DeleteChatMembers(chatID string, members []string) error { + return b.client.DeleteChatMembers(chatID, members) +} + +// AddChatMembers adds multiple members to chat +func (b *Bot) AddChatMembers(chatID string, members []string) error { + return b.client.AddChatMembers(chatID, members) +} + +// ResolveChatJoinRequests resolves pending join requests for specified user or all pending users func (b *Bot) ResolveChatJoinRequests(chatID, userID string, accept, everyone bool) error { return b.client.ResolveChatPending(chatID, userID, accept, everyone) } diff --git a/button_easyjson.go b/button_easyjson.go index 0eabfdb..fe1bccf 100644 --- a/button_easyjson.go +++ b/button_easyjson.go @@ -28,7 +28,7 @@ func easyjsonF248ab8DecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Butt } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -122,7 +122,7 @@ func easyjsonF248ab8DecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *But } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() diff --git a/chat.go b/chat.go index f09ac48..38b6f1d 100644 --- a/chat.go +++ b/chat.go @@ -94,6 +94,16 @@ func (c *Chat) GetPendingUsers() ([]User, error) { return c.client.GetChatPendingUsers(c.ID) } +// DeleteMembers removes members from chat +func (c *Chat) DeleteMembers(members []string) error { + return c.client.DeleteChatMembers(c.ID, members) +} + +// AddMembers adds members to chat +func (c *Chat) AddMembers(members []string) error { + return c.client.AddChatMembers(c.ID, members) +} + // Block user and remove him from chat. // If deleteLastMessages is true, the messages written recently will be deleted func (c *Chat) BlockUser(userID string, deleteLastMessages bool) error { @@ -129,3 +139,13 @@ func (c *Chat) SetAbout(about string) error { func (c *Chat) SetRules(rules string) error { return c.client.SetChatRules(c.ID, rules) } + +// AddThread adds a new thread to the specified chat and returns the thread ID +func (c *Chat) AddThread(msgID string) (*Thread, error) { + return c.client.AddThread(c.ID, msgID) +} + +// AutosubscribeToThreads toggles thread auto-subscription for the chat +func (c *Chat) AutosubscribeToThreads(enable, withExisting bool) error { + return c.client.AutosubscribeToThreads(c.ID, enable, withExisting) +} diff --git a/chat_easyjson.go b/chat_easyjson.go index 6d9a48f..9b22ee8 100644 --- a/chat_easyjson.go +++ b/chat_easyjson.go @@ -28,7 +28,7 @@ func easyjson9b8f5552DecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Cha } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() diff --git a/client.go b/client.go index a10e449..73e707c 100644 --- a/client.go +++ b/client.go @@ -114,6 +114,64 @@ func (c *Client) DoWithContext(ctx context.Context, path string, params url.Valu return responseBody, nil } +func (c *Client) AutosubscribeToThreads(chatID string, enable, withExisting bool) error { + params := url.Values{ + "chatId": {chatID}, + "enable": {strconv.FormatBool(enable)}, + "withExisting": {strconv.FormatBool(withExisting)}, + } + + if _, err := c.Do("/threads/autosubscribe", params, nil); err != nil { + return fmt.Errorf("error while requesting threads autosubscribe: %s", err) + } + + return nil +} + +func (c *Client) AddThread(chatID, msgID string) (*Thread, error) { + params := url.Values{ + "chatId": {chatID}, + "msgId": {msgID}, + } + + response, err := c.Do("/threads/add", params, nil) + if err != nil { + return nil, fmt.Errorf("error while adding thread: %s", err) + } + + thread := &Thread{} + if err := json.Unmarshal(response, thread); err != nil { + return nil, fmt.Errorf("error while unmarshalling thread response: %s", err) + } + + return thread, nil +} + +func (c *Client) GetThreadSubscribers(threadID string, cursor string, pageSize int) (*ThreadSubscribers, error) { + params := url.Values{ + "threadId": {threadID}, + } + + if cursor != "" { + params.Set("cursor", cursor) + } + if pageSize > 0 { + params.Set("pageSize", strconv.Itoa(pageSize)) + } + + response, err := c.Do("/threads/subscribers/get", params, nil) + if err != nil { + return nil, fmt.Errorf("error while getting thread subscribers: %s", err) + } + + threadSubscribers := &ThreadSubscribers{} + if err := json.Unmarshal(response, threadSubscribers); err != nil { + return nil, fmt.Errorf("error while unmarshalling thread subscribers response: %s", err) + } + + return threadSubscribers, nil +} + func (c *Client) GetInfo() (*BotInfo, error) { response, err := c.Do("/self/get", url.Values{}, nil) if err != nil { @@ -293,6 +351,50 @@ func (c *Client) ResolveChatPending(chatID, userID string, approve, everyone boo return nil } +func (c *Client) DeleteChatMembers(chatID string, members []string) error { + membersList := make([]map[string]string, len(members)) + for i, member := range members { + membersList[i] = map[string]string{"sn": member} + } + + membersJSON, err := json.Marshal(membersList) + if err != nil { + return fmt.Errorf("error while marshalling members list: %s", err) + } + + params := url.Values{ + "chatId": {chatID}, + "members": {string(membersJSON)}, + } + + if _, err := c.Do("/chats/members/delete", params, nil); err != nil { + return fmt.Errorf("error while deleting chat members: %s", err) + } + return nil +} + +func (c *Client) AddChatMembers(chatID string, members []string) error { + membersList := make([]map[string]string, len(members)) + for i, member := range members { + membersList[i] = map[string]string{"sn": member} + } + + membersJSON, err := json.Marshal(membersList) + if err != nil { + return fmt.Errorf("error while marshalling members list: %s", err) + } + + params := url.Values{ + "chatId": {chatID}, + "members": {string(membersJSON)}, + } + + if _, err := c.Do("/chats/members/add", params, nil); err != nil { + return fmt.Errorf("error while adding chat members: %s", err) + } + return nil +} + func (c *Client) SetChatTitle(chatID, title string) error { params := url.Values{ "chatId": {chatID}, diff --git a/file_easyjson.go b/file_easyjson.go index 7563790..bcf4fd1 100644 --- a/file_easyjson.go +++ b/file_easyjson.go @@ -28,7 +28,7 @@ func easyjson8ceb9162DecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Fil } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() diff --git a/message.go b/message.go index 4d3a903..bc16f86 100644 --- a/message.go +++ b/message.go @@ -53,6 +53,8 @@ type Message struct { Timestamp int `json:"timestamp"` + ParentMessage *ParentMessage `json:"parent_topic"` + // The markup for the inline keyboard InlineKeyboard *Keyboard `json:"inlineKeyboardMarkup"` @@ -86,6 +88,12 @@ func (m *Message) AttachExistingVoice(fileID string) { m.ContentType = Voice } +type ParentMessage struct { + ChatID string `json:"chatId"` + MsgID int64 `json:"messageId"` + Type string `json:"type"` +} + // ParseMode represent a type of text formatting type ParseMode string diff --git a/message_easyjson.go b/message_easyjson.go index 4f12a71..d93871a 100644 --- a/message_easyjson.go +++ b/message_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Message) { +func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *ParentMessage) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -28,7 +28,87 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Mes } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "chatId": + out.ChatID = string(in.String()) + case "messageId": + out.MsgID = int64(in.Int64()) + case "type": + out.Type = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson4086215fEncodeGithubComMailRuImBotGolang(out *jwriter.Writer, in ParentMessage) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"chatId\":" + out.RawString(prefix[1:]) + out.String(string(in.ChatID)) + } + { + const prefix string = ",\"messageId\":" + out.RawString(prefix) + out.Int64(int64(in.MsgID)) + } + { + const prefix string = ",\"type\":" + out.RawString(prefix) + out.String(string(in.Type)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v ParentMessage) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson4086215fEncodeGithubComMailRuImBotGolang(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v ParentMessage) MarshalEasyJSON(w *jwriter.Writer) { + easyjson4086215fEncodeGithubComMailRuImBotGolang(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *ParentMessage) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson4086215fDecodeGithubComMailRuImBotGolang(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *ParentMessage) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson4086215fDecodeGithubComMailRuImBotGolang(l, v) +} +func easyjson4086215fDecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *Message) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -54,6 +134,16 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Mes out.ForwardChatID = string(in.String()) case "timestamp": out.Timestamp = int(in.Int()) + case "parent_topic": + if in.IsNull() { + in.Skip() + out.ParentMessage = nil + } else { + if out.ParentMessage == nil { + out.ParentMessage = new(ParentMessage) + } + (*out.ParentMessage).UnmarshalEasyJSON(in) + } case "inlineKeyboardMarkup": if in.IsNull() { in.Skip() @@ -62,7 +152,7 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Mes if out.InlineKeyboard == nil { out.InlineKeyboard = new(Keyboard) } - easyjson4086215fDecodeGithubComMailRuImBotGolang1(in, out.InlineKeyboard) + easyjson4086215fDecodeGithubComMailRuImBotGolang2(in, out.InlineKeyboard) } case "parseMode": out.ParseMode = ParseMode(in.String()) @@ -80,7 +170,7 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *Mes in.Consumed() } } -func easyjson4086215fEncodeGithubComMailRuImBotGolang(out *jwriter.Writer, in Message) { +func easyjson4086215fEncodeGithubComMailRuImBotGolang1(out *jwriter.Writer, in Message) { out.RawByte('{') first := true _ = first @@ -129,13 +219,22 @@ func easyjson4086215fEncodeGithubComMailRuImBotGolang(out *jwriter.Writer, in Me out.RawString(prefix) out.Int(int(in.Timestamp)) } + { + const prefix string = ",\"parent_topic\":" + out.RawString(prefix) + if in.ParentMessage == nil { + out.RawString("null") + } else { + (*in.ParentMessage).MarshalEasyJSON(out) + } + } { const prefix string = ",\"inlineKeyboardMarkup\":" out.RawString(prefix) if in.InlineKeyboard == nil { out.RawString("null") } else { - easyjson4086215fEncodeGithubComMailRuImBotGolang1(out, *in.InlineKeyboard) + easyjson4086215fEncodeGithubComMailRuImBotGolang2(out, *in.InlineKeyboard) } } { @@ -159,27 +258,27 @@ func easyjson4086215fEncodeGithubComMailRuImBotGolang(out *jwriter.Writer, in Me // MarshalJSON supports json.Marshaler interface func (v Message) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson4086215fEncodeGithubComMailRuImBotGolang(&w, v) + easyjson4086215fEncodeGithubComMailRuImBotGolang1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Message) MarshalEasyJSON(w *jwriter.Writer) { - easyjson4086215fEncodeGithubComMailRuImBotGolang(w, v) + easyjson4086215fEncodeGithubComMailRuImBotGolang1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Message) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson4086215fDecodeGithubComMailRuImBotGolang(&r, v) + easyjson4086215fDecodeGithubComMailRuImBotGolang1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Message) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson4086215fDecodeGithubComMailRuImBotGolang(l, v) + easyjson4086215fDecodeGithubComMailRuImBotGolang1(l, v) } -func easyjson4086215fDecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *Keyboard) { +func easyjson4086215fDecodeGithubComMailRuImBotGolang2(in *jlexer.Lexer, out *Keyboard) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -190,7 +289,7 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *Ke } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -252,7 +351,7 @@ func easyjson4086215fDecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *Ke in.Consumed() } } -func easyjson4086215fEncodeGithubComMailRuImBotGolang1(out *jwriter.Writer, in Keyboard) { +func easyjson4086215fEncodeGithubComMailRuImBotGolang2(out *jwriter.Writer, in Keyboard) { out.RawByte('{') first := true _ = first diff --git a/types.go b/types.go index e51168c..9227dd4 100644 --- a/types.go +++ b/types.go @@ -29,6 +29,24 @@ type Response struct { Description string `json:"description,omitempty"` } +type Thread struct { + ThreadID string `json:"threadId"` +} + +type UserState struct { + Lastseen int `json:"lastseen"` +} + +type Subscriber struct { + SN string `json:"sn"` + UserState UserState `json:"userState"` +} + +type ThreadSubscribers struct { + Cursor string `json:"cursor"` + Subscribers []Subscriber `json:"subscribers"` +} + type Photo struct { URL string `json:"url"` } @@ -102,6 +120,8 @@ type BaseEventPayload struct { // Timestamp of the event. Timestamp int `json:"timestamp"` + + ParentMessage *ParentMessage `json:"parent_topic"` } type EventPayload struct { @@ -144,11 +164,12 @@ func (ep *EventPayload) CallbackMessage() *Message { func message(client *Client, msg BaseEventPayload) *Message { msg.Chat.client = client return &Message{ - client: client, - ID: msg.MsgID, - Text: msg.Text, - Chat: msg.Chat, - Timestamp: msg.Timestamp, + client: client, + ID: msg.MsgID, + Text: msg.Text, + Chat: msg.Chat, + Timestamp: msg.Timestamp, + ParentMessage: msg.ParentMessage, } } diff --git a/types_easyjson.go b/types_easyjson.go index 1b824f5..ab934ee 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -28,7 +28,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang(in *jlexer.Lexer, out *eve } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -145,7 +145,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang1(in *jlexer.Lexer, out *Us } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -232,7 +232,7 @@ func (v *UsersListResponse) UnmarshalJSON(data []byte) error { func (v *UsersListResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson6601e8cdDecodeGithubComMailRuImBotGolang1(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(in *jlexer.Lexer, out *User) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(in *jlexer.Lexer, out *UserState) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -243,7 +243,73 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(in *jlexer.Lexer, out *Us } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "lastseen": + out.Lastseen = int(in.Int()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(out *jwriter.Writer, in UserState) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"lastseen\":" + out.RawString(prefix[1:]) + out.Int(int(in.Lastseen)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v UserState) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v UserState) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *UserState) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *UserState) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(l, v) +} +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(in *jlexer.Lexer, out *User) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -263,7 +329,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(in *jlexer.Lexer, out *Us in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(out *jwriter.Writer, in User) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(out *jwriter.Writer, in User) { out.RawByte('{') first := true _ = first @@ -278,27 +344,271 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(out *jwriter.Writer, in U // MarshalJSON supports json.Marshaler interface func (v User) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v User) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang2(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *User) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *User) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang2(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(l, v) +} +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(in *jlexer.Lexer, out *ThreadSubscribers) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "cursor": + out.Cursor = string(in.String()) + case "subscribers": + if in.IsNull() { + in.Skip() + out.Subscribers = nil + } else { + in.Delim('[') + if out.Subscribers == nil { + if !in.IsDelim(']') { + out.Subscribers = make([]Subscriber, 0, 2) + } else { + out.Subscribers = []Subscriber{} + } + } else { + out.Subscribers = (out.Subscribers)[:0] + } + for !in.IsDelim(']') { + var v7 Subscriber + (v7).UnmarshalEasyJSON(in) + out.Subscribers = append(out.Subscribers, v7) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(out *jwriter.Writer, in ThreadSubscribers) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"cursor\":" + out.RawString(prefix[1:]) + out.String(string(in.Cursor)) + } + { + const prefix string = ",\"subscribers\":" + out.RawString(prefix) + if in.Subscribers == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v8, v9 := range in.Subscribers { + if v8 > 0 { + out.RawByte(',') + } + (v9).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v ThreadSubscribers) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v ThreadSubscribers) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *ThreadSubscribers) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *ThreadSubscribers) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(l, v) +} +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(in *jlexer.Lexer, out *Thread) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "threadId": + out.ThreadID = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(out *jwriter.Writer, in Thread) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"threadId\":" + out.RawString(prefix[1:]) + out.String(string(in.ThreadID)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Thread) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Thread) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Thread) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Thread) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(l, v) +} +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(in *jlexer.Lexer, out *Subscriber) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "sn": + out.SN = string(in.String()) + case "userState": + (out.UserState).UnmarshalEasyJSON(in) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(out *jwriter.Writer, in Subscriber) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"sn\":" + out.RawString(prefix[1:]) + out.String(string(in.SN)) + } + { + const prefix string = ",\"userState\":" + out.RawString(prefix) + (in.UserState).MarshalEasyJSON(out) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Subscriber) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Subscriber) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Subscriber) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Subscriber) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(in *jlexer.Lexer, out *Response) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(in *jlexer.Lexer, out *Response) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -309,7 +619,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(in *jlexer.Lexer, out *Re } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -331,7 +641,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(in *jlexer.Lexer, out *Re in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(out *jwriter.Writer, in Response) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(out *jwriter.Writer, in Response) { out.RawByte('{') first := true _ = first @@ -351,27 +661,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(out *jwriter.Writer, in R // MarshalJSON supports json.Marshaler interface func (v Response) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Response) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang3(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Response) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang3(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(in *jlexer.Lexer, out *Photo) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(in *jlexer.Lexer, out *Photo) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -382,7 +692,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(in *jlexer.Lexer, out *Ph } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -402,7 +712,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(in *jlexer.Lexer, out *Ph in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(out *jwriter.Writer, in Photo) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(out *jwriter.Writer, in Photo) { out.RawByte('{') first := true _ = first @@ -417,27 +727,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(out *jwriter.Writer, in P // MarshalJSON supports json.Marshaler interface func (v Photo) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Photo) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang4(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Photo) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Photo) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang4(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(in *jlexer.Lexer, out *PartPayload) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *PartPayload) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -448,7 +758,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(in *jlexer.Lexer, out *Pa } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -480,7 +790,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(in *jlexer.Lexer, out *Pa in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(out *jwriter.Writer, in PartPayload) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in PartPayload) { out.RawByte('{') first := true _ = first @@ -525,27 +835,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(out *jwriter.Writer, in P // MarshalJSON supports json.Marshaler interface func (v PartPayload) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PartPayload) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang5(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PartPayload) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PartPayload) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang5(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(in *jlexer.Lexer, out *PartMessage) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(in *jlexer.Lexer, out *PartMessage) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -556,7 +866,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(in *jlexer.Lexer, out *Pa } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -582,7 +892,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(in *jlexer.Lexer, out *Pa in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(out *jwriter.Writer, in PartMessage) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(out *jwriter.Writer, in PartMessage) { out.RawByte('{') first := true _ = first @@ -612,27 +922,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(out *jwriter.Writer, in P // MarshalJSON supports json.Marshaler interface func (v PartMessage) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PartMessage) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang6(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PartMessage) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PartMessage) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang6(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(in *jlexer.Lexer, out *Part) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(in *jlexer.Lexer, out *Part) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -643,7 +953,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(in *jlexer.Lexer, out *Pa } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -665,7 +975,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(in *jlexer.Lexer, out *Pa in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(out *jwriter.Writer, in Part) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(out *jwriter.Writer, in Part) { out.RawByte('{') first := true _ = first @@ -685,27 +995,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(out *jwriter.Writer, in P // MarshalJSON supports json.Marshaler interface func (v Part) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Part) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang7(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Part) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Part) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang7(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(in *jlexer.Lexer, out *MembersListResponse) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(in *jlexer.Lexer, out *MembersListResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -716,7 +1026,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(in *jlexer.Lexer, out *Me } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -740,9 +1050,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(in *jlexer.Lexer, out *Me out.List = (out.List)[:0] } for !in.IsDelim(']') { - var v7 ChatMember - (v7).UnmarshalEasyJSON(in) - out.List = append(out.List, v7) + var v10 ChatMember + (v10).UnmarshalEasyJSON(in) + out.List = append(out.List, v10) in.WantComma() } in.Delim(']') @@ -757,7 +1067,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(in *jlexer.Lexer, out *Me in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(out *jwriter.Writer, in MembersListResponse) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(out *jwriter.Writer, in MembersListResponse) { out.RawByte('{') first := true _ = first @@ -768,11 +1078,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(out *jwriter.Writer, in M out.RawString("null") } else { out.RawByte('[') - for v8, v9 := range in.List { - if v8 > 0 { + for v11, v12 := range in.List { + if v11 > 0 { out.RawByte(',') } - (v9).MarshalEasyJSON(out) + (v12).MarshalEasyJSON(out) } out.RawByte(']') } @@ -783,27 +1093,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(out *jwriter.Writer, in M // MarshalJSON supports json.Marshaler interface func (v MembersListResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v MembersListResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang8(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *MembersListResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *MembersListResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang8(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *EventPayload) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(in *jlexer.Lexer, out *EventPayload) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -814,7 +1124,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -830,7 +1140,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev in.Delim('[') if out.Parts == nil { if !in.IsDelim(']') { - out.Parts = make([]Part, 0, 1) + out.Parts = make([]Part, 0, 0) } else { out.Parts = []Part{} } @@ -838,9 +1148,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev out.Parts = (out.Parts)[:0] } for !in.IsDelim(']') { - var v10 Part - (v10).UnmarshalEasyJSON(in) - out.Parts = append(out.Parts, v10) + var v13 Part + (v13).UnmarshalEasyJSON(in) + out.Parts = append(out.Parts, v13) in.WantComma() } in.Delim(']') @@ -867,9 +1177,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev out.LeftMembers = (out.LeftMembers)[:0] } for !in.IsDelim(']') { - var v11 Contact - (v11).UnmarshalEasyJSON(in) - out.LeftMembers = append(out.LeftMembers, v11) + var v14 Contact + (v14).UnmarshalEasyJSON(in) + out.LeftMembers = append(out.LeftMembers, v14) in.WantComma() } in.Delim(']') @@ -890,9 +1200,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev out.NewMembers = (out.NewMembers)[:0] } for !in.IsDelim(']') { - var v12 Contact - (v12).UnmarshalEasyJSON(in) - out.NewMembers = append(out.NewMembers, v12) + var v15 Contact + (v15).UnmarshalEasyJSON(in) + out.NewMembers = append(out.NewMembers, v15) in.WantComma() } in.Delim(']') @@ -911,6 +1221,16 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev out.Text = string(in.String()) case "timestamp": out.Timestamp = int(in.Int()) + case "parent_topic": + if in.IsNull() { + in.Skip() + out.ParentMessage = nil + } else { + if out.ParentMessage == nil { + out.ParentMessage = new(ParentMessage) + } + (*out.ParentMessage).UnmarshalEasyJSON(in) + } default: in.SkipRecursive() } @@ -921,7 +1241,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(in *jlexer.Lexer, out *Ev in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in EventPayload) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(out *jwriter.Writer, in EventPayload) { out.RawByte('{') first := true _ = first @@ -932,11 +1252,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawString("null") } else { out.RawByte('[') - for v13, v14 := range in.Parts { - if v13 > 0 { + for v16, v17 := range in.Parts { + if v16 > 0 { out.RawByte(',') } - (v14).MarshalEasyJSON(out) + (v17).MarshalEasyJSON(out) } out.RawByte(']') } @@ -963,11 +1283,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawString("null") } else { out.RawByte('[') - for v15, v16 := range in.LeftMembers { - if v15 > 0 { + for v18, v19 := range in.LeftMembers { + if v18 > 0 { out.RawByte(',') } - (v16).MarshalEasyJSON(out) + (v19).MarshalEasyJSON(out) } out.RawByte(']') } @@ -979,11 +1299,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawString("null") } else { out.RawByte('[') - for v17, v18 := range in.NewMembers { - if v17 > 0 { + for v20, v21 := range in.NewMembers { + if v20 > 0 { out.RawByte(',') } - (v18).MarshalEasyJSON(out) + (v21).MarshalEasyJSON(out) } out.RawByte(']') } @@ -1023,33 +1343,42 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(out *jwriter.Writer, in E out.RawString(prefix) out.Int(int(in.Timestamp)) } + { + const prefix string = ",\"parent_topic\":" + out.RawString(prefix) + if in.ParentMessage == nil { + out.RawString("null") + } else { + (*in.ParentMessage).MarshalEasyJSON(out) + } + } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface func (v EventPayload) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v EventPayload) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang9(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *EventPayload) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *EventPayload) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang9(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(in *jlexer.Lexer, out *Event) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(in *jlexer.Lexer, out *Event) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1060,7 +1389,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(in *jlexer.Lexer, out *E } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1084,7 +1413,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(in *jlexer.Lexer, out *E in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(out *jwriter.Writer, in Event) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(out *jwriter.Writer, in Event) { out.RawByte('{') first := true _ = first @@ -1109,27 +1438,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v Event) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Event) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang10(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Event) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang10(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(in *jlexer.Lexer, out *Contact) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(in *jlexer.Lexer, out *Contact) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1140,7 +1469,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(in *jlexer.Lexer, out *C } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1164,7 +1493,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(in *jlexer.Lexer, out *C in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(out *jwriter.Writer, in Contact) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(out *jwriter.Writer, in Contact) { out.RawByte('{') first := true _ = first @@ -1189,27 +1518,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v Contact) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Contact) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang11(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Contact) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Contact) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang11(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(in *jlexer.Lexer, out *ChatMember) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang16(in *jlexer.Lexer, out *ChatMember) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1220,7 +1549,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(in *jlexer.Lexer, out *C } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1244,7 +1573,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(in *jlexer.Lexer, out *C in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(out *jwriter.Writer, in ChatMember) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang16(out *jwriter.Writer, in ChatMember) { out.RawByte('{') first := true _ = first @@ -1269,27 +1598,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v ChatMember) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang16(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v ChatMember) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang12(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang16(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *ChatMember) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang16(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *ChatMember) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang12(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang16(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(in *jlexer.Lexer, out *BotInfo) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang17(in *jlexer.Lexer, out *BotInfo) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1300,7 +1629,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(in *jlexer.Lexer, out *B } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1330,9 +1659,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(in *jlexer.Lexer, out *B out.Photo = (out.Photo)[:0] } for !in.IsDelim(']') { - var v19 Photo - (v19).UnmarshalEasyJSON(in) - out.Photo = append(out.Photo, v19) + var v22 Photo + (v22).UnmarshalEasyJSON(in) + out.Photo = append(out.Photo, v22) in.WantComma() } in.Delim(']') @@ -1349,7 +1678,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(in *jlexer.Lexer, out *B in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(out *jwriter.Writer, in BotInfo) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang17(out *jwriter.Writer, in BotInfo) { out.RawByte('{') first := true _ = first @@ -1375,11 +1704,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(out *jwriter.Writer, in out.RawString("null") } else { out.RawByte('[') - for v20, v21 := range in.Photo { - if v20 > 0 { + for v23, v24 := range in.Photo { + if v23 > 0 { out.RawByte(',') } - (v21).MarshalEasyJSON(out) + (v24).MarshalEasyJSON(out) } out.RawByte(']') } @@ -1395,27 +1724,27 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v BotInfo) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang17(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v BotInfo) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang13(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang17(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *BotInfo) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang17(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *BotInfo) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang13(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang17(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(in *jlexer.Lexer, out *BaseEventPayload) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang18(in *jlexer.Lexer, out *BaseEventPayload) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1426,7 +1755,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(in *jlexer.Lexer, out *B } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1444,6 +1773,16 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(in *jlexer.Lexer, out *B out.Text = string(in.String()) case "timestamp": out.Timestamp = int(in.Int()) + case "parent_topic": + if in.IsNull() { + in.Skip() + out.ParentMessage = nil + } else { + if out.ParentMessage == nil { + out.ParentMessage = new(ParentMessage) + } + (*out.ParentMessage).UnmarshalEasyJSON(in) + } default: in.SkipRecursive() } @@ -1454,7 +1793,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(in *jlexer.Lexer, out *B in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(out *jwriter.Writer, in BaseEventPayload) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang18(out *jwriter.Writer, in BaseEventPayload) { out.RawByte('{') first := true _ = first @@ -1483,33 +1822,42 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(out *jwriter.Writer, in out.RawString(prefix) out.Int(int(in.Timestamp)) } + { + const prefix string = ",\"parent_topic\":" + out.RawString(prefix) + if in.ParentMessage == nil { + out.RawString("null") + } else { + (*in.ParentMessage).MarshalEasyJSON(out) + } + } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface func (v BaseEventPayload) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang18(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v BaseEventPayload) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang14(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang18(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *BaseEventPayload) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang18(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *BaseEventPayload) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang14(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang18(l, v) } -func easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(in *jlexer.Lexer, out *AdminsListResponse) { +func easyjson6601e8cdDecodeGithubComMailRuImBotGolang19(in *jlexer.Lexer, out *AdminsListResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1520,7 +1868,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(in *jlexer.Lexer, out *A } in.Delim('{') for !in.IsDelim('}') { - key := in.UnsafeString() + key := in.UnsafeFieldName(false) in.WantColon() if in.IsNull() { in.Skip() @@ -1544,9 +1892,9 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(in *jlexer.Lexer, out *A out.List = (out.List)[:0] } for !in.IsDelim(']') { - var v22 ChatMember - (v22).UnmarshalEasyJSON(in) - out.List = append(out.List, v22) + var v25 ChatMember + (v25).UnmarshalEasyJSON(in) + out.List = append(out.List, v25) in.WantComma() } in.Delim(']') @@ -1561,7 +1909,7 @@ func easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(in *jlexer.Lexer, out *A in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(out *jwriter.Writer, in AdminsListResponse) { +func easyjson6601e8cdEncodeGithubComMailRuImBotGolang19(out *jwriter.Writer, in AdminsListResponse) { out.RawByte('{') first := true _ = first @@ -1572,11 +1920,11 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(out *jwriter.Writer, in out.RawString("null") } else { out.RawByte('[') - for v23, v24 := range in.List { - if v23 > 0 { + for v26, v27 := range in.List { + if v26 > 0 { out.RawByte(',') } - (v24).MarshalEasyJSON(out) + (v27).MarshalEasyJSON(out) } out.RawByte(']') } @@ -1587,23 +1935,23 @@ func easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(out *jwriter.Writer, in // MarshalJSON supports json.Marshaler interface func (v AdminsListResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(&w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang19(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AdminsListResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMailRuImBotGolang15(w, v) + easyjson6601e8cdEncodeGithubComMailRuImBotGolang19(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AdminsListResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(&r, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang19(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AdminsListResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMailRuImBotGolang15(l, v) + easyjson6601e8cdDecodeGithubComMailRuImBotGolang19(l, v) } From 2e4d2bef55d8d50e670faecdf9bc96fa36bfa445 Mon Sep 17 00:00:00 2001 From: Mikhai Kalinin Date: Wed, 16 Jul 2025 14:31:34 +0300 Subject: [PATCH 2/3] [IMSERVER-20667] add empty checks --- client.go | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 73e707c..06e6a7d 100644 --- a/client.go +++ b/client.go @@ -115,6 +115,10 @@ func (c *Client) DoWithContext(ctx context.Context, path string, params url.Valu } func (c *Client) AutosubscribeToThreads(chatID string, enable, withExisting bool) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "enable": {strconv.FormatBool(enable)}, @@ -129,6 +133,13 @@ func (c *Client) AutosubscribeToThreads(chatID string, enable, withExisting bool } func (c *Client) AddThread(chatID, msgID string) (*Thread, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + if msgID == "" { + return nil, fmt.Errorf("msgID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "msgId": {msgID}, @@ -148,6 +159,10 @@ func (c *Client) AddThread(chatID, msgID string) (*Thread, error) { } func (c *Client) GetThreadSubscribers(threadID string, cursor string, pageSize int) (*ThreadSubscribers, error) { + if threadID == "" { + return nil, fmt.Errorf("threadID cannot be empty") + } + params := url.Values{ "threadId": {threadID}, } @@ -187,6 +202,10 @@ func (c *Client) GetInfo() (*BotInfo, error) { } func (c *Client) GetChatInfo(chatID string) (*Chat, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, } @@ -210,6 +229,13 @@ func (c *Client) GetChatInfo(chatID string) (*Chat, error) { } func (c *Client) SendChatActions(chatID string, actions ...ChatAction) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if len(actions) == 0 { + return fmt.Errorf("actions cannot be empty") + } + actionsMap := make(map[ChatAction]bool) filteredActions := make([]ChatAction, 0) for _, action := range actions { @@ -230,6 +256,10 @@ func (c *Client) SendChatActions(chatID string, actions ...ChatAction) error { } func (c *Client) GetChatAdmins(chatID string) ([]ChatMember, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, } @@ -247,6 +277,10 @@ func (c *Client) GetChatAdmins(chatID string) ([]ChatMember, error) { } func (c *Client) GetChatMembers(chatID string) ([]ChatMember, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, } @@ -264,6 +298,10 @@ func (c *Client) GetChatMembers(chatID string) ([]ChatMember, error) { } func (c *Client) GetChatBlockedUsers(chatID string) ([]User, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, } @@ -281,6 +319,10 @@ func (c *Client) GetChatBlockedUsers(chatID string) ([]User, error) { } func (c *Client) GetChatPendingUsers(chatID string) ([]User, error) { + if chatID == "" { + return nil, fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, } @@ -298,6 +340,13 @@ func (c *Client) GetChatPendingUsers(chatID string) ([]User, error) { } func (c *Client) BlockChatUser(chatID, userID string, deleteLastMessages bool) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if userID == "" { + return fmt.Errorf("userID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "userId": {userID}, @@ -317,6 +366,13 @@ func (c *Client) BlockChatUser(chatID, userID string, deleteLastMessages bool) e } func (c *Client) UnblockChatUser(chatID, userID string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if userID == "" { + return fmt.Errorf("userID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "userId": {userID}, @@ -335,6 +391,10 @@ func (c *Client) UnblockChatUser(chatID, userID string) error { } func (c *Client) ResolveChatPending(chatID, userID string, approve, everyone bool) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "approve": {strconv.FormatBool(approve)}, @@ -352,6 +412,13 @@ func (c *Client) ResolveChatPending(chatID, userID string, approve, everyone boo } func (c *Client) DeleteChatMembers(chatID string, members []string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if len(members) == 0 { + return fmt.Errorf("members list cannot be empty") + } + membersList := make([]map[string]string, len(members)) for i, member := range members { membersList[i] = map[string]string{"sn": member} @@ -374,6 +441,13 @@ func (c *Client) DeleteChatMembers(chatID string, members []string) error { } func (c *Client) AddChatMembers(chatID string, members []string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if len(members) == 0 { + return fmt.Errorf("members list cannot be empty") + } + membersList := make([]map[string]string, len(members)) for i, member := range members { membersList[i] = map[string]string{"sn": member} @@ -396,6 +470,13 @@ func (c *Client) AddChatMembers(chatID string, members []string) error { } func (c *Client) SetChatTitle(chatID, title string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if title == "" { + return fmt.Errorf("title cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "title": {title}, @@ -408,6 +489,10 @@ func (c *Client) SetChatTitle(chatID, title string) error { } func (c *Client) SetChatAbout(chatID, about string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "about": {about}, @@ -420,6 +505,10 @@ func (c *Client) SetChatAbout(chatID, about string) error { } func (c *Client) SetChatRules(chatID, rules string) error { + if chatID == "" { + return fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "chatId": {chatID}, "rules": {rules}, @@ -432,6 +521,10 @@ func (c *Client) SetChatRules(chatID, rules string) error { } func (c *Client) GetFileInfo(fileID string) (*File, error) { + if fileID == "" { + return nil, fmt.Errorf("fileID cannot be empty") + } + params := url.Values{ "fileId": {fileID}, } @@ -453,6 +546,16 @@ func (c *Client) GetVoiceInfo(fileID string) (*File, error) { } func (c *Client) SendTextMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.Text == "" { + return fmt.Errorf("text cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "text": {message.Text}, @@ -494,6 +597,16 @@ func (c *Client) SendTextMessage(message *Message) error { } func (c *Client) SendTextWithDeeplinkMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.Text == "" { + return fmt.Errorf("text cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "text": {message.Text}, @@ -540,6 +653,19 @@ func (c *Client) SendTextWithDeeplinkMessage(message *Message) error { } func (c *Client) EditMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.ID == "" { + return fmt.Errorf("message ID cannot be empty") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.Text == "" { + return fmt.Errorf("text cannot be empty") + } + params := url.Values{ "msgId": {message.ID}, "chatId": {message.Chat.ID}, @@ -572,6 +698,16 @@ func (c *Client) EditMessage(message *Message) error { } func (c *Client) DeleteMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.ID == "" { + return fmt.Errorf("message ID cannot be empty") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + params := url.Values{ "msgId": {message.ID}, "chatId": {message.Chat.ID}, @@ -585,6 +721,16 @@ func (c *Client) DeleteMessage(message *Message) error { } func (c *Client) SendFileMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.FileID == "" { + return fmt.Errorf("fileID cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "caption": {message.Text}, @@ -626,6 +772,16 @@ func (c *Client) SendFileMessage(message *Message) error { } func (c *Client) SendVoiceMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.FileID == "" { + return fmt.Errorf("fileID cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "caption": {message.Text}, @@ -663,6 +819,16 @@ func (c *Client) SendVoiceMessage(message *Message) error { } func (c *Client) UploadFile(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.File == nil { + return fmt.Errorf("file cannot be nil") + } + params := url.Values{ "chatId": {message.Chat.ID}, "caption": {message.Text}, @@ -690,6 +856,16 @@ func (c *Client) UploadFile(message *Message) error { } func (c *Client) UploadVoice(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.File == nil { + return fmt.Errorf("file cannot be nil") + } + params := url.Values{ "chatId": {message.Chat.ID}, "caption": {message.Text}, @@ -740,6 +916,16 @@ func (c *Client) GetEventsWithContext(ctx context.Context, lastEventID int, poll } func (c *Client) PinMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.ID == "" { + return fmt.Errorf("message ID cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "msgId": {message.ID}, @@ -753,6 +939,16 @@ func (c *Client) PinMessage(message *Message) error { } func (c *Client) UnpinMessage(message *Message) error { + if message == nil { + return fmt.Errorf("message cannot be nil") + } + if message.Chat.ID == "" { + return fmt.Errorf("chatID cannot be empty") + } + if message.ID == "" { + return fmt.Errorf("message ID cannot be empty") + } + params := url.Values{ "chatId": {message.Chat.ID}, "msgId": {message.ID}, @@ -766,6 +962,13 @@ func (c *Client) UnpinMessage(message *Message) error { } func (c *Client) SendAnswerCallbackQuery(answer *ButtonResponse) error { + if answer == nil { + return fmt.Errorf("answer cannot be nil") + } + if answer.QueryID == "" { + return fmt.Errorf("queryID cannot be empty") + } + params := url.Values{ "queryId": {answer.QueryID}, "text": {answer.Text}, @@ -783,7 +986,6 @@ func (c *Client) SendAnswerCallbackQuery(answer *ButtonResponse) error { func NewClient(baseURL string, token string, logger *logrus.Logger) *Client { return NewCustomClient(http.DefaultClient, baseURL, token, logger) - } func NewCustomClient(client *http.Client, baseURL string, token string, logger *logrus.Logger) *Client { From 9163e4d2554024be14cfbdb38bf03ca4d8d9059a Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 21 Jul 2025 11:21:54 +0300 Subject: [PATCH 3/3] [IMSERVER-20667] fix error format --- client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 06e6a7d..d5ef665 100644 --- a/client.go +++ b/client.go @@ -126,7 +126,7 @@ func (c *Client) AutosubscribeToThreads(chatID string, enable, withExisting bool } if _, err := c.Do("/threads/autosubscribe", params, nil); err != nil { - return fmt.Errorf("error while requesting threads autosubscribe: %s", err) + return fmt.Errorf("error while requesting threads autosubscribe: %w", err) } return nil @@ -147,12 +147,12 @@ func (c *Client) AddThread(chatID, msgID string) (*Thread, error) { response, err := c.Do("/threads/add", params, nil) if err != nil { - return nil, fmt.Errorf("error while adding thread: %s", err) + return nil, fmt.Errorf("error while adding thread: %w", err) } thread := &Thread{} if err := json.Unmarshal(response, thread); err != nil { - return nil, fmt.Errorf("error while unmarshalling thread response: %s", err) + return nil, fmt.Errorf("error while unmarshalling thread response: %w", err) } return thread, nil @@ -176,12 +176,12 @@ func (c *Client) GetThreadSubscribers(threadID string, cursor string, pageSize i response, err := c.Do("/threads/subscribers/get", params, nil) if err != nil { - return nil, fmt.Errorf("error while getting thread subscribers: %s", err) + return nil, fmt.Errorf("error while getting thread subscribers: %w", err) } threadSubscribers := &ThreadSubscribers{} if err := json.Unmarshal(response, threadSubscribers); err != nil { - return nil, fmt.Errorf("error while unmarshalling thread subscribers response: %s", err) + return nil, fmt.Errorf("error while unmarshalling thread subscribers response: %w", err) } return threadSubscribers, nil