Ring Daemon
Loading...
Searching...
No Matches
jami::ConversationRepository Class Reference

This class gives access to the git repository that represents the conversation. More...

#include <conversationrepository.h>

Collaboration diagram for jami::ConversationRepository:
Collaboration graph

Classes

class  Impl
 

Public Member Functions

std::string addMember (const std::string &uri)
 Write the certificate in /members and commit the change.
 
std::string amend (const std::string &id, const std::string &msg)
 Amend a commit message.
 
std::string commitMessage (const std::string &msg, bool verifyDevice=true)
 Add a new commit to the conversation.
 
std::vector< std::string > commitMessages (const std::vector< std::string > &msgs)
 
std::vector< std::map< std::string, std::string > > convCommitsToMap (const std::vector< ConversationCommit > &commits) const
 Convert ConversationCommit to MapStringString for the client.
 
std::optional< std::map< std::string, std::string > > convCommitToMap (const ConversationCommit &commit) const
 
 ConversationRepository (const std::shared_ptr< JamiAccount > &account, const std::string &id)
 Open a conversation repository for an account and an id.
 
std::map< std::string, std::vector< DeviceId > > devices (bool ignoreExpired=true) const
 Get conversation's devices.
 
std::string diffStats (const std::string &newId, const std::string &oldId="") const
 Get current diff stats between two commits.
 
void erase ()
 Erase repository.
 
bool fetch (const std::string &remoteDeviceId)
 Fetch a remote repository via the given socket.
 
std::optional< ConversationCommitgetCommit (const std::string &commitId) const
 
std::string getHead () const
 Get current HEAD hash.
 
std::vector< std::string > getInitialMembers () const
 One to one util, get initial members.
 
bool hasCommit (const std::string &commitId) const
 Check if a commit exists in the repository.
 
const std::string & id () const
 Return the conversation id.
 
std::map< std::string, std::string > infos () const
 Retrieve current infos (title, description, avatar, mode)
 
bool isValidUserAtCommit (const std::string &userDevice, const std::string &commitId, const git_buf &sig, const git_buf &sig_data) const
 Verify the signature against the given commit.
 
std::string join ()
 Join a repository.
 
std::string leave ()
 Erase self from repository.
 
std::optional< std::string > linearizedParent (const std::string &commitId) const
 Get parent via topological + date sort in branch main of a commit.
 
std::vector< ConversationCommitlog (const LogOptions &options={}) const
 Get commits depending on the options we pass.
 
void log (PreConditionCb &&preCondition, std::function< void(ConversationCommit &&)> &&emplaceCb, PostConditionCb &&postCondition, const std::string &from="", bool logIfNotFound=true) const
 
std::vector< ConversationMembermembers () const
 Get conversation's members.
 
std::set< std::string > memberUris (std::string_view filter, const std::set< MemberRole > &filteredRoles) const
 
std::pair< bool, std::string > merge (const std::string &merge_id, bool force=false)
 Merge another branch into the main branch.
 
std::vector< std::map< std::string, std::string > > mergeHistory (const std::string &uri, std::function< void(const std::string &)> &&disconnectFromPeerCb={})
 Merge the history of the conversation with another peer.
 
ConversationMode mode () const
 Get conversation's mode.
 
void onMembersChanged (OnMembersChanged &&cb)
 
void pinCertificates (bool blocking=false)
 Because conversations can contains non contacts certificates, this methods loads certificates in conversations into the cert store.
 
void refreshMembers () const
 To use after a merge with member's events, refresh members knowledge.
 
std::string remoteHead (const std::string &remoteDeviceId, const std::string &branch="main") const
 Retrieve remote head.
 
void removeBranchWith (const std::string &remoteDevice)
 Delete branch with remote.
 
std::string resolveVote (const std::string &uri, const std::string_view type, const std::string &voteType)
 Validate if a vote is finished.
 
std::string updateInfos (const std::map< std::string, std::string > &map)
 Change repository's infos.
 
std::string uriFromDevice (const std::string &deviceId) const
 Retrieve the uri from a deviceId.
 
std::pair< std::vector< ConversationCommit >, boolvalidClone () const
 Validate a clone.
 
bool validCommits (const std::vector< ConversationCommit > &commitsToValidate) const
 Validate that commits are not malformed.
 
std::pair< std::vector< ConversationCommit >, boolvalidFetch (const std::string &remoteDevice) const
 Validate a fetch with remote device.
 
std::string voteKick (const std::string &uri, const std::string &type)
 The voting system is divided in two parts.
 
std::string voteUnban (const std::string &uri, const std::string_view type)
 Add a vote to re-add a user.
 
 ~ConversationRepository ()
 

Static Public Member Functions

static std::vector< std::string > changedFiles (std::string_view diffStats)
 Get changed files from a git diff.
 
static LIBJAMI_TEST_EXPORT std::pair< std::unique_ptr< ConversationRepository >, std::vector< ConversationCommit > > cloneConversation (const std::shared_ptr< JamiAccount > &account, const std::string &deviceId, const std::string &conversationId)
 Clones a conversation on a remote device.
 
static LIBJAMI_TEST_EXPORT std::unique_ptr< ConversationRepositorycreateConversation (const std::shared_ptr< JamiAccount > &account, ConversationMode mode=ConversationMode::INVITES_ONLY, const std::string &otherMember="")
 Creates a new repository, with initial files, where the first commit hash is the conversation id.
 
static std::map< std::string, std::string > infosFromVCard (vCard::utils::VCardData &&details)
 

Detailed Description

This class gives access to the git repository that represents the conversation.

Definition at line 133 of file conversationrepository.h.

Constructor & Destructor Documentation

◆ ConversationRepository()

jami::ConversationRepository::ConversationRepository ( const std::shared_ptr< JamiAccount > &  account,
const std::string &  id 
)

Open a conversation repository for an account and an id.

Parameters
accountThe related account
idThe conversation id

Definition at line 3165 of file conversationrepository.cpp.

◆ ~ConversationRepository()

jami::ConversationRepository::~ConversationRepository ( )
default

Member Function Documentation

◆ addMember()

std::string jami::ConversationRepository::addMember ( const std::string &  uri)

Write the certificate in /members and commit the change.

Parameters
uriMember to add
Returns
the commit id if successful

Definition at line 3178 of file conversationrepository.cpp.

References jami::emitSignal(), jami::INVITED, jami::MemberPath::INVITED, JAMI_ERROR, JAMI_WARNING, and jami::json::toString().

Here is the call graph for this function:

◆ amend()

std::string jami::ConversationRepository::amend ( const std::string &  id,
const std::string &  msg 
)

Amend a commit message.

Parameters
idThe commit to amend
msgThe commit message of the commit
Returns
<empty> on failure, else the message id

Definition at line 3232 of file conversationrepository.cpp.

References jami::ECOMMIT, jami::emitSignal(), JAMI_DEBUG, JAMI_ERROR, and JAMI_WARNING.

Here is the call graph for this function:

◆ changedFiles()

◆ cloneConversation()

std::pair< std::unique_ptr< ConversationRepository >, std::vector< ConversationCommit > > jami::ConversationRepository::cloneConversation ( const std::shared_ptr< JamiAccount > &  account,
const std::string &  deviceId,
const std::string &  conversationId 
)
static

Clones a conversation on a remote device.

Note
This will use the socket registered for the conversation with JamiAccount::addGitSocket()
Parameters
accountThe account getting the conversation
deviceIdRemote device
conversationIdConversation to clone

Definition at line 2779 of file conversationrepository.cpp.

References jami::emitSignal(), jami::fileutils::get_data_dir(), JAMI_DEBUG, JAMI_ERROR, JAMI_LOG, JAMI_WARNING, and MAX_FETCH_SIZE.

Here is the call graph for this function:

◆ commitMessage()

std::string jami::ConversationRepository::commitMessage ( const std::string &  msg,
bool  verifyDevice = true 
)

Add a new commit to the conversation.

Parameters
msgThe commit message of the commit
verifyDeviceIf we need to validate that certificates are correct (used for testing)
Returns
<empty> on failure, else the message id

Definition at line 3478 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ commitMessages()

std::vector< std::string > jami::ConversationRepository::commitMessages ( const std::vector< std::string > &  msgs)

Definition at line 3493 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ convCommitsToMap()

std::vector< std::map< std::string, std::string > > jami::ConversationRepository::convCommitsToMap ( const std::vector< ConversationCommit > &  commits) const

Convert ConversationCommit to MapStringString for the client.

Definition at line 4354 of file conversationrepository.cpp.

References jami::emitSignal().

Referenced by mergeHistory().

Here is the call graph for this function:

◆ convCommitToMap()

std::optional< std::map< std::string, std::string > > jami::ConversationRepository::convCommitToMap ( const ConversationCommit commit) const

◆ createConversation()

std::unique_ptr< ConversationRepository > jami::ConversationRepository::createConversation ( const std::shared_ptr< JamiAccount > &  account,
ConversationMode  mode = ConversationMode::INVITES_ONLY,
const std::string &  otherMember = "" 
)
static

Creates a new repository, with initial files, where the first commit hash is the conversation id.

Parameters
accountThe related account
modeThe wanted mode
otherMemberThe other uri
Returns
the conversation repository object

Definition at line 2726 of file conversationrepository.cpp.

References jami::add_initial_files(), jami::create_empty_repository(), jami::emitSignal(), jami::fileutils::get_data_dir(), id(), jami::initial_commit(), JAMI_ERROR, JAMI_LOG, and mode().

Here is the call graph for this function:

◆ devices()

std::map< std::string, std::vector< DeviceId > > jami::ConversationRepository::devices ( bool  ignoreExpired = true) const

Get conversation's devices.

Parameters
ignoreExpiredIf we want to ignore expired devices
Returns
members

Definition at line 4165 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ diffStats()

std::string jami::ConversationRepository::diffStats ( const std::string &  newId,
const std::string &  oldId = "" 
) const

◆ erase()

void jami::ConversationRepository::erase ( )

Erase repository.

Definition at line 3834 of file conversationrepository.cpp.

References jami::emitSignal(), and JAMI_LOG.

Here is the call graph for this function:

◆ fetch()

bool jami::ConversationRepository::fetch ( const std::string &  remoteDeviceId)

Fetch a remote repository via the given socket.

Note
This will use the socket registered for the conversation with JamiAccount::addGitSocket()
will create a remote identified by the deviceId
Parameters
remoteDeviceIdRemote device id to fetch
Returns
if the operation was successful

Definition at line 3277 of file conversationrepository.cpp.

References jami::emitSignal(), jami::fileutils::get_data_dir(), JAMI_ERROR, JAMI_WARNING, and MAX_FETCH_SIZE.

Here is the call graph for this function:

◆ getCommit()

std::optional< ConversationCommit > jami::ConversationRepository::getCommit ( const std::string &  commitId) const

◆ getHead()

std::string jami::ConversationRepository::getHead ( ) const

Get current HEAD hash.

Definition at line 4333 of file conversationrepository.cpp.

References jami::emitSignal(), and JAMI_ERROR.

Here is the call graph for this function:

◆ getInitialMembers()

std::vector< std::string > jami::ConversationRepository::getInitialMembers ( ) const

One to one util, get initial members.

Returns
initial members

Definition at line 4147 of file conversationrepository.cpp.

Referenced by jami::ConversationRepository::Impl::checkValidAdd(), and jami::ConversationRepository::Impl::initMembers().

◆ hasCommit()

bool jami::ConversationRepository::hasCommit ( const std::string &  commitId) const

Check if a commit exists in the repository.

Parameters
commitIdThe commit id to check
Returns
true if the commit was found, false if not or if an error occurred

Definition at line 3520 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ id()

const std::string & jami::ConversationRepository::id ( ) const

Return the conversation id.

Definition at line 3172 of file conversationrepository.cpp.

Referenced by jami::ConversationRepository::Impl::convCommitToMap(), and createConversation().

◆ infos()

std::map< std::string, std::string > jami::ConversationRepository::infos ( ) const

Retrieve current infos (title, description, avatar, mode)

Returns
infos

Definition at line 4291 of file conversationrepository.cpp.

References jami::emitSignal(), infosFromVCard(), jami::fileutils::loadFile(), mode(), and jami::vCard::utils::toMap().

Referenced by updateInfos().

Here is the call graph for this function:

◆ infosFromVCard()

std::map< std::string, std::string > jami::ConversationRepository::infosFromVCard ( vCard::utils::VCardData &&  details)
static

◆ isValidUserAtCommit()

bool jami::ConversationRepository::isValidUserAtCommit ( const std::string &  userDevice,
const std::string &  commitId,
const git_buf sig,
const git_buf sig_data 
) const

Verify the signature against the given commit.

Parameters
userDevicethe email of the sender (i.e. their device's public key)
commitIdthe id of the commit

Definition at line 4118 of file conversationrepository.cpp.

References jami::emitSignal().

Referenced by jami::ConversationRepository::Impl::validCommits().

Here is the call graph for this function:

◆ join()

std::string jami::ConversationRepository::join ( )

◆ leave()

std::string jami::ConversationRepository::leave ( )

Erase self from repository.

Returns
commit Id

Definition at line 3763 of file conversationrepository.cpp.

References jami::MemberPath::ADMINS, jami::emitSignal(), jami::git_add_all(), jami::fileutils::loadFile(), jami::MemberPath::MEMBERS, and jami::json::toString().

Here is the call graph for this function:

◆ linearizedParent()

std::optional< std::string > jami::ConversationRepository::linearizedParent ( const std::string &  commitId) const

Get parent via topological + date sort in branch main of a commit.

Parameters
commitIdid to choice

◆ log() [1/2]

std::vector< ConversationCommit > jami::ConversationRepository::log ( const LogOptions options = {}) const

Get commits depending on the options we pass.

Returns
a list of commits

Definition at line 3504 of file conversationrepository.cpp.

References jami::emitSignal().

Referenced by jami::ConversationRepository::Impl::behind(), and validClone().

Here is the call graph for this function:

◆ log() [2/2]

void jami::ConversationRepository::log ( PreConditionCb &&  preCondition,
std::function< void(ConversationCommit &&)> &&  emplaceCb,
PostConditionCb &&  postCondition,
const std::string &  from = "",
bool  logIfNotFound = true 
) const

Definition at line 3510 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ members()

std::vector< ConversationMember > jami::ConversationRepository::members ( ) const

Get conversation's members.

Returns
members

Definition at line 4153 of file conversationrepository.cpp.

◆ memberUris()

std::set< std::string > jami::ConversationRepository::memberUris ( std::string_view  filter,
const std::set< MemberRole > &  filteredRoles 
) const
Parameters
filterIf we want to remove one member
filteredRolesIf we want to ignore some roles
Returns
members' uris

Definition at line 4159 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ merge()

std::pair< bool, std::string > jami::ConversationRepository::merge ( const std::string &  merge_id,
bool  force = false 
)

Merge another branch into the main branch.

Parameters
merge_idThe reference to merge
forceShould be false, skip validateDevice() ; used for test purpose
Returns
a pair containing if the merge was successful and the merge commit id generated if one (can be a fast forward merge without commit)

Definition at line 3532 of file conversationrepository.cpp.

References jami::emitSignal(), jami::git_add_all(), JAMI_ERROR, and JAMI_LOG.

Referenced by mergeHistory().

Here is the call graph for this function:

◆ mergeHistory()

std::vector< std::map< std::string, std::string > > jami::ConversationRepository::mergeHistory ( const std::string &  uri,
std::function< void(const std::string &)> &&  disconnectFromPeerCb = {} 
)

Merge the history of the conversation with another peer.

Parameters
uriThe peer uri
disconnectFromPeerCbCallback to disconnect from peer when banning
Returns
A vector of media maps representing the merged history

Definition at line 3347 of file conversationrepository.cpp.

References convCommitsToMap(), jami::emitSignal(), getCommit(), JAMI_ERROR, JAMI_LOG, JAMI_WARNING, merge(), refreshMembers(), remoteHead(), removeBranchWith(), and validFetch().

Here is the call graph for this function:

◆ mode()

◆ onMembersChanged()

void jami::ConversationRepository::onMembersChanged ( OnMembersChanged &&  cb)

Definition at line 3226 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ pinCertificates()

void jami::ConversationRepository::pinCertificates ( bool  blocking = false)

Because conversations can contains non contacts certificates, this methods loads certificates in conversations into the cert store.

Parameters
blockingif we need to wait that certificates are pinned

Definition at line 4180 of file conversationrepository.cpp.

References jami::MemberPath::ADMINS, jami::MemberPath::DEVICES, jami::emitSignal(), and jami::MemberPath::MEMBERS.

Here is the call graph for this function:

◆ refreshMembers()

void jami::ConversationRepository::refreshMembers ( ) const

To use after a merge with member's events, refresh members knowledge.

Definition at line 4171 of file conversationrepository.cpp.

Referenced by mergeHistory().

◆ remoteHead()

std::string jami::ConversationRepository::remoteHead ( const std::string &  remoteDeviceId,
const std::string &  branch = "main" 
) const

Retrieve remote head.

Can be useful after a fetch operation

Parameters
remoteDeviceIdThe remote name
branchRemote branch to check (default: main)
Returns
the commit id pointed

Definition at line 3400 of file conversationrepository.cpp.

References jami::emitSignal(), JAMI_ERROR, JAMI_WARNING, and remoteHead().

Referenced by mergeHistory(), remoteHead(), and validFetch().

Here is the call graph for this function:

◆ removeBranchWith()

void jami::ConversationRepository::removeBranchWith ( const std::string &  remoteDevice)

Delete branch with remote.

Parameters
remoteDevice

Definition at line 4133 of file conversationrepository.cpp.

References jami::emitSignal(), and JAMI_WARNING.

Referenced by mergeHistory().

Here is the call graph for this function:

◆ resolveVote()

std::string jami::ConversationRepository::resolveVote ( const std::string &  uri,
const std::string_view  type,
const std::string &  voteType 
)

Validate if a vote is finished.

Parameters
uriidentified of the user/device
typedevice, members, admins or invited
voteType"ban" or "unban"
Returns
the commit id or empty if failed

Definition at line 4041 of file conversationrepository.cpp.

References jami::MemberPath::ADMINS, jami::emitSignal(), jami::fileutils::getFullPath(), jami::git_add_all(), JAMI_WARNING, and jami::json::toString().

Here is the call graph for this function:

◆ updateInfos()

◆ uriFromDevice()

◆ validClone()

std::pair< std::vector< ConversationCommit >, bool > jami::ConversationRepository::validClone ( ) const

Validate a clone.

Returns
the validated commits and false if an error occurs

Definition at line 4109 of file conversationrepository.cpp.

References jami::emitSignal(), and log().

Here is the call graph for this function:

◆ validCommits()

bool jami::ConversationRepository::validCommits ( const std::vector< ConversationCommit > &  commitsToValidate) const

Validate that commits are not malformed.

Parameters
commitsToValidatethe list of commits

Definition at line 4127 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ validFetch()

std::pair< std::vector< ConversationCommit >, bool > jami::ConversationRepository::validFetch ( const std::string &  remoteDevice) const

Validate a fetch with remote device.

Parameters
remotedevice
Returns
the validated commits and if an error occurs

Definition at line 4095 of file conversationrepository.cpp.

References jami::emitSignal(), and remoteHead().

Referenced by mergeHistory().

Here is the call graph for this function:

◆ voteKick()

std::string jami::ConversationRepository::voteKick ( const std::string &  uri,
const std::string &  type 
)

The voting system is divided in two parts.

The voting phase where admins can decide an action (such as kicking someone) and the resolving phase, when > 50% of the admins voted, we can considered the vote as finished Add a vote to kick a device or a user

Parameters
uriidentified of the user/device
typedevice, members, admins or invited
Returns
the commit id or empty if failed

Definition at line 3851 of file conversationrepository.cpp.

References jami::emitSignal(), jami::fileutils::getFullPath(), JAMI_ERROR, JAMI_WARNING, and jami::json::toString().

Here is the call graph for this function:

◆ voteUnban()

std::string jami::ConversationRepository::voteUnban ( const std::string &  uri,
const std::string_view  type 
)

Add a vote to re-add a user.

Parameters
uriidentified of the user
typedevice, members, admins or invited
Returns
the commit id or empty if failed

Definition at line 3900 of file conversationrepository.cpp.

References jami::emitSignal(), jami::fileutils::getFullPath(), JAMI_ERROR, and jami::json::toString().

Here is the call graph for this function:

The documentation for this class was generated from the following files: