move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package mtproto
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
)
|
||||
|
||||
func (c *Conn) writeContentMessage(ctx context.Context, msgID int64, seqNo int32, message bin.Encoder) error {
|
||||
return c.write(ctx, msgID, seqNo, message)
|
||||
}
|
||||
|
||||
func (c *Conn) writeServiceMessage(ctx context.Context, message bin.Encoder) error {
|
||||
msgID, seqNo := c.nextMsgSeq(false)
|
||||
return c.write(ctx, msgID, seqNo, message)
|
||||
}
|
||||
|
||||
var bufPool = bin.NewPool(0)
|
||||
|
||||
func (c *Conn) write(ctx context.Context, msgID int64, seqNo int32, message bin.Encoder) error {
|
||||
// Grab shared lock for writing.
|
||||
// It prevents message sending during key regeneration if server forgot current auth key.
|
||||
c.exchangeLock.RLock()
|
||||
defer c.exchangeLock.RUnlock()
|
||||
|
||||
b := bufPool.Get()
|
||||
defer bufPool.Put(b)
|
||||
|
||||
if err := c.newEncryptedMessage(msgID, seqNo, message, b); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.conn.Send(ctx, b); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) nextMsgSeq(content bool) (msgID int64, seqNo int32) {
|
||||
c.reqMux.Lock()
|
||||
defer c.reqMux.Unlock()
|
||||
|
||||
msgID = c.newMessageID()
|
||||
|
||||
// Computing current sequence number (seqno).
|
||||
// This should be serialized with new message id generation.
|
||||
//
|
||||
// See https://github.com/gotd/td/issues/245 for reference.
|
||||
seqNo = c.sentContentMessages * 2
|
||||
if content {
|
||||
seqNo++
|
||||
c.sentContentMessages++
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user