Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ type LineClient struct {
paidReactionIconMXC map[string]string // LINE sticon URL -> cached MXC URI
unblockBackfills sync.Map // chat MID -> *unblockBackfillState while unblock history restoration is active

stickerSyncMu sync.Mutex
stickerMu sync.Mutex
stickerCatalogs map[string]stickerCatalog
pendingStickerRooms sync.Map
sticonMetaMu sync.Mutex
sticonMeta map[string]sticonMetaCache

wg sync.WaitGroup
}

type lineClientRun struct {
ctx context.Context
cancel context.CancelFunc
}

Expand Down Expand Up @@ -156,7 +164,7 @@ func (lc *LineClient) isSessionInvalidated() bool {

func (lc *LineClient) beginRun(parent context.Context) (context.Context, *lineClientRun, bool) {
ctx, cancel := context.WithCancel(parent)
run := &lineClientRun{cancel: cancel}
run := &lineClientRun{ctx: ctx, cancel: cancel}
lc.runMu.Lock()
if lc.stopped {
lc.runMu.Unlock()
Expand Down Expand Up @@ -184,6 +192,16 @@ func (lc *LineClient) cancelActiveRun() {
}
}

func (lc *LineClient) startRunTask() (context.Context, bool) {
lc.runMu.Lock()
defer lc.runMu.Unlock()
if lc.stopped || lc.activeRun == nil || lc.activeRun.ctx.Err() != nil {
return nil, false
}
lc.wg.Add(1)
return lc.activeRun.ctx, true
}

func (lc *LineClient) retire() {
lc.Disconnect()
}
Expand Down Expand Up @@ -641,7 +659,8 @@ func (lc *LineClient) Connect(ctx context.Context) {
return
}

lc.wg.Add(3)
lc.wg.Add(4)
go lc.syncStickerPacks(ctx)
go lc.syncDMChats(ctx)
go lc.prefetchMessages(ctx)
go lc.pollLoop(ctx)
Expand Down
8 changes: 6 additions & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.mau.fi/util/configupgrade"

"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/commands"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/bridgev2/networkid"
"maunium.net/go/mautrix/bridgev2/status"
Expand Down Expand Up @@ -41,6 +42,9 @@ func (lc *LineConnector) Init(bridge *bridgev2.Bridge) {
// user doesn't already have one.
bridge.Config.BridgeStatusNotices = "none"
lc.br = bridge
if processor, ok := bridge.Commands.(*commands.Processor); ok {
processor.AddHandlers(commandStickers)
}
}

func (lc *LineConnector) Start(ctx context.Context) error {
Expand All @@ -52,14 +56,14 @@ func (lc *LineConnector) Start(ctx context.Context) error {
}

func (lc *LineConnector) GetBridgeInfoVersion() (info, capabilities int) {
return 1, 3
return 1, 4
}

func (lc *LineConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
return &bridgev2.NetworkGeneralCapabilities{
AggressiveUpdateInfo: true,
Provisioning: bridgev2.ProvisioningCapabilities{
ImagePackImport: false,
ImagePackImport: true,
ResolveIdentifier: bridgev2.ResolveIdentifierCapabilities{
Search: true,
ContactList: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/creategroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ func (lc *LineClient) CreateGroup(ctx context.Context, params *bridgev2.GroupCre
return &bridgev2.CreateChatResponse{
PortalKey: portalKey,
Portal: portal,
PortalInfo: &bridgev2.ChatInfo{
PortalInfo: lc.withStickerPacks(&bridgev2.ChatInfo{
Type: &ct,
Name: &chatName,
Members: &bridgev2.ChatMemberList{
IsFull: true,
MemberMap: chatMemberMapFromList(members),
},
},
}),
}, nil
}

Expand Down
Loading