startchat: update group creation interface
This commit is contained in:
@@ -36,7 +36,7 @@ require (
|
||||
golang.org/x/sync v0.16.0
|
||||
golang.org/x/tools v0.36.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
maunium.net/go/mautrix v0.25.1-0.20250826140716-0345a5356de1
|
||||
maunium.net/go/mautrix v0.25.1-0.20250902152424-709f48f2b370
|
||||
rsc.io/qr v0.2.0
|
||||
)
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/mautrix v0.25.1-0.20250826140716-0345a5356de1 h1:8U8dwv4dxhMLrtqjf9LoDuQ6daGj9qdw1/62HIvK2cY=
|
||||
maunium.net/go/mautrix v0.25.1-0.20250826140716-0345a5356de1/go.mod h1:pDd6Ppg+1PbWrw/rg4ZQQfVYZICRGzH+DcliZ/BODvU=
|
||||
maunium.net/go/mautrix v0.25.1-0.20250902152424-709f48f2b370 h1:1rz6V3P38i2qSJKEe0QBXozfI/9yaM/zWrZPDrtKVYQ=
|
||||
maunium.net/go/mautrix v0.25.1-0.20250902152424-709f48f2b370/go.mod h1:pDd6Ppg+1PbWrw/rg4ZQQfVYZICRGzH+DcliZ/BODvU=
|
||||
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
|
||||
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
|
||||
|
||||
@@ -32,6 +32,27 @@ import (
|
||||
func (tg *TelegramConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
|
||||
return &bridgev2.NetworkGeneralCapabilities{
|
||||
DisappearingMessages: true,
|
||||
Provisioning: bridgev2.ProvisioningCapabilities{
|
||||
ResolveIdentifier: bridgev2.ResolveIdentifierCapabilities{
|
||||
CreateDM: true,
|
||||
LookupPhone: true,
|
||||
LookupUsername: true,
|
||||
ContactList: true,
|
||||
Search: true,
|
||||
},
|
||||
GroupCreation: map[string]bridgev2.GroupTypeCapabilities{
|
||||
"minigroup": {
|
||||
TypeDescription: "a normal group",
|
||||
Name: bridgev2.GroupFieldCapability{Allowed: true, Required: true, MaxLength: 255},
|
||||
Participants: bridgev2.GroupFieldCapability{Allowed: true, Required: true, MinLength: 1, MaxLength: 200},
|
||||
// TODO implement
|
||||
//Disappear: bridgev2.GroupFieldCapability{Allowed: true},
|
||||
},
|
||||
// TODO
|
||||
//"channel": {},
|
||||
//"supergroup": {},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/ptr"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
"maunium.net/go/mautrix/bridgev2/networkid"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/telegram/query/hasher"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
@@ -224,16 +224,11 @@ func (t *TelegramClient) GetContactList(ctx context.Context) (resp []*bridgev2.R
|
||||
}
|
||||
|
||||
// TODO support channels
|
||||
func (t *TelegramClient) CreateGroup(ctx context.Context, name string, users ...networkid.UserID) (*bridgev2.CreateChatResponse, error) {
|
||||
if len(users) == 0 {
|
||||
return nil, fmt.Errorf("no users provided")
|
||||
} else if len(users) > 200 {
|
||||
return nil, fmt.Errorf("too many users provided: %d (max 200)", len(users))
|
||||
}
|
||||
func (t *TelegramClient) CreateGroup(ctx context.Context, params *bridgev2.GroupCreateParams) (*bridgev2.CreateChatResponse, error) {
|
||||
req := tg.MessagesCreateChatRequest{
|
||||
Title: name,
|
||||
Title: ptr.Val(params.Name).Name,
|
||||
}
|
||||
for _, networkUserID := range users {
|
||||
for _, networkUserID := range params.Participants {
|
||||
if peerType, userID, err := ids.ParseUserID(networkUserID); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse user ID: %w", err)
|
||||
} else if peerType != ids.PeerTypeUser {
|
||||
@@ -262,8 +257,28 @@ func (t *TelegramClient) CreateGroup(ctx context.Context, name string, users ...
|
||||
} else if chat, ok := chats[0].(*tg.Chat); !ok {
|
||||
return nil, fmt.Errorf("unexpected chat type: %T", chats[0])
|
||||
} else {
|
||||
portalKey := t.makePortalKeyFromID(ids.PeerTypeChat, chat.ID)
|
||||
if params.RoomID != "" {
|
||||
portal, err := t.main.Bridge.GetPortalByKey(ctx, portalKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = portal.UpdateMatrixRoomID(ctx, params.RoomID, bridgev2.UpdateMatrixRoomIDParams{
|
||||
SyncDBMetadata: func() {
|
||||
portal.Name = req.Title
|
||||
portal.NameSet = true
|
||||
},
|
||||
OverwriteOldPortal: true,
|
||||
TombstoneOldRoom: true,
|
||||
DeleteOldRoom: true,
|
||||
ChatInfoSource: t.userLogin,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &bridgev2.CreateChatResponse{
|
||||
PortalKey: t.makePortalKeyFromID(ids.PeerTypeChat, chat.ID),
|
||||
PortalKey: portalKey,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user