all: add some todos and fix small issues
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "go.mau.fi/util/dbutil/litestream"
|
||||
"maunium.net/go/mautrix/bridgev2/matrix/mxmain"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/connector"
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func (t *TelegramClient) getDMChatInfo(ctx context.Context, userID int64) (*bridgev2.ChatInfo, error) {
|
||||
// FIXME there's no reason for this function to fetch the user info
|
||||
chatInfo := bridgev2.ChatInfo{
|
||||
Type: ptr.Ptr(database.RoomTypeDM),
|
||||
Members: &bridgev2.ChatMemberList{IsFull: true},
|
||||
@@ -74,7 +75,7 @@ func (t *TelegramClient) getGroupChatInfo(fullChat *tg.MessagesChatFull, chatID
|
||||
|
||||
chatInfo := bridgev2.ChatInfo{
|
||||
Name: name,
|
||||
Type: ptr.Ptr(database.RoomTypeGroupDM), // TODO Is this correct for channels?
|
||||
Type: ptr.Ptr(database.RoomTypeDefault),
|
||||
Members: &bridgev2.ChatMemberList{
|
||||
IsFull: true,
|
||||
MemberMap: map[networkid.UserID]bridgev2.ChatMember{},
|
||||
@@ -138,6 +139,8 @@ func (t *TelegramClient) filterChannelParticipants(chatParticipants []tg.Channel
|
||||
}
|
||||
|
||||
func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) (*bridgev2.ChatInfo, error) {
|
||||
// FIXME GetFullChat should be avoided. Using only bundled info should be preferred whenever possible
|
||||
// (e.g. when syncing dialogs, only use the data in the dialog list, don't fetch each chat info separately).
|
||||
peerType, id, err := ids.ParsePortalID(portal.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -90,7 +90,7 @@ func (u UpdateDispatcher) Handle(ctx context.Context, updates tg.UpdatesClass) e
|
||||
return u.UpdateDispatcher.Handle(ctx, updates)
|
||||
}
|
||||
|
||||
var messageLinkRegex = regexp.MustCompile(`^https?:\/\/t(?:elegram)?\.(?:me|dog)\/([A-Za-z][A-Za-z0-9_]{3,31}[A-Za-z0-9]|[Cc]\/[0-9]{1,20})\/([0-9]{1,20})$`)
|
||||
var messageLinkRegex = regexp.MustCompile(`^https?://t(?:elegram)?\.(?:me|dog)/([A-Za-z][A-Za-z0-9_]{3,31}[A-Za-z0-9]|[Cc]/[0-9]{1,20})/([0-9]{1,20})$`)
|
||||
|
||||
func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridgev2.UserLogin) (*TelegramClient, error) {
|
||||
telegramUserID, err := ids.ParseUserLoginID(login.ID)
|
||||
@@ -197,12 +197,14 @@ func NewTelegramClient(ctx context.Context, tc *TelegramConnector, login *bridge
|
||||
return telegramfmt.UserInfo{}, err
|
||||
}
|
||||
userInfo := telegramfmt.UserInfo{MXID: ghost.Intent.GetMXID(), Name: ghost.Name}
|
||||
// FIXME this should look for user logins by ID, not hardcode the current user
|
||||
if id == client.telegramUserID {
|
||||
userInfo.MXID = client.userLogin.UserMXID
|
||||
}
|
||||
return userInfo, nil
|
||||
},
|
||||
GetUserInfoByUsername: func(ctx context.Context, username string) (telegramfmt.UserInfo, error) {
|
||||
// FIXME this should just query telegram_user_metadata by username
|
||||
ghosts, err := tc.Bridge.DB.Ghost.GetByMetadata(ctx, "username", username)
|
||||
if err != nil {
|
||||
return telegramfmt.UserInfo{}, err
|
||||
|
||||
@@ -29,6 +29,7 @@ func (c MemberListConfig) NormalizedMaxInitialSync() int {
|
||||
}
|
||||
|
||||
type TelegramConfig struct {
|
||||
// FIXME these should be called api_id and api_hash
|
||||
AppID int `yaml:"app_id"`
|
||||
AppHash string `yaml:"app_hash"`
|
||||
|
||||
|
||||
@@ -65,12 +65,13 @@ func (tc *TelegramConnector) LoadUserLogin(ctx context.Context, login *bridgev2.
|
||||
|
||||
func (tg *TelegramConnector) GetName() bridgev2.BridgeName {
|
||||
return bridgev2.BridgeName{
|
||||
DisplayName: "Telegram",
|
||||
NetworkURL: "https://telegram.org/",
|
||||
NetworkIcon: "mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX",
|
||||
NetworkID: "telegram",
|
||||
BeeperBridgeType: "telegram",
|
||||
DefaultPort: 29317,
|
||||
DisplayName: "Telegram",
|
||||
NetworkURL: "https://telegram.org/",
|
||||
NetworkIcon: "mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX",
|
||||
NetworkID: "telegram",
|
||||
BeeperBridgeType: "telegram",
|
||||
DefaultPort: 29317,
|
||||
DefaultCommandPrefix: "!tg",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ func (tc *TelegramConnector) Download(ctx context.Context, mediaID networkid.Med
|
||||
ctx = log.WithContext(ctx)
|
||||
log.Info().Msg("handling direct download")
|
||||
|
||||
// TODO have an in-memory cache for media references?
|
||||
|
||||
userLogin, err := tc.Bridge.GetExistingUserLoginByID(ctx, ids.MakeUserLoginID(info.ReceiverID))
|
||||
if err != nil {
|
||||
if info.PeerType != ids.PeerTypeChannel {
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TODO this should probably be moved to mautrix-go
|
||||
|
||||
type GeoURI struct {
|
||||
Lat float64
|
||||
Long float64
|
||||
|
||||
@@ -25,7 +25,6 @@ func MakeUserLoginID(userID int64) networkid.UserLoginID {
|
||||
return networkid.UserLoginID(strconv.FormatInt(userID, 10))
|
||||
}
|
||||
|
||||
// TODO: add space ID
|
||||
func MakeMessageID(messageID int) networkid.MessageID {
|
||||
return networkid.MessageID(strconv.Itoa(messageID))
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ import (
|
||||
"go.mau.fi/mautrix-telegram/pkg/connector/util"
|
||||
)
|
||||
|
||||
// TODO QR login support
|
||||
|
||||
const LoginFlowIDPhone = "phone"
|
||||
|
||||
func (tg *TelegramConnector) GetLoginFlows() []bridgev2.LoginFlow {
|
||||
|
||||
@@ -367,6 +367,7 @@ func (parser *HTMLParser) linkToString(node *html.Node, ctx Context) *EntityStri
|
||||
// Mention not allowed, use name as-is
|
||||
return str
|
||||
}
|
||||
// FIXME this or GetGhostDetails needs to support non-ghost users too
|
||||
userID, username, accessHash, ok := parser.GetGhostDetails(ctx.Ctx, mxid)
|
||||
if !ok {
|
||||
return str
|
||||
|
||||
@@ -29,6 +29,7 @@ func getLargestPhotoSize(sizes []tg.PhotoSizeClass) (width, height int, largest
|
||||
panic("cannot get largest size from empty list of sizes")
|
||||
}
|
||||
|
||||
// FIXME this max size seems to be confusing bytes and dimensions.
|
||||
var maxSize int
|
||||
for _, s := range sizes {
|
||||
var currentSize int
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
-- v0 -> v3: Latest revision
|
||||
|
||||
CREATE TABLE telegram_session (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
user_id BIGINT PRIMARY KEY,
|
||||
session_data BYTEA NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE telegram_user_state (
|
||||
user_id INTEGER PRIMARY KEY,
|
||||
pts INTEGER NOT NULL,
|
||||
qts INTEGER NOT NULL,
|
||||
date INTEGER NOT NULL,
|
||||
seq INTEGER NOT NULL
|
||||
user_id BIGINT PRIMARY KEY,
|
||||
pts BIGINT NOT NULL,
|
||||
qts BIGINT NOT NULL,
|
||||
date BIGINT NOT NULL,
|
||||
seq BIGINT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE telegram_channel_state (
|
||||
user_id INTEGER,
|
||||
channel_id INTEGER,
|
||||
pts INTEGER NOT NULL,
|
||||
user_id BIGINT,
|
||||
channel_id BIGINT,
|
||||
pts BIGINT NOT NULL,
|
||||
|
||||
PRIMARY KEY (user_id, channel_id)
|
||||
);
|
||||
@@ -24,18 +24,18 @@ CREATE TABLE telegram_channel_state (
|
||||
CREATE INDEX idx_telegram_channel_state_user_id ON telegram_channel_state (user_id);
|
||||
|
||||
CREATE TABLE telegram_channel_access_hashes (
|
||||
user_id INTEGER,
|
||||
channel_id INTEGER,
|
||||
access_hash INTEGER NOT NULL,
|
||||
user_id BIGINT,
|
||||
channel_id BIGINT,
|
||||
access_hash BIGINT NOT NULL,
|
||||
|
||||
PRIMARY KEY (user_id, channel_id)
|
||||
);
|
||||
|
||||
CREATE TABLE telegram_user_metadata (
|
||||
receiver_id INTEGER,
|
||||
user_id INTEGER,
|
||||
receiver_id BIGINT,
|
||||
user_id BIGINT,
|
||||
|
||||
access_hash INTEGER NOT NULL,
|
||||
access_hash BIGINT NOT NULL,
|
||||
username TEXT,
|
||||
|
||||
PRIMARY KEY (receiver_id, user_id)
|
||||
@@ -48,4 +48,5 @@ CREATE TABLE telegram_file (
|
||||
size BIGINT
|
||||
);
|
||||
|
||||
-- TODO this will be unnecessary once the queries switch to reading telegram_user_metadata
|
||||
CREATE INDEX idx_ghost_username ON ghost ((metadata->>'username'));
|
||||
|
||||
@@ -317,6 +317,7 @@ func (t *TelegramClient) handleTyping(portal networkid.PortalKey, userID int64,
|
||||
if action.TypeID() != tg.SendMessageTypingActionTypeID {
|
||||
timeout = 0
|
||||
}
|
||||
// TODO send proper TypingTypes
|
||||
t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.Typing{
|
||||
EventMeta: simplevent.EventMeta{
|
||||
Type: bridgev2.RemoteEventTyping,
|
||||
|
||||
Reference in New Issue
Block a user