-
Notifications
You must be signed in to change notification settings - Fork 246
/
api.go
1211 lines (956 loc) · 45.6 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package ext
import (
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
"time"
"github.com/status-im/status-go/services/browsers"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/mailserver"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/communities"
"github.com/status-im/status-go/protocol/discord"
"github.com/status-im/status-go/protocol/encryption/multidevice"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/pushnotificationclient"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/transport"
"github.com/status-im/status-go/protocol/urls"
"github.com/status-im/status-go/protocol/verification"
"github.com/status-im/status-go/services/ext/mailservers"
)
const (
// defaultRequestTimeout is the default request timeout in seconds
defaultRequestTimeout = 10
)
var (
// ErrInvalidMailServerPeer is returned when it fails to parse enode from params.
ErrInvalidMailServerPeer = errors.New("invalid mailServerPeer value")
// ErrInvalidSymKeyID is returned when it fails to get a symmetric key.
ErrInvalidSymKeyID = errors.New("invalid symKeyID value")
// ErrInvalidPublicKey is returned when public key can't be extracted
// from MailServer's nodeID.
ErrInvalidPublicKey = errors.New("can't extract public key")
// ErrPFSNotEnabled is returned when an endpoint PFS only is called but
// PFS is disabled
ErrPFSNotEnabled = errors.New("pfs not enabled")
)
// -----
// PAYLOADS
// -----
// MessagesRequest is a RequestMessages() request payload.
type MessagesRequest struct {
// MailServerPeer is MailServer's enode address.
MailServerPeer string `json:"mailServerPeer"`
// From is a lower bound of time range (optional).
// Default is 24 hours back from now.
From uint32 `json:"from"`
// To is a upper bound of time range (optional).
// Default is now.
To uint32 `json:"to"`
// Limit determines the number of messages sent by the mail server
// for the current paginated request
Limit uint32 `json:"limit"`
// Cursor is used as starting point for paginated requests
Cursor string `json:"cursor"`
// StoreCursor is used as starting point for WAKUV2 paginatedRequests
StoreCursor *StoreRequestCursor `json:"storeCursor"`
// Topic is a regular Whisper topic.
// DEPRECATED
Topic types.TopicType `json:"topic"`
// Topics is a list of Whisper topics.
Topics []types.TopicType `json:"topics"`
// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
// It's derived from MailServer password.
SymKeyID string `json:"symKeyID"`
// Timeout is the time to live of the request specified in seconds.
// Default is 10 seconds
Timeout time.Duration `json:"timeout"`
// Force ensures that requests will bypass enforced delay.
Force bool `json:"force"`
}
type StoreRequestCursor struct {
Digest []byte `json:"digest"`
ReceivedTime float64 `json:"receivedTime"`
}
func (r *MessagesRequest) SetDefaults(now time.Time) {
// set From and To defaults
if r.To == 0 {
r.To = uint32(now.UTC().Unix())
}
if r.From == 0 {
oneDay := uint32(86400) // -24 hours
if r.To < oneDay {
r.From = 0
} else {
r.From = r.To - oneDay
}
}
if r.Timeout == 0 {
r.Timeout = defaultRequestTimeout
}
}
// MessagesResponse is a response for requestMessages2 method.
type MessagesResponse struct {
// Cursor from the response can be used to retrieve more messages
// for the previous request.
Cursor string `json:"cursor"`
// Error indicates that something wrong happened when sending messages
// to the requester.
Error error `json:"error"`
}
// -----
// PUBLIC API
// -----
// PublicAPI extends whisper public API.
type PublicAPI struct {
service *Service
eventSub mailservers.EnvelopeEventSubscriber
log log.Logger
}
// NewPublicAPI returns instance of the public API.
func NewPublicAPI(s *Service, eventSub mailservers.EnvelopeEventSubscriber) *PublicAPI {
return &PublicAPI{
service: s,
eventSub: eventSub,
log: log.New("package", "status-go/services/sshext.PublicAPI"),
}
}
// RetryConfig specifies configuration for retries with timeout and max amount of retries.
type RetryConfig struct {
BaseTimeout time.Duration
// StepTimeout defines duration increase per each retry.
StepTimeout time.Duration
MaxRetries int
}
func WaitForExpiredOrCompleted(requestID types.Hash, events chan types.EnvelopeEvent, timeout time.Duration) (*types.MailServerResponse, error) {
expired := fmt.Errorf("request %x expired", requestID)
after := time.NewTimer(timeout)
defer after.Stop()
for {
var ev types.EnvelopeEvent
select {
case ev = <-events:
case <-after.C:
return nil, expired
}
if ev.Hash != requestID {
continue
}
switch ev.Event {
case types.EventMailServerRequestCompleted:
data, ok := ev.Data.(*types.MailServerResponse)
if ok {
return data, nil
}
return nil, errors.New("invalid event data type")
case types.EventMailServerRequestExpired:
return nil, expired
}
}
}
type Author struct {
PublicKey types.HexBytes `json:"publicKey"`
Alias string `json:"alias"`
Identicon string `json:"identicon"`
}
type Metadata struct {
DedupID []byte `json:"dedupId"`
EncryptionID types.HexBytes `json:"encryptionId"`
MessageID types.HexBytes `json:"messageId"`
Author Author `json:"author"`
}
func (api *PublicAPI) LeaveGroupChat(ctx Context, chatID string, remove bool) (*protocol.MessengerResponse, error) {
return api.service.messenger.LeaveGroupChat(ctx, chatID, remove)
}
func (api *PublicAPI) CreateGroupChatWithMembers(ctx Context, name string, members []string) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateGroupChatWithMembers(ctx, name, members)
}
func (api *PublicAPI) CreateGroupChatFromInvitation(name string, chatID string, adminPK string) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateGroupChatFromInvitation(name, chatID, adminPK)
}
func (api *PublicAPI) AddMembersToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
return api.service.messenger.AddMembersToGroupChat(ctx, chatID, members)
}
func (api *PublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
return api.service.messenger.RemoveMemberFromGroupChat(ctx, chatID, member)
}
func (api *PublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
return api.service.messenger.AddAdminsToGroupChat(ctx, chatID, members)
}
func (api *PublicAPI) ConfirmJoiningGroup(ctx context.Context, chatID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.ConfirmJoiningGroup(ctx, chatID)
}
func (api *PublicAPI) ChangeGroupChatName(ctx Context, chatID string, name string) (*protocol.MessengerResponse, error) {
return api.service.messenger.ChangeGroupChatName(ctx, chatID, name)
}
func (api *PublicAPI) SendGroupChatInvitationRequest(ctx Context, chatID string, adminPK string, message string) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendGroupChatInvitationRequest(ctx, chatID, adminPK, message)
}
func (api *PublicAPI) GetGroupChatInvitations() ([]*protocol.GroupChatInvitation, error) {
return api.service.messenger.GetGroupChatInvitations()
}
func (api *PublicAPI) SendGroupChatInvitationRejection(ctx Context, invitationRequestID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendGroupChatInvitationRejection(ctx, invitationRequestID)
}
func (api *PublicAPI) LoadFilters(parent context.Context, chats []*transport.Filter) ([]*transport.Filter, error) {
return api.service.messenger.LoadFilters(chats)
}
func (api *PublicAPI) SaveChat(parent context.Context, chat *protocol.Chat) error {
return api.service.messenger.SaveChat(chat)
}
func (api *PublicAPI) SaveMessages(parent context.Context, messages []*common.Message) error {
return api.service.messenger.SaveMessages(messages)
}
func (api *PublicAPI) CreateOneToOneChat(parent context.Context, request *requests.CreateOneToOneChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateOneToOneChat(request)
}
func (api *PublicAPI) CreatePublicChat(parent context.Context, request *requests.CreatePublicChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreatePublicChat(request)
}
func (api *PublicAPI) CreateProfileChat(parent context.Context, request *requests.CreateProfileChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateProfileChat(request)
}
func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
return api.service.messenger.Chats()
}
func (api *PublicAPI) ChatsPreview(parent context.Context) []*protocol.ChatPreview {
return api.service.messenger.ChatsPreview()
}
func (api *PublicAPI) Chat(parent context.Context, chatID string) *protocol.Chat {
return api.service.messenger.Chat(chatID)
}
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
return api.service.messenger.ActiveChats()
}
func (api *PublicAPI) DeleteChat(parent context.Context, chatID string) error {
return api.service.messenger.DeleteChat(chatID)
}
func (api *PublicAPI) MuteCommunityCategory(communityID string, categoryID string) error {
return api.service.messenger.SetMutePropertyOnChatsByCategory(communityID, categoryID, true)
}
func (api *PublicAPI) UnmuteCommunityCategory(communityID string, categoryID string) error {
return api.service.messenger.SetMutePropertyOnChatsByCategory(communityID, categoryID, false)
}
func (api *PublicAPI) MuteChat(parent context.Context, chatID string) error {
return api.service.messenger.MuteChat(chatID)
}
func (api *PublicAPI) UnmuteChat(parent context.Context, chatID string) error {
return api.service.messenger.UnmuteChat(chatID)
}
func (api *PublicAPI) BlockContact(parent context.Context, contactID string) (*protocol.MessengerResponse, error) {
api.log.Info("blocking contact", "contact", contactID)
return api.service.messenger.BlockContact(contactID)
}
// This function is the same as the one above, but used only on the desktop side, since at the end it doesn't set
// `Added` flag to `false`, but only `Blocked` to `true`
func (api *PublicAPI) BlockContactDesktop(parent context.Context, contactID string) (*protocol.MessengerResponse, error) {
api.log.Info("blocking contact", "contact", contactID)
return api.service.messenger.BlockContactDesktop(contactID)
}
func (api *PublicAPI) UnblockContact(parent context.Context, contactID string) error {
return api.service.messenger.UnblockContact(contactID)
}
func (api *PublicAPI) Contacts(parent context.Context) []*protocol.Contact {
return api.service.messenger.Contacts()
}
func (api *PublicAPI) GetContactByID(parent context.Context, id string) *protocol.Contact {
return api.service.messenger.GetContactByID(id)
}
func (api *PublicAPI) RemoveFilters(parent context.Context, chats []*transport.Filter) error {
return api.service.messenger.RemoveFilters(chats)
}
// EnableInstallation enables an installation for multi-device sync.
func (api *PublicAPI) EnableInstallation(installationID string) error {
return api.service.messenger.EnableInstallation(installationID)
}
// DisableInstallation disables an installation for multi-device sync.
func (api *PublicAPI) DisableInstallation(installationID string) error {
return api.service.messenger.DisableInstallation(installationID)
}
// GetOurInstallations returns all the installations available given an identity
func (api *PublicAPI) GetOurInstallations() []*multidevice.Installation {
return api.service.messenger.Installations()
}
// SetInstallationMetadata sets the metadata for our own installation
func (api *PublicAPI) SetInstallationMetadata(installationID string, data *multidevice.InstallationMetadata) error {
return api.service.messenger.SetInstallationMetadata(installationID, data)
}
// Communities returns a list of communities that are stored
func (api *PublicAPI) Communities(parent context.Context) ([]*communities.Community, error) {
return api.service.messenger.Communities()
}
// JoinedCommunities returns a list of communities that the user has joined
func (api *PublicAPI) JoinedCommunities(parent context.Context) ([]*communities.Community, error) {
return api.service.messenger.JoinedCommunities()
}
// CommunityTags return the list of possible community tags
func (api *PublicAPI) CommunityTags(parent context.Context) map[string]string {
return requests.TagsEmojies
}
// CuratedCommunities returns the list of curated communities stored in the smart contract. If a community is
// already known by the node, its description will be returned and and will asynchronously retrieve the
// description for the communities it does not know
func (api *PublicAPI) CuratedCommunities(parent context.Context) (*communities.KnownCommunitiesResponse, error) {
return api.service.messenger.CuratedCommunities()
}
// JoinCommunity joins a community with the given ID
func (api *PublicAPI) JoinCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
return api.service.messenger.JoinCommunity(parent, communityID)
}
// LeaveCommunity leaves a commuity with the given ID
func (api *PublicAPI) LeaveCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
return api.service.messenger.LeaveCommunity(communityID)
}
// CreateCommunity creates a new community with the provided description
func (api *PublicAPI) CreateCommunity(request *requests.CreateCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateCommunity(request, true)
}
// EditCommunity edits an existing community with the provided description
func (api *PublicAPI) EditCommunity(request *requests.EditCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.EditCommunity(request)
}
// ExportCommunity exports the private key of the community with given ID
func (api *PublicAPI) ExportCommunity(id types.HexBytes) (types.HexBytes, error) {
key, err := api.service.messenger.ExportCommunity(id)
if err != nil {
return nil, err
}
return crypto.FromECDSA(key), nil
}
// ImportCommunity imports a community with the given private key in hex
func (api *PublicAPI) ImportCommunity(ctx context.Context, hexPrivateKey string) (*protocol.MessengerResponse, error) {
// Strip the 0x from the beginning
privateKey, err := crypto.HexToECDSA(hexPrivateKey[2:])
if err != nil {
return nil, err
}
return api.service.messenger.ImportCommunity(ctx, privateKey)
}
// CreateCommunityChat creates a community chat in the given community
func (api *PublicAPI) CreateCommunityChat(communityID types.HexBytes, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateCommunityChat(communityID, c)
}
// EditCommunityChat edits a community chat in the given community
func (api *PublicAPI) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.EditCommunityChat(communityID, chatID, c)
}
// DeleteCommunityChat deletes a community chat in the given community
func (api *PublicAPI) DeleteCommunityChat(communityID types.HexBytes, chatID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeleteCommunityChat(communityID, chatID)
}
// InviteUsersToCommunity invites the users with pks to the community with ID
func (api *PublicAPI) InviteUsersToCommunity(request *requests.InviteUsersToCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.InviteUsersToCommunity(request)
}
// ShareCommunity share the community with a set of users
func (api *PublicAPI) ShareCommunity(request *requests.ShareCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.ShareCommunity(request)
}
// ShareImageMessage share the selected chat image with a set of users
func (api *PublicAPI) ShareImageMessage(request *requests.ShareImageMessage) (*protocol.MessengerResponse, error) {
return api.service.messenger.ShareImageMessage(request)
}
// RemoveUserFromCommunity removes the user with pk from the community with ID
func (api *PublicAPI) RemoveUserFromCommunity(communityID types.HexBytes, userPublicKey string) (*protocol.MessengerResponse, error) {
return api.service.messenger.RemoveUserFromCommunity(communityID, userPublicKey)
}
// SetCommunityMuted sets the community's muted value
func (api *PublicAPI) SetCommunityMuted(communityID types.HexBytes, muted bool) error {
return api.service.messenger.SetMuted(communityID, muted)
}
// BanUserFromCommunity removes the user with pk from the community with ID
func (api *PublicAPI) BanUserFromCommunity(request *requests.BanUserFromCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.BanUserFromCommunity(request)
}
// UnbanUserFromCommunity removes the user's pk from the community ban list
func (api *PublicAPI) UnbanUserFromCommunity(request *requests.UnbanUserFromCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.UnbanUserFromCommunity(request)
}
// MyPendingRequestsToJoin returns the pending requests for the logged in user
func (api *PublicAPI) MyPendingRequestsToJoin() ([]*communities.RequestToJoin, error) {
return api.service.messenger.MyPendingRequestsToJoin()
}
// PendingRequestsToJoinForCommunity returns the pending requests to join for a given community
func (api *PublicAPI) PendingRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
return api.service.messenger.PendingRequestsToJoinForCommunity(id)
}
// DeclinedRequestsToJoinForCommunity returns the declined requests to join for a given community
func (api *PublicAPI) DeclinedRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
return api.service.messenger.DeclinedRequestsToJoinForCommunity(id)
}
// AcceptRequestToJoinCommunity accepts a pending request to join a community
func (api *PublicAPI) AcceptRequestToJoinCommunity(request *requests.AcceptRequestToJoinCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.AcceptRequestToJoinCommunity(request)
}
// DeclineRequestToJoinCommunity accepts a pending request to join a community
func (api *PublicAPI) DeclineRequestToJoinCommunity(request *requests.DeclineRequestToJoinCommunity) error {
return api.service.messenger.DeclineRequestToJoinCommunity(request)
}
// RequestToJoinCommunity requests to join a particular community
func (api *PublicAPI) RequestToJoinCommunity(request *requests.RequestToJoinCommunity) (*protocol.MessengerResponse, error) {
return api.service.messenger.RequestToJoinCommunity(request)
}
// CreateCommunityCategory creates a category within a particular community
func (api *PublicAPI) CreateCommunityCategory(request *requests.CreateCommunityCategory) (*protocol.MessengerResponse, error) {
return api.service.messenger.CreateCommunityCategory(request)
}
// ReorderCommunityCategories is used to change the order of the categories of a community
func (api *PublicAPI) ReorderCommunityCategories(request *requests.ReorderCommunityCategories) (*protocol.MessengerResponse, error) {
return api.service.messenger.ReorderCommunityCategories(request)
}
// ReorderCommunityChat allows changing the order of the chat or switching its category
func (api *PublicAPI) ReorderCommunityChat(request *requests.ReorderCommunityChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.ReorderCommunityChat(request)
}
// EditCommunityCategory modifies a category within a particular community
func (api *PublicAPI) EditCommunityCategory(request *requests.EditCommunityCategory) (*protocol.MessengerResponse, error) {
return api.service.messenger.EditCommunityCategory(request)
}
// DeleteCommunityCategory deletes a category within a particular community and removes this category from any chat that has it
func (api *PublicAPI) DeleteCommunityCategory(request *requests.DeleteCommunityCategory) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeleteCommunityCategory(request)
}
type ApplicationMessagesResponse struct {
Messages []*common.Message `json:"messages"`
Cursor string `json:"cursor"`
}
type MarkMessagSeenResponse struct {
Count uint64 `json:"count"`
CountWithMentions uint64 `json:"countWithMentions"`
}
type ApplicationPinnedMessagesResponse struct {
PinnedMessages []*common.PinnedMessage `json:"pinnedMessages"`
Cursor string `json:"cursor"`
}
type ApplicationStatusUpdatesResponse struct {
StatusUpdates []protocol.UserStatus `json:"statusUpdates"`
}
func (api *PublicAPI) ChatMessages(chatID, cursor string, limit int) (*ApplicationMessagesResponse, error) {
messages, cursor, err := api.service.messenger.MessageByChatID(chatID, cursor, limit)
if err != nil {
return nil, err
}
return &ApplicationMessagesResponse{
Messages: messages,
Cursor: cursor,
}, nil
}
func (api *PublicAPI) MessageByMessageID(messageID string) (*common.Message, error) {
return api.service.messenger.MessageByID(messageID)
}
func (api *PublicAPI) AllMessagesFromChatWhichMatchTerm(chatID, searchTerm string, caseSensitive bool) (*ApplicationMessagesResponse, error) {
messages, err := api.service.messenger.AllMessageByChatIDWhichMatchTerm(chatID, searchTerm, caseSensitive)
if err != nil {
return nil, err
}
return &ApplicationMessagesResponse{
Messages: messages,
}, nil
}
func (api *PublicAPI) AllMessagesFromChatsAndCommunitiesWhichMatchTerm(communityIds []string, chatIds []string, searchTerm string, caseSensitive bool) (*ApplicationMessagesResponse, error) {
messages, err := api.service.messenger.AllMessagesFromChatsAndCommunitiesWhichMatchTerm(communityIds, chatIds, searchTerm, caseSensitive)
if err != nil {
return nil, err
}
return &ApplicationMessagesResponse{
Messages: messages,
}, nil
}
func (api *PublicAPI) ChatPinnedMessages(chatID, cursor string, limit int) (*ApplicationPinnedMessagesResponse, error) {
pinnedMessages, cursor, err := api.service.messenger.PinnedMessageByChatID(chatID, cursor, limit)
if err != nil {
return nil, err
}
return &ApplicationPinnedMessagesResponse{
PinnedMessages: pinnedMessages,
Cursor: cursor,
}, nil
}
func (api *PublicAPI) StatusUpdates() (*ApplicationStatusUpdatesResponse, error) {
statusUpdates, err := api.service.messenger.StatusUpdates()
if err != nil {
return nil, err
}
return &ApplicationStatusUpdatesResponse{
StatusUpdates: statusUpdates,
}, nil
}
func (api *PublicAPI) StartMessenger() (*protocol.MessengerResponse, error) {
return api.service.StartMessenger()
}
func (api *PublicAPI) SetUserStatus(ctx context.Context, status int, customText string) error {
return api.service.messenger.SetUserStatus(ctx, status, customText)
}
func (api *PublicAPI) DeleteMessage(id string) error {
return api.service.messenger.DeleteMessage(id)
}
func (api *PublicAPI) DeleteMessagesByChatID(id string) error {
return api.service.messenger.DeleteMessagesByChatID(id)
}
func (api *PublicAPI) MarkMessagesSeen(chatID string, ids []string) (*MarkMessagSeenResponse, error) {
count, withMentions, err := api.service.messenger.MarkMessagesSeen(chatID, ids)
if err != nil {
return nil, err
}
response := &MarkMessagSeenResponse{Count: count, CountWithMentions: withMentions}
return response, nil
}
func (api *PublicAPI) MarkAllRead(chatID string) error {
return api.service.messenger.MarkAllRead(chatID)
}
func (api *PublicAPI) MarkAllReadInCommunity(communityID string) ([]string, error) {
return api.service.messenger.MarkAllReadInCommunity(communityID)
}
func (api *PublicAPI) AddContact(ctx context.Context, request *requests.AddContact) (*protocol.MessengerResponse, error) {
return api.service.messenger.AddContact(ctx, request)
}
func (api *PublicAPI) SendContactRequest(ctx context.Context, request *requests.SendContactRequest) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendContactRequest(ctx, request)
}
func (api *PublicAPI) AcceptContactRequest(ctx context.Context, request *requests.AcceptContactRequest) (*protocol.MessengerResponse, error) {
return api.service.messenger.AcceptContactRequest(ctx, request)
}
func (api *PublicAPI) AcceptLatestContactRequestForContact(ctx context.Context, request *requests.AcceptLatestContactRequestForContact) (*protocol.MessengerResponse, error) {
return api.service.messenger.AcceptLatestContactRequestForContact(ctx, request)
}
func (api *PublicAPI) DismissLatestContactRequestForContact(ctx context.Context, request *requests.DismissLatestContactRequestForContact) (*protocol.MessengerResponse, error) {
return api.service.messenger.DismissLatestContactRequestForContact(ctx, request)
}
func (api *PublicAPI) RetractContactRequest(ctx context.Context, request *requests.RetractContactRequest) (*protocol.MessengerResponse, error) {
return api.service.messenger.RetractContactRequest(request)
}
func (api *PublicAPI) RejectContactRequest(ctx context.Context, request *requests.RejectContactRequest) (*protocol.MessengerResponse, error) {
return api.service.messenger.RejectContactRequest(ctx, request)
}
func (api *PublicAPI) DismissContactRequest(ctx context.Context, request *requests.DismissContactRequest) (*protocol.MessengerResponse, error) {
return api.service.messenger.DismissContactRequest(ctx, request)
}
func (api *PublicAPI) RemoveContact(ctx context.Context, pubKey string) (*protocol.MessengerResponse, error) {
return api.service.messenger.RemoveContact(ctx, pubKey)
}
func (api *PublicAPI) SetContactLocalNickname(ctx context.Context, request *requests.SetContactLocalNickname) (*protocol.MessengerResponse, error) {
return api.service.messenger.SetContactLocalNickname(request)
}
func (api *PublicAPI) ClearHistory(request *requests.ClearHistory) (*protocol.MessengerResponse, error) {
return api.service.messenger.ClearHistory(request)
}
func (api *PublicAPI) DeactivateChat(request *requests.DeactivateChat) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeactivateChat(request)
}
func (api *PublicAPI) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) error {
return api.service.messenger.UpdateMessageOutgoingStatus(id, newOutgoingStatus)
}
func (api *PublicAPI) SendChatMessage(ctx context.Context, message *common.Message) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendChatMessage(ctx, message)
}
func (api *PublicAPI) ReSendChatMessage(ctx context.Context, messageID string) error {
return api.service.messenger.ReSendChatMessage(ctx, messageID)
}
func (api *PublicAPI) SendChatMessages(ctx context.Context, messages []*common.Message) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendChatMessages(ctx, messages)
}
func (api *PublicAPI) EditMessage(ctx context.Context, request *requests.EditMessage) (*protocol.MessengerResponse, error) {
return api.service.messenger.EditMessage(ctx, request)
}
func (api *PublicAPI) DeleteMessageAndSend(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeleteMessageAndSend(ctx, messageID)
}
func (api *PublicAPI) SendPinMessage(ctx context.Context, message *common.PinMessage) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendPinMessage(ctx, message)
}
func (api *PublicAPI) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*protocol.MessengerResponse, error) {
return api.service.messenger.RequestTransaction(ctx, chatID, value, contract, address)
}
func (api *PublicAPI) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*protocol.MessengerResponse, error) {
return api.service.messenger.RequestAddressForTransaction(ctx, chatID, from, value, contract)
}
func (api *PublicAPI) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeclineRequestAddressForTransaction(ctx, messageID)
}
func (api *PublicAPI) DeclineRequestTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.DeclineRequestTransaction(ctx, messageID)
}
func (api *PublicAPI) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*protocol.MessengerResponse, error) {
return api.service.messenger.AcceptRequestAddressForTransaction(ctx, messageID, address)
}
func (api *PublicAPI) SendTransaction(ctx context.Context, chatID, value, contract, transactionHash string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendTransaction(ctx, chatID, value, contract, transactionHash, signature)
}
func (api *PublicAPI) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
return api.service.messenger.AcceptRequestTransaction(ctx, transactionHash, messageID, signature)
}
func (api *PublicAPI) SendContactUpdates(ctx context.Context, name, picture string) error {
return api.service.messenger.SendContactUpdates(ctx, name, picture)
}
func (api *PublicAPI) SendContactUpdate(ctx context.Context, contactID, name, picture string) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendContactUpdate(ctx, contactID, name, picture)
}
func (api *PublicAPI) SetDisplayName(ctx context.Context, displayName string) error {
return api.service.messenger.SetDisplayName(displayName)
}
func (api *PublicAPI) MarkAsTrusted(ctx context.Context, contactID string) error {
return api.service.messenger.MarkAsTrusted(ctx, contactID)
}
func (api *PublicAPI) MarkAsUntrustworthy(ctx context.Context, contactID string) error {
return api.service.messenger.MarkAsUntrustworthy(ctx, contactID)
}
func (api *PublicAPI) RemoveTrustStatus(ctx context.Context, contactID string) error {
return api.service.messenger.RemoveTrustStatus(ctx, contactID)
}
func (api *PublicAPI) GetTrustStatus(ctx context.Context, contactID string) (verification.TrustStatus, error) {
return api.service.messenger.GetTrustStatus(contactID)
}
func (api *PublicAPI) SendContactVerificationRequest(ctx context.Context, contactID string, challenge string) error {
return api.service.messenger.SendContactVerificationRequest(ctx, contactID, challenge)
}
func (api *PublicAPI) GetVerificationRequestFrom(ctx context.Context, contactID string) (*verification.Request, error) {
return api.service.messenger.GetVerificationRequestFrom(ctx, contactID)
}
func (api *PublicAPI) GetReceivedVerificationRequests(ctx context.Context) ([]*verification.Request, error) {
return api.service.messenger.GetReceivedVerificationRequests(ctx)
}
func (api *PublicAPI) GetVerificationRequestSentTo(ctx context.Context, contactID string) (*verification.Request, error) {
return api.service.messenger.GetVerificationRequestSentTo(ctx, contactID)
}
func (api *PublicAPI) CancelVerificationRequest(ctx context.Context, contactID string) error {
return api.service.messenger.CancelVerificationRequest(ctx, contactID)
}
func (api *PublicAPI) AcceptContactVerificationRequest(ctx context.Context, contactID string, response string) error {
return api.service.messenger.AcceptContactVerificationRequest(ctx, contactID, response)
}
func (api *PublicAPI) DeclineContactVerificationRequest(ctx context.Context, contactID string) error {
return api.service.messenger.DeclineContactVerificationRequest(ctx, contactID)
}
func (api *PublicAPI) VerifiedTrusted(ctx context.Context, contactID string) error {
return api.service.messenger.VerifiedTrusted(ctx, contactID)
}
func (api *PublicAPI) VerifiedUntrustworthy(ctx context.Context, contactID string) error {
return api.service.messenger.VerifiedUntrustworthy(ctx, contactID)
}
func (api *PublicAPI) SendPairInstallation(ctx context.Context) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendPairInstallation(ctx)
}
func (api *PublicAPI) SyncDevices(ctx context.Context, name, picture string) error {
return api.service.messenger.SyncDevices(ctx, name, picture)
}
func (api *PublicAPI) AddBookmark(ctx context.Context, bookmark browsers.Bookmark) error {
return api.service.messenger.AddBookmark(ctx, bookmark)
}
func (api *PublicAPI) AddBrowser(ctx context.Context, browser browsers.Browser) error {
return api.service.messenger.AddBrowser(ctx, browser)
}
func (api *PublicAPI) GetBrowsers(ctx context.Context) (browsers []*browsers.Browser, err error) {
return api.service.messenger.GetBrowsers(ctx)
}
func (api *PublicAPI) DeleteBrowser(ctx context.Context, id string) error {
return api.service.messenger.DeleteBrowser(ctx, id)
}
func (api *PublicAPI) RemoveBookmark(ctx context.Context, url string) error {
return api.service.messenger.RemoveBookmark(ctx, url)
}
func (api *PublicAPI) UpdateBookmark(ctx context.Context, oldURL string, bookmark browsers.Bookmark) error {
return api.service.messenger.UpdateBookmark(ctx, oldURL, bookmark)
}
func (api *PublicAPI) SignMessageWithChatKey(ctx context.Context, message string) (types.HexBytes, error) {
return api.service.messenger.SignMessage(message)
}
// wallet connect session apis
func (api *PublicAPI) AddWalletConnectSession(ctx context.Context, request *requests.AddWalletConnectSession) error {
return api.service.messenger.AddWalletConnectSession(request)
}
func (api *PublicAPI) GetWalletConnectSession(ctx context.Context) ([]protocol.WalletConnectSession, error) {
return api.service.messenger.GetWalletConnectSession()
}
func (api *PublicAPI) DestroyWalletConnectSession(ctx context.Context, PeerID string) error {
return api.service.messenger.DestroyWalletConnectSession(PeerID)
}
// PushNotifications server endpoints
func (api *PublicAPI) StartPushNotificationsServer() error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsServerEnabled, true)
if err != nil {
return err
}
return api.service.messenger.StartPushNotificationsServer()
}
func (api *PublicAPI) StopPushNotificationsServer() error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsServerEnabled, false)
if err != nil {
return err
}
return api.service.messenger.StopPushNotificationsServer()
}
// PushNotification client endpoints
func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType) error {
return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken, apnTopic, tokenType)
}
func (api *PublicAPI) UnregisterFromPushNotifications(ctx context.Context) error {
return api.service.messenger.UnregisterFromPushNotifications(ctx)
}
func (api *PublicAPI) DisableSendingNotifications(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.SendPushNotifications, false)
if err != nil {
return err
}
return api.service.messenger.DisableSendingPushNotifications()
}
func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.SendPushNotifications, true)
if err != nil {
return err
}
return api.service.messenger.EnableSendingPushNotifications()
}
func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsFromContactsOnly, true)
if err != nil {
return err
}
return api.service.messenger.EnablePushNotificationsFromContactsOnly()
}
func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsFromContactsOnly, false)
if err != nil {
return err
}
return api.service.messenger.DisablePushNotificationsFromContactsOnly()
}
func (api *PublicAPI) EnablePushNotificationsBlockMentions(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsBlockMentions, true)
if err != nil {
return err
}
return api.service.messenger.EnablePushNotificationsBlockMentions()
}
func (api *PublicAPI) DisablePushNotificationsBlockMentions(ctx context.Context) error {
err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsBlockMentions, false)
if err != nil {
return err
}
return api.service.messenger.DisablePushNotificationsBlockMentions()
}
func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
if err != nil {
return err
}
// this is coming from a user, so it has to be a custom server
return api.service.messenger.AddPushNotificationsServer(ctx, publicKey, pushnotificationclient.ServerTypeCustom)
}
func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
if err != nil {
return err
}
return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
}
func (api *PublicAPI) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
return api.service.messenger.GetPushNotificationsServers()
}
func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) {
return api.service.messenger.RegisteredForPushNotifications()
}
// Emoji
func (api *PublicAPI) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID protobuf.EmojiReaction_Type) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, emojiID)
}
func (api *PublicAPI) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendEmojiReactionRetraction(ctx, emojiReactionID)
}
func (api *PublicAPI) EmojiReactionsByChatID(chatID string, cursor string, limit int) ([]*protocol.EmojiReaction, error) {
return api.service.messenger.EmojiReactionsByChatID(chatID, cursor, limit)
}
func (api *PublicAPI) EmojiReactionsByChatIDMessageID(chatID string, messageID string) ([]*protocol.EmojiReaction, error) {
return api.service.messenger.EmojiReactionsByChatIDMessageID(chatID, messageID)
}
// Urls
func (api *PublicAPI) GetLinkPreviewWhitelist() []urls.Site {
return urls.LinkPreviewWhitelist()
}
func (api *PublicAPI) GetLinkPreviewData(link string) (previewData urls.LinkPreviewData, err error) {
return urls.GetLinkPreviewData(link)
}
func (api *PublicAPI) EnsVerified(pk, ensName string) error {
return api.service.messenger.ENSVerified(pk, ensName)
}
func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) {
return api.service.messenger.RequestCommunityInfoFromMailserver(communityID)
}
func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string) error {
return api.service.messenger.RequestCommunityInfoFromMailserverAsync(communityID)
}
func (api *PublicAPI) UnreadActivityCenterNotificationsCount() (uint64, error) {
return api.service.messenger.UnreadActivityCenterNotificationsCount()
}