@@ -45,7 +45,7 @@ const (
45
45
flushMessageCount = 100
46
46
)
47
47
48
- type server struct {
48
+ type Server struct {
49
49
log * logrus.Entry
50
50
51
51
data code_data.Provider
@@ -60,9 +60,9 @@ type server struct {
60
60
chatpb.UnimplementedChatServer
61
61
}
62
62
63
- func NewChatServer (data code_data.Provider , auth * auth_util.RPCSignatureVerifier ) chatpb. ChatServer {
64
- s := & server {
65
- log : logrus .StandardLogger ().WithField ("type" , "chat/v2/server " ),
63
+ func NewChatServer (data code_data.Provider , auth * auth_util.RPCSignatureVerifier ) * Server {
64
+ s := & Server {
65
+ log : logrus .StandardLogger ().WithField ("type" , "chat/v2/Server " ),
66
66
67
67
data : data ,
68
68
auth : auth ,
@@ -81,7 +81,7 @@ func NewChatServer(data code_data.Provider, auth *auth_util.RPCSignatureVerifier
81
81
}
82
82
83
83
// todo: This will require a lot of optimizations since we iterate and make several DB calls for each chat membership
84
- func (s * server ) GetChats (ctx context.Context , req * chatpb.GetChatsRequest ) (* chatpb.GetChatsResponse , error ) {
84
+ func (s * Server ) GetChats (ctx context.Context , req * chatpb.GetChatsRequest ) (* chatpb.GetChatsResponse , error ) {
85
85
log := s .log .WithField ("method" , "GetChats" )
86
86
log = client .InjectLoggingMetadata (ctx , log )
87
87
@@ -181,7 +181,7 @@ func (s *server) GetChats(ctx context.Context, req *chatpb.GetChatsRequest) (*ch
181
181
}, nil
182
182
}
183
183
184
- func (s * server ) GetMessages (ctx context.Context , req * chatpb.GetMessagesRequest ) (* chatpb.GetMessagesResponse , error ) {
184
+ func (s * Server ) GetMessages (ctx context.Context , req * chatpb.GetMessagesRequest ) (* chatpb.GetMessagesResponse , error ) {
185
185
log := s .log .WithField ("method" , "GetMessages" )
186
186
log = client .InjectLoggingMetadata (ctx , log )
187
187
@@ -284,7 +284,7 @@ func (s *server) GetMessages(ctx context.Context, req *chatpb.GetMessagesRequest
284
284
}, nil
285
285
}
286
286
287
- func (s * server ) StreamChatEvents (streamer chatpb.Chat_StreamChatEventsServer ) error {
287
+ func (s * Server ) StreamChatEvents (streamer chatpb.Chat_StreamChatEventsServer ) error {
288
288
ctx := streamer .Context ()
289
289
290
290
log := s .log .WithField ("method" , "StreamChatEvents" )
@@ -359,9 +359,9 @@ func (s *server) StreamChatEvents(streamer chatpb.Chat_StreamChatEventsServer) e
359
359
stream , exists := s .streams [streamKey ]
360
360
if exists {
361
361
s .streamsMu .Unlock ()
362
- // There's an existing stream on this server that must be terminated first.
362
+ // There's an existing stream on this Server that must be terminated first.
363
363
// Warn to see how often this happens in practice
364
- log .Warnf ("existing stream detected on this server (stream=%p) ; aborting" , stream )
364
+ log .Warnf ("existing stream detected on this Server (stream=%p) ; aborting" , stream )
365
365
return status .Error (codes .Aborted , "stream already exists" )
366
366
}
367
367
@@ -442,7 +442,7 @@ func (s *server) StreamChatEvents(streamer chatpb.Chat_StreamChatEventsServer) e
442
442
}
443
443
}
444
444
445
- func (s * server ) flushMessages (ctx context.Context , chatId chat.ChatId , owner * common.Account , stream * chatEventStream ) {
445
+ func (s * Server ) flushMessages (ctx context.Context , chatId chat.ChatId , owner * common.Account , stream * chatEventStream ) {
446
446
log := s .log .WithFields (logrus.Fields {
447
447
"method" : "flushMessages" ,
448
448
"chat_id" : chatId .String (),
@@ -477,7 +477,7 @@ func (s *server) flushMessages(ctx context.Context, chatId chat.ChatId, owner *c
477
477
}
478
478
}
479
479
480
- func (s * server ) flushPointers (ctx context.Context , chatId chat.ChatId , stream * chatEventStream ) {
480
+ func (s * Server ) flushPointers (ctx context.Context , chatId chat.ChatId , stream * chatEventStream ) {
481
481
log := s .log .WithFields (logrus.Fields {
482
482
"method" : "flushPointers" ,
483
483
"chat_id" : chatId .String (),
@@ -520,7 +520,7 @@ func (s *server) flushPointers(ctx context.Context, chatId chat.ChatId, stream *
520
520
}
521
521
}
522
522
523
- func (s * server ) StartChat (ctx context.Context , req * chatpb.StartChatRequest ) (* chatpb.StartChatResponse , error ) {
523
+ func (s * Server ) StartChat (ctx context.Context , req * chatpb.StartChatRequest ) (* chatpb.StartChatResponse , error ) {
524
524
log := s .log .WithField ("method" , "StartChat" )
525
525
log = client .InjectLoggingMetadata (ctx , log )
526
526
@@ -695,7 +695,7 @@ func (s *server) StartChat(ctx context.Context, req *chatpb.StartChatRequest) (*
695
695
}
696
696
}
697
697
698
- func (s * server ) SendMessage (ctx context.Context , req * chatpb.SendMessageRequest ) (* chatpb.SendMessageResponse , error ) {
698
+ func (s * Server ) SendMessage (ctx context.Context , req * chatpb.SendMessageRequest ) (* chatpb.SendMessageResponse , error ) {
699
699
log := s .log .WithField ("method" , "SendMessage" )
700
700
log = client .InjectLoggingMetadata (ctx , log )
701
701
@@ -784,8 +784,8 @@ func (s *server) SendMessage(ctx context.Context, req *chatpb.SendMessageRequest
784
784
}, nil
785
785
}
786
786
787
- // TODO(api): This likely needs an RPC that can be called from any other server .
788
- func (s * server ) NotifyNewMessage (ctx context.Context , chatID chat.ChatId , message * chatpb.ChatMessage ) error {
787
+ // TODO(api): This likely needs an RPC that can be called from any other Server .
788
+ func (s * Server ) NotifyNewMessage (ctx context.Context , chatID chat.ChatId , message * chatpb.ChatMessage ) error {
789
789
members , err := s .data .GetAllChatMembersV2 (ctx , chatID )
790
790
if errors .Is (err , chat .ErrMemberNotFound ) {
791
791
return nil
@@ -827,7 +827,7 @@ func (s *server) NotifyNewMessage(ctx context.Context, chatID chat.ChatId, messa
827
827
}
828
828
829
829
// todo: This belongs in the common chat utility, which currently only operates on v1 chats
830
- func (s * server ) persistChatMessage (ctx context.Context , chatId chat.ChatId , protoChatMessage * chatpb.ChatMessage ) error {
830
+ func (s * Server ) persistChatMessage (ctx context.Context , chatId chat.ChatId , protoChatMessage * chatpb.ChatMessage ) error {
831
831
if err := protoChatMessage .Validate (); err != nil {
832
832
return errors .Wrap (err , "proto chat message failed validation" )
833
833
}
@@ -877,7 +877,7 @@ func (s *server) persistChatMessage(ctx context.Context, chatId chat.ChatId, pro
877
877
return nil
878
878
}
879
879
880
- func (s * server ) AdvancePointer (ctx context.Context , req * chatpb.AdvancePointerRequest ) (* chatpb.AdvancePointerResponse , error ) {
880
+ func (s * Server ) AdvancePointer (ctx context.Context , req * chatpb.AdvancePointerRequest ) (* chatpb.AdvancePointerResponse , error ) {
881
881
log := s .log .WithField ("method" , "AdvancePointer" )
882
882
log = client .InjectLoggingMetadata (ctx , log )
883
883
@@ -981,7 +981,7 @@ func (s *server) AdvancePointer(ctx context.Context, req *chatpb.AdvancePointerR
981
981
}, nil
982
982
}
983
983
984
- func (s * server ) RevealIdentity (ctx context.Context , req * chatpb.RevealIdentityRequest ) (* chatpb.RevealIdentityResponse , error ) {
984
+ func (s * Server ) RevealIdentity (ctx context.Context , req * chatpb.RevealIdentityRequest ) (* chatpb.RevealIdentityResponse , error ) {
985
985
log := s .log .WithField ("method" , "RevealIdentity" )
986
986
log = client .InjectLoggingMetadata (ctx , log )
987
987
@@ -1135,7 +1135,7 @@ func (s *server) RevealIdentity(ctx context.Context, req *chatpb.RevealIdentityR
1135
1135
}
1136
1136
}
1137
1137
1138
- func (s * server ) SetMuteState (ctx context.Context , req * chatpb.SetMuteStateRequest ) (* chatpb.SetMuteStateResponse , error ) {
1138
+ func (s * Server ) SetMuteState (ctx context.Context , req * chatpb.SetMuteStateRequest ) (* chatpb.SetMuteStateResponse , error ) {
1139
1139
log := s .log .WithField ("method" , "SetMuteState" )
1140
1140
log = client .InjectLoggingMetadata (ctx , log )
1141
1141
@@ -1200,7 +1200,7 @@ func (s *server) SetMuteState(ctx context.Context, req *chatpb.SetMuteStateReque
1200
1200
}, nil
1201
1201
}
1202
1202
1203
- func (s * server ) SetSubscriptionState (ctx context.Context , req * chatpb.SetSubscriptionStateRequest ) (* chatpb.SetSubscriptionStateResponse , error ) {
1203
+ func (s * Server ) SetSubscriptionState (ctx context.Context , req * chatpb.SetSubscriptionStateRequest ) (* chatpb.SetSubscriptionStateResponse , error ) {
1204
1204
log := s .log .WithField ("method" , "SetSubscriptionState" )
1205
1205
log = client .InjectLoggingMetadata (ctx , log )
1206
1206
@@ -1265,7 +1265,7 @@ func (s *server) SetSubscriptionState(ctx context.Context, req *chatpb.SetSubscr
1265
1265
}, nil
1266
1266
}
1267
1267
1268
- func (s * server ) toProtoChat (ctx context.Context , chatRecord * chat.ChatRecord , memberRecords []* chat.MemberRecord , myIdentitiesByPlatform map [chat.Platform ]string ) (* chatpb.ChatMetadata , error ) {
1268
+ func (s * Server ) toProtoChat (ctx context.Context , chatRecord * chat.ChatRecord , memberRecords []* chat.MemberRecord , myIdentitiesByPlatform map [chat.Platform ]string ) (* chatpb.ChatMetadata , error ) {
1269
1269
protoChat := & chatpb.ChatMetadata {
1270
1270
ChatId : chatRecord .ChatId .ToProto (),
1271
1271
Type : chatRecord .ChatType .ToProto (),
@@ -1349,7 +1349,7 @@ func (s *server) toProtoChat(ctx context.Context, chatRecord *chat.ChatRecord, m
1349
1349
return protoChat , nil
1350
1350
}
1351
1351
1352
- func (s * server ) getProtoChatMessages (ctx context.Context , chatId chat.ChatId , owner * common.Account , queryOptions ... query.Option ) ([]* chatpb.ChatMessage , error ) {
1352
+ func (s * Server ) getProtoChatMessages (ctx context.Context , chatId chat.ChatId , owner * common.Account , queryOptions ... query.Option ) ([]* chatpb.ChatMessage , error ) {
1353
1353
messageRecords , err := s .data .GetAllChatMessagesV2 (
1354
1354
ctx ,
1355
1355
chatId ,
@@ -1405,7 +1405,7 @@ func (s *server) getProtoChatMessages(ctx context.Context, chatId chat.ChatId, o
1405
1405
return res , nil
1406
1406
}
1407
1407
1408
- func (s * server ) onPersistChatMessage (log * logrus.Entry , chatId chat.ChatId , chatMessage * chatpb.ChatMessage ) {
1408
+ func (s * Server ) onPersistChatMessage (log * logrus.Entry , chatId chat.ChatId , chatMessage * chatpb.ChatMessage ) {
1409
1409
event := & chatpb.ChatStreamEvent {
1410
1410
Type : & chatpb.ChatStreamEvent_Message {
1411
1411
Message : chatMessage ,
@@ -1418,7 +1418,7 @@ func (s *server) onPersistChatMessage(log *logrus.Entry, chatId chat.ChatId, cha
1418
1418
// todo: send the push
1419
1419
}
1420
1420
1421
- func (s * server ) getAllIdentities (ctx context.Context , owner * common.Account ) (map [chat.Platform ]string , error ) {
1421
+ func (s * Server ) getAllIdentities (ctx context.Context , owner * common.Account ) (map [chat.Platform ]string , error ) {
1422
1422
identities := map [chat.Platform ]string {
1423
1423
chat .PlatformCode : owner .PublicKey ().ToBase58 (),
1424
1424
}
@@ -1434,7 +1434,7 @@ func (s *server) getAllIdentities(ctx context.Context, owner *common.Account) (m
1434
1434
return identities , nil
1435
1435
}
1436
1436
1437
- func (s * server ) ownsChatMemberWithoutRecord (ctx context.Context , chatId chat.ChatId , memberId chat.MemberId , owner * common.Account ) (bool , error ) {
1437
+ func (s * Server ) ownsChatMemberWithoutRecord (ctx context.Context , chatId chat.ChatId , memberId chat.MemberId , owner * common.Account ) (bool , error ) {
1438
1438
memberRecord , err := s .data .GetChatMemberByIdV2 (ctx , chatId , memberId )
1439
1439
switch err {
1440
1440
case nil :
@@ -1447,7 +1447,7 @@ func (s *server) ownsChatMemberWithoutRecord(ctx context.Context, chatId chat.Ch
1447
1447
return s .ownsChatMemberWithRecord (ctx , chatId , memberRecord , owner )
1448
1448
}
1449
1449
1450
- func (s * server ) ownsChatMemberWithRecord (ctx context.Context , chatId chat.ChatId , memberRecord * chat.MemberRecord , owner * common.Account ) (bool , error ) {
1450
+ func (s * Server ) ownsChatMemberWithRecord (ctx context.Context , chatId chat.ChatId , memberRecord * chat.MemberRecord , owner * common.Account ) (bool , error ) {
1451
1451
switch memberRecord .Platform {
1452
1452
case chat .PlatformCode :
1453
1453
return memberRecord .PlatformId == owner .PublicKey ().ToBase58 (), nil
@@ -1459,7 +1459,7 @@ func (s *server) ownsChatMemberWithRecord(ctx context.Context, chatId chat.ChatI
1459
1459
}
1460
1460
1461
1461
// todo: This logic should live elsewhere in somewhere more common
1462
- func (s * server ) ownsTwitterUsername (ctx context.Context , owner * common.Account , username string ) (bool , error ) {
1462
+ func (s * Server ) ownsTwitterUsername (ctx context.Context , owner * common.Account , username string ) (bool , error ) {
1463
1463
ownerTipAccount , err := owner .ToTimelockVault (timelock_token .DataVersion1 , common .KinMintAccount )
1464
1464
if err != nil {
1465
1465
return false , errors .Wrap (err , "error deriving twitter tip address" )
@@ -1478,7 +1478,7 @@ func (s *server) ownsTwitterUsername(ctx context.Context, owner *common.Account,
1478
1478
}
1479
1479
1480
1480
// todo: This logic should live elsewhere in somewhere more common
1481
- func (s * server ) getOwnedTwitterUsername (ctx context.Context , owner * common.Account ) (string , bool , error ) {
1481
+ func (s * Server ) getOwnedTwitterUsername (ctx context.Context , owner * common.Account ) (string , bool , error ) {
1482
1482
ownerTipAccount , err := owner .ToTimelockVault (timelock_token .DataVersion1 , common .KinMintAccount )
1483
1483
if err != nil {
1484
1484
return "" , false , errors .Wrap (err , "error deriving twitter tip address" )
0 commit comments