diff --git a/pkg/connector/userinfo.go b/pkg/connector/userinfo.go index 39a5f7f..3b1db10 100644 --- a/pkg/connector/userinfo.go +++ b/pkg/connector/userinfo.go @@ -151,16 +151,36 @@ func (lc *LineClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal) mid := string(portal.ID) lowerMid := strings.ToLower(mid) if strings.HasPrefix(lowerMid, "c") || strings.HasPrefix(lowerMid, "r") { - _, res, err := callLineResult(lc, ctx, func(client *line.Client) (*line.GetChatsResponse, error) { - return client.GetChats([]string{mid}, true, true) - }) - if err != nil { - return nil, err - } - if len(res.Chats) == 0 { - return nil, fmt.Errorf("chat not found") + var chat *line.Chat + if strings.HasPrefix(lowerMid, "r") { + // Legacy multi-person rooms aren't returned by getChats. + _, rooms, err := callLineResult(lc, ctx, func(client *line.Client) ([]line.Room, error) { + return client.GetRoomsV2([]string{mid}) + }) + if err != nil { + return nil, err + } + if len(rooms) == 0 { + return nil, fmt.Errorf("room not found") + } + chat = &line.Chat{ + ChatMid: mid, + Type: 1, + Extra: line.ChatExtra{GroupExtra: &line.GroupExtra{MemberMids: rooms[0].MemberMids}}, + } + } else { + _, res, err := callLineResult(lc, ctx, func(client *line.Client) (*line.GetChatsResponse, error) { + return client.GetChats([]string{mid}, true, true) + }) + if err != nil { + return nil, err + } + if len(res.Chats) == 0 { + return nil, fmt.Errorf("chat not found") + } + chat = &res.Chats[0] } - info := lc.chatToChatInfo(ctx, &res.Chats[0], true) + info := lc.chatToChatInfo(ctx, chat, true) if portal.MXID == "" && lc.shouldSkipDeletedChat(mid, "") { lc.stripRemoteMembersFromInitialChatInfo(info) } diff --git a/pkg/line/methods.go b/pkg/line/methods.go index b08a48a..801e965 100644 --- a/pkg/line/methods.go +++ b/pkg/line/methods.go @@ -640,6 +640,25 @@ func (c *Client) GetChats(mids []string, withMembers, withInvitees bool) (*GetCh return &wrapper.Data, nil } +func (c *Client) GetRoomsV2(mids []string) ([]Room, error) { + resp, err := c.callRPC("TalkService", "getRoomsV2", mids) + if err != nil { + return nil, err + } + var wrapper struct { + Code int `json:"code"` + Message string `json:"message"` + Data []Room `json:"data"` + } + if err := json.Unmarshal(resp, &wrapper); err != nil { + return nil, err + } + if wrapper.Code != 0 { + return nil, fmt.Errorf("getRoomsV2 failed: %s", wrapper.Message) + } + return wrapper.Data, nil +} + func (c *Client) GetLastOpRevision() (int64, error) { return c.GetLastOpRevisionContext(context.Background()) } diff --git a/pkg/line/structs.go b/pkg/line/structs.go index 1816f6d..43a3abd 100644 --- a/pkg/line/structs.go +++ b/pkg/line/structs.go @@ -271,6 +271,10 @@ type Chat struct { Type int `json:"type"` // 0=GROUP, 1=ROOM } +type Room struct { + MemberMids FlexibleMidMap `json:"memberMids"` +} + type ChatExtra struct { GroupExtra *GroupExtra `json:"groupExtra,omitempty"` PeerExtra *PeerExtra `json:"peerExtra,omitempty"`