Skip to content

Commit

Permalink
implement GetUserInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed Jan 2, 2025
1 parent e375933 commit 57c48aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
21 changes: 19 additions & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (c *GChatClient) GetChatInfo(ctx context.Context, portal *bridgev2.Portal)
}

func (c *GChatClient) GetUserInfo(ctx context.Context, ghost *bridgev2.Ghost) (*bridgev2.UserInfo, error) {
return nil, nil
user, err := c.getUser(ctx, string(ghost.ID))
return c.makeUserInfo(user), err
}

func (c *GChatClient) IsLoggedIn() bool {
Expand All @@ -85,8 +86,24 @@ func (c *GChatClient) IsThisUser(ctx context.Context, userID networkid.UserID) b
func (c *GChatClient) LogoutRemote(ctx context.Context) {
}

func (c *GChatClient) getUser(ctx context.Context, userId string) (*proto.User, error) {
if c.users[userId] == nil {
err := c.getUsers(ctx, []string{userId})
if err != nil {
return nil, err
}
}
return c.users[userId], nil
}

func (c *GChatClient) getUsers(ctx context.Context, userIds []string) error {
res, err := c.client.GetMembers(ctx, userIds)
idsToFetch := make([]string, 0)
for _, id := range userIds {
if c.users[id] == nil {
idsToFetch = append(idsToFetch, id)
}
}
res, err := c.client.GetMembers(ctx, idsToFetch)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/handlegchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func (c *GChatClient) handleMembershipChanged(ctx context.Context, evt *proto.Ev
member.Membership = event.MembershipJoin
case proto.MembershipState_MEMBER_NOT_A_MEMBER:
member.Membership = event.MembershipLeave
case proto.MembershipState_MEMBER_INVITED:
member.Membership = event.MembershipInvite
// case proto.MembershipState_MEMBER_INVITED:
// member.Membership = event.MembershipInvite
}
memberMap := map[networkid.UserID]bridgev2.ChatMember{}
memberMap[networkid.UserID(userId)] = member
Expand Down
15 changes: 11 additions & 4 deletions pkg/connector/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ func (c *GChatClient) makeAvatar(avatarURL string) *bridgev2.Avatar {
}
}

func (c *GChatClient) makeUserInfo(user *proto.User) *bridgev2.UserInfo {
if user == nil {
return nil
}
return &bridgev2.UserInfo{
Name: &user.Name,
Avatar: c.makeAvatar(user.AvatarUrl),
}
}

func (c *GChatClient) gcMembersToMatrix(isDm bool, gcMembers []*proto.UserId) *bridgev2.ChatMemberList {
var otherUserId string
memberMap := map[networkid.UserID]bridgev2.ChatMember{}
Expand All @@ -48,10 +58,7 @@ func (c *GChatClient) gcMembersToMatrix(isDm bool, gcMembers []*proto.UserId) *b
}
user := c.users[gcMember.Id]
if user != nil {
member.UserInfo = &bridgev2.UserInfo{
Name: &user.Name,
Avatar: c.makeAvatar(user.AvatarUrl),
}
member.UserInfo = c.makeUserInfo(user)
}
memberMap[userId] = member
}
Expand Down

0 comments on commit 57c48aa

Please sign in to comment.