Skip to content

Commit f62c762

Browse files
author
Jeff Yanta
committed
Initial implementation of StartChat that always starts a new chat
1 parent 8366e10 commit f62c762

File tree

6 files changed

+350
-145
lines changed

6 files changed

+350
-145
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
firebase.google.com/go/v4 v4.8.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.16.7-0.20240617171852-5885f1307f31
9+
github.com/code-payments/code-protobuf-api v1.16.7-0.20240618135651-59879f609687
1010
github.com/emirpasic/gods v1.12.0
1111
github.com/envoyproxy/protoc-gen-validate v1.0.4
1212
github.com/golang-jwt/jwt/v5 v5.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
121121
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
122122
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
123123
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
124-
github.com/code-payments/code-protobuf-api v1.16.7-0.20240617171852-5885f1307f31 h1:nJ2H/SHJipF/tNJns89brkSCrZdkd9M57BqxfTqAr/s=
125-
github.com/code-payments/code-protobuf-api v1.16.7-0.20240617171852-5885f1307f31/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
124+
github.com/code-payments/code-protobuf-api v1.16.7-0.20240618135651-59879f609687 h1:1/DZnT2ipA/Eo/AmFgheQomKeSFwsIAaUcxV9dOvTRg=
125+
github.com/code-payments/code-protobuf-api v1.16.7-0.20240618135651-59879f609687/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
126126
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
127127
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
128128
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=

pkg/code/data/chat/v2/memory/store.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func (s *store) GetAllMembersByChatId(_ context.Context, chatId chat.ChatId) ([]
8080
return cloneMemberRecords(items), nil
8181
}
8282

83-
// GetAllMembersByPlatformId implements chat.store.GetAllMembersByPlatformId
84-
func (s *store) GetAllMembersByPlatformId(_ context.Context, platform chat.Platform, platformId string, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*chat.MemberRecord, error) {
83+
// GetAllMembersByPlatformIds implements chat.store.GetAllMembersByPlatformIds
84+
func (s *store) GetAllMembersByPlatformIds(_ context.Context, idByPlatform map[chat.Platform]string, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*chat.MemberRecord, error) {
8585
s.mu.Lock()
8686
defer s.mu.Unlock()
8787

88-
items := s.findMembersByPlatformId(platform, platformId)
88+
items := s.findMembersByPlatformIds(idByPlatform)
8989
items, err := s.getMemberRecordPage(items, cursor, direction, limit)
9090
if err != nil {
9191
return nil, err
@@ -324,10 +324,15 @@ func (s *store) findMembersByChatId(chatId chat.ChatId) []*chat.MemberRecord {
324324
return res
325325
}
326326

327-
func (s *store) findMembersByPlatformId(platform chat.Platform, platformId string) []*chat.MemberRecord {
327+
func (s *store) findMembersByPlatformIds(idByPlatform map[chat.Platform]string) []*chat.MemberRecord {
328328
var res []*chat.MemberRecord
329329
for _, item := range s.memberRecords {
330-
if platform == item.Platform && platformId == item.PlatformId {
330+
platformId, ok := idByPlatform[item.Platform]
331+
if !ok {
332+
continue
333+
}
334+
335+
if platformId == item.PlatformId {
331336
res = append(res, item)
332337
}
333338
}

pkg/code/data/chat/v2/store.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ type Store interface {
3333
// todo: Add paging when we introduce group chats
3434
GetAllMembersByChatId(ctx context.Context, chatId ChatId) ([]*MemberRecord, error)
3535

36-
// GetAllMembersByPlatformId gets all members for a given platform user across
37-
// all chats
38-
GetAllMembersByPlatformId(ctx context.Context, platform Platform, platformId string, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*MemberRecord, error)
36+
// GetAllMembersByPlatformIds gets all members for platform users across all chats
37+
GetAllMembersByPlatformIds(ctx context.Context, idByPlatform map[Platform]string, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*MemberRecord, error)
3938

4039
// GetAllMessagesByChatId gets all messages for a given chat
4140
//

pkg/code/data/internal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ type DatabaseData interface {
400400
GetChatMemberByIdV2(ctx context.Context, chatId chat_v2.ChatId, memberId chat_v2.MemberId) (*chat_v2.MemberRecord, error)
401401
GetChatMessageByIdV2(ctx context.Context, chatId chat_v2.ChatId, messageId chat_v2.MessageId) (*chat_v2.MessageRecord, error)
402402
GetAllChatMembersV2(ctx context.Context, chatId chat_v2.ChatId) ([]*chat_v2.MemberRecord, error)
403-
GetPlatformUserChatMembershipV2(ctx context.Context, platform chat_v2.Platform, platformId string, opts ...query.Option) ([]*chat_v2.MemberRecord, error)
403+
GetPlatformUserChatMembershipV2(ctx context.Context, idByPlatform map[chat_v2.Platform]string, opts ...query.Option) ([]*chat_v2.MemberRecord, error)
404404
GetAllChatMessagesV2(ctx context.Context, chatId chat_v2.ChatId, opts ...query.Option) ([]*chat_v2.MessageRecord, error)
405405
GetChatUnreadCountV2(ctx context.Context, chatId chat_v2.ChatId, memberId chat_v2.MemberId, readPointer chat_v2.MessageId) (uint32, error)
406406
PutChatV2(ctx context.Context, record *chat_v2.ChatRecord) error
@@ -1478,12 +1478,12 @@ func (dp *DatabaseProvider) GetChatMessageByIdV2(ctx context.Context, chatId cha
14781478
func (dp *DatabaseProvider) GetAllChatMembersV2(ctx context.Context, chatId chat_v2.ChatId) ([]*chat_v2.MemberRecord, error) {
14791479
return dp.chatv2.GetAllMembersByChatId(ctx, chatId)
14801480
}
1481-
func (dp *DatabaseProvider) GetPlatformUserChatMembershipV2(ctx context.Context, platform chat_v2.Platform, platformId string, opts ...query.Option) ([]*chat_v2.MemberRecord, error) {
1481+
func (dp *DatabaseProvider) GetPlatformUserChatMembershipV2(ctx context.Context, idByPlatform map[chat_v2.Platform]string, opts ...query.Option) ([]*chat_v2.MemberRecord, error) {
14821482
req, err := query.DefaultPaginationHandler(opts...)
14831483
if err != nil {
14841484
return nil, err
14851485
}
1486-
return dp.chatv2.GetAllMembersByPlatformId(ctx, platform, platformId, req.Cursor, req.SortBy, req.Limit)
1486+
return dp.chatv2.GetAllMembersByPlatformIds(ctx, idByPlatform, req.Cursor, req.SortBy, req.Limit)
14871487
}
14881488
func (dp *DatabaseProvider) GetAllChatMessagesV2(ctx context.Context, chatId chat_v2.ChatId, opts ...query.Option) ([]*chat_v2.MessageRecord, error) {
14891489
req, err := query.DefaultPaginationHandler(opts...)

0 commit comments

Comments
 (0)