Difference between revisions of "Truxton communication add participant"

From truxwiki.com
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
=Syntax=
 
=Syntax=
 
<source lang="C">
 
<source lang="C">
int truxton_communication_add_participant( uint64_t communication_handle, uint64_t role, char const* value, char * buffer, size_t buffer_size );
+
int truxton_communication_add_participant( uint64_t communication_handle, uint64_t role, char const * value, char * buffer, size_t buffer_size );
 
</source>
 
</source>
  
Line 12: Line 12:
 
==<code>role</code>==
 
==<code>role</code>==
 
This tells Truxton what role this participant had in this communication.
 
This tells Truxton what role this participant had in this communication.
This is stored in the <code>[MessageAddressTypeID]</code> of the <code>[MessageAddress_Message]</code> in the database.
+
This is stored in the <code>[MessageAddressTypeID]</code> column of the <code>[MessageAddress_Message]</code> table in the database.
 
It should be a value that appears in the <code>[ID]</code> column of the <code>[MessageAddressType]</code> table or a [[Message Participants|defined constant.]]
 
It should be a value that appears in the <code>[ID]</code> column of the <code>[MessageAddressType]</code> table or a [[Message Participants|defined constant.]]
  
Line 28: Line 28:
  
 
=Sample=
 
=Sample=
<source lang="C" highlight="37,46">
+
<source lang="C" highlight="30,39">
 
#define TAG_ORIGIN_AUTOMATIC (1)
 
#define TAG_ORIGIN_AUTOMATIC (1)
 
#define TAG_ORIGIN_HUMAN    (2)
 
#define TAG_ORIGIN_HUMAN    (2)
Line 39: Line 39:
 
   uint64_t communication = truxton_communication_create( parent_file );
 
   uint64_t communication = truxton_communication_create( parent_file );
  
   FILETIME now;
+
   uint64_t now = truxton_time_now();
 
 
  GetSystemTimePreciseAsFileTime( &now );
 
 
 
  ULARGE_INTEGER ticks;
 
 
 
  ticks.LowPart = now.dwLowDateTime;
 
  ticks.HighPart = now.dwHighDateTime;
 
  
 
   truxton_communication_set_received( communication, ticks.QuadPart );
 
   truxton_communication_set_received( communication, ticks.QuadPart );

Latest revision as of 18:26, 13 April 2024

This adds a participant to a message.

Syntax

int truxton_communication_add_participant( uint64_t communication_handle, uint64_t role, char const * value, char * buffer, size_t buffer_size );

Parameters

communication_handle

The handle returned by calling truxton_communication_create.

role

This tells Truxton what role this participant had in this communication. This is stored in the [MessageAddressTypeID] column of the [MessageAddress_Message] table in the database. It should be a value that appears in the [ID] column of the [MessageAddressType] table or a defined constant.

value

A string representation of the account.

buffer

An optional address of a buffer to receive the unique identifier of the participant should the function call succeed.

buffer_size

The number of bytes that can be written to buffer.

Return value

A non-zero value on success, zero on failure.

Sample

#define TAG_ORIGIN_AUTOMATIC (1)
#define TAG_ORIGIN_HUMAN     (2)

void add_message( uint64_t truxton, uint64_t parent_file )
{
   char id[40];
   char sender_id[80];

   uint64_t communication = truxton_communication_create( parent_file );

   uint64_t now = truxton_time_now();

   truxton_communication_set_received( communication, ticks.QuadPart );
   truxton_communication_set_sent( communication, ticks.QuadPart );
   truxton_communication_set_type( communication, MESSAGE_TYPE_MIME );
   truxton_communication_set_subject( communication, "Test Message" );

   if ( truxton_communication_save( communication ) == 0 )
   {
      printf( "Failed to add communication to Truxton\n" );
      truxton_communication_destroy( communication );
      return;
   }

   truxton_communication_get_id( parent_file, id, sizeof(id) );
   printf( "Saved as id %s\n", id );

   // Now that we have an id, we can add participants.

   if ( truxton_communication_add_participant( communication, MESSAGE_PARTICIPANT_FROM, "sam@abc.xyz", sender_id, sizeof(sender_id) ) == 0 )
   {
      printf( "Could not save FROM participant.\n" );
   }
   else
   {
      printf( "Sender id is %s\n", sender_id );
   }

   if ( truxton_communication_add_participant( communication, MESSAGE_PARTICIPANT_TO, "laura@abc.xyz", NULL, 0 ) == 0 )
   {
      printf( "Could not save TO participant.\n" );
   }

   uint64_t message_body_1 = create_message_body_1( truxton );
   uint64_t message_body_2 = create_message_body_2( truxton );
   uint64_t attachment_1 = create_attachment_1( truxton );
   uint64_t attachment_2 = create_attachment_2( truxton );

   if ( truxton_communication_add_piece( communication, message_body_1, ORIGIN_EMAIL_BODY, 1 ) == 0 )
   {
      printf( "Could not add first body to message.\n" );
   }

   if ( truxton_communication_add_piece( communication, message_body_1, ORIGIN_EMAIL_BODY, 2 ) == 0 )
   {
      printf( "Could not add second body to message.\n" );
   }

   if ( truxton_communication_add_piece( communication, attachment_1, ORIGIN_EMAIL_ATTACHMENT, 1 ) == 0 )
   {
      printf( "Could not add first attachment to message.\n" );
   }

   if ( truxton_communication_add_piece( communication, attachment_2, ORIGIN_EMAIL_ATTACHMENT, 2 ) == 0 )
   {
      printf( "Could not add second attachment to message.\n" );
   }

   if ( truxton_communication_finished( communication ) == 0 )
   {
      printf( "Could not complete message record.\n" );
   }

   if ( truxton_communication_tag( communication, "Man Made", "Testing the API", TAG_ORIGIN_HUMAN ) == 0 )
   {
      printf( "Could not tag message.\n" );
   }

   truxton_communication_destroy( communication );
}