diff --git a/pkg/connector/capabilities.go b/pkg/connector/capabilities.go index c5d958bd..df0b01be 100644 --- a/pkg/connector/capabilities.go +++ b/pkg/connector/capabilities.go @@ -57,7 +57,7 @@ func (tg *TelegramConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilit } func (tg *TelegramConnector) GetBridgeInfoVersion() (info, capabilities int) { - return 1, 3 + return 1, 4 } // TODO get these from getConfig instead of hardcoding? @@ -207,7 +207,7 @@ func makeTimerList() []jsontime.Milliseconds { var telegramTimers = makeTimerList() func (t *TelegramClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures { - baseID := "fi.mau.telegram.capabilities.2025_08_26" + baseID := "fi.mau.telegram.capabilities.2025_09_11" feat := &event.RoomFeatures{ Formatting: formattingCaps, File: fileCaps, diff --git a/pkg/connector/metadata.go b/pkg/connector/metadata.go index f2b36211..55246d71 100644 --- a/pkg/connector/metadata.go +++ b/pkg/connector/metadata.go @@ -49,7 +49,6 @@ type GhostMetadata struct { type PortalMetadata struct { IsSuperGroup bool `json:"is_supergroup,omitempty"` ReadUpTo int `json:"read_up_to,omitempty"` - MessagesTTL int `json:"messages_ttl,omitempty"` AllowedReactions []string `json:"allowed_reactions"` } diff --git a/pkg/connector/store/upgrades/00-latest.sql b/pkg/connector/store/upgrades/00-latest.sql index ad1baea2..0b064fa9 100644 --- a/pkg/connector/store/upgrades/00-latest.sql +++ b/pkg/connector/store/upgrades/00-latest.sql @@ -1,4 +1,4 @@ --- v0 -> v2: Latest revision +-- v0 -> v3 (compatible with v2+): Latest revision CREATE TABLE telegram_user_state ( user_id BIGINT NOT NULL PRIMARY KEY, diff --git a/pkg/connector/store/upgrades/03-disappearing-timer-migrate.sql b/pkg/connector/store/upgrades/03-disappearing-timer-migrate.sql new file mode 100644 index 00000000..b1b1d78f --- /dev/null +++ b/pkg/connector/store/upgrades/03-disappearing-timer-migrate.sql @@ -0,0 +1,15 @@ +-- v3 (compatible with v2+): Migrate disappearing timer to standard column + +-- only: postgres +UPDATE portal SET disappear_type='after_send', disappear_timer=(metadata->>'messages_ttl')::BIGINT * 1_000_000_000; +-- only: sqlite +UPDATE portal SET disappear_type='after_send', disappear_timer=CAST(metadata->>'$.messages_ttl' AS INTEGER) * 1_000_000_000; + +-- The above migration sets disappear type/timer for all portals, so clear out the ones that don't have a TTL +UPDATE portal SET disappear_type=NULL, disappear_timer=NULL WHERE disappear_timer=0; + +-- Finally, reset the timer set ca +-- only: postgres +UPDATE portal SET cap_state=jsonb_delete(cap_state, 'flags') WHERE disappear_timer IS NOT NULL; +-- only: sqlite +UPDATE portal SET cap_state=json_remove(cap_state, '$.flags') WHERE disappear_timer IS NOT NULL; diff --git a/pkg/connector/telegram.go b/pkg/connector/telegram.go index 6273dcfe..26fa8d56 100644 --- a/pkg/connector/telegram.go +++ b/pkg/connector/telegram.go @@ -356,31 +356,16 @@ func (t *TelegramClient) onUpdateNewMessage(ctx context.Context, entities tg.Ent return err } case *tg.MessageActionSetMessagesTTL: - res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatResync{ - EventMeta: eventMeta.WithType(bridgev2.RemoteEventChatResync), - ChatInfo: &bridgev2.ChatInfo{ - ExtraUpdates: func(ctx context.Context, p *bridgev2.Portal) bool { - updated := p.Portal.Metadata.(*PortalMetadata).MessagesTTL != action.Period - p.Portal.Metadata.(*PortalMetadata).MessagesTTL = action.Period - return updated - }, - }, - }) - if err := resultToError(res); err != nil { - return err + setting := database.DisappearingSetting{ + Type: event.DisappearingTypeAfterSend, + Timer: time.Duration(action.Period) * time.Second, } - - // Send a notice about the TTL change - content := bridgev2.DisappearingMessageNotice(time.Duration(action.Period)*time.Second, false) - res = t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.Message[any]{ - EventMeta: eventMeta.WithType(bridgev2.RemoteEventMessage), - ID: ids.GetMessageIDFromMessage(msg), - ConvertMessageFunc: func(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI, data any) (*bridgev2.ConvertedMessage, error) { - return &bridgev2.ConvertedMessage{ - Parts: []*bridgev2.ConvertedMessagePart{ - {Type: event.EventMessage, Content: content}, - }, - }, nil + res := t.main.Bridge.QueueRemoteEvent(t.userLogin, &simplevent.ChatInfoChange{ + EventMeta: eventMeta.WithType(bridgev2.RemoteEventChatInfoChange), + ChatInfoChange: &bridgev2.ChatInfoChange{ + ChatInfo: &bridgev2.ChatInfo{ + Disappear: &setting, + }, }, }) if err := resultToError(res); err != nil { diff --git a/pkg/connector/tomatrix.go b/pkg/connector/tomatrix.go index 28411c95..7ea4a3ac 100644 --- a/pkg/connector/tomatrix.go +++ b/pkg/connector/tomatrix.go @@ -278,11 +278,8 @@ func (c *TelegramClient) convertToMatrix(ctx context.Context, portal *bridgev2.P Type: event.DisappearingTypeAfterSend, Timer: time.Duration(ttl) * time.Second, } - } else if portal.Metadata.(*PortalMetadata).MessagesTTL > 0 { - cm.Disappear = database.DisappearingSetting{ - Type: event.DisappearingTypeAfterSend, - Timer: time.Duration(ttl) * time.Second, - } + } else { + cm.Disappear = portal.Disappear } }