github.com/status-im/status-go@v1.1.0/services/ext/api.go (about)

     1  package ext
     2  
     3  import (
     4  	"context"
     5  	"crypto/ecdsa"
     6  	"encoding/hex"
     7  	"errors"
     8  	"fmt"
     9  	"math/big"
    10  	"time"
    11  
    12  	"github.com/libp2p/go-libp2p/core/peer"
    13  	"github.com/multiformats/go-multiaddr"
    14  
    15  	"github.com/status-im/status-go/account"
    16  	"github.com/status-im/status-go/services/browsers"
    17  	"github.com/status-im/status-go/services/wallet"
    18  	"github.com/status-im/status-go/services/wallet/bigint"
    19  
    20  	"github.com/ethereum/go-ethereum/common/hexutil"
    21  	"github.com/ethereum/go-ethereum/log"
    22  	"github.com/ethereum/go-ethereum/p2p/enode"
    23  	"github.com/ethereum/go-ethereum/rlp"
    24  
    25  	ethcommon "github.com/ethereum/go-ethereum/common"
    26  
    27  	"github.com/status-im/status-go/eth-node/crypto"
    28  	"github.com/status-im/status-go/eth-node/types"
    29  	"github.com/status-im/status-go/images"
    30  	"github.com/status-im/status-go/mailserver"
    31  	multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
    32  	"github.com/status-im/status-go/multiaccounts/settings"
    33  	"github.com/status-im/status-go/protocol"
    34  	"github.com/status-im/status-go/protocol/common"
    35  	"github.com/status-im/status-go/protocol/common/shard"
    36  	"github.com/status-im/status-go/protocol/communities"
    37  	"github.com/status-im/status-go/protocol/communities/token"
    38  	"github.com/status-im/status-go/protocol/discord"
    39  	"github.com/status-im/status-go/protocol/encryption/multidevice"
    40  	"github.com/status-im/status-go/protocol/identity"
    41  	"github.com/status-im/status-go/protocol/protobuf"
    42  	"github.com/status-im/status-go/protocol/pushnotificationclient"
    43  	"github.com/status-im/status-go/protocol/requests"
    44  	"github.com/status-im/status-go/protocol/transport"
    45  	"github.com/status-im/status-go/protocol/verification"
    46  	"github.com/status-im/status-go/services/ext/mailservers"
    47  )
    48  
    49  const (
    50  	// defaultRequestTimeout is the default request timeout in seconds
    51  	defaultRequestTimeout = 10
    52  )
    53  
    54  var (
    55  	// ErrInvalidMailServerPeer is returned when it fails to parse enode from params.
    56  	ErrInvalidMailServerPeer = errors.New("invalid mailServerPeer value")
    57  	// ErrInvalidSymKeyID is returned when it fails to get a symmetric key.
    58  	ErrInvalidSymKeyID = errors.New("invalid symKeyID value")
    59  	// ErrInvalidPublicKey is returned when public key can't be extracted
    60  	// from MailServer's nodeID.
    61  	ErrInvalidPublicKey = errors.New("can't extract public key")
    62  	// ErrPFSNotEnabled is returned when an endpoint PFS only is called but
    63  	// PFS is disabled
    64  	ErrPFSNotEnabled = errors.New("pfs not enabled")
    65  )
    66  
    67  // -----
    68  // PAYLOADS
    69  // -----
    70  
    71  // MessagesRequest is a RequestMessages() request payload.
    72  type MessagesRequest struct {
    73  	// MailServerPeer is MailServer's enode address.
    74  	MailServerPeer string `json:"mailServerPeer"`
    75  
    76  	// From is a lower bound of time range (optional).
    77  	// Default is 24 hours back from now.
    78  	From uint32 `json:"from"`
    79  
    80  	// To is a upper bound of time range (optional).
    81  	// Default is now.
    82  	To uint32 `json:"to"`
    83  
    84  	// Limit determines the number of messages sent by the mail server
    85  	// for the current paginated request
    86  	Limit uint32 `json:"limit"`
    87  
    88  	// Cursor is used as starting point for paginated requests
    89  	Cursor string `json:"cursor"`
    90  
    91  	// StoreCursor is used as starting point for WAKUV2 paginatedRequests
    92  	StoreCursor *StoreRequestCursor `json:"storeCursor"`
    93  
    94  	// Topic is a regular Whisper topic.
    95  	// DEPRECATED
    96  	Topic types.TopicType `json:"topic"`
    97  
    98  	// Topics is a list of Whisper topics.
    99  	Topics []types.TopicType `json:"topics"`
   100  
   101  	// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
   102  	// It's derived from MailServer password.
   103  	SymKeyID string `json:"symKeyID"`
   104  
   105  	// Timeout is the time to live of the request specified in seconds.
   106  	// Default is 10 seconds
   107  	Timeout time.Duration `json:"timeout"`
   108  
   109  	// Force ensures that requests will bypass enforced delay.
   110  	Force bool `json:"force"`
   111  }
   112  
   113  type StoreRequestCursor struct {
   114  	Digest       []byte  `json:"digest"`
   115  	ReceivedTime float64 `json:"receivedTime"`
   116  }
   117  
   118  func (r *MessagesRequest) SetDefaults(now time.Time) {
   119  	// set From and To defaults
   120  	if r.To == 0 {
   121  		r.To = uint32(now.UTC().Unix())
   122  	}
   123  
   124  	if r.From == 0 {
   125  		oneDay := uint32(86400) // -24 hours
   126  		if r.To < oneDay {
   127  			r.From = 0
   128  		} else {
   129  			r.From = r.To - oneDay
   130  		}
   131  	}
   132  
   133  	if r.Timeout == 0 {
   134  		r.Timeout = defaultRequestTimeout
   135  	}
   136  }
   137  
   138  // MessagesResponse is a response for requestMessages2 method.
   139  type MessagesResponse struct {
   140  	// Cursor from the response can be used to retrieve more messages
   141  	// for the previous request.
   142  	Cursor string `json:"cursor"`
   143  
   144  	// Error indicates that something wrong happened when sending messages
   145  	// to the requester.
   146  	Error error `json:"error"`
   147  }
   148  
   149  // -----
   150  // PUBLIC API
   151  // -----
   152  
   153  // PublicAPI extends whisper public API.
   154  type PublicAPI struct {
   155  	service  *Service
   156  	eventSub mailservers.EnvelopeEventSubscriber
   157  	log      log.Logger
   158  }
   159  
   160  // NewPublicAPI returns instance of the public API.
   161  func NewPublicAPI(s *Service, eventSub mailservers.EnvelopeEventSubscriber) *PublicAPI {
   162  	return &PublicAPI{
   163  		service:  s,
   164  		eventSub: eventSub,
   165  		log:      log.New("package", "status-go/services/sshext.PublicAPI"),
   166  	}
   167  }
   168  
   169  // RetryConfig specifies configuration for retries with timeout and max amount of retries.
   170  type RetryConfig struct {
   171  	BaseTimeout time.Duration
   172  	// StepTimeout defines duration increase per each retry.
   173  	StepTimeout time.Duration
   174  	MaxRetries  int
   175  }
   176  
   177  func WaitForExpiredOrCompleted(requestID types.Hash, events chan types.EnvelopeEvent, timeout time.Duration) (*types.MailServerResponse, error) {
   178  	expired := fmt.Errorf("request %x expired", requestID)
   179  	after := time.NewTimer(timeout)
   180  	defer after.Stop()
   181  	for {
   182  		var ev types.EnvelopeEvent
   183  		select {
   184  		case ev = <-events:
   185  		case <-after.C:
   186  			return nil, expired
   187  		}
   188  		if ev.Hash != requestID {
   189  			continue
   190  		}
   191  		switch ev.Event {
   192  		case types.EventMailServerRequestCompleted:
   193  			data, ok := ev.Data.(*types.MailServerResponse)
   194  			if ok {
   195  				return data, nil
   196  			}
   197  			return nil, errors.New("invalid event data type")
   198  		case types.EventMailServerRequestExpired:
   199  			return nil, expired
   200  		}
   201  	}
   202  }
   203  
   204  type Author struct {
   205  	PublicKey types.HexBytes `json:"publicKey"`
   206  	Alias     string         `json:"alias"`
   207  	Identicon string         `json:"identicon"`
   208  }
   209  
   210  type Metadata struct {
   211  	DedupID      []byte         `json:"dedupId"`
   212  	EncryptionID types.HexBytes `json:"encryptionId"`
   213  	MessageID    types.HexBytes `json:"messageId"`
   214  	Author       Author         `json:"author"`
   215  }
   216  
   217  func (api *PublicAPI) LeaveGroupChat(ctx Context, chatID string, remove bool) (*protocol.MessengerResponse, error) {
   218  	return api.service.messenger.LeaveGroupChat(ctx, chatID, remove)
   219  }
   220  
   221  func (api *PublicAPI) CreateGroupChatWithMembers(ctx Context, name string, members []string) (*protocol.MessengerResponse, error) {
   222  	return api.service.messenger.CreateGroupChatWithMembers(ctx, name, members)
   223  }
   224  
   225  func (api *PublicAPI) CreateGroupChatFromInvitation(name string, chatID string, adminPK string) (*protocol.MessengerResponse, error) {
   226  	return api.service.messenger.CreateGroupChatFromInvitation(name, chatID, adminPK)
   227  }
   228  
   229  func (api *PublicAPI) AddMembersToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
   230  	return api.service.messenger.AddMembersToGroupChat(ctx, chatID, members)
   231  }
   232  
   233  func (api *PublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
   234  	return api.service.messenger.RemoveMembersFromGroupChat(ctx, chatID, []string{member})
   235  }
   236  
   237  func (api *PublicAPI) RemoveMembersFromGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
   238  	return api.service.messenger.RemoveMembersFromGroupChat(ctx, chatID, members)
   239  }
   240  
   241  func (api *PublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
   242  	return api.service.messenger.AddAdminsToGroupChat(ctx, chatID, members)
   243  }
   244  
   245  func (api *PublicAPI) ConfirmJoiningGroup(ctx context.Context, chatID string) (*protocol.MessengerResponse, error) {
   246  	return api.service.messenger.ConfirmJoiningGroup(ctx, chatID)
   247  }
   248  
   249  func (api *PublicAPI) ChangeGroupChatName(ctx Context, chatID string, name string) (*protocol.MessengerResponse, error) {
   250  	return api.service.messenger.ChangeGroupChatName(ctx, chatID, name)
   251  }
   252  
   253  func (api *PublicAPI) SendGroupChatInvitationRequest(ctx Context, chatID string, adminPK string, message string) (*protocol.MessengerResponse, error) {
   254  	return api.service.messenger.SendGroupChatInvitationRequest(ctx, chatID, adminPK, message)
   255  }
   256  
   257  func (api *PublicAPI) GetGroupChatInvitations() ([]*protocol.GroupChatInvitation, error) {
   258  	return api.service.messenger.GetGroupChatInvitations()
   259  }
   260  
   261  func (api *PublicAPI) SendGroupChatInvitationRejection(ctx Context, invitationRequestID string) (*protocol.MessengerResponse, error) {
   262  	return api.service.messenger.SendGroupChatInvitationRejection(ctx, invitationRequestID)
   263  }
   264  
   265  func (api *PublicAPI) LoadFilters(parent context.Context, chats []*transport.Filter) ([]*transport.Filter, error) {
   266  	return api.service.messenger.LoadFilters(chats)
   267  }
   268  
   269  func (api *PublicAPI) SaveChat(parent context.Context, chat *protocol.Chat) error {
   270  	return api.service.messenger.SaveChat(chat)
   271  }
   272  
   273  func (api *PublicAPI) SaveMessages(parent context.Context, messages []*common.Message) error {
   274  	return api.service.messenger.SaveMessages(messages)
   275  }
   276  
   277  func (api *PublicAPI) CreateOneToOneChat(parent context.Context, request *requests.CreateOneToOneChat) (*protocol.MessengerResponse, error) {
   278  	return api.service.messenger.CreateOneToOneChat(request)
   279  }
   280  
   281  func (api *PublicAPI) CreatePublicChat(parent context.Context, request *requests.CreatePublicChat) (*protocol.MessengerResponse, error) {
   282  	return api.service.messenger.CreatePublicChat(request)
   283  }
   284  
   285  func (api *PublicAPI) CreateProfileChat(parent context.Context, request *requests.CreateProfileChat) (*protocol.MessengerResponse, error) {
   286  	return api.service.messenger.CreateProfileChat(request)
   287  }
   288  
   289  func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
   290  	return api.service.messenger.Chats()
   291  }
   292  
   293  func (api *PublicAPI) ChatsPreview(parent context.Context) []*protocol.ChatPreview {
   294  	return api.service.messenger.ChatsPreview()
   295  }
   296  
   297  func (api *PublicAPI) Chat(parent context.Context, chatID string) *protocol.Chat {
   298  	return api.service.messenger.Chat(chatID)
   299  }
   300  
   301  func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
   302  	return api.service.messenger.ActiveChats()
   303  }
   304  
   305  func (api *PublicAPI) DeleteChat(parent context.Context, chatID string) error {
   306  	return api.service.messenger.DeleteChat(chatID)
   307  }
   308  
   309  func (api *PublicAPI) MuteCommunityCategory(request *requests.MuteCategory) error {
   310  	return api.service.messenger.SetMutePropertyOnChatsByCategory(request, true)
   311  }
   312  
   313  // Updates the lastOpenedAt key of a community
   314  func (api *PublicAPI) CommunityUpdateLastOpenedAt(communityID string) (int64, error) {
   315  	return api.service.messenger.CommunityUpdateLastOpenedAt(communityID)
   316  }
   317  
   318  func (api *PublicAPI) UnmuteCommunityCategory(communityID string, categoryID string) error {
   319  	return api.service.messenger.SetMutePropertyOnChatsByCategory(&requests.MuteCategory{CommunityID: communityID, CategoryID: categoryID, MutedType: protocol.Unmuted}, false)
   320  }
   321  
   322  func (api *PublicAPI) MuteCommunityChats(request *requests.MuteCommunity) (time.Time, error) {
   323  	return api.service.messenger.MuteAllCommunityChats(request)
   324  }
   325  
   326  func (api *PublicAPI) UnMuteCommunityChats(communityID string) (time.Time, error) {
   327  	return api.service.messenger.UnMuteAllCommunityChats(communityID)
   328  }
   329  
   330  func (api *PublicAPI) MuteChatV2(parent context.Context, request *requests.MuteChat) (time.Time, error) {
   331  	return api.service.messenger.MuteChatV2(request)
   332  }
   333  
   334  func (api *PublicAPI) MuteChat(parent context.Context, chatID string) (time.Time, error) {
   335  	return api.service.messenger.MuteChat(&requests.MuteChat{ChatID: chatID, MutedType: 0})
   336  }
   337  
   338  func (api *PublicAPI) UnmuteChat(parent context.Context, chatID string) error {
   339  	return api.service.messenger.UnmuteChat(chatID)
   340  }
   341  
   342  func (api *PublicAPI) BlockContact(ctx context.Context, contactID string) (*protocol.MessengerResponse, error) {
   343  	api.log.Info("blocking contact", "contact", contactID)
   344  	return api.service.messenger.BlockContact(ctx, contactID, false)
   345  }
   346  
   347  // This function is the same as the one above, but used only on the desktop side, since at the end it doesn't set
   348  // `Added` flag to `false`, but only `Blocked` to `true`
   349  func (api *PublicAPI) BlockContactDesktop(ctx context.Context, contactID string) (*protocol.MessengerResponse, error) {
   350  	api.log.Info("blocking contact", "contact", contactID)
   351  	return api.service.messenger.BlockContactDesktop(ctx, contactID)
   352  }
   353  
   354  func (api *PublicAPI) UnblockContact(parent context.Context, contactID string) (*protocol.MessengerResponse, error) {
   355  	return api.service.messenger.UnblockContact(contactID)
   356  }
   357  
   358  func (api *PublicAPI) Contacts(parent context.Context) []*protocol.Contact {
   359  	return api.service.messenger.Contacts()
   360  }
   361  
   362  func (api *PublicAPI) GetContactByID(parent context.Context, id string) *protocol.Contact {
   363  	return api.service.messenger.GetContactByID(id)
   364  }
   365  
   366  func (api *PublicAPI) RequestContactInfoFromMailserver(pubkey string) (*protocol.Contact, error) {
   367  	return api.service.messenger.FetchContact(pubkey, true)
   368  }
   369  
   370  func (api *PublicAPI) RemoveFilters(parent context.Context, chats []*transport.Filter) error {
   371  	return api.service.messenger.RemoveFilters(chats)
   372  }
   373  
   374  // EnableInstallation enables an installation for multi-device sync.
   375  func (api *PublicAPI) EnableInstallation(installationID string) error {
   376  	return api.service.messenger.EnableInstallation(installationID)
   377  }
   378  
   379  // DisableInstallation disables an installation for multi-device sync.
   380  func (api *PublicAPI) DisableInstallation(installationID string) error {
   381  	return api.service.messenger.DisableInstallation(installationID)
   382  }
   383  
   384  // GetOurInstallations returns all the installations available given an identity
   385  func (api *PublicAPI) GetOurInstallations() []*multidevice.Installation {
   386  	return api.service.messenger.Installations()
   387  }
   388  
   389  // SetInstallationMetadata sets the metadata for our own installation
   390  func (api *PublicAPI) SetInstallationMetadata(installationID string, data *multidevice.InstallationMetadata) error {
   391  	return api.service.messenger.SetInstallationMetadata(installationID, data)
   392  }
   393  
   394  // SetInstallationName sets the only the name in metadata for a given installation
   395  func (api *PublicAPI) SetInstallationName(installationID string, name string) error {
   396  	return api.service.messenger.SetInstallationName(installationID, name)
   397  }
   398  
   399  // Communities returns a list of communities that are stored
   400  func (api *PublicAPI) Communities(parent context.Context) ([]*communities.Community, error) {
   401  	return api.service.messenger.Communities()
   402  }
   403  
   404  // Deprecated: renamed back to Communities. Should be removed after implementing on all platforms
   405  func (api *PublicAPI) SerializedCommunities(parent context.Context) ([]*communities.Community, error) {
   406  	return api.Communities(parent)
   407  }
   408  
   409  // JoinedCommunities returns a list of communities that the user has joined
   410  func (api *PublicAPI) JoinedCommunities(parent context.Context) ([]*communities.Community, error) {
   411  	return api.service.messenger.JoinedCommunities()
   412  }
   413  
   414  // IsDisplayNameDupeOfCommunityMember returns if any controlled or joined community has a member with provided display name
   415  func (api *PublicAPI) IsDisplayNameDupeOfCommunityMember(name string) (bool, error) {
   416  	return api.service.messenger.IsDisplayNameDupeOfCommunityMember(name)
   417  }
   418  
   419  // CommunityTags return the list of possible community tags
   420  func (api *PublicAPI) CommunityTags(parent context.Context) map[string]string {
   421  	return requests.AvailableTagsEmojis()
   422  }
   423  
   424  // CuratedCommunities returns the list of curated communities stored in the smart contract. If a community is
   425  // already known by the node, its description will be returned and and will asynchronously retrieve the
   426  // description for the communities it does not know
   427  func (api *PublicAPI) CuratedCommunities(parent context.Context) (*communities.KnownCommunitiesResponse, error) {
   428  	return api.service.messenger.CuratedCommunities()
   429  }
   430  
   431  // SpectateCommunity spectates community with the given ID
   432  // Meaning user is only a spectator, not a member
   433  func (api *PublicAPI) SpectateCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
   434  	return api.service.messenger.SpectateCommunity(communityID)
   435  }
   436  
   437  // JoinCommunity joins a community with the given ID
   438  func (api *PublicAPI) JoinCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
   439  	return api.service.messenger.JoinCommunity(parent, communityID, false)
   440  }
   441  
   442  // LeaveCommunity leaves a commuity with the given ID
   443  func (api *PublicAPI) LeaveCommunity(ctx context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
   444  	return api.service.messenger.LeaveCommunity(communityID)
   445  }
   446  
   447  // CreateCommunity creates a new community with the provided description
   448  func (api *PublicAPI) CreateCommunity(request *requests.CreateCommunity) (*protocol.MessengerResponse, error) {
   449  	return api.service.messenger.CreateCommunity(request, true)
   450  }
   451  
   452  // EditCommunity edits an existing community with the provided description
   453  func (api *PublicAPI) EditCommunity(request *requests.EditCommunity) (*protocol.MessengerResponse, error) {
   454  	return api.service.messenger.EditCommunity(request)
   455  }
   456  
   457  // RemovePrivateKey removes the private key of the community with given ID
   458  func (api *PublicAPI) RemovePrivateKey(id types.HexBytes) (*protocol.MessengerResponse, error) {
   459  	return api.service.messenger.RemovePrivateKey(id)
   460  }
   461  
   462  // Sets the community shard for a community and updates all active filters for the community
   463  func (api *PublicAPI) SetCommunityShard(request *requests.SetCommunityShard) (*protocol.MessengerResponse, error) {
   464  	return api.service.messenger.SetCommunityShard(request)
   465  }
   466  
   467  // Sets the community storenodes for a community
   468  func (api *PublicAPI) SetCommunityStorenodes(request *requests.SetCommunityStorenodes) (*protocol.MessengerResponse, error) {
   469  	return api.service.messenger.SetCommunityStorenodes(request)
   470  }
   471  
   472  // Gets the community storenodes for a community
   473  func (api *PublicAPI) GetCommunityStorenodes(id types.HexBytes) (*protocol.MessengerResponse, error) {
   474  	return api.service.messenger.GetCommunityStorenodes(id)
   475  }
   476  
   477  // ExportCommunity exports the private key of the community with given ID
   478  func (api *PublicAPI) ExportCommunity(id types.HexBytes) (types.HexBytes, error) {
   479  	key, err := api.service.messenger.ExportCommunity(id)
   480  	if err != nil {
   481  		return nil, err
   482  	}
   483  	return crypto.FromECDSA(key), nil
   484  }
   485  
   486  // ImportCommunity imports a community with the given private key in hex
   487  func (api *PublicAPI) ImportCommunity(ctx context.Context, hexPrivateKey string) (*protocol.MessengerResponse, error) {
   488  	// Strip the 0x from the beginning
   489  	privateKey, err := crypto.HexToECDSA(hexPrivateKey[2:])
   490  	if err != nil {
   491  		return nil, err
   492  	}
   493  	return api.service.messenger.ImportCommunity(ctx, privateKey)
   494  }
   495  
   496  // GetCommunityPublicKeyFromPrivateKey gets the community's public key from its private key
   497  func (api *PublicAPI) GetCommunityPublicKeyFromPrivateKey(ctx context.Context, hexPrivateKey string) string {
   498  	publicKey := protocol.GetCommunityIDFromKey(hexPrivateKey)
   499  	return publicKey
   500  }
   501  
   502  // Get community members contact list for provided wallet addresses
   503  func (api *PublicAPI) GetCommunityMembersForWalletAddresses(communityID types.HexBytes, chainID uint64) (map[string]*protocol.Contact, error) {
   504  	return api.service.messenger.GetCommunityMembersForWalletAddresses(communityID, chainID)
   505  }
   506  
   507  // Speeds up importing messages from archives
   508  func (api *PublicAPI) SpeedupArchivesImport(ctx context.Context) {
   509  	api.service.messenger.SpeedupArchivesImport()
   510  }
   511  
   512  // Slows down importing messages from archives
   513  func (api *PublicAPI) SlowdownArchivesImport(ctx context.Context) {
   514  	api.service.messenger.SlowdownArchivesImport()
   515  }
   516  
   517  // CreateCommunityChat creates a community chat in the given community
   518  func (api *PublicAPI) CreateCommunityChat(communityID types.HexBytes, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
   519  	return api.service.messenger.CreateCommunityChat(communityID, c)
   520  }
   521  
   522  // EditCommunityChat edits a community chat in the given community
   523  func (api *PublicAPI) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
   524  	return api.service.messenger.EditCommunityChat(communityID, chatID, c)
   525  }
   526  
   527  // DeleteCommunityChat deletes a community chat in the given community
   528  func (api *PublicAPI) DeleteCommunityChat(communityID types.HexBytes, chatID string) (*protocol.MessengerResponse, error) {
   529  	return api.service.messenger.DeleteCommunityChat(communityID, chatID)
   530  }
   531  
   532  // ShareCommunity share the community with a set of users
   533  func (api *PublicAPI) ShareCommunity(request *requests.ShareCommunity) (*protocol.MessengerResponse, error) {
   534  	return api.service.messenger.ShareCommunity(request)
   535  }
   536  
   537  // ShareImageMessage share the selected chat image with a set of users
   538  func (api *PublicAPI) ShareImageMessage(request *requests.ShareImageMessage) (*protocol.MessengerResponse, error) {
   539  	return api.service.messenger.ShareImageMessage(request)
   540  }
   541  
   542  // RemoveUserFromCommunity removes the user with pk from the community with ID
   543  func (api *PublicAPI) RemoveUserFromCommunity(communityID types.HexBytes, userPublicKey string) (*protocol.MessengerResponse, error) {
   544  	return api.service.messenger.RemoveUserFromCommunity(communityID, userPublicKey)
   545  }
   546  
   547  // SetCommunityMuted sets the community's muted value
   548  func (api *PublicAPI) SetCommunityMuted(request *requests.MuteCommunity) error {
   549  	return api.service.messenger.SetMuted(request)
   550  }
   551  
   552  // BanUserFromCommunity removes the user with pk from the community with ID
   553  func (api *PublicAPI) BanUserFromCommunity(ctx context.Context, request *requests.BanUserFromCommunity) (*protocol.MessengerResponse, error) {
   554  	return api.service.messenger.BanUserFromCommunity(ctx, request)
   555  }
   556  
   557  // UnbanUserFromCommunity removes the user's pk from the community ban list
   558  func (api *PublicAPI) UnbanUserFromCommunity(request *requests.UnbanUserFromCommunity) (*protocol.MessengerResponse, error) {
   559  	return api.service.messenger.UnbanUserFromCommunity(request)
   560  }
   561  
   562  func (api *PublicAPI) AddRoleToMember(request *requests.AddRoleToMember) (*protocol.MessengerResponse, error) {
   563  	return api.service.messenger.AddRoleToMember(request)
   564  }
   565  
   566  func (api *PublicAPI) RemoveRoleFromMember(request *requests.RemoveRoleFromMember) (*protocol.MessengerResponse, error) {
   567  	return api.service.messenger.RemoveRoleFromMember(request)
   568  }
   569  
   570  func (api *PublicAPI) CreateCommunityTokenPermission(request *requests.CreateCommunityTokenPermission) (*protocol.MessengerResponse, error) {
   571  	return api.service.messenger.CreateCommunityTokenPermission(request)
   572  }
   573  
   574  // ReevaluateCommunityMembersPermissions reevaluates community members permissions
   575  func (api *PublicAPI) ReevaluateCommunityMembersPermissions(request *requests.ReevaluateCommunityMembersPermissions) (*protocol.MessengerResponse, error) {
   576  	return api.service.messenger.ReevaluateCommunityMembersPermissions(request)
   577  }
   578  
   579  func (api *PublicAPI) DeleteCommunityTokenPermission(request *requests.DeleteCommunityTokenPermission) (*protocol.MessengerResponse, error) {
   580  	return api.service.messenger.DeleteCommunityTokenPermission(request)
   581  }
   582  
   583  func (api *PublicAPI) EditCommunityTokenPermission(request *requests.EditCommunityTokenPermission) (*protocol.MessengerResponse, error) {
   584  	return api.service.messenger.EditCommunityTokenPermission(request)
   585  }
   586  
   587  func (api *PublicAPI) LatestRequestToJoinForCommunity(id types.HexBytes) (*communities.RequestToJoin, error) {
   588  	return api.service.messenger.LatestRequestToJoinForCommunity(id)
   589  }
   590  
   591  // MyPendingRequestsToJoin returns the pending requests for the logged in user
   592  func (api *PublicAPI) MyPendingRequestsToJoin() ([]*communities.RequestToJoin, error) {
   593  	return api.service.messenger.MyPendingRequestsToJoin()
   594  }
   595  
   596  // MyCanceledRequestsToJoin returns the pending requests for the logged in user
   597  func (api *PublicAPI) MyCanceledRequestsToJoin() ([]*communities.RequestToJoin, error) {
   598  	return api.service.messenger.MyCanceledRequestsToJoin()
   599  }
   600  
   601  // PendingRequestsToJoinForCommunity returns the pending requests to join for a given community
   602  func (api *PublicAPI) PendingRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
   603  	return api.service.messenger.PendingRequestsToJoinForCommunity(id)
   604  }
   605  
   606  // DeclinedRequestsToJoinForCommunity returns the declined requests to join for a given community
   607  func (api *PublicAPI) DeclinedRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
   608  	return api.service.messenger.DeclinedRequestsToJoinForCommunity(id)
   609  }
   610  
   611  // CanceledRequestsToJoinForCommunity returns the declined requests to join for a given community
   612  func (api *PublicAPI) CanceledRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
   613  	return api.service.messenger.CanceledRequestsToJoinForCommunity(id)
   614  }
   615  
   616  // AllNonApprovedCommunitiesRequestsToJoin returns the all non-approved requests to join for all communities
   617  func (api *PublicAPI) AllNonApprovedCommunitiesRequestsToJoin() ([]*communities.RequestToJoin, error) {
   618  	return api.service.messenger.AllNonApprovedCommunitiesRequestsToJoin()
   619  }
   620  
   621  // Generates a single hash for each address that needs to be revealed to a community.
   622  // Each hash needs to be signed.
   623  // The order of retuned hashes corresponds to the order of addresses in addressesToReveal.
   624  func (api *PublicAPI) GenerateJoiningCommunityRequestsForSigning(memberPubKey string, communityID types.HexBytes, addressesToReveal []string) ([]account.SignParams, error) {
   625  	return api.service.messenger.GenerateJoiningCommunityRequestsForSigning(memberPubKey, communityID, addressesToReveal)
   626  }
   627  
   628  // Generates a single hash for each address that needs to be revealed to a community.
   629  // Each hash needs to be signed.
   630  // The order of retuned hashes corresponds to the order of addresses in addressesToReveal.
   631  func (api *PublicAPI) GenerateEditCommunityRequestsForSigning(memberPubKey string, communityID types.HexBytes, addressesToReveal []string) ([]account.SignParams, error) {
   632  	return api.service.messenger.GenerateEditCommunityRequestsForSigning(memberPubKey, communityID, addressesToReveal)
   633  }
   634  
   635  // Signs the provided messages with the provided accounts and password.
   636  // Provided accounts must not belong to a keypair that is migrated to a keycard.
   637  // Otherwise, the signing will fail, cause such accounts should be signed with a keycard.
   638  func (api *PublicAPI) SignData(signParams []account.SignParams) ([]string, error) {
   639  	return api.service.messenger.SignData(signParams)
   640  }
   641  
   642  // CancelRequestToJoinCommunity accepts a pending request to join a community
   643  func (api *PublicAPI) CancelRequestToJoinCommunity(ctx context.Context, request *requests.CancelRequestToJoinCommunity) (*protocol.MessengerResponse, error) {
   644  	return api.service.messenger.CancelRequestToJoinCommunity(ctx, request)
   645  }
   646  
   647  // AcceptRequestToJoinCommunity accepts a pending request to join a community
   648  func (api *PublicAPI) AcceptRequestToJoinCommunity(request *requests.AcceptRequestToJoinCommunity) (*protocol.MessengerResponse, error) {
   649  	return api.service.messenger.AcceptRequestToJoinCommunity(request)
   650  }
   651  
   652  // DeclineRequestToJoinCommunity accepts a pending request to join a community
   653  func (api *PublicAPI) DeclineRequestToJoinCommunity(request *requests.DeclineRequestToJoinCommunity) (*protocol.MessengerResponse, error) {
   654  	return api.service.messenger.DeclineRequestToJoinCommunity(request)
   655  }
   656  
   657  // RequestToJoinCommunity requests to join a particular community
   658  func (api *PublicAPI) RequestToJoinCommunity(request *requests.RequestToJoinCommunity) (*protocol.MessengerResponse, error) {
   659  	return api.service.messenger.RequestToJoinCommunity(request)
   660  }
   661  
   662  // EditSharedAddressesForCommunity edits the addresses that are shared with the owner of the community
   663  func (api *PublicAPI) EditSharedAddressesForCommunity(request *requests.EditSharedAddresses) (*protocol.MessengerResponse, error) {
   664  	return api.service.messenger.EditSharedAddressesForCommunity(request)
   665  }
   666  
   667  // GetRevealedAccounts gets the revealed addresses for a member in a community
   668  func (api *PublicAPI) GetRevealedAccounts(communityID types.HexBytes, memberPk string) ([]*protobuf.RevealedAccount, error) {
   669  	return api.service.messenger.GetRevealedAccounts(communityID, memberPk)
   670  }
   671  
   672  // GetRevealedAccountsForAllMembers gets the revealed addresses for all the members of a community
   673  func (api *PublicAPI) GetRevealedAccountsForAllMembers(communityID types.HexBytes) (map[string][]*protobuf.RevealedAccount, error) {
   674  	return api.service.messenger.GetRevealedAccountsForAllMembers(communityID)
   675  }
   676  
   677  // CheckAndClearPendingRequestToJoinCommunity to delete pending request to join a community which are older than 7 days
   678  func (api *PublicAPI) CheckAndDeletePendingRequestToJoinCommunity(ctx context.Context) (*protocol.MessengerResponse, error) {
   679  	return api.service.messenger.CheckAndDeletePendingRequestToJoinCommunity(ctx, true)
   680  }
   681  
   682  // CreateCommunityCategory creates a category within a particular community
   683  func (api *PublicAPI) CreateCommunityCategory(request *requests.CreateCommunityCategory) (*protocol.MessengerResponse, error) {
   684  	return api.service.messenger.CreateCommunityCategory(request)
   685  }
   686  
   687  // ReorderCommunityCategories is used to change the order of the categories of a community
   688  func (api *PublicAPI) ReorderCommunityCategories(request *requests.ReorderCommunityCategories) (*protocol.MessengerResponse, error) {
   689  	return api.service.messenger.ReorderCommunityCategories(request)
   690  }
   691  
   692  // ReorderCommunityChat allows changing the order of the chat or switching its category
   693  func (api *PublicAPI) ReorderCommunityChat(request *requests.ReorderCommunityChat) (*protocol.MessengerResponse, error) {
   694  	return api.service.messenger.ReorderCommunityChat(request)
   695  }
   696  
   697  // EditCommunityCategory modifies a category within a particular community
   698  func (api *PublicAPI) EditCommunityCategory(request *requests.EditCommunityCategory) (*protocol.MessengerResponse, error) {
   699  	return api.service.messenger.EditCommunityCategory(request)
   700  }
   701  
   702  // DeleteCommunityCategory deletes a category within a particular community and removes this category from any chat that has it
   703  func (api *PublicAPI) DeleteCommunityCategory(request *requests.DeleteCommunityCategory) (*protocol.MessengerResponse, error) {
   704  	return api.service.messenger.DeleteCommunityCategory(request)
   705  }
   706  
   707  func (api *PublicAPI) PromoteSelfToControlNode(communityID types.HexBytes) (*protocol.MessengerResponse, error) {
   708  	return api.service.messenger.PromoteSelfToControlNode(communityID)
   709  }
   710  
   711  type ApplicationMessagesResponse struct {
   712  	Messages []*common.Message `json:"messages"`
   713  	Cursor   string            `json:"cursor"`
   714  }
   715  
   716  type MarkMessageSeenResponse struct {
   717  	Count                       uint64                                 `json:"count"`
   718  	CountWithMentions           uint64                                 `json:"countWithMentions"`
   719  	ActivityCenterNotifications []*protocol.ActivityCenterNotification `json:"activityCenterNotifications,omitempty"`
   720  }
   721  
   722  type ApplicationPinnedMessagesResponse struct {
   723  	PinnedMessages []*common.PinnedMessage `json:"pinnedMessages"`
   724  	Cursor         string                  `json:"cursor"`
   725  }
   726  
   727  type ApplicationStatusUpdatesResponse struct {
   728  	StatusUpdates []protocol.UserStatus `json:"statusUpdates"`
   729  }
   730  
   731  type ApplicationSwitcherCardsResponse struct {
   732  	SwitcherCards []protocol.SwitcherCard `json:"switcherCards"`
   733  }
   734  
   735  func (api *PublicAPI) ChatMessages(chatID, cursor string, limit int) (*ApplicationMessagesResponse, error) {
   736  	messages, cursor, err := api.service.messenger.MessageByChatID(chatID, cursor, limit)
   737  	if err != nil {
   738  		return nil, err
   739  	}
   740  
   741  	return &ApplicationMessagesResponse{
   742  		Messages: messages,
   743  		Cursor:   cursor,
   744  	}, nil
   745  }
   746  
   747  func (api *PublicAPI) MessageByMessageID(messageID string) (*common.Message, error) {
   748  	return api.service.messenger.MessageByID(messageID)
   749  }
   750  
   751  func (api *PublicAPI) FirstUnseenMessageID(chatID string) (string, error) {
   752  	return api.service.messenger.FirstUnseenMessageID(chatID)
   753  }
   754  
   755  func (api *PublicAPI) AllMessagesFromChatWhichMatchTerm(chatID, searchTerm string, caseSensitive bool) (*ApplicationMessagesResponse, error) {
   756  	messages, err := api.service.messenger.AllMessageByChatIDWhichMatchTerm(chatID, searchTerm, caseSensitive)
   757  	if err != nil {
   758  		return nil, err
   759  	}
   760  
   761  	return &ApplicationMessagesResponse{
   762  		Messages: messages,
   763  	}, nil
   764  }
   765  
   766  func (api *PublicAPI) AllMessagesFromChatsAndCommunitiesWhichMatchTerm(communityIds []string, chatIds []string, searchTerm string, caseSensitive bool) (*ApplicationMessagesResponse, error) {
   767  	messages, err := api.service.messenger.AllMessagesFromChatsAndCommunitiesWhichMatchTerm(communityIds, chatIds, searchTerm, caseSensitive)
   768  	if err != nil {
   769  		return nil, err
   770  	}
   771  
   772  	return &ApplicationMessagesResponse{
   773  		Messages: messages,
   774  	}, nil
   775  }
   776  
   777  func (api *PublicAPI) ChatPinnedMessages(chatID, cursor string, limit int) (*ApplicationPinnedMessagesResponse, error) {
   778  	pinnedMessages, cursor, err := api.service.messenger.PinnedMessageByChatID(chatID, cursor, limit)
   779  	if err != nil {
   780  		return nil, err
   781  	}
   782  
   783  	return &ApplicationPinnedMessagesResponse{
   784  		PinnedMessages: pinnedMessages,
   785  		Cursor:         cursor,
   786  	}, nil
   787  }
   788  
   789  func (api *PublicAPI) StatusUpdates() (*ApplicationStatusUpdatesResponse, error) {
   790  	statusUpdates, err := api.service.messenger.StatusUpdates()
   791  	if err != nil {
   792  		return nil, err
   793  	}
   794  
   795  	return &ApplicationStatusUpdatesResponse{
   796  		StatusUpdates: statusUpdates,
   797  	}, nil
   798  }
   799  
   800  func (api *PublicAPI) UpsertSwitcherCard(request *requests.UpsertSwitcherCard) error {
   801  	return api.service.messenger.UpsertSwitcherCard(request)
   802  }
   803  
   804  func (api *PublicAPI) DeleteSwitcherCard(id string) error {
   805  	return api.service.messenger.DeleteSwitcherCard(id)
   806  }
   807  
   808  func (api *PublicAPI) SwitcherCards() (*ApplicationSwitcherCardsResponse, error) {
   809  	switcherCards, err := api.service.messenger.SwitcherCards()
   810  	if err != nil {
   811  		return nil, err
   812  	}
   813  
   814  	return &ApplicationSwitcherCardsResponse{
   815  		SwitcherCards: switcherCards,
   816  	}, nil
   817  }
   818  
   819  func (api *PublicAPI) StartMessenger() (*protocol.MessengerResponse, error) {
   820  	return api.service.StartMessenger()
   821  }
   822  
   823  func (api *PublicAPI) SetUserStatus(ctx context.Context, status int, customText string) error {
   824  	return api.service.messenger.SetUserStatus(ctx, status, customText)
   825  }
   826  
   827  func (api *PublicAPI) DeleteMessage(id string) error {
   828  	return api.service.messenger.DeleteMessage(id)
   829  }
   830  
   831  func (api *PublicAPI) DeleteMessagesByChatID(id string) error {
   832  	return api.service.messenger.DeleteMessagesByChatID(id)
   833  }
   834  
   835  // Deprecated: Use MarkMessagesRead instead
   836  func (api *PublicAPI) MarkMessagesSeen(chatID string, ids []string) (*MarkMessageSeenResponse, error) {
   837  	count, withMentions, notifications, err := api.service.messenger.MarkMessagesSeen(chatID, ids)
   838  	if err != nil {
   839  		return nil, err
   840  	}
   841  
   842  	response := &MarkMessageSeenResponse{
   843  		Count:                       count,
   844  		CountWithMentions:           withMentions,
   845  		ActivityCenterNotifications: notifications,
   846  	}
   847  	return response, nil
   848  }
   849  
   850  func (api *PublicAPI) MarkMessagesRead(chatID string, ids []string) (*protocol.MessengerResponse, error) {
   851  	return api.service.messenger.MarkMessagesRead(chatID, ids)
   852  }
   853  
   854  func (api *PublicAPI) MarkMessageAsUnread(chatID string, messageID string) (*protocol.MessengerResponse, error) {
   855  	return api.service.messenger.MarkMessageAsUnread(chatID, messageID)
   856  }
   857  
   858  func (api *PublicAPI) MarkAllRead(ctx context.Context, chatID string) (*protocol.MessengerResponse, error) {
   859  	return api.service.messenger.MarkAllRead(ctx, chatID)
   860  }
   861  
   862  func (api *PublicAPI) DismissActivityCenterNotificationsByCommunity(ctx context.Context, request *requests.DismissCommunityNotifications) error {
   863  	return api.service.messenger.DismissActivityCenterNotificationsByCommunity(ctx, request)
   864  }
   865  
   866  func (api *PublicAPI) MarkAllReadInCommunity(ctx context.Context, communityID string) (*protocol.MessengerResponse, error) {
   867  	return api.service.messenger.MarkAllReadInCommunity(ctx, communityID)
   868  }
   869  
   870  func (api *PublicAPI) SendContactRequest(ctx context.Context, request *requests.SendContactRequest) (*protocol.MessengerResponse, error) {
   871  	return api.service.messenger.SendContactRequest(ctx, request)
   872  }
   873  
   874  func (api *PublicAPI) AddContact(ctx context.Context, request *requests.AddContact) (*protocol.MessengerResponse, error) {
   875  	return api.service.messenger.AddContact(ctx, request)
   876  }
   877  
   878  func (api *PublicAPI) AcceptContactRequest(ctx context.Context, request *requests.AcceptContactRequest) (*protocol.MessengerResponse, error) {
   879  	return api.service.messenger.AcceptContactRequest(ctx, request)
   880  }
   881  
   882  func (api *PublicAPI) DeclineContactRequest(ctx context.Context, request *requests.DeclineContactRequest) (*protocol.MessengerResponse, error) {
   883  	return api.service.messenger.DeclineContactRequest(ctx, request)
   884  }
   885  
   886  func (api *PublicAPI) AcceptLatestContactRequestForContact(ctx context.Context, request *requests.AcceptLatestContactRequestForContact) (*protocol.MessengerResponse, error) {
   887  	return api.service.messenger.AcceptLatestContactRequestForContact(ctx, request)
   888  }
   889  
   890  func (api *PublicAPI) DismissLatestContactRequestForContact(ctx context.Context, request *requests.DismissLatestContactRequestForContact) (*protocol.MessengerResponse, error) {
   891  	return api.service.messenger.DismissLatestContactRequestForContact(ctx, request)
   892  }
   893  
   894  func (api *PublicAPI) GetLatestContactRequestForContact(ctx context.Context, contactID string) (*protocol.MessengerResponse, error) {
   895  	return api.service.messenger.GetLatestContactRequestForContact(contactID)
   896  }
   897  
   898  func (api *PublicAPI) RetractContactRequest(ctx context.Context, request *requests.RetractContactRequest) (*protocol.MessengerResponse, error) {
   899  	return api.service.messenger.RetractContactRequest(request)
   900  }
   901  
   902  func (api *PublicAPI) RemoveContact(ctx context.Context, pubKey string) (*protocol.MessengerResponse, error) {
   903  	return api.service.messenger.RemoveContact(ctx, pubKey)
   904  }
   905  
   906  func (api *PublicAPI) SetContactLocalNickname(ctx context.Context, request *requests.SetContactLocalNickname) (*protocol.MessengerResponse, error) {
   907  	return api.service.messenger.SetContactLocalNickname(request)
   908  }
   909  
   910  func (api *PublicAPI) ClearHistory(request *requests.ClearHistory) (*protocol.MessengerResponse, error) {
   911  	return api.service.messenger.ClearHistory(request)
   912  }
   913  
   914  func (api *PublicAPI) DeactivateChat(request *requests.DeactivateChat) (*protocol.MessengerResponse, error) {
   915  	return api.service.messenger.DeactivateChat(request)
   916  }
   917  
   918  func (api *PublicAPI) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) error {
   919  	return api.service.messenger.UpdateMessageOutgoingStatus(id, newOutgoingStatus)
   920  }
   921  
   922  func (api *PublicAPI) SendChatMessage(ctx context.Context, message *common.Message) (*protocol.MessengerResponse, error) {
   923  	return api.service.messenger.SendChatMessage(ctx, message)
   924  }
   925  
   926  func (api *PublicAPI) ReSendChatMessage(ctx context.Context, messageID string) error {
   927  	return api.service.messenger.ReSendChatMessage(ctx, messageID)
   928  }
   929  
   930  func (api *PublicAPI) SendChatMessages(ctx context.Context, messages []*common.Message) (*protocol.MessengerResponse, error) {
   931  	return api.service.messenger.SendChatMessages(ctx, messages)
   932  }
   933  
   934  func (api *PublicAPI) SendOneToOneMessage(request *requests.SendOneToOneMessage) (*protocol.MessengerResponse, error) {
   935  	return api.service.messenger.SendOneToOneMessage(request)
   936  }
   937  
   938  func (api *PublicAPI) SendGroupChatMessage(request *requests.SendGroupChatMessage) (*protocol.MessengerResponse, error) {
   939  	return api.service.messenger.SendGroupChatMessage(request)
   940  }
   941  
   942  func (api *PublicAPI) EditMessage(ctx context.Context, request *requests.EditMessage) (*protocol.MessengerResponse, error) {
   943  	return api.service.messenger.EditMessage(ctx, request)
   944  }
   945  
   946  func (api *PublicAPI) DeleteMessageAndSend(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
   947  	return api.service.messenger.DeleteMessageAndSend(ctx, messageID)
   948  }
   949  
   950  func (api *PublicAPI) DeleteMessageForMeAndSync(ctx context.Context, chatID string, messageID string) (*protocol.MessengerResponse, error) {
   951  	return api.service.messenger.DeleteMessageForMeAndSync(ctx, chatID, messageID)
   952  }
   953  
   954  func (api *PublicAPI) SendPinMessage(ctx context.Context, message *common.PinMessage) (*protocol.MessengerResponse, error) {
   955  	return api.service.messenger.SendPinMessage(ctx, message)
   956  }
   957  
   958  func (api *PublicAPI) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*protocol.MessengerResponse, error) {
   959  	return api.service.messenger.RequestTransaction(ctx, chatID, value, contract, address)
   960  }
   961  
   962  func (api *PublicAPI) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*protocol.MessengerResponse, error) {
   963  	return api.service.messenger.RequestAddressForTransaction(ctx, chatID, from, value, contract)
   964  }
   965  
   966  func (api *PublicAPI) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
   967  	return api.service.messenger.DeclineRequestAddressForTransaction(ctx, messageID)
   968  }
   969  
   970  func (api *PublicAPI) DeclineRequestTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
   971  	return api.service.messenger.DeclineRequestTransaction(ctx, messageID)
   972  }
   973  
   974  func (api *PublicAPI) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*protocol.MessengerResponse, error) {
   975  	return api.service.messenger.AcceptRequestAddressForTransaction(ctx, messageID, address)
   976  }
   977  
   978  func (api *PublicAPI) SendTransaction(ctx context.Context, chatID, value, contract, transactionHash string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
   979  	return api.service.messenger.SendTransaction(ctx, chatID, value, contract, transactionHash, signature)
   980  }
   981  
   982  func (api *PublicAPI) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
   983  	return api.service.messenger.AcceptRequestTransaction(ctx, transactionHash, messageID, signature)
   984  }
   985  
   986  func (api *PublicAPI) SendContactUpdates(ctx context.Context, name, picture string, customizationColor multiaccountscommon.CustomizationColor) error {
   987  	return api.service.messenger.SendContactUpdates(ctx, name, picture, customizationColor)
   988  }
   989  
   990  func (api *PublicAPI) SendContactUpdate(ctx context.Context, contactID, name, picture string, customizationColor multiaccountscommon.CustomizationColor) (*protocol.MessengerResponse, error) {
   991  	return api.service.messenger.SendContactUpdate(ctx, contactID, name, picture, customizationColor)
   992  }
   993  
   994  func (api *PublicAPI) SetDisplayName(ctx context.Context, displayName string) error {
   995  	return api.service.messenger.SetDisplayName(displayName)
   996  }
   997  
   998  func (api *PublicAPI) SetBio(ctx context.Context, bio string) error {
   999  	return api.service.messenger.SetBio(bio)
  1000  }
  1001  
  1002  func (api *PublicAPI) MarkAsTrusted(ctx context.Context, contactID string) error {
  1003  	return api.service.messenger.MarkAsTrusted(ctx, contactID)
  1004  }
  1005  
  1006  func (api *PublicAPI) MarkAsUntrustworthy(ctx context.Context, contactID string) error {
  1007  	return api.service.messenger.MarkAsUntrustworthy(ctx, contactID)
  1008  }
  1009  
  1010  func (api *PublicAPI) RemoveTrustStatus(ctx context.Context, contactID string) error {
  1011  	return api.service.messenger.RemoveTrustStatus(ctx, contactID)
  1012  }
  1013  
  1014  func (api *PublicAPI) RemoveTrustVerificationStatus(ctx context.Context, contactID string) (*protocol.MessengerResponse, error) {
  1015  	return api.service.messenger.RemoveTrustVerificationStatus(ctx, contactID)
  1016  }
  1017  
  1018  func (api *PublicAPI) GetTrustStatus(ctx context.Context, contactID string) (verification.TrustStatus, error) {
  1019  	return api.service.messenger.GetTrustStatus(contactID)
  1020  }
  1021  
  1022  func (api *PublicAPI) GetLatestVerificationRequestFrom(ctx context.Context, contactID string) (*verification.Request, error) {
  1023  	return api.service.messenger.GetLatestVerificationRequestFrom(contactID)
  1024  }
  1025  
  1026  func (api *PublicAPI) SendContactVerificationRequest(ctx context.Context, contactID string, challenge string) (*protocol.MessengerResponse, error) {
  1027  	return api.service.messenger.SendContactVerificationRequest(ctx, contactID, challenge)
  1028  }
  1029  
  1030  func (api *PublicAPI) GetReceivedVerificationRequests(ctx context.Context) ([]*verification.Request, error) {
  1031  	return api.service.messenger.GetReceivedVerificationRequests(ctx)
  1032  }
  1033  
  1034  func (api *PublicAPI) GetVerificationRequestSentTo(ctx context.Context, contactID string) (*verification.Request, error) {
  1035  	return api.service.messenger.GetVerificationRequestSentTo(ctx, contactID)
  1036  }
  1037  
  1038  func (api *PublicAPI) CancelVerificationRequest(ctx context.Context, id string) (*protocol.MessengerResponse, error) {
  1039  	return api.service.messenger.CancelVerificationRequest(ctx, id)
  1040  }
  1041  
  1042  func (api *PublicAPI) AcceptContactVerificationRequest(ctx context.Context, id string, response string) (*protocol.MessengerResponse, error) {
  1043  	return api.service.messenger.AcceptContactVerificationRequest(ctx, id, response)
  1044  }
  1045  
  1046  func (api *PublicAPI) DeclineContactVerificationRequest(ctx context.Context, id string) (*protocol.MessengerResponse, error) {
  1047  	return api.service.messenger.DeclineContactVerificationRequest(ctx, id)
  1048  }
  1049  
  1050  func (api *PublicAPI) VerifiedTrusted(ctx context.Context, request *requests.VerifiedTrusted) (*protocol.MessengerResponse, error) {
  1051  	return api.service.messenger.VerifiedTrusted(ctx, request)
  1052  }
  1053  
  1054  func (api *PublicAPI) VerifiedUntrustworthy(ctx context.Context, request *requests.VerifiedUntrustworthy) (*protocol.MessengerResponse, error) {
  1055  	return api.service.messenger.VerifiedUntrustworthy(ctx, request)
  1056  }
  1057  
  1058  func (api *PublicAPI) SendPairInstallation(ctx context.Context) (*protocol.MessengerResponse, error) {
  1059  	return api.service.messenger.SendPairInstallation(ctx, nil)
  1060  }
  1061  
  1062  func (api *PublicAPI) SyncDevices(ctx context.Context, name, picture string) error {
  1063  	return api.service.messenger.SyncDevices(ctx, name, picture, nil)
  1064  }
  1065  
  1066  func (api *PublicAPI) EnableAndSyncInstallation(request *requests.EnableAndSyncInstallation) error {
  1067  	return api.service.messenger.EnableAndSyncInstallation(request)
  1068  }
  1069  
  1070  func (api *PublicAPI) EnableInstallationAndPair(request *requests.EnableInstallationAndPair) (*protocol.MessengerResponse, error) {
  1071  	return api.service.messenger.EnableInstallationAndPair(request)
  1072  }
  1073  
  1074  func (api *PublicAPI) AddBookmark(ctx context.Context, bookmark browsers.Bookmark) error {
  1075  	return api.service.messenger.AddBookmark(ctx, bookmark)
  1076  }
  1077  
  1078  func (api *PublicAPI) AddBrowser(ctx context.Context, browser browsers.Browser) error {
  1079  	return api.service.messenger.AddBrowser(ctx, browser)
  1080  }
  1081  
  1082  func (api *PublicAPI) GetBrowsers(ctx context.Context) (browsers []*browsers.Browser, err error) {
  1083  	return api.service.messenger.GetBrowsers(ctx)
  1084  }
  1085  
  1086  func (api *PublicAPI) DeleteBrowser(ctx context.Context, id string) error {
  1087  	return api.service.messenger.DeleteBrowser(ctx, id)
  1088  }
  1089  
  1090  func (api *PublicAPI) RemoveBookmark(ctx context.Context, url string) error {
  1091  	return api.service.messenger.RemoveBookmark(ctx, url)
  1092  }
  1093  
  1094  func (api *PublicAPI) UpdateBookmark(ctx context.Context, oldURL string, bookmark browsers.Bookmark) error {
  1095  	return api.service.messenger.UpdateBookmark(ctx, oldURL, bookmark)
  1096  }
  1097  
  1098  func (api *PublicAPI) SignMessageWithChatKey(ctx context.Context, message string) (types.HexBytes, error) {
  1099  	return api.service.messenger.SignMessage(message)
  1100  }
  1101  
  1102  func (api *PublicAPI) CreateCommunityTokenDeploymentSignature(ctx context.Context, chainID uint64, addressFrom string, communityID string) (types.HexBytes, error) {
  1103  	return api.service.messenger.CreateCommunityTokenDeploymentSignature(ctx, chainID, addressFrom, communityID)
  1104  }
  1105  
  1106  // wallet connect session apis
  1107  func (api *PublicAPI) AddWalletConnectSession(ctx context.Context, request *requests.AddWalletConnectSession) error {
  1108  	return api.service.messenger.AddWalletConnectSession(request)
  1109  }
  1110  
  1111  func (api *PublicAPI) GetWalletConnectSession(ctx context.Context) ([]protocol.WalletConnectSession, error) {
  1112  	return api.service.messenger.GetWalletConnectSession()
  1113  }
  1114  
  1115  func (api *PublicAPI) DestroyWalletConnectSession(ctx context.Context, PeerID string) error {
  1116  	return api.service.messenger.DestroyWalletConnectSession(PeerID)
  1117  }
  1118  
  1119  // Saved Addresses APIs
  1120  func (api *PublicAPI) UpsertSavedAddress(ctx context.Context, sa wallet.SavedAddress) error {
  1121  	return api.service.messenger.UpsertSavedAddress(ctx, sa)
  1122  }
  1123  
  1124  func (api *PublicAPI) DeleteSavedAddress(ctx context.Context, address ethcommon.Address, isTest bool) error {
  1125  	return api.service.messenger.DeleteSavedAddress(ctx, address, isTest)
  1126  }
  1127  
  1128  func (api *PublicAPI) GetSavedAddresses(ctx context.Context) ([]*wallet.SavedAddress, error) {
  1129  	return api.service.messenger.GetSavedAddresses(ctx)
  1130  }
  1131  
  1132  func (api *PublicAPI) GetSavedAddressesPerMode(ctx context.Context, testnetMode bool) ([]*wallet.SavedAddress, error) {
  1133  	return api.service.messenger.GetSavedAddressesPerMode(testnetMode)
  1134  }
  1135  
  1136  // RemainingCapacityForSavedAddresses returns the number of saved addresses that can be added
  1137  func (api *PublicAPI) RemainingCapacityForSavedAddresses(ctx context.Context, testnetMode bool) (int, error) {
  1138  	return api.service.messenger.RemainingCapacityForSavedAddresses(testnetMode)
  1139  }
  1140  
  1141  // PushNotifications server endpoints
  1142  func (api *PublicAPI) StartPushNotificationsServer() error {
  1143  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsServerEnabled, true)
  1144  	if err != nil {
  1145  		return err
  1146  	}
  1147  
  1148  	return api.service.messenger.StartPushNotificationsServer()
  1149  }
  1150  
  1151  func (api *PublicAPI) StopPushNotificationsServer() error {
  1152  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsServerEnabled, false)
  1153  	if err != nil {
  1154  		return err
  1155  	}
  1156  
  1157  	return api.service.messenger.StopPushNotificationsServer()
  1158  }
  1159  
  1160  // PushNotification client endpoints
  1161  
  1162  func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType) error {
  1163  	return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken, apnTopic, tokenType)
  1164  }
  1165  
  1166  func (api *PublicAPI) UnregisterFromPushNotifications(ctx context.Context) error {
  1167  	return api.service.messenger.UnregisterFromPushNotifications(ctx)
  1168  }
  1169  
  1170  func (api *PublicAPI) DisableSendingNotifications(ctx context.Context) error {
  1171  	err := api.service.accountsDB.SaveSettingField(settings.SendPushNotifications, false)
  1172  	if err != nil {
  1173  		return err
  1174  	}
  1175  
  1176  	return api.service.messenger.DisableSendingPushNotifications()
  1177  }
  1178  
  1179  func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
  1180  	err := api.service.accountsDB.SaveSettingField(settings.SendPushNotifications, true)
  1181  	if err != nil {
  1182  		return err
  1183  	}
  1184  	return api.service.messenger.EnableSendingPushNotifications()
  1185  }
  1186  
  1187  func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Context) error {
  1188  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsFromContactsOnly, true)
  1189  	if err != nil {
  1190  		return err
  1191  	}
  1192  	return api.service.messenger.EnablePushNotificationsFromContactsOnly()
  1193  }
  1194  
  1195  func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Context) error {
  1196  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsFromContactsOnly, false)
  1197  	if err != nil {
  1198  		return err
  1199  	}
  1200  	return api.service.messenger.DisablePushNotificationsFromContactsOnly()
  1201  }
  1202  
  1203  func (api *PublicAPI) EnablePushNotificationsBlockMentions(ctx context.Context) error {
  1204  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsBlockMentions, true)
  1205  	if err != nil {
  1206  		return err
  1207  	}
  1208  	return api.service.messenger.EnablePushNotificationsBlockMentions()
  1209  }
  1210  
  1211  func (api *PublicAPI) DisablePushNotificationsBlockMentions(ctx context.Context) error {
  1212  	err := api.service.accountsDB.SaveSettingField(settings.PushNotificationsBlockMentions, false)
  1213  	if err != nil {
  1214  		return err
  1215  	}
  1216  	return api.service.messenger.DisablePushNotificationsBlockMentions()
  1217  }
  1218  
  1219  func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
  1220  	publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
  1221  	if err != nil {
  1222  		return err
  1223  	}
  1224  
  1225  	// this is coming from a user, so it has to be a custom server
  1226  	return api.service.messenger.AddPushNotificationsServer(ctx, publicKey, pushnotificationclient.ServerTypeCustom)
  1227  }
  1228  
  1229  func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
  1230  	publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
  1231  	if err != nil {
  1232  		return err
  1233  	}
  1234  
  1235  	return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
  1236  }
  1237  
  1238  func (api *PublicAPI) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
  1239  	return api.service.messenger.GetPushNotificationsServers()
  1240  }
  1241  
  1242  func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) {
  1243  	return api.service.messenger.RegisteredForPushNotifications()
  1244  }
  1245  
  1246  // Emoji
  1247  
  1248  func (api *PublicAPI) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID protobuf.EmojiReaction_Type) (*protocol.MessengerResponse, error) {
  1249  	return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, emojiID)
  1250  }
  1251  
  1252  func (api *PublicAPI) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*protocol.MessengerResponse, error) {
  1253  	return api.service.messenger.SendEmojiReactionRetraction(ctx, emojiReactionID)
  1254  }
  1255  
  1256  func (api *PublicAPI) EmojiReactionsByChatID(chatID string, cursor string, limit int) ([]*protocol.EmojiReaction, error) {
  1257  	return api.service.messenger.EmojiReactionsByChatID(chatID, cursor, limit)
  1258  }
  1259  
  1260  func (api *PublicAPI) EmojiReactionsByChatIDMessageID(chatID string, messageID string) ([]*protocol.EmojiReaction, error) {
  1261  	return api.service.messenger.EmojiReactionsByChatIDMessageID(chatID, messageID)
  1262  }
  1263  
  1264  // GetTextURLsToUnfurl parses text and returns a deduplicated and (somewhat) normalized
  1265  // slice of URLs. The returned URLs can be used as cache keys by clients.
  1266  // For each URL there's a corresponding metadata which should be used as to plan the unfurling.
  1267  func (api *PublicAPI) GetTextURLsToUnfurl(text string) *protocol.URLsUnfurlPlan {
  1268  	return api.service.messenger.GetTextURLsToUnfurl(text)
  1269  }
  1270  
  1271  // Deprecated: GetTextURLs is deprecated in favor of more generic GetTextURLsToUnfurl.
  1272  //
  1273  // GetTextURLs parses text and returns a deduplicated and (somewhat) normalized
  1274  // slice of URLs. The returned URLs can be used as cache keys by clients.
  1275  func (api *PublicAPI) GetTextURLs(text string) []string {
  1276  	return api.service.messenger.GetURLs(text)
  1277  }
  1278  
  1279  // UnfurlURLs uses a best-effort approach to unfurl each URL. Failed URLs will
  1280  // be removed from the response.
  1281  //
  1282  // This endpoint expects the client to send URLs normalized by GetTextURLs.
  1283  func (api *PublicAPI) UnfurlURLs(urls []string) (protocol.UnfurlURLsResponse, error) {
  1284  	return api.service.messenger.UnfurlURLs(nil, urls)
  1285  }
  1286  
  1287  func (api *PublicAPI) EnsVerified(pk, ensName string) error {
  1288  	return api.service.messenger.ENSVerified(pk, ensName)
  1289  }
  1290  
  1291  // Deprecated: RequestCommunityInfoFromMailserver is deprecated in favor of
  1292  // configurable FetchCommunity.
  1293  func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) {
  1294  	request := &protocol.FetchCommunityRequest{
  1295  		CommunityKey:    communityID,
  1296  		Shard:           nil,
  1297  		TryDatabase:     true,
  1298  		WaitForResponse: true,
  1299  	}
  1300  	return api.FetchCommunity(request)
  1301  }
  1302  
  1303  // Deprecated: RequestCommunityInfoFromMailserverWithShard is deprecated in favor of
  1304  // configurable FetchCommunity.
  1305  func (api *PublicAPI) RequestCommunityInfoFromMailserverWithShard(communityID string, shard *shard.Shard) (*communities.Community, error) {
  1306  	request := &protocol.FetchCommunityRequest{
  1307  		CommunityKey:    communityID,
  1308  		Shard:           shard,
  1309  		TryDatabase:     true,
  1310  		WaitForResponse: true,
  1311  	}
  1312  	return api.FetchCommunity(request)
  1313  }
  1314  
  1315  // Deprecated: RequestCommunityInfoFromMailserverAsync is deprecated in favor of
  1316  // configurable FetchCommunity.
  1317  func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string) error {
  1318  	request := &protocol.FetchCommunityRequest{
  1319  		CommunityKey:    communityID,
  1320  		Shard:           nil,
  1321  		TryDatabase:     true,
  1322  		WaitForResponse: false,
  1323  	}
  1324  	_, err := api.FetchCommunity(request)
  1325  	return err
  1326  }
  1327  
  1328  // Deprecated: RequestCommunityInfoFromMailserverAsyncWithShard is deprecated in favor of
  1329  // configurable FetchCommunity.
  1330  func (api *PublicAPI) RequestCommunityInfoFromMailserverAsyncWithShard(communityID string, shard *shard.Shard) error {
  1331  	request := &protocol.FetchCommunityRequest{
  1332  		CommunityKey:    communityID,
  1333  		Shard:           shard,
  1334  		TryDatabase:     true,
  1335  		WaitForResponse: false,
  1336  	}
  1337  	_, err := api.FetchCommunity(request)
  1338  	return err
  1339  }
  1340  
  1341  func (api *PublicAPI) FetchCommunity(request *protocol.FetchCommunityRequest) (*communities.Community, error) {
  1342  	return api.service.messenger.FetchCommunity(request)
  1343  }
  1344  
  1345  func (api *PublicAPI) ActivityCenterNotifications(request protocol.ActivityCenterNotificationsRequest) (*protocol.ActivityCenterPaginationResponse, error) {
  1346  	return api.service.messenger.ActivityCenterNotifications(request)
  1347  }
  1348  
  1349  func (api *PublicAPI) ActivityCenterNotificationsCount(request protocol.ActivityCenterCountRequest) (*protocol.ActivityCenterCountResponse, error) {
  1350  	return api.service.messenger.ActivityCenterNotificationsCount(request)
  1351  }
  1352  
  1353  func (api *PublicAPI) HasUnseenActivityCenterNotifications() (bool, error) {
  1354  	return api.service.messenger.HasUnseenActivityCenterNotifications()
  1355  }
  1356  
  1357  func (api *PublicAPI) GetActivityCenterState() (*protocol.ActivityCenterState, error) {
  1358  	return api.service.messenger.GetActivityCenterState()
  1359  }
  1360  
  1361  func (api *PublicAPI) MarkAsSeenActivityCenterNotifications() (*protocol.MessengerResponse, error) {
  1362  	return api.service.messenger.MarkAsSeenActivityCenterNotifications()
  1363  }
  1364  
  1365  func (api *PublicAPI) MarkAllActivityCenterNotificationsRead(ctx context.Context) (*protocol.MessengerResponse, error) {
  1366  	return api.service.messenger.MarkAllActivityCenterNotificationsRead(ctx)
  1367  }
  1368  
  1369  func (api *PublicAPI) MarkActivityCenterNotificationsRead(ctx context.Context, ids []types.HexBytes) (*protocol.MessengerResponse, error) {
  1370  	return api.service.messenger.MarkActivityCenterNotificationsRead(ctx, ids, 0, true)
  1371  }
  1372  
  1373  func (api *PublicAPI) MarkActivityCenterNotificationsUnread(ctx context.Context, ids []types.HexBytes) (*protocol.MessengerResponse, error) {
  1374  	m := api.service.messenger
  1375  	updatedAt := m.GetCurrentTimeInMillis()
  1376  	return m.MarkActivityCenterNotificationsUnread(ctx, ids, updatedAt, true)
  1377  }
  1378  
  1379  func (api *PublicAPI) AcceptActivityCenterNotifications(ctx context.Context, ids []types.HexBytes) (*protocol.MessengerResponse, error) {
  1380  	m := api.service.messenger
  1381  	updatedAt := m.GetCurrentTimeInMillis()
  1382  	return api.service.messenger.AcceptActivityCenterNotifications(ctx, ids, updatedAt, true)
  1383  }
  1384  
  1385  func (api *PublicAPI) DismissActivityCenterNotifications(ctx context.Context, ids []types.HexBytes) error {
  1386  	_, err := api.service.messenger.DismissActivityCenterNotifications(ctx, ids, 0, true)
  1387  	return err
  1388  }
  1389  
  1390  func (api *PublicAPI) DeleteActivityCenterNotifications(ctx context.Context, ids []types.HexBytes) error {
  1391  	m := api.service.messenger
  1392  	updatedAt := m.GetCurrentTimeInMillis()
  1393  	_, err := m.MarkActivityCenterNotificationsDeleted(ctx, ids, updatedAt, true)
  1394  	return err
  1395  }
  1396  
  1397  func (api *PublicAPI) RequestAllHistoricMessages(forceFetchingBackup bool) (*protocol.MessengerResponse, error) {
  1398  	return api.service.messenger.RequestAllHistoricMessages(forceFetchingBackup, false)
  1399  }
  1400  
  1401  func (api *PublicAPI) RequestAllHistoricMessagesWithRetries(forceFetchingBackup bool) (*protocol.MessengerResponse, error) {
  1402  	return api.service.messenger.RequestAllHistoricMessages(forceFetchingBackup, true)
  1403  }
  1404  
  1405  func (api *PublicAPI) DisconnectActiveMailserver() {
  1406  	api.service.messenger.DisconnectActiveMailserver()
  1407  }
  1408  
  1409  // Echo is a method for testing purposes.
  1410  func (api *PublicAPI) Echo(ctx context.Context, message string) (string, error) {
  1411  	return message, nil
  1412  }
  1413  
  1414  func (api *PublicAPI) FillGaps(chatID string, messageIDs []string) error {
  1415  	return api.service.messenger.FillGaps(chatID, messageIDs)
  1416  }
  1417  
  1418  func (api *PublicAPI) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
  1419  	return api.service.messenger.SyncChatFromSyncedFrom(chatID)
  1420  }
  1421  
  1422  // BloomFilter returns the current bloom filter bytes
  1423  func (api *PublicAPI) BloomFilter() string {
  1424  	return hexutil.Encode(api.service.messenger.BloomFilter())
  1425  }
  1426  
  1427  func (api *PublicAPI) StartDiscV5() error {
  1428  	return api.service.messenger.StartDiscV5()
  1429  }
  1430  
  1431  func (api *PublicAPI) StopDiscV5() error {
  1432  	return api.service.messenger.StopDiscV5()
  1433  }
  1434  
  1435  func (api *PublicAPI) GetCommunitiesSettings() ([]communities.CommunitySettings, error) {
  1436  	return api.service.messenger.GetCommunitiesSettings()
  1437  }
  1438  
  1439  func (api *PublicAPI) EnableCommunityHistoryArchiveProtocol() error {
  1440  	return api.service.messenger.EnableCommunityHistoryArchiveProtocol()
  1441  }
  1442  
  1443  func (api *PublicAPI) DisableCommunityHistoryArchiveProtocol() error {
  1444  	return api.service.messenger.DisableCommunityHistoryArchiveProtocol()
  1445  }
  1446  
  1447  func (api *PublicAPI) SubscribeToPubsubTopic(topic string, optPublicKey string) error {
  1448  	var publicKey *ecdsa.PublicKey
  1449  	if optPublicKey != "" {
  1450  		keyBytes, err := hexutil.Decode(optPublicKey)
  1451  		if err != nil {
  1452  			return err
  1453  		}
  1454  
  1455  		publicKey, err = crypto.UnmarshalPubkey(keyBytes)
  1456  		if err != nil {
  1457  			return err
  1458  		}
  1459  	}
  1460  
  1461  	return api.service.messenger.SubscribeToPubsubTopic(topic, publicKey)
  1462  }
  1463  
  1464  func (api *PublicAPI) StorePubsubTopicKey(topic string, privKey string) error {
  1465  	keyBytes, err := hexutil.Decode(privKey)
  1466  	if err != nil {
  1467  		return err
  1468  	}
  1469  
  1470  	p, err := crypto.ToECDSA(keyBytes)
  1471  	if err != nil {
  1472  		return err
  1473  	}
  1474  
  1475  	return api.service.messenger.StorePubsubTopicKey(topic, p)
  1476  }
  1477  
  1478  func (api *PublicAPI) AddStorePeer(address string) (peer.ID, error) {
  1479  	maddr, err := multiaddr.NewMultiaddr(address)
  1480  	if err != nil {
  1481  		return "", err
  1482  	}
  1483  	return api.service.messenger.AddStorePeer(maddr)
  1484  }
  1485  
  1486  func (api *PublicAPI) AddRelayPeer(address string) (peer.ID, error) {
  1487  	maddr, err := multiaddr.NewMultiaddr(address)
  1488  	if err != nil {
  1489  		return "", err
  1490  	}
  1491  	return api.service.messenger.AddRelayPeer(maddr)
  1492  }
  1493  
  1494  func (api *PublicAPI) DialPeer(address string) error {
  1495  	maddr, err := multiaddr.NewMultiaddr(address)
  1496  	if err != nil {
  1497  		return err
  1498  	}
  1499  	return api.service.messenger.DialPeer(maddr)
  1500  }
  1501  
  1502  func (api *PublicAPI) DialPeerByID(peerID string) error {
  1503  	pID, err := peer.Decode(peerID)
  1504  	if err != nil {
  1505  		return err
  1506  	}
  1507  	return api.service.messenger.DialPeerByID(pID)
  1508  }
  1509  
  1510  func (api *PublicAPI) DropPeer(peerID string) error {
  1511  	pID, err := peer.Decode(peerID)
  1512  	if err != nil {
  1513  		return err
  1514  	}
  1515  	return api.service.messenger.DropPeer(pID)
  1516  }
  1517  
  1518  func (api *PublicAPI) Peers() types.PeerStats {
  1519  	return api.service.messenger.Peers()
  1520  }
  1521  
  1522  func (api *PublicAPI) RelayPeersByTopic(topic string) (*types.PeerList, error) {
  1523  	return api.service.messenger.RelayPeersByTopic(topic)
  1524  }
  1525  
  1526  func (api *PublicAPI) ListenAddresses() ([]multiaddr.Multiaddr, error) {
  1527  	return api.service.messenger.ListenAddresses()
  1528  }
  1529  
  1530  func (api *PublicAPI) Enr() (*enode.Node, error) {
  1531  	return api.service.messenger.ENR()
  1532  }
  1533  
  1534  func (api *PublicAPI) ChangeIdentityImageShowTo(showTo settings.ProfilePicturesShowToType) error {
  1535  	err := api.service.accountsDB.SaveSettingField(settings.ProfilePicturesShowTo, showTo)
  1536  	if err != nil {
  1537  		return err
  1538  	}
  1539  
  1540  	return api.service.messenger.PublishIdentityImage()
  1541  }
  1542  
  1543  func (api *PublicAPI) BackupData() (uint64, error) {
  1544  	return api.service.messenger.BackupData(context.Background())
  1545  }
  1546  
  1547  func (api *PublicAPI) ImageServerURL() string {
  1548  	return api.service.messenger.ImageServerURL()
  1549  }
  1550  
  1551  func (api *PublicAPI) ToggleUseMailservers(value bool) error {
  1552  	return api.service.messenger.ToggleUseMailservers(value)
  1553  }
  1554  
  1555  func (api *PublicAPI) TogglePeerSyncing(request *requests.TogglePeerSyncingRequest) error {
  1556  	return api.service.messenger.TogglePeerSyncing(request)
  1557  }
  1558  
  1559  func (api *PublicAPI) SetSyncingOnMobileNetwork(request *requests.SetSyncingOnMobileNetwork) error {
  1560  	return api.service.messenger.SetSyncingOnMobileNetwork(request)
  1561  }
  1562  
  1563  func (api *PublicAPI) SetPinnedMailservers(pinnedMailservers map[string]string) error {
  1564  	return api.service.messenger.SetPinnedMailservers(pinnedMailservers)
  1565  }
  1566  
  1567  func (api *PublicAPI) RequestExtractDiscordChannelsAndCategories(filesToImport []string) {
  1568  	api.service.messenger.RequestExtractDiscordChannelsAndCategories(filesToImport)
  1569  }
  1570  
  1571  func (api *PublicAPI) ExtractDiscordChannelsAndCategories(filesToImport []string) (*protocol.MessengerResponse, map[string]*discord.ImportError) {
  1572  	return api.service.messenger.ExtractDiscordChannelsAndCategories(filesToImport)
  1573  }
  1574  
  1575  func (api *PublicAPI) RequestImportDiscordChannel(request *requests.ImportDiscordChannel) {
  1576  	api.service.messenger.RequestImportDiscordChannel(request)
  1577  }
  1578  
  1579  func (api *PublicAPI) RequestImportDiscordCommunity(request *requests.ImportDiscordCommunity) {
  1580  	api.service.messenger.RequestImportDiscordCommunity(request)
  1581  }
  1582  
  1583  func (api *PublicAPI) RequestCancelDiscordCommunityImport(id string) {
  1584  	api.service.messenger.MarkDiscordCommunityImportAsCancelled(id)
  1585  }
  1586  
  1587  func (api *PublicAPI) RequestCancelDiscordChannelImport(discordChannelID string) {
  1588  	api.service.messenger.MarkDiscordChannelImportAsCancelled(discordChannelID)
  1589  }
  1590  
  1591  func (api *PublicAPI) BuildContact(request *requests.BuildContact) (*protocol.Contact, error) {
  1592  	return api.service.messenger.BuildContact(request)
  1593  }
  1594  
  1595  func (api *PublicAPI) GetCommunityTokens(communityID string) ([]*token.CommunityToken, error) {
  1596  	return api.service.messenger.GetCommunityTokens(communityID)
  1597  }
  1598  
  1599  // GetCommunityPermissionedBalances returns balances indexed by account address.
  1600  func (api *PublicAPI) GetCommunityPermissionedBalances(request *requests.GetPermissionedBalances) (map[ethcommon.Address][]communities.PermissionedBalance, error) {
  1601  	return api.service.messenger.GetCommunityPermissionedBalances(request)
  1602  }
  1603  
  1604  func (api *PublicAPI) GetAllCommunityTokens() ([]*token.CommunityToken, error) {
  1605  	return api.service.messenger.GetAllCommunityTokens()
  1606  }
  1607  
  1608  func (api *PublicAPI) SaveCommunityToken(token *token.CommunityToken, croppedImage *images.CroppedImage) (*token.CommunityToken, error) {
  1609  	return api.service.messenger.SaveCommunityToken(token, croppedImage)
  1610  }
  1611  
  1612  func (api *PublicAPI) AddCommunityToken(communityID string, chainID int, address string) error {
  1613  	return api.service.messenger.AddCommunityToken(communityID, chainID, address)
  1614  }
  1615  
  1616  func (api *PublicAPI) UpdateCommunityTokenState(chainID int, contractAddress string, deployState token.DeployState) error {
  1617  	return api.service.messenger.UpdateCommunityTokenState(chainID, contractAddress, deployState)
  1618  }
  1619  
  1620  func (api *PublicAPI) UpdateCommunityTokenAddress(chainID int, oldContractAddress string, newContractAddress string) error {
  1621  	return api.service.messenger.UpdateCommunityTokenAddress(chainID, oldContractAddress, newContractAddress)
  1622  }
  1623  
  1624  func (api *PublicAPI) UpdateCommunityTokenSupply(chainID int, contractAddress string, supply *bigint.BigInt) error {
  1625  	return api.service.messenger.UpdateCommunityTokenSupply(chainID, contractAddress, supply)
  1626  }
  1627  
  1628  func (api *PublicAPI) RemoveCommunityToken(chainID int, contractAddress string) error {
  1629  	return api.service.messenger.RemoveCommunityToken(chainID, contractAddress)
  1630  }
  1631  
  1632  func (api *PublicAPI) ToggleCollapsedCommunityCategory(request *requests.ToggleCollapsedCommunityCategory) error {
  1633  	return api.service.messenger.ToggleCollapsedCommunityCategory(request)
  1634  }
  1635  
  1636  func (api *PublicAPI) CollapsedCommunityCategories() ([]protocol.CollapsedCommunityCategory, error) {
  1637  	return api.service.messenger.CollapsedCommunityCategories()
  1638  }
  1639  
  1640  func (api *PublicAPI) CheckPermissionsToJoinCommunity(request *requests.CheckPermissionToJoinCommunity) (*communities.CheckPermissionToJoinResponse, error) {
  1641  	return api.service.messenger.CheckPermissionsToJoinCommunity(request)
  1642  }
  1643  
  1644  func (api *PublicAPI) CheckCommunityChannelPermissions(request *requests.CheckCommunityChannelPermissions) (*communities.CheckChannelPermissionsResponse, error) {
  1645  	return api.service.messenger.CheckCommunityChannelPermissions(request)
  1646  }
  1647  
  1648  func (api *PublicAPI) CheckAllCommunityChannelsPermissions(request *requests.CheckAllCommunityChannelsPermissions) (*communities.CheckAllChannelsPermissionsResponse, error) {
  1649  	return api.service.messenger.CheckAllCommunityChannelsPermissions(request)
  1650  }
  1651  
  1652  func (api *PublicAPI) CollectCommunityMetrics(request *requests.CommunityMetricsRequest) (*protocol.CommunityMetricsResponse, error) {
  1653  	return api.service.messenger.CollectCommunityMetrics(request)
  1654  }
  1655  
  1656  func (api *PublicAPI) ShareCommunityURLWithChatKey(communityID types.HexBytes) (string, error) {
  1657  	return api.service.messenger.ShareCommunityURLWithChatKey(communityID)
  1658  }
  1659  
  1660  func (api *PublicAPI) ShareCommunityURLWithData(communityID types.HexBytes) (string, error) {
  1661  	return api.service.messenger.ShareCommunityURLWithData(communityID)
  1662  }
  1663  
  1664  func (api *PublicAPI) ShareCommunityChannelURLWithChatKey(request *requests.CommunityChannelShareURL) (string, error) {
  1665  	return api.service.messenger.ShareCommunityChannelURLWithChatKey(request)
  1666  }
  1667  
  1668  func (api *PublicAPI) ShareCommunityChannelURLWithData(request *requests.CommunityChannelShareURL) (string, error) {
  1669  	return api.service.messenger.ShareCommunityChannelURLWithData(request)
  1670  }
  1671  
  1672  func (api *PublicAPI) ShareUserURLWithENS(pubKey string) (string, error) {
  1673  	return api.service.messenger.ShareUserURLWithENS(pubKey)
  1674  }
  1675  
  1676  func (api *PublicAPI) ShareUserURLWithChatKey(pubKey string) (string, error) {
  1677  	return api.service.messenger.ShareUserURLWithChatKey(pubKey)
  1678  }
  1679  
  1680  func (api *PublicAPI) ShareUserURLWithData(pubKey string) (string, error) {
  1681  	return api.service.messenger.ShareUserURLWithData(pubKey)
  1682  }
  1683  
  1684  func (api *PublicAPI) ParseSharedURL(url string) (*protocol.URLDataResponse, error) {
  1685  	return protocol.ParseSharedURL(url)
  1686  }
  1687  
  1688  func (api *PublicAPI) Messenger() *protocol.Messenger {
  1689  	return api.service.messenger
  1690  }
  1691  
  1692  // ChatMentionReplaceWithPublicKey checks if the text contains mentions and replace mention with user public key.
  1693  // e.g. abc @alice -> abc 0x123
  1694  func (api *PublicAPI) ChatMentionReplaceWithPublicKey(chatID, text string) (string, error) {
  1695  	return api.service.messenger.GetMentionsManager().ReplaceWithPublicKey(chatID, text)
  1696  }
  1697  
  1698  // ChatMentionOnChangeText
  1699  // chatID: chat id
  1700  // text: the full text user input in the chat input field
  1701  // as performance consideration, we don't need to call this function each time after user input a character,
  1702  // say user input "abc", we don't need to call this function 3 times, instead,
  1703  // we can call this function 2 times as following:
  1704  // 1. user input "a", call this function with text "a"
  1705  // 2. user input "c", call this function with text "abc"
  1706  // whatever, we should ensure ChatMentionOnChangeText know(invoked) the latest full text.
  1707  // ChatMentionOnChangeText will maintain state of fulltext and diff between previous/latest full text internally.
  1708  func (api *PublicAPI) ChatMentionOnChangeText(chatID, text string, callID uint64) (*protocol.ChatMentionContext, error) {
  1709  	return api.service.messenger.GetMentionsManager().OnChangeText(chatID, text, callID)
  1710  }
  1711  
  1712  // ChatMentionSelectMention select mention from mention suggestion list
  1713  func (api *PublicAPI) ChatMentionSelectMention(chatID, text, primaryName, publicKey string) (*protocol.ChatMentionContext, error) {
  1714  	return api.service.messenger.GetMentionsManager().SelectMention(chatID, text, primaryName, publicKey)
  1715  }
  1716  
  1717  func (api *PublicAPI) ChatMentionClearMentions(chatID string) {
  1718  	api.service.messenger.GetMentionsManager().ClearMentions(chatID)
  1719  }
  1720  
  1721  // ChatMentionToInputField checks if the text contains mentions and replace mention with readable username.
  1722  // generally, this function is invoked before user editing a sent message.
  1723  func (api *PublicAPI) ChatMentionToInputField(chatID, text string) (*protocol.ChatMentionContext, error) {
  1724  	return api.service.messenger.GetMentionsManager().ToInputField(chatID, text)
  1725  }
  1726  
  1727  func (api *PublicAPI) GetCheckChannelPermissionResponses(parent context.Context, communityID types.HexBytes) (*communities.CheckAllChannelsPermissionsResponse, error) {
  1728  	return api.service.messenger.GetCommunityCheckChannelPermissionResponses(communityID)
  1729  }
  1730  
  1731  // CreateClosedCommunity used only for test purposes
  1732  func (api *PublicAPI) CreateClosedCommunity() (*protocol.MessengerResponse, error) {
  1733  	return api.service.messenger.CreateClosedCommunity()
  1734  }
  1735  
  1736  // CreateOpenCommunity used only for test purposes
  1737  func (api *PublicAPI) CreateOpenCommunity() (*protocol.MessengerResponse, error) {
  1738  	return api.service.messenger.CreateOpenCommunity()
  1739  }
  1740  
  1741  // CreateTokenGatedCommunity used only for test purposes
  1742  func (api *PublicAPI) CreateTokenGatedCommunity() (*protocol.MessengerResponse, error) {
  1743  	return api.service.messenger.CreateTokenGatedCommunity()
  1744  }
  1745  
  1746  // Set profile showcase preference for current user
  1747  func (api *PublicAPI) SetProfileShowcasePreferences(preferences *identity.ProfileShowcasePreferences) error {
  1748  	return api.service.messenger.SetProfileShowcasePreferences(preferences, true)
  1749  }
  1750  
  1751  // Get all profile showcase preferences for current user
  1752  func (api *PublicAPI) GetProfileShowcasePreferences() (*identity.ProfileShowcasePreferences, error) {
  1753  	return api.service.messenger.GetProfileShowcasePreferences()
  1754  }
  1755  
  1756  // Get profile showcase for a contact
  1757  func (api *PublicAPI) GetProfileShowcaseForContact(contactID string, validate bool) (*identity.ProfileShowcase, error) {
  1758  	return api.service.messenger.GetProfileShowcaseForContact(contactID, validate)
  1759  }
  1760  
  1761  // Get profile showcase accounts by address
  1762  func (api *PublicAPI) GetProfileShowcaseAccountsByAddress(address string) ([]*identity.ProfileShowcaseAccount, error) {
  1763  	return api.service.messenger.GetProfileShowcaseAccountsByAddress(address)
  1764  }
  1765  
  1766  // Get profile showcase max social link entries count
  1767  func (api *PublicAPI) GetProfileShowcaseSocialLinksLimit() (int, error) {
  1768  	return api.service.messenger.GetProfileShowcaseSocialLinksLimit()
  1769  }
  1770  
  1771  // Get profile showcase max entries count (excluding social links)
  1772  func (api *PublicAPI) GetProfileShowcaseEntriesLimit() (int, error) {
  1773  	return api.service.messenger.GetProfileShowcaseEntriesLimit()
  1774  }
  1775  
  1776  // Returns response with AC notification when owner token is received
  1777  func (api *PublicAPI) RegisterOwnerTokenReceivedNotification(communityID string) (*protocol.MessengerResponse, error) {
  1778  	return api.service.messenger.CreateResponseWithACNotification(communityID, protocol.ActivityCenterNotificationTypeOwnerTokenReceived, false, "")
  1779  }
  1780  
  1781  // Returns response with AC notification when setting signer is successful
  1782  func (api *PublicAPI) RegisterReceivedOwnershipNotification(communityID string) (*protocol.MessengerResponse, error) {
  1783  	return api.service.messenger.CreateResponseWithACNotification(communityID, protocol.ActivityCenterNotificationTypeOwnershipReceived, false, "")
  1784  }
  1785  
  1786  // Returns response with AC notification when community token is received
  1787  func (api *PublicAPI) RegisterReceivedCommunityTokenNotification(communityID string, isFirst bool, tokenData string) (*protocol.MessengerResponse, error) {
  1788  	activityType := protocol.ActivityCenterNotificationTypeCommunityTokenReceived
  1789  	if isFirst {
  1790  		activityType = protocol.ActivityCenterNotificationTypeFirstCommunityTokenReceived
  1791  	}
  1792  	return api.service.messenger.CreateResponseWithACNotification(communityID, activityType, false, tokenData)
  1793  }
  1794  
  1795  // Returns response with AC notification when setting signer is failed
  1796  func (api *PublicAPI) RegisterSetSignerFailedNotification(communityID string) (*protocol.MessengerResponse, error) {
  1797  	return api.service.messenger.CreateResponseWithACNotification(communityID, protocol.ActivityCenterNotificationTypeSetSignerFailed, false, "")
  1798  }
  1799  
  1800  // Returns response with AC notification when setting signer is declined
  1801  func (api *PublicAPI) RegisterSetSignerDeclinedNotification(communityID string) (*protocol.MessengerResponse, error) {
  1802  	return api.service.messenger.CreateResponseWithACNotification(communityID, protocol.ActivityCenterNotificationTypeSetSignerDeclined, true, "")
  1803  }
  1804  
  1805  // Returns response with AC notification when ownership is lost
  1806  func (api *PublicAPI) RegisterLostOwnershipNotification(communityID string) (*protocol.MessengerResponse, error) {
  1807  	return api.service.messenger.CreateResponseWithACNotification(communityID, protocol.ActivityCenterNotificationTypeOwnershipLost, false, "")
  1808  }
  1809  
  1810  func (api *PublicAPI) PromoteSelfToControlMode(communityID string) error {
  1811  	_, err := api.service.messenger.PromoteSelfToControlNode([]byte(communityID))
  1812  	return err
  1813  }
  1814  
  1815  func (api *PublicAPI) FetchMessages(request *requests.FetchMessages) error {
  1816  	return api.service.messenger.FetchMessages(request)
  1817  }
  1818  
  1819  func (api *PublicAPI) SetLightClient(request *requests.SetLightClient) error {
  1820  	return api.service.messenger.SetLightClient(request)
  1821  }
  1822  
  1823  func (api *PublicAPI) SetStoreConfirmationForMessagesSent(request *requests.SetStoreConfirmationForMessagesSent) error {
  1824  	return api.service.messenger.SetStoreConfirmationForMessagesSent(request)
  1825  }
  1826  
  1827  func (api *PublicAPI) SetLogLevel(request *requests.SetLogLevel) error {
  1828  	return api.service.messenger.SetLogLevel(request)
  1829  }
  1830  
  1831  func (api *PublicAPI) SetMaxLogBackups(request *requests.SetMaxLogBackups) error {
  1832  	return api.service.messenger.SetMaxLogBackups(request)
  1833  }
  1834  
  1835  func (api *PublicAPI) SetCustomNodes(request *requests.SetCustomNodes) error {
  1836  	return api.service.messenger.SetCustomNodes(request)
  1837  }
  1838  
  1839  func (api *PublicAPI) SaveNewWakuNode(request *requests.SaveNewWakuNode) error {
  1840  	return api.service.messenger.SaveNewWakuNode(request)
  1841  }
  1842  
  1843  func (api *PublicAPI) SetCustomizationColor(ctx context.Context, request *requests.SetCustomizationColor) error {
  1844  	return api.service.messenger.SetCustomizationColor(ctx, request)
  1845  }
  1846  
  1847  func (api *PublicAPI) GetCommunityMemberAllMessages(request *requests.CommunityMemberMessages) ([]*common.Message, error) {
  1848  	return api.service.messenger.GetCommunityMemberAllMessages(request)
  1849  }
  1850  
  1851  // Delete a specific community member messages or all community member messages (based on provided parameters)
  1852  func (api *PublicAPI) DeleteCommunityMemberMessages(request *requests.DeleteCommunityMemberMessages) (*protocol.MessengerResponse, error) {
  1853  	return api.service.messenger.DeleteCommunityMemberMessages(request)
  1854  }
  1855  
  1856  // -----
  1857  // HELPER
  1858  // -----
  1859  
  1860  // MakeMessagesRequestPayload makes a specific payload for MailServer
  1861  // to request historic messages.
  1862  // DEPRECATED
  1863  func MakeMessagesRequestPayload(r MessagesRequest) ([]byte, error) {
  1864  	cursor, err := hex.DecodeString(r.Cursor)
  1865  	if err != nil {
  1866  		return nil, fmt.Errorf("invalid cursor: %v", err)
  1867  	}
  1868  
  1869  	if len(cursor) > 0 && len(cursor) != mailserver.CursorLength {
  1870  		return nil, fmt.Errorf("invalid cursor size: expected %d but got %d", mailserver.CursorLength, len(cursor))
  1871  	}
  1872  
  1873  	payload := mailserver.MessagesRequestPayload{
  1874  		Lower: r.From,
  1875  		Upper: r.To,
  1876  		// We need to pass bloom filter for
  1877  		// backward compatibility
  1878  		Bloom:  createBloomFilter(r),
  1879  		Topics: topicsToByteArray(r.Topics),
  1880  		Limit:  r.Limit,
  1881  		Cursor: cursor,
  1882  		// Client must tell the MailServer if it supports batch responses.
  1883  		// This can be removed in the future.
  1884  		Batch: true,
  1885  	}
  1886  
  1887  	return rlp.EncodeToBytes(payload)
  1888  }
  1889  
  1890  func topicsToByteArray(topics []types.TopicType) [][]byte {
  1891  
  1892  	var response [][]byte
  1893  	for idx := range topics {
  1894  		response = append(response, topics[idx][:])
  1895  	}
  1896  
  1897  	return response
  1898  }
  1899  
  1900  func createBloomFilter(r MessagesRequest) []byte {
  1901  	if len(r.Topics) > 0 {
  1902  		return topicsToBloom(r.Topics...)
  1903  	}
  1904  	return types.TopicToBloom(r.Topic)
  1905  }
  1906  
  1907  func topicsToBloom(topics ...types.TopicType) []byte {
  1908  	i := new(big.Int)
  1909  	for _, topic := range topics {
  1910  		bloom := types.TopicToBloom(topic)
  1911  		i.Or(i, new(big.Int).SetBytes(bloom[:]))
  1912  	}
  1913  
  1914  	combined := make([]byte, types.BloomFilterSize)
  1915  	data := i.Bytes()
  1916  	copy(combined[types.BloomFilterSize-len(data):], data[:])
  1917  
  1918  	return combined
  1919  }
  1920  
  1921  // TopicsToBloom squashes all topics into a single bloom filter.
  1922  func TopicsToBloom(topics ...types.TopicType) []byte {
  1923  	return topicsToBloom(topics...)
  1924  }