X-Git-Url: https://gitweb.ps.run/matrix_esp_thesis/blobdiff_plain/f2840d9dd5b8a0683abee189e408c5a6de294eb7..c351768df98c8239eb123ff9af036e574f47df99:/examples/SendEncrypted.c diff --git a/examples/SendEncrypted.c b/examples/SendEncrypted.c index 7e0b1d4..3debeab 100644 --- a/examples/SendEncrypted.c +++ b/examples/SendEncrypted.c @@ -2,8 +2,6 @@ #include #define SERVER "https://matrix.org" -#define ACCESS_TOKEN "syt_cHNjaG8_yBvTjVTquGCikvsAenOJ_49mBMO" -#define DEVICE_ID "MAZNCCZLBR" #define USER_ID "@pscho:matrix.org" #define ROOM_ID "!XKFUjAsGrSSrpDFIxB:matrix.org" @@ -11,36 +9,41 @@ int main(void) { MatrixClient client; - MatrixClientInit(&client, - SERVER); + MatrixClientInit(&client); - MatrixHttpInit(&client); + MatrixHttpInit(&client.hc, SERVER); - MatrixClientSetAccessToken(&client, - ACCESS_TOKEN); - MatrixClientSetDeviceId(&client, - DEVICE_ID); - MatrixClientSetUserId(&client, - USER_ID); + MatrixClientSetUserId(&client, USER_ID); - // MatrixMegolmOutSession megolmOutSession; - // MatrixMegolmOutSessionInit(&megolmOutSession); + MatrixClientLoginPassword(&client, + "pscho", + "Wc23EbmB9G3faMq", + "Test1"); - // MatrixClientSetMegolmOutSession(&client, - // ROOM_ID, - // megolmOutSession); + MatrixClientUploadDeviceKeys(&client); + MatrixClientGenerateOnetimeKeys(&client, 10); + MatrixClientUploadOnetimeKeys(&client); - MatrixClientSendEventEncrypted(&client, + // create megolmsession + MatrixMegolmOutSession * megolmOutSession; + MatrixClientNewMegolmOutSession(&client, ROOM_ID, - "m.room.message", - "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"); + &megolmOutSession); + printf("megolm session id: %.10s... key: %.10s...\n", megolmOutSession->id, megolmOutSession->key); MatrixClientShareMegolmOutSession(&client, USER_ID, "ULZZOKJBYN", - &client.megolmOutSessions[0]); - - MatrixHttpDeinit(&client); + megolmOutSession); + + MatrixClientSendEventEncrypted(&client, + ROOM_ID, + "m.room.message", + "{\"body\":\"Hello\",\"msgtype\":\"m.text\"}"); + + MatrixClientDeleteDevice(&client); + + MatrixHttpDeinit(&client.hc); return 0; }