Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Telegram schema to the latest layer #874

Merged
merged 2 commits into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
132 changes: 104 additions & 28 deletions _schema/tdesktop.tl

Large diffs are not rendered by default.

132 changes: 104 additions & 28 deletions _schema/telegram.tl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions telegram/message/request.go
Expand Up @@ -14,13 +14,13 @@ type RequestBuilder struct {
}

// Reaction sends reaction for given message.
func (b *RequestBuilder) Reaction(ctx context.Context, msgID int, reaction string) (tg.UpdatesClass, error) {
func (b *RequestBuilder) Reaction(ctx context.Context, msgID int, reaction ...tg.ReactionClass) (tg.UpdatesClass, error) {
p, err := b.peer(ctx)
if err != nil {
return nil, errors.Wrap(err, "peer")
}

upd, err := b.sender.sendReaction(ctx, p, msgID, reaction)
upd, err := b.sender.sendReaction(ctx, p, msgID, reaction...)
if err != nil {
return nil, errors.Wrap(err, "send reaction")
}
Expand Down
11 changes: 7 additions & 4 deletions telegram/message/request_test.go
Expand Up @@ -14,20 +14,23 @@ func TestRequestBuilder_Reaction(t *testing.T) {
ctx := context.Background()
sender, mock := testSender(t)

reaction := []tg.ReactionClass{
&tg.ReactionEmoji{Emoticon: "A"},
}
mock.ExpectCall(&tg.MessagesSendReactionRequest{
Peer: &tg.InputPeerSelf{},
MsgID: 10,
Reaction: "A",
Reaction: reaction,
}).ThenResult(&tg.Updates{})
_, err := sender.Self().Reaction(ctx, 10, "A")
_, err := sender.Self().Reaction(ctx, 10, reaction[0])
require.NoError(t, err)

mock.ExpectCall(&tg.MessagesSendReactionRequest{
Peer: &tg.InputPeerSelf{},
MsgID: 10,
Reaction: "A",
Reaction: reaction,
}).ThenRPCErr(testRPCError())
_, err = sender.Self().Reaction(ctx, 10, "A")
_, err = sender.Self().Reaction(ctx, 10, reaction[0])
require.Error(t, err)
}

Expand Down
2 changes: 1 addition & 1 deletion telegram/message/sender.go
Expand Up @@ -171,7 +171,7 @@ func (s *Sender) reportSpam(ctx context.Context, p tg.InputPeerClass) (bool, err

func (s *Sender) sendReaction(
ctx context.Context,
p tg.InputPeerClass, msgID int, reaction string,
p tg.InputPeerClass, msgID int, reaction ...tg.ReactionClass,
) (tg.UpdatesClass, error) {
return s.raw.MessagesSendReaction(ctx, &tg.MessagesSendReactionRequest{
Peer: p,
Expand Down
8 changes: 5 additions & 3 deletions telegram/peers/channel.go
Expand Up @@ -287,13 +287,15 @@ func (c Channel) SetDescription(ctx context.Context, about string) error {
// SetReactions sets list of available reactions.
//
// Empty list disables reactions at all.
func (c Channel) SetReactions(ctx context.Context, reactions ...string) error {
return c.m.editReactions(ctx, c.InputPeer(), reactions...)
func (c Channel) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error {
return c.m.editReactions(ctx, c.InputPeer(), &tg.ChatReactionsSome{
Reactions: reactions,
})
}

// DisableReactions disables reactions.
func (c Channel) DisableReactions(ctx context.Context) error {
return c.m.editReactions(ctx, c.InputPeer())
return c.m.editReactions(ctx, c.InputPeer(), &tg.ChatReactionsNone{})
}

// TODO(tdakkota): add more getters, helpers and convertors
8 changes: 5 additions & 3 deletions telegram/peers/chat.go
Expand Up @@ -258,13 +258,15 @@ func (c Chat) SetDescription(ctx context.Context, about string) error {
// SetReactions sets list of available reactions.
//
// Empty list disables reactions at all.
func (c Chat) SetReactions(ctx context.Context, reactions ...string) error {
return c.m.editReactions(ctx, c.InputPeer(), reactions...)
func (c Chat) SetReactions(ctx context.Context, reactions ...tg.ReactionClass) error {
return c.m.editReactions(ctx, c.InputPeer(), &tg.ChatReactionsSome{
Reactions: reactions,
})
}

// DisableReactions disables reactions.
func (c Chat) DisableReactions(ctx context.Context) error {
return c.m.editReactions(ctx, c.InputPeer())
return c.m.editReactions(ctx, c.InputPeer(), &tg.ChatReactionsNone{})
}

// LeaveAndDelete leaves this chat and removes the entire chat history of this user in this chat.
Expand Down
2 changes: 1 addition & 1 deletion telegram/peers/multichat.go
Expand Up @@ -21,7 +21,7 @@ func (m *Manager) editAbout(ctx context.Context, p tg.InputPeerClass, about stri
return nil
}

func (m *Manager) editReactions(ctx context.Context, p tg.InputPeerClass, reactions ...string) error {
func (m *Manager) editReactions(ctx context.Context, p tg.InputPeerClass, reactions tg.ChatReactionsClass) error {
if _, err := m.api.MessagesSetChatAvailableReactions(ctx, &tg.MessagesSetChatAvailableReactionsRequest{
Peer: p,
AvailableReactions: reactions,
Expand Down
15 changes: 11 additions & 4 deletions telegram/peers/multichat_test.go
Expand Up @@ -31,7 +31,7 @@ type multiChat interface {
ToSupergroup() (Supergroup, bool)
IsSupergroup() bool

SetReactions(ctx context.Context, r ...string) error
SetReactions(ctx context.Context, r ...tg.ReactionClass) error
DisableReactions(ctx context.Context) error
}

Expand All @@ -45,13 +45,20 @@ func TestReactions(t *testing.T) {
ctx := context.Background()
mock, m := testManager(t)

req := func(p Peer, r ...string) *tgmock.RequestBuilder {
req := func(p Peer, r ...tg.ReactionClass) *tgmock.RequestBuilder {
var reactions tg.ChatReactionsClass = &tg.ChatReactionsSome{Reactions: r}
if len(r) == 0 {
reactions = &tg.ChatReactionsNone{}
}
return mock.ExpectCall(&tg.MessagesSetChatAvailableReactionsRequest{
Peer: p.InputPeer(),
AvailableReactions: r,
AvailableReactions: reactions,
})
}
reactions := []string{"a", "b", "c"}
reactions := []tg.ReactionClass{
&tg.ReactionEmoji{Emoticon: "👍"},
&tg.ReactionEmoji{Emoticon: "A"},
}
for _, p := range []multiChat{
m.Chat(getTestChat()),
m.Channel(getTestChannel()),
Expand Down