2020-01-20 20:56:06 +00:00
|
|
|
package ext
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2020-02-17 14:38:59 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
|
2020-07-14 14:07:19 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/mailserver"
|
|
|
|
"github.com/status-im/status-go/protocol"
|
2020-09-01 13:27:01 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
2020-07-27 12:27:48 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2020-07-22 07:41:40 +00:00
|
|
|
"github.com/status-im/status-go/protocol/pushnotificationclient"
|
2021-01-11 10:32:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/protocol/transport"
|
2020-10-27 17:35:28 +00:00
|
|
|
"github.com/status-im/status-go/protocol/urls"
|
2020-01-20 20:56:06 +00:00
|
|
|
"github.com/status-im/status-go/services/ext/mailservers"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// defaultRequestTimeout is the default request timeout in seconds
|
|
|
|
defaultRequestTimeout = 10
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrInvalidMailServerPeer is returned when it fails to parse enode from params.
|
|
|
|
ErrInvalidMailServerPeer = errors.New("invalid mailServerPeer value")
|
|
|
|
// ErrInvalidSymKeyID is returned when it fails to get a symmetric key.
|
|
|
|
ErrInvalidSymKeyID = errors.New("invalid symKeyID value")
|
|
|
|
// ErrInvalidPublicKey is returned when public key can't be extracted
|
|
|
|
// from MailServer's nodeID.
|
|
|
|
ErrInvalidPublicKey = errors.New("can't extract public key")
|
|
|
|
// ErrPFSNotEnabled is returned when an endpoint PFS only is called but
|
|
|
|
// PFS is disabled
|
|
|
|
ErrPFSNotEnabled = errors.New("pfs not enabled")
|
|
|
|
)
|
|
|
|
|
|
|
|
// -----
|
|
|
|
// PAYLOADS
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// MessagesRequest is a RequestMessages() request payload.
|
|
|
|
type MessagesRequest struct {
|
|
|
|
// MailServerPeer is MailServer's enode address.
|
|
|
|
MailServerPeer string `json:"mailServerPeer"`
|
|
|
|
|
|
|
|
// From is a lower bound of time range (optional).
|
|
|
|
// Default is 24 hours back from now.
|
|
|
|
From uint32 `json:"from"`
|
|
|
|
|
|
|
|
// To is a upper bound of time range (optional).
|
|
|
|
// Default is now.
|
|
|
|
To uint32 `json:"to"`
|
|
|
|
|
|
|
|
// Limit determines the number of messages sent by the mail server
|
|
|
|
// for the current paginated request
|
|
|
|
Limit uint32 `json:"limit"`
|
|
|
|
|
|
|
|
// Cursor is used as starting point for paginated requests
|
|
|
|
Cursor string `json:"cursor"`
|
|
|
|
|
|
|
|
// Topic is a regular Whisper topic.
|
|
|
|
// DEPRECATED
|
|
|
|
Topic types.TopicType `json:"topic"`
|
|
|
|
|
|
|
|
// Topics is a list of Whisper topics.
|
|
|
|
Topics []types.TopicType `json:"topics"`
|
|
|
|
|
|
|
|
// SymKeyID is an ID of a symmetric key to authenticate to MailServer.
|
|
|
|
// It's derived from MailServer password.
|
|
|
|
SymKeyID string `json:"symKeyID"`
|
|
|
|
|
|
|
|
// Timeout is the time to live of the request specified in seconds.
|
|
|
|
// Default is 10 seconds
|
|
|
|
Timeout time.Duration `json:"timeout"`
|
|
|
|
|
|
|
|
// Force ensures that requests will bypass enforced delay.
|
|
|
|
Force bool `json:"force"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *MessagesRequest) SetDefaults(now time.Time) {
|
|
|
|
// set From and To defaults
|
|
|
|
if r.To == 0 {
|
|
|
|
r.To = uint32(now.UTC().Unix())
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.From == 0 {
|
|
|
|
oneDay := uint32(86400) // -24 hours
|
|
|
|
if r.To < oneDay {
|
|
|
|
r.From = 0
|
|
|
|
} else {
|
|
|
|
r.From = r.To - oneDay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Timeout == 0 {
|
|
|
|
r.Timeout = defaultRequestTimeout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessagesResponse is a response for requestMessages2 method.
|
|
|
|
type MessagesResponse struct {
|
|
|
|
// Cursor from the response can be used to retrieve more messages
|
|
|
|
// for the previous request.
|
|
|
|
Cursor string `json:"cursor"`
|
|
|
|
|
|
|
|
// Error indicates that something wrong happened when sending messages
|
|
|
|
// to the requester.
|
|
|
|
Error error `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
// PUBLIC API
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// PublicAPI extends whisper public API.
|
|
|
|
type PublicAPI struct {
|
|
|
|
service *Service
|
|
|
|
eventSub mailservers.EnvelopeEventSubscriber
|
|
|
|
log log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPublicAPI returns instance of the public API.
|
|
|
|
func NewPublicAPI(s *Service, eventSub mailservers.EnvelopeEventSubscriber) *PublicAPI {
|
|
|
|
return &PublicAPI{
|
|
|
|
service: s,
|
|
|
|
eventSub: eventSub,
|
|
|
|
log: log.New("package", "status-go/services/sshext.PublicAPI"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RetryConfig specifies configuration for retries with timeout and max amount of retries.
|
|
|
|
type RetryConfig struct {
|
|
|
|
BaseTimeout time.Duration
|
|
|
|
// StepTimeout defines duration increase per each retry.
|
|
|
|
StepTimeout time.Duration
|
|
|
|
MaxRetries int
|
|
|
|
}
|
|
|
|
|
|
|
|
func WaitForExpiredOrCompleted(requestID types.Hash, events chan types.EnvelopeEvent, timeout time.Duration) (*types.MailServerResponse, error) {
|
|
|
|
expired := fmt.Errorf("request %x expired", requestID)
|
|
|
|
after := time.NewTimer(timeout)
|
|
|
|
defer after.Stop()
|
|
|
|
for {
|
|
|
|
var ev types.EnvelopeEvent
|
|
|
|
select {
|
|
|
|
case ev = <-events:
|
|
|
|
case <-after.C:
|
|
|
|
return nil, expired
|
|
|
|
}
|
|
|
|
if ev.Hash != requestID {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
switch ev.Event {
|
|
|
|
case types.EventMailServerRequestCompleted:
|
|
|
|
data, ok := ev.Data.(*types.MailServerResponse)
|
|
|
|
if ok {
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
return nil, errors.New("invalid event data type")
|
|
|
|
case types.EventMailServerRequestExpired:
|
|
|
|
return nil, expired
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Author struct {
|
|
|
|
PublicKey types.HexBytes `json:"publicKey"`
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
Identicon string `json:"identicon"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Metadata struct {
|
|
|
|
DedupID []byte `json:"dedupId"`
|
|
|
|
EncryptionID types.HexBytes `json:"encryptionId"`
|
|
|
|
MessageID types.HexBytes `json:"messageId"`
|
|
|
|
Author Author `json:"author"`
|
|
|
|
}
|
|
|
|
|
2020-04-14 11:49:03 +00:00
|
|
|
func (api *PublicAPI) LeaveGroupChat(ctx Context, chatID string, remove bool) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.LeaveGroupChat(ctx, chatID, remove)
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) CreateGroupChatWithMembers(ctx Context, name string, members []string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateGroupChatWithMembers(ctx, name, members)
|
|
|
|
}
|
|
|
|
|
2020-08-07 13:49:37 +00:00
|
|
|
func (api *PublicAPI) CreateGroupChatFromInvitation(name string, chatID string, adminPK string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateGroupChatFromInvitation(name, chatID, adminPK)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) AddMembersToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AddMembersToGroupChat(ctx, chatID, members)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) RemoveMemberFromGroupChat(ctx Context, chatID string, member string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RemoveMemberFromGroupChat(ctx, chatID, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) AddAdminsToGroupChat(ctx Context, chatID string, members []string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AddAdminsToGroupChat(ctx, chatID, members)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) ConfirmJoiningGroup(ctx context.Context, chatID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ConfirmJoiningGroup(ctx, chatID)
|
|
|
|
}
|
|
|
|
|
2020-04-14 11:48:32 +00:00
|
|
|
func (api *PublicAPI) ChangeGroupChatName(ctx Context, chatID string, name string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ChangeGroupChatName(ctx, chatID, name)
|
|
|
|
}
|
|
|
|
|
2020-08-07 13:49:37 +00:00
|
|
|
func (api *PublicAPI) SendGroupChatInvitationRequest(ctx Context, chatID string, adminPK string, message string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendGroupChatInvitationRequest(ctx, chatID, adminPK, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) GetGroupChatInvitations() ([]*protocol.GroupChatInvitation, error) {
|
|
|
|
return api.service.messenger.GetGroupChatInvitations()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendGroupChatInvitationRejection(ctx Context, invitationRequestID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendGroupChatInvitationRejection(ctx, invitationRequestID)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) LoadFilters(parent context.Context, chats []*transport.Filter) ([]*transport.Filter, error) {
|
|
|
|
return api.service.messenger.LoadFilters(chats)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SaveChat(parent context.Context, chat *protocol.Chat) error {
|
|
|
|
return api.service.messenger.SaveChat(chat)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) CreateOneToOneChat(parent context.Context, request *requests.CreateOneToOneChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateOneToOneChat(request)
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:15:22 +00:00
|
|
|
func (api *PublicAPI) CreatePublicChat(parent context.Context, request *requests.CreatePublicChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreatePublicChat(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) CreateProfileChat(parent context.Context, request *requests.CreateProfileChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateProfileChat(request)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
|
|
|
|
return api.service.messenger.Chats()
|
|
|
|
}
|
|
|
|
|
2021-04-07 12:57:14 +00:00
|
|
|
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
|
|
|
|
return api.service.messenger.ActiveChats()
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) DeleteChat(parent context.Context, chatID string) error {
|
|
|
|
return api.service.messenger.DeleteChat(chatID)
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:46:14 +00:00
|
|
|
func (api *PublicAPI) MuteChat(parent context.Context, chatID string) error {
|
|
|
|
return api.service.messenger.MuteChat(chatID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) UnmuteChat(parent context.Context, chatID string) error {
|
|
|
|
return api.service.messenger.UnmuteChat(chatID)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) SaveContact(parent context.Context, contact *protocol.Contact) error {
|
|
|
|
return api.service.messenger.SaveContact(contact)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) BlockContact(parent context.Context, contact *protocol.Contact) ([]*protocol.Chat, error) {
|
|
|
|
api.log.Info("blocking contact", "contact", contact.ID)
|
|
|
|
return api.service.messenger.BlockContact(contact)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) Contacts(parent context.Context) []*protocol.Contact {
|
|
|
|
return api.service.messenger.Contacts()
|
|
|
|
}
|
|
|
|
|
2020-06-04 13:32:47 +00:00
|
|
|
func (api *PublicAPI) GetContactByID(parent context.Context, id string) *protocol.Contact {
|
|
|
|
return api.service.messenger.GetContactByID(id)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) RemoveFilters(parent context.Context, chats []*transport.Filter) error {
|
|
|
|
return api.service.messenger.RemoveFilters(chats)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnableInstallation enables an installation for multi-device sync.
|
|
|
|
func (api *PublicAPI) EnableInstallation(installationID string) error {
|
|
|
|
return api.service.messenger.EnableInstallation(installationID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisableInstallation disables an installation for multi-device sync.
|
|
|
|
func (api *PublicAPI) DisableInstallation(installationID string) error {
|
|
|
|
return api.service.messenger.DisableInstallation(installationID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOurInstallations returns all the installations available given an identity
|
|
|
|
func (api *PublicAPI) GetOurInstallations() []*multidevice.Installation {
|
|
|
|
return api.service.messenger.Installations()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetInstallationMetadata sets the metadata for our own installation
|
|
|
|
func (api *PublicAPI) SetInstallationMetadata(installationID string, data *multidevice.InstallationMetadata) error {
|
|
|
|
return api.service.messenger.SetInstallationMetadata(installationID, data)
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// Communities returns a list of communities that are stored
|
2020-11-18 09:16:51 +00:00
|
|
|
func (api *PublicAPI) Communities(parent context.Context) ([]*communities.Community, error) {
|
|
|
|
return api.service.messenger.Communities()
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// JoinedCommunities returns a list of communities that the user has joined
|
2020-11-18 09:16:51 +00:00
|
|
|
func (api *PublicAPI) JoinedCommunities(parent context.Context) ([]*communities.Community, error) {
|
|
|
|
return api.service.messenger.JoinedCommunities()
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// JoinCommunity joins a community with the given ID
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) JoinCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
|
2020-11-18 09:16:51 +00:00
|
|
|
return api.service.messenger.JoinCommunity(communityID)
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// LeaveCommunity leaves a commuity with the given ID
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) LeaveCommunity(parent context.Context, communityID types.HexBytes) (*protocol.MessengerResponse, error) {
|
2020-11-18 09:16:51 +00:00
|
|
|
return api.service.messenger.LeaveCommunity(communityID)
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// CreateCommunity creates a new community with the provided description
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) CreateCommunity(request *requests.CreateCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateCommunity(request)
|
2021-05-18 19:32:15 +00:00
|
|
|
}
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-05-18 19:32:15 +00:00
|
|
|
// EditCommunity edits an existing community with the provided description
|
|
|
|
func (api *PublicAPI) EditCommunity(request *requests.EditCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.EditCommunity(request)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// ExportCommunity exports the private key of the community with given ID
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) ExportCommunity(id types.HexBytes) (types.HexBytes, error) {
|
2020-11-18 09:16:51 +00:00
|
|
|
key, err := api.service.messenger.ExportCommunity(id)
|
|
|
|
if err != nil {
|
2021-01-11 10:32:51 +00:00
|
|
|
return nil, err
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
return crypto.FromECDSA(key), nil
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// ImportCommunity imports a community with the given private key in hex
|
2020-11-18 09:16:51 +00:00
|
|
|
func (api *PublicAPI) ImportCommunity(hexPrivateKey string) (*protocol.MessengerResponse, error) {
|
|
|
|
// Strip the 0x from the beginning
|
|
|
|
privateKey, err := crypto.HexToECDSA(hexPrivateKey[2:])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return api.service.messenger.ImportCommunity(privateKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-17 14:36:09 +00:00
|
|
|
// CreateCommunityChat creates a community chat in the given community
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) CreateCommunityChat(communityID types.HexBytes, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateCommunityChat(communityID, c)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 12:13:17 +00:00
|
|
|
// CreateCommunityChat creates a community chat in the given community
|
|
|
|
func (api *PublicAPI) EditCommunityChat(communityID types.HexBytes, chatID string, c *protobuf.CommunityChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.EditCommunityChat(communityID, chatID, c)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// InviteUsersToCommunity invites the users with pks to the community with ID
|
|
|
|
func (api *PublicAPI) InviteUsersToCommunity(request *requests.InviteUsersToCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.InviteUsersToCommunity(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ShareCommunity share the community with a set of users
|
|
|
|
func (api *PublicAPI) ShareCommunity(request *requests.ShareCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ShareCommunity(request)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 15:10:52 +00:00
|
|
|
// RemoveUserFromCommunity removes the user with pk from the community with ID
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) RemoveUserFromCommunity(communityID types.HexBytes, userPublicKey string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RemoveUserFromCommunity(communityID, userPublicKey)
|
|
|
|
}
|
|
|
|
|
2021-03-19 09:15:45 +00:00
|
|
|
// BanUserFromCommunity removes the user with pk from the community with ID
|
|
|
|
func (api *PublicAPI) BanUserFromCommunity(request *requests.BanUserFromCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.BanUserFromCommunity(request)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// MyPendingRequestsToJoin returns the pending requests for the logged in user
|
|
|
|
func (api *PublicAPI) MyPendingRequestsToJoin() ([]*communities.RequestToJoin, error) {
|
|
|
|
return api.service.messenger.MyPendingRequestsToJoin()
|
|
|
|
}
|
|
|
|
|
|
|
|
// PendingRequestsToJoinForCommunity returns the pending requests to join for a given community
|
|
|
|
func (api *PublicAPI) PendingRequestsToJoinForCommunity(id types.HexBytes) ([]*communities.RequestToJoin, error) {
|
|
|
|
return api.service.messenger.PendingRequestsToJoinForCommunity(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AcceptRequestToJoinCommunity accepts a pending request to join a community
|
|
|
|
func (api *PublicAPI) AcceptRequestToJoinCommunity(request *requests.AcceptRequestToJoinCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AcceptRequestToJoinCommunity(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeclineRequestToJoinCommunity accepts a pending request to join a community
|
|
|
|
func (api *PublicAPI) DeclineRequestToJoinCommunity(request *requests.DeclineRequestToJoinCommunity) error {
|
|
|
|
return api.service.messenger.DeclineRequestToJoinCommunity(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestToJoinCommunity requests to join a particular community
|
|
|
|
func (api *PublicAPI) RequestToJoinCommunity(request *requests.RequestToJoinCommunity) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RequestToJoinCommunity(request)
|
2020-12-21 15:10:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-23 13:34:17 +00:00
|
|
|
// CreateCommunityCategory creates a category within a particular community
|
|
|
|
func (api *PublicAPI) CreateCommunityCategory(request *requests.CreateCommunityCategory) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.CreateCommunityCategory(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReorderCommunityCategories is used to change the order of the categories of a community
|
|
|
|
func (api *PublicAPI) ReorderCommunityCategories(request *requests.ReorderCommunityCategories) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ReorderCommunityCategories(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReorderCommunityChat allows changing the order of the chat or switching its category
|
|
|
|
func (api *PublicAPI) ReorderCommunityChat(request *requests.ReorderCommunityChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ReorderCommunityChat(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EditCommunityCategory modifies a category within a particular community
|
|
|
|
func (api *PublicAPI) EditCommunityCategory(request *requests.EditCommunityCategory) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.EditCommunityCategory(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteCommunityCategory deletes a category within a particular community and removes this category from any chat that has it
|
|
|
|
func (api *PublicAPI) DeleteCommunityCategory(request *requests.DeleteCommunityCategory) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.DeleteCommunityCategory(request)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
type ApplicationMessagesResponse struct {
|
2020-09-01 13:27:01 +00:00
|
|
|
Messages []*common.Message `json:"messages"`
|
|
|
|
Cursor string `json:"cursor"`
|
2020-01-20 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 21:22:50 +00:00
|
|
|
type ApplicationPinnedMessagesResponse struct {
|
2021-06-08 15:23:32 +00:00
|
|
|
PinnedMessages []*common.PinnedMessage `json:"pinnedMessages"`
|
|
|
|
Cursor string `json:"cursor"`
|
2021-05-14 21:22:50 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) ChatMessages(chatID, cursor string, limit int) (*ApplicationMessagesResponse, error) {
|
|
|
|
messages, cursor, err := api.service.messenger.MessageByChatID(chatID, cursor, limit)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ApplicationMessagesResponse{
|
|
|
|
Messages: messages,
|
|
|
|
Cursor: cursor,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-14 21:22:50 +00:00
|
|
|
func (api *PublicAPI) ChatPinnedMessages(chatID, cursor string, limit int) (*ApplicationPinnedMessagesResponse, error) {
|
2021-06-08 15:23:32 +00:00
|
|
|
pinnedMessages, cursor, err := api.service.messenger.PinnedMessageByChatID(chatID, cursor, limit)
|
2021-05-14 21:22:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ApplicationPinnedMessagesResponse{
|
2021-06-08 15:23:32 +00:00
|
|
|
PinnedMessages: pinnedMessages,
|
|
|
|
Cursor: cursor,
|
2021-05-14 21:22:50 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-01-14 22:15:13 +00:00
|
|
|
func (api *PublicAPI) StartMessenger() (*protocol.MessengerResponse, error) {
|
2020-01-29 19:40:06 +00:00
|
|
|
return api.service.StartMessenger()
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) DeleteMessage(id string) error {
|
|
|
|
return api.service.messenger.DeleteMessage(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DeleteMessagesByChatID(id string) error {
|
|
|
|
return api.service.messenger.DeleteMessagesByChatID(id)
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:08:53 +00:00
|
|
|
func (api *PublicAPI) MarkMessagesSeen(chatID string, ids []string) (uint64, error) {
|
2020-01-20 20:56:06 +00:00
|
|
|
return api.service.messenger.MarkMessagesSeen(chatID, ids)
|
|
|
|
}
|
|
|
|
|
2020-02-26 12:31:48 +00:00
|
|
|
func (api *PublicAPI) MarkAllRead(chatID string) error {
|
|
|
|
return api.service.messenger.MarkAllRead(chatID)
|
|
|
|
}
|
|
|
|
|
2020-12-22 10:49:25 +00:00
|
|
|
func (api *PublicAPI) AddContact(ctx context.Context, pubKey string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AddContact(ctx, pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) RemoveContact(ctx context.Context, pubKey string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RemoveContact(ctx, pubKey)
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:15:22 +00:00
|
|
|
func (api *PublicAPI) ClearHistory(request *requests.ClearHistory) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.ClearHistory(request)
|
2020-12-22 10:49:25 +00:00
|
|
|
}
|
|
|
|
|
2021-03-25 15:15:22 +00:00
|
|
|
func (api *PublicAPI) DeactivateChat(request *requests.DeactivateChat) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.DeactivateChat(request)
|
2020-12-22 10:49:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) UpdateMessageOutgoingStatus(id, newOutgoingStatus string) error {
|
|
|
|
return api.service.messenger.UpdateMessageOutgoingStatus(id, newOutgoingStatus)
|
|
|
|
}
|
|
|
|
|
2020-09-01 13:27:01 +00:00
|
|
|
func (api *PublicAPI) SendChatMessage(ctx context.Context, message *common.Message) (*protocol.MessengerResponse, error) {
|
2020-01-20 20:56:06 +00:00
|
|
|
return api.service.messenger.SendChatMessage(ctx, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) ReSendChatMessage(ctx context.Context, messageID string) error {
|
|
|
|
return api.service.messenger.ReSendChatMessage(ctx, messageID)
|
|
|
|
}
|
|
|
|
|
2020-12-01 09:43:46 +00:00
|
|
|
func (api *PublicAPI) SendChatMessages(ctx context.Context, messages []*common.Message) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendChatMessages(ctx, messages)
|
|
|
|
}
|
|
|
|
|
2021-05-14 21:22:50 +00:00
|
|
|
func (api *PublicAPI) SendPinMessage(ctx context.Context, message *common.PinMessage) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendPinMessage(ctx, message)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func (api *PublicAPI) RequestTransaction(ctx context.Context, chatID, value, contract, address string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RequestTransaction(ctx, chatID, value, contract, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) RequestAddressForTransaction(ctx context.Context, chatID, from, value, contract string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RequestAddressForTransaction(ctx, chatID, from, value, contract)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.DeclineRequestAddressForTransaction(ctx, messageID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DeclineRequestTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.DeclineRequestTransaction(ctx, messageID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AcceptRequestAddressForTransaction(ctx, messageID, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendTransaction(ctx context.Context, chatID, value, contract, transactionHash string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendTransaction(ctx, chatID, value, contract, transactionHash, signature)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) AcceptRequestTransaction(ctx context.Context, transactionHash, messageID string, signature types.HexBytes) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AcceptRequestTransaction(ctx, transactionHash, messageID, signature)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendContactUpdates(ctx context.Context, name, picture string) error {
|
|
|
|
return api.service.messenger.SendContactUpdates(ctx, name, picture)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendContactUpdate(ctx context.Context, contactID, name, picture string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendContactUpdate(ctx, contactID, name, picture)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendPairInstallation(ctx context.Context) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendPairInstallation(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SyncDevices(ctx context.Context, name, picture string) error {
|
|
|
|
return api.service.messenger.SyncDevices(ctx, name, picture)
|
|
|
|
}
|
|
|
|
|
2020-03-20 08:32:13 +00:00
|
|
|
func (api *PublicAPI) SignMessageWithChatKey(ctx context.Context, message string) (types.HexBytes, error) {
|
|
|
|
return api.service.messenger.SignMessage(message)
|
|
|
|
}
|
|
|
|
|
2020-02-17 14:38:59 +00:00
|
|
|
func (api *PublicAPI) UpdateMailservers(enodes []string) error {
|
|
|
|
nodes := make([]*enode.Node, len(enodes))
|
|
|
|
for i, rawurl := range enodes {
|
|
|
|
node, err := enode.ParseV4(rawurl)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
nodes[i] = node
|
|
|
|
}
|
|
|
|
return api.service.UpdateMailservers(nodes)
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
// PushNotifications server endpoints
|
2020-07-14 14:07:19 +00:00
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
func (api *PublicAPI) StartPushNotificationsServer() error {
|
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled?", true)
|
2020-07-17 11:41:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
return api.service.messenger.StartPushNotificationsServer()
|
2020-07-14 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
func (api *PublicAPI) StopPushNotificationsServer() error {
|
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-server-enabled?", false)
|
2020-07-17 11:41:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
return api.service.messenger.StopPushNotificationsServer()
|
2020-07-14 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
// PushNotification client endpoints
|
2020-07-14 14:07:19 +00:00
|
|
|
|
2020-07-30 08:24:30 +00:00
|
|
|
func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
// We set both for now as they are equivalent
|
|
|
|
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled?", true)
|
2020-07-15 12:43:15 +00:00
|
|
|
if err != nil {
|
2020-07-16 08:36:17 +00:00
|
|
|
return err
|
2020-07-15 12:43:15 +00:00
|
|
|
}
|
2020-07-17 11:41:49 +00:00
|
|
|
err = api.service.accountsDB.SaveSetting("notifications-enabled?", true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-30 08:24:30 +00:00
|
|
|
return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken, apnTopic, tokenType)
|
2020-07-14 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 13:37:32 +00:00
|
|
|
func (api *PublicAPI) UnregisterFromPushNotifications(ctx context.Context) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled?", false)
|
2020-07-15 12:43:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-17 11:41:49 +00:00
|
|
|
err = api.service.accountsDB.SaveSetting("notifications-enabled?", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-15 12:43:15 +00:00
|
|
|
return api.service.messenger.UnregisterFromPushNotifications(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DisableSendingNotifications(ctx context.Context) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
err := api.service.accountsDB.SaveSetting("send-push-notifications?", false)
|
2020-07-15 12:43:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.service.messenger.DisableSendingPushNotifications()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) EnableSendingNotifications(ctx context.Context) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
err := api.service.accountsDB.SaveSetting("send-push-notifications?", true)
|
2020-07-15 12:43:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return api.service.messenger.EnableSendingPushNotifications()
|
|
|
|
}
|
|
|
|
|
2020-07-17 11:41:49 +00:00
|
|
|
func (api *PublicAPI) EnablePushNotificationsFromContactsOnly(ctx context.Context) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only?", true)
|
2020-07-17 11:41:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return api.service.messenger.EnablePushNotificationsFromContactsOnly()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DisablePushNotificationsFromContactsOnly(ctx context.Context) error {
|
2020-07-22 07:41:40 +00:00
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-from-contacts-only?", false)
|
2020-07-17 11:41:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return api.service.messenger.DisablePushNotificationsFromContactsOnly()
|
|
|
|
}
|
|
|
|
|
2020-09-03 07:30:03 +00:00
|
|
|
func (api *PublicAPI) EnablePushNotificationsBlockMentions(ctx context.Context) error {
|
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-block-mentions?", true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return api.service.messenger.EnablePushNotificationsBlockMentions()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DisablePushNotificationsBlockMentions(ctx context.Context) error {
|
|
|
|
err := api.service.accountsDB.SaveSetting("push-notifications-block-mentions?", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return api.service.messenger.DisablePushNotificationsBlockMentions()
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:41:40 +00:00
|
|
|
func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
2020-07-14 14:07:19 +00:00
|
|
|
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-20 09:05:39 +00:00
|
|
|
// this is coming from a user, so it has to be a custom server
|
|
|
|
return api.service.messenger.AddPushNotificationsServer(ctx, publicKey, pushnotificationclient.ServerTypeCustom)
|
2020-07-14 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 11:41:49 +00:00
|
|
|
func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
|
|
|
|
publicKey, err := crypto.UnmarshalPubkey(publicKeyBytes)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
|
|
|
|
}
|
|
|
|
|
2020-08-20 09:05:39 +00:00
|
|
|
func (api *PublicAPI) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
|
|
|
|
return api.service.messenger.GetPushNotificationsServers()
|
2020-07-16 08:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) {
|
|
|
|
return api.service.messenger.RegisteredForPushNotifications()
|
|
|
|
}
|
|
|
|
|
2020-07-27 12:27:48 +00:00
|
|
|
// Emoji
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendEmojiReaction(ctx context.Context, chatID, messageID string, emojiID protobuf.EmojiReaction_Type) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendEmojiReaction(ctx, chatID, messageID, emojiID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SendEmojiReactionRetraction(ctx context.Context, emojiReactionID string) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.SendEmojiReactionRetraction(ctx, emojiReactionID)
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:57:01 +00:00
|
|
|
func (api *PublicAPI) EmojiReactionsByChatID(chatID string, cursor string, limit int) ([]*protocol.EmojiReaction, error) {
|
|
|
|
return api.service.messenger.EmojiReactionsByChatID(chatID, cursor, limit)
|
|
|
|
}
|
|
|
|
|
2020-10-27 17:35:28 +00:00
|
|
|
// Urls
|
|
|
|
|
|
|
|
func (api *PublicAPI) GetLinkPreviewWhitelist() []urls.Site {
|
|
|
|
return urls.LinkPreviewWhitelist()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) GetLinkPreviewData(link string) (previewData urls.LinkPreviewData, err error) {
|
|
|
|
return urls.GetLinkPreviewData(link)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (api *PublicAPI) EnsVerified(pk, ensName string) error {
|
|
|
|
return api.service.messenger.ENSVerified(pk, ensName)
|
|
|
|
}
|
|
|
|
|
2021-04-19 12:09:46 +00:00
|
|
|
func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) error {
|
|
|
|
return api.service.messenger.RequestCommunityInfoFromMailserver(communityID)
|
|
|
|
}
|
|
|
|
|
2021-04-07 12:57:14 +00:00
|
|
|
func (api *PublicAPI) UnreadActivityCenterNotificationsCount() (uint64, error) {
|
|
|
|
return api.service.messenger.UnreadActivityCenterNotificationsCount()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) MarkAllActivityCenterNotificationsRead() error {
|
|
|
|
return api.service.messenger.MarkAllActivityCenterNotificationsRead()
|
|
|
|
}
|
|
|
|
|
2021-06-11 16:47:53 +00:00
|
|
|
func (api *PublicAPI) MarkActivityCenterNotificationsRead(ids []types.HexBytes) error {
|
|
|
|
return api.service.messenger.MarkActivityCenterNotificationsRead(ids)
|
|
|
|
}
|
|
|
|
|
2021-04-07 12:57:14 +00:00
|
|
|
func (api *PublicAPI) AcceptAllActivityCenterNotifications() (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AcceptAllActivityCenterNotifications()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) AcceptActivityCenterNotifications(ids []types.HexBytes) (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.AcceptActivityCenterNotifications(ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DismissAllActivityCenterNotifications() error {
|
|
|
|
return api.service.messenger.DismissAllActivityCenterNotifications()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) DismissActivityCenterNotifications(ids []types.HexBytes) error {
|
|
|
|
return api.service.messenger.DismissActivityCenterNotifications(ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) ActivityCenterNotifications(cursor string, limit uint64) (*protocol.ActivityCenterPaginationResponse, error) {
|
|
|
|
return api.service.messenger.ActivityCenterNotifications(cursor, limit)
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:15:22 +00:00
|
|
|
func (api *PublicAPI) RequestAllHistoricMessages() (*protocol.MessengerResponse, error) {
|
|
|
|
return api.service.messenger.RequestAllHistoricMessages()
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
// Echo is a method for testing purposes.
|
|
|
|
func (api *PublicAPI) Echo(ctx context.Context, message string) (string, error) {
|
|
|
|
return message, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:15:22 +00:00
|
|
|
func (api *PublicAPI) FillGaps(chatID string, messageIDs []string) error {
|
|
|
|
return api.service.messenger.FillGaps(chatID, messageIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *PublicAPI) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
|
|
|
|
return api.service.messenger.SyncChatFromSyncedFrom(chatID)
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
// -----
|
|
|
|
// HELPER
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// MakeMessagesRequestPayload makes a specific payload for MailServer
|
|
|
|
// to request historic messages.
|
|
|
|
// DEPRECATED
|
|
|
|
func MakeMessagesRequestPayload(r MessagesRequest) ([]byte, error) {
|
|
|
|
cursor, err := hex.DecodeString(r.Cursor)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid cursor: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cursor) > 0 && len(cursor) != mailserver.CursorLength {
|
|
|
|
return nil, fmt.Errorf("invalid cursor size: expected %d but got %d", mailserver.CursorLength, len(cursor))
|
|
|
|
}
|
|
|
|
|
|
|
|
payload := mailserver.MessagesRequestPayload{
|
2020-11-23 07:18:53 +00:00
|
|
|
Lower: r.From,
|
|
|
|
Upper: r.To,
|
|
|
|
// We need to pass bloom filter for
|
|
|
|
// backward compatibility
|
2020-01-20 20:56:06 +00:00
|
|
|
Bloom: createBloomFilter(r),
|
2020-11-23 07:18:53 +00:00
|
|
|
Topics: topicsToByteArray(r.Topics),
|
2020-01-20 20:56:06 +00:00
|
|
|
Limit: r.Limit,
|
|
|
|
Cursor: cursor,
|
|
|
|
// Client must tell the MailServer if it supports batch responses.
|
|
|
|
// This can be removed in the future.
|
|
|
|
Batch: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
return rlp.EncodeToBytes(payload)
|
|
|
|
}
|
|
|
|
|
2020-11-23 07:18:53 +00:00
|
|
|
func topicsToByteArray(topics []types.TopicType) [][]byte {
|
|
|
|
|
|
|
|
var response [][]byte
|
|
|
|
for idx := range topics {
|
|
|
|
response = append(response, topics[idx][:])
|
|
|
|
}
|
|
|
|
|
|
|
|
return response
|
|
|
|
}
|
|
|
|
|
2020-01-20 20:56:06 +00:00
|
|
|
func createBloomFilter(r MessagesRequest) []byte {
|
|
|
|
if len(r.Topics) > 0 {
|
|
|
|
return topicsToBloom(r.Topics...)
|
|
|
|
}
|
|
|
|
return types.TopicToBloom(r.Topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
func topicsToBloom(topics ...types.TopicType) []byte {
|
|
|
|
i := new(big.Int)
|
|
|
|
for _, topic := range topics {
|
|
|
|
bloom := types.TopicToBloom(topic)
|
|
|
|
i.Or(i, new(big.Int).SetBytes(bloom[:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
combined := make([]byte, types.BloomFilterSize)
|
|
|
|
data := i.Bytes()
|
|
|
|
copy(combined[types.BloomFilterSize-len(data):], data[:])
|
|
|
|
|
|
|
|
return combined
|
|
|
|
}
|
|
|
|
|
|
|
|
// TopicsToBloom squashes all topics into a single bloom filter.
|
|
|
|
func TopicsToBloom(topics ...types.TopicType) []byte {
|
|
|
|
return topicsToBloom(topics...)
|
|
|
|
}
|