Ring Daemon 16.0.0
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, bool logIfNotFound=true) const
 
std::string getHead () const
 Get current HEAD hash.
 
std::vector< std::string > getInitialMembers () const
 One to one util, get initial members.
 
const std::string & id () const
 Return the conversation id.
 
std::map< std::string, std::string > infos () const
 Retrieve current infos (title, description, avatar, mode)
 
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::string mergeBase (const std::string &from, const std::string &to) const
 Get the common parent between two branches.
 
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.
 
bool validClone (std::function< void(std::vector< ConversationCommit >)> &&checkCommitCb) const
 
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::unique_ptr< ConversationRepositorycloneConversation (const std::shared_ptr< JamiAccount > &account, const std::string &deviceId, const std::string &conversationId, std::function< void(std::vector< ConversationCommit >)> &&checkCommitCb={})
 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 (std::map< std::string, std::string > &&details)
 

Detailed Description

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

Definition at line 141 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 2888 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 2902 of file conversationrepository.cpp.

References jami::emitSignal(), jami::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 2953 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::unique_ptr< ConversationRepository > jami::ConversationRepository::cloneConversation ( const std::shared_ptr< JamiAccount > &  account,
const std::string &  deviceId,
const std::string &  conversationId,
std::function< void(std::vector< ConversationCommit >)> &&  checkCommitCb = {} 
)
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
checkCommitCbUsed if commits should be treated

Definition at line 2632 of file conversationrepository.cpp.

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

Referenced by jami::Conversation::Impl::Impl().

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 3149 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 3164 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 4008 of file conversationrepository.cpp.

References jami::emitSignal().

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 2579 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 3818 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 3498 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 3004 of file conversationrepository.cpp.

References jami::emitSignal(), JAMI_ERROR, JAMI_WARNING, log(), MAX_FETCH_SIZE, and jami::LogOptions::nbOfCommits.

Here is the call graph for this function:

◆ getCommit()

std::optional< ConversationCommit > jami::ConversationRepository::getCommit ( const std::string &  commitId,
bool  logIfNotFound = true 
) const

Definition at line 3195 of file conversationrepository.cpp.

References jami::emitSignal().

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

Here is the call graph for this function:

◆ getHead()

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

Get current HEAD hash.

Definition at line 3987 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 3799 of file conversationrepository.cpp.

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

◆ id()

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

◆ infos()

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

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

Returns
infos

Definition at line 3945 of file conversationrepository.cpp.

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

Referenced by updateInfos().

Here is the call graph for this function:

◆ infosFromVCard()

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

◆ join()

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

Join a repository.

Returns
commit Id

Definition at line 3357 of file conversationrepository.cpp.

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

Here is the call graph for this function:

◆ leave()

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

Erase self from repository.

Returns
commit Id

Definition at line 3428 of file conversationrepository.cpp.

References jami::emitSignal(), jami::git_add_all(), jami::fileutils::loadFile(), 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 3175 of file conversationrepository.cpp.

References jami::emitSignal().

Referenced by jami::ConversationRepository::Impl::behind(), fetch(), jami::ConversationRepository::Impl::getInitialMembers(), jami::ConversationRepository::Impl::mode(), 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 3181 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 3805 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 3811 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 3201 of file conversationrepository.cpp.

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

Here is the call graph for this function:

◆ mergeBase()

std::string jami::ConversationRepository::mergeBase ( const std::string &  from,
const std::string &  to 
) const

Get the common parent between two branches.

Parameters
fromThe first branch
toThe second branch
Returns
the common parent

Definition at line 3322 of file conversationrepository.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ mode()

◆ onMembersChanged()

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

Definition at line 2947 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 3833 of file conversationrepository.cpp.

References jami::emitSignal().

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 3824 of file conversationrepository.cpp.

◆ 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 3070 of file conversationrepository.cpp.

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

Referenced by 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 3785 of file conversationrepository.cpp.

References jami::emitSignal(), and JAMI_WARNING.

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 3702 of file conversationrepository.cpp.

References 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()

bool jami::ConversationRepository::validClone ( std::function< void(std::vector< ConversationCommit >)> &&  checkCommitCb) const

Definition at line 3772 of file conversationrepository.cpp.

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

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 3758 of file conversationrepository.cpp.

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

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 3515 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 3564 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: