startchat: update group creation interface
This commit is contained in:
@@ -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