package tg
import "context"
type AnyMessageHandler func (ctx context .Context , e Entities , msg MessageClass ) error
func (u UpdateDispatcher ) OnAnyNewMessage (handler AnyMessageHandler ) {
u .OnNewMessage (func (ctx context .Context , e Entities , update *UpdateNewMessage ) error {
return handler (ctx , e , update .Message )
})
u .OnNewChannelMessage (func (ctx context .Context , e Entities , update *UpdateNewChannelMessage ) error {
return handler (ctx , e , update .Message )
})
}
func (u UpdateDispatcher ) OnAnyEditMessage (handler AnyMessageHandler ) {
u .OnEditMessage (func (ctx context .Context , e Entities , update *UpdateEditMessage ) error {
return handler (ctx , e , update .Message )
})
u .OnEditChannelMessage (func (ctx context .Context , e Entities , update *UpdateEditChannelMessage ) error {
return handler (ctx , e , update .Message )
})
}
type AnyDeleteMessagesHandler func (ctx context .Context , e Entities , channelID int64 , ids []int ) error
func (u UpdateDispatcher ) OnAnyDeleteMessages (handler AnyDeleteMessagesHandler ) {
u .OnDeleteMessages (func (ctx context .Context , e Entities , update *UpdateDeleteMessages ) error {
return handler (ctx , e , 0 , update .Messages )
})
u .OnDeleteChannelMessages (func (ctx context .Context , e Entities , update *UpdateDeleteChannelMessages ) error {
return handler (ctx , e , update .ChannelID , update .Messages )
})
}
type AnyRead struct {
Peer PeerClass
MaxID int
TopMsgID int
SavedPeer PeerClass
Update UpdateClass
}
type AnyReadHandler func (ctx context .Context , e Entities , read AnyRead ) error
func (u UpdateDispatcher ) OnAnyReadInbox (handler AnyReadHandler ) {
u .OnReadHistoryInbox (func (ctx context .Context , e Entities , update *UpdateReadHistoryInbox ) error {
return handler (ctx , e , AnyRead {
Peer : update .Peer ,
MaxID : update .MaxID ,
TopMsgID : update .TopMsgID ,
Update : update ,
})
})
u .OnReadChannelInbox (func (ctx context .Context , e Entities , update *UpdateReadChannelInbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .MaxID ,
Update : update ,
})
})
u .OnReadChannelDiscussionInbox (func (ctx context .Context , e Entities , update *UpdateReadChannelDiscussionInbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .ReadMaxID ,
TopMsgID : update .TopMsgID ,
Update : update ,
})
})
u .OnReadMonoForumInbox (func (ctx context .Context , e Entities , update *UpdateReadMonoForumInbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .ReadMaxID ,
SavedPeer : update .SavedPeerID ,
Update : update ,
})
})
}
func (u UpdateDispatcher ) OnAnyReadOutbox (handler AnyReadHandler ) {
u .OnReadHistoryOutbox (func (ctx context .Context , e Entities , update *UpdateReadHistoryOutbox ) error {
return handler (ctx , e , AnyRead {
Peer : update .Peer ,
MaxID : update .MaxID ,
Update : update ,
})
})
u .OnReadChannelOutbox (func (ctx context .Context , e Entities , update *UpdateReadChannelOutbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .MaxID ,
Update : update ,
})
})
u .OnReadChannelDiscussionOutbox (func (ctx context .Context , e Entities , update *UpdateReadChannelDiscussionOutbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .ReadMaxID ,
TopMsgID : update .TopMsgID ,
Update : update ,
})
})
u .OnReadMonoForumOutbox (func (ctx context .Context , e Entities , update *UpdateReadMonoForumOutbox ) error {
return handler (ctx , e , AnyRead {
Peer : &PeerChannel {ChannelID : update .ChannelID },
MaxID : update .ReadMaxID ,
SavedPeer : update .SavedPeerID ,
Update : update ,
})
})
}
type AnyTyping struct {
Peer PeerClass
From PeerClass
TopMsgID int
Action SendMessageActionClass
Update UpdateClass
}
type AnyTypingHandler func (ctx context .Context , e Entities , typing AnyTyping ) error
func (u UpdateDispatcher ) OnAnyTyping (handler AnyTypingHandler ) {
u .OnUserTyping (func (ctx context .Context , e Entities , update *UpdateUserTyping ) error {
user := &PeerUser {UserID : update .UserID }
return handler (ctx , e , AnyTyping {
Peer : user ,
From : user ,
TopMsgID : update .TopMsgID ,
Action : update .Action ,
Update : update ,
})
})
u .OnChatUserTyping (func (ctx context .Context , e Entities , update *UpdateChatUserTyping ) error {
return handler (ctx , e , AnyTyping {
Peer : &PeerChat {ChatID : update .ChatID },
From : update .FromID ,
Action : update .Action ,
Update : update ,
})
})
u .OnChannelUserTyping (func (ctx context .Context , e Entities , update *UpdateChannelUserTyping ) error {
return handler (ctx , e , AnyTyping {
Peer : &PeerChannel {ChannelID : update .ChannelID },
From : update .FromID ,
TopMsgID : update .TopMsgID ,
Action : update .Action ,
Update : update ,
})
})
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .