Reintroduce api endpoint

This commit is contained in:
Andrea Maria Piana 2022-10-28 15:08:18 +01:00
parent c2b17acc07
commit 2162b76546
3 changed files with 31 additions and 0 deletions

View File

@ -894,6 +894,10 @@ func (m *Messenger) HandleContactVerificationTrusted(state *ReceivedMessageState
return nil
}
func (m *Messenger) GetLatestVerificationRequestFrom(contactID string) (*verification.Request, error) {
return m.verificationDatabase.GetLatestVerificationRequestFrom(contactID)
}
func (m *Messenger) createContactVerificationNotification(contact *Contact, messageState *ReceivedMessageState, vr *verification.Request, chatMessage *common.Message) error {
notification := &ActivityCenterNotification{
ID: types.FromHex(vr.ID),

View File

@ -149,6 +149,29 @@ func (p *Persistence) GetVerificationRequestSentTo(contactID string) (*Request,
}
}
func (p *Persistence) GetLatestVerificationRequestFrom(contactID string) (*Request, error) {
var vr Request
err := p.db.QueryRow(`SELECT id, from_user, to_user, challenge, response, requested_at, verification_status, replied_at FROM verification_requests_individual WHERE from_user = ? ORDER BY requested_at DESC`, contactID).Scan(
&vr.ID,
&vr.From,
&vr.To,
&vr.Challenge,
&vr.Response,
&vr.RequestedAt,
&vr.RequestStatus,
&vr.RepliedAt,
)
switch err {
case sql.ErrNoRows:
return nil, nil
case nil:
return &vr, nil
default:
return nil, err
}
}
func (p *Persistence) SaveVerificationRequest(vr *Request) error {
if vr == nil {
return errors.New("invalid verification request provided")

View File

@ -792,6 +792,10 @@ func (api *PublicAPI) GetTrustStatus(ctx context.Context, contactID string) (ver
return api.service.messenger.GetTrustStatus(contactID)
}
func (api *PublicAPI) GetLatestVerificationRequestFrom(ctx context.Context, contactID string) (*verification.Request, error) {
return api.service.messenger.GetLatestVerificationRequestFrom(contactID)
}
func (api *PublicAPI) SendContactVerificationRequest(ctx context.Context, contactID string, challenge string) (*protocol.MessengerResponse, error) {
return api.service.messenger.SendContactVerificationRequest(ctx, contactID, challenge)
}