connector: rename files to be more consistent with other bridges
This commit is contained in:
@@ -34,6 +34,11 @@ import (
|
|||||||
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
|
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ bridgev2.BackfillingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.BackfillingNetworkAPIWithLimits = (*TelegramClient)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
// getTakeoutID blocks until the takeout ID is available.
|
// getTakeoutID blocks until the takeout ID is available.
|
||||||
func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err error) {
|
func (t *TelegramClient) getTakeoutID(ctx context.Context) (takeoutID int64, err error) {
|
||||||
// Always stop the takeout timeout timer
|
// Always stop the takeout timeout timer
|
||||||
|
|||||||
+1
-17
@@ -109,23 +109,7 @@ type TelegramClient struct {
|
|||||||
prevReactionPoll map[networkid.PortalKey]time.Time
|
prevReactionPoll map[networkid.PortalKey]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var _ bridgev2.NetworkAPI = (*TelegramClient)(nil)
|
||||||
_ bridgev2.NetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.EditHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.ReactionHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.RedactionHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.ReadReceiptHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.TypingHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.BackfillingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.BackfillingNetworkAPIWithLimits = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.IdentifierResolvingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.ContactListingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.UserSearchingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.GroupCreatingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.MuteHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.TagHandlingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
_ bridgev2.DisappearTimerChangingNetworkAPI = (*TelegramClient)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateDispatcher struct {
|
type UpdateDispatcher struct {
|
||||||
tg.UpdateDispatcher
|
tg.UpdateDispatcher
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
"math"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -36,6 +38,7 @@ import (
|
|||||||
"go.mau.fi/util/ffmpeg"
|
"go.mau.fi/util/ffmpeg"
|
||||||
"go.mau.fi/util/variationselector"
|
"go.mau.fi/util/variationselector"
|
||||||
"go.mau.fi/webp"
|
"go.mau.fi/webp"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
"maunium.net/go/mautrix/bridgev2"
|
"maunium.net/go/mautrix/bridgev2"
|
||||||
"maunium.net/go/mautrix/bridgev2/database"
|
"maunium.net/go/mautrix/bridgev2/database"
|
||||||
"maunium.net/go/mautrix/bridgev2/networkid"
|
"maunium.net/go/mautrix/bridgev2/networkid"
|
||||||
@@ -53,6 +56,17 @@ import (
|
|||||||
"go.mau.fi/mautrix-telegram/pkg/connector/waveform"
|
"go.mau.fi/mautrix-telegram/pkg/connector/waveform"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ bridgev2.EditHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.ReactionHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.RedactionHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.ReadReceiptHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.TypingHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.DisappearTimerChangingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.MuteHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.TagHandlingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
func getMediaFilename(content *event.MessageEventContent) (filename string) {
|
func getMediaFilename(content *event.MessageEventContent) (filename string) {
|
||||||
if content.FileName != "" {
|
if content.FileName != "" {
|
||||||
filename = content.FileName
|
filename = content.FileName
|
||||||
@@ -734,3 +748,34 @@ func (t *TelegramClient) HandleMatrixDisappearingTimer(ctx context.Context, msg
|
|||||||
}
|
}
|
||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TelegramClient) HandleMute(ctx context.Context, msg *bridgev2.MatrixMute) error {
|
||||||
|
inputPeer, err := t.inputPeerForPortalID(ctx, msg.Portal.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
settings := tg.InputPeerNotifySettings{
|
||||||
|
Silent: msg.Content.IsMuted(),
|
||||||
|
MuteUntil: int(max(0, min(msg.Content.GetMutedUntilTime().Unix(), math.MaxInt32))),
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = t.client.API().AccountUpdateNotifySettings(ctx, &tg.AccountUpdateNotifySettingsRequest{
|
||||||
|
Peer: &tg.InputNotifyPeer{Peer: inputPeer},
|
||||||
|
Settings: settings,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TelegramClient) HandleRoomTag(ctx context.Context, msg *bridgev2.MatrixRoomTag) error {
|
||||||
|
inputPeer, err := t.inputPeerForPortalID(ctx, msg.Portal.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = t.client.API().MessagesToggleDialogPin(ctx, &tg.MessagesToggleDialogPinRequest{
|
||||||
|
Pinned: slices.Contains(maps.Keys(msg.Content.Tags), event.RoomTagFavourite),
|
||||||
|
Peer: &tg.InputDialogPeer{Peer: inputPeer},
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -1172,24 +1171,6 @@ func (t *TelegramClient) onNotifySettings(ctx context.Context, e tg.Entities, up
|
|||||||
return resultToError(res)
|
return resultToError(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) HandleMute(ctx context.Context, msg *bridgev2.MatrixMute) error {
|
|
||||||
inputPeer, err := t.inputPeerForPortalID(ctx, msg.Portal.ID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
settings := tg.InputPeerNotifySettings{
|
|
||||||
Silent: msg.Content.IsMuted(),
|
|
||||||
MuteUntil: int(max(0, min(msg.Content.GetMutedUntilTime().Unix(), math.MaxInt32))),
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = t.client.API().AccountUpdateNotifySettings(ctx, &tg.AccountUpdateNotifySettingsRequest{
|
|
||||||
Peer: &tg.InputNotifyPeer{Peer: inputPeer},
|
|
||||||
Settings: settings,
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TelegramClient) onPinnedDialogs(ctx context.Context, e tg.Entities, msg *tg.UpdatePinnedDialogs) error {
|
func (t *TelegramClient) onPinnedDialogs(ctx context.Context, e tg.Entities, msg *tg.UpdatePinnedDialogs) error {
|
||||||
needsUnpinning := map[networkid.PortalKey]struct{}{}
|
needsUnpinning := map[networkid.PortalKey]struct{}{}
|
||||||
for _, portalID := range t.userLogin.Metadata.(*UserLoginMetadata).PinnedDialogs {
|
for _, portalID := range t.userLogin.Metadata.(*UserLoginMetadata).PinnedDialogs {
|
||||||
@@ -1249,19 +1230,6 @@ func (t *TelegramClient) onPinnedDialogs(ctx context.Context, e tg.Entities, msg
|
|||||||
return t.userLogin.Save(ctx)
|
return t.userLogin.Save(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) HandleRoomTag(ctx context.Context, msg *bridgev2.MatrixRoomTag) error {
|
|
||||||
inputPeer, err := t.inputPeerForPortalID(ctx, msg.Portal.ID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = t.client.API().MessagesToggleDialogPin(ctx, &tg.MessagesToggleDialogPinRequest{
|
|
||||||
Pinned: slices.Contains(maps.Keys(msg.Content.Tags), event.RoomTagFavourite),
|
|
||||||
Peer: &tg.InputDialogPeer{Peer: inputPeer},
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TelegramClient) onChatDefaultBannedRights(ctx context.Context, entities tg.Entities, update *tg.UpdateChatDefaultBannedRights) error {
|
func (t *TelegramClient) onChatDefaultBannedRights(ctx context.Context, entities tg.Entities, update *tg.UpdateChatDefaultBannedRights) error {
|
||||||
res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatResync{
|
res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatResync{
|
||||||
ChatInfo: &bridgev2.ChatInfo{
|
ChatInfo: &bridgev2.ChatInfo{
|
||||||
@@ -33,6 +33,13 @@ import (
|
|||||||
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
|
"go.mau.fi/mautrix-telegram/pkg/connector/ids"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ bridgev2.IdentifierResolvingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.ContactListingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.UserSearchingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
_ bridgev2.GroupCreatingNetworkAPI = (*TelegramClient)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
func (t *TelegramClient) getResolveIdentifierResponseForUser(ctx context.Context, user tg.UserClass) (*bridgev2.ResolveIdentifierResponse, error) {
|
func (t *TelegramClient) getResolveIdentifierResponseForUser(ctx context.Context, user tg.UserClass) (*bridgev2.ResolveIdentifierResponse, error) {
|
||||||
networkUserID := ids.MakeUserID(user.GetID())
|
networkUserID := ids.MakeUserID(user.GetID())
|
||||||
if userInfo, err := t.getUserInfoFromTelegramUser(ctx, user); err != nil {
|
if userInfo, err := t.getUserInfoFromTelegramUser(ctx, user); err != nil {
|
||||||
Reference in New Issue
Block a user