From 88019229de1b917af61ef1bcc8c2675eade33d57 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 21 Apr 2018 14:33:35 +0200 Subject: [PATCH] add verified-group-type --- cmdline/cmdline.c | 4 +++- cmdline/stress.c | 1 + src/mrchat-private.h | 4 ++++ src/mrchat.c | 5 ++++- src/mrchat.h | 7 ++++--- src/mrchatlist.c | 2 +- src/mrlot.c | 2 +- src/mrmailbox.c | 19 +++++++++++++------ src/mrmailbox_receive_imf.c | 2 +- src/mrmimefactory.c | 4 ++-- src/mrmsg.c | 2 +- 11 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 4a592d15..13923798 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -705,8 +705,10 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline) char* temp_subtitle = mrchat_get_subtitle(chat); char* temp_name = mrchat_get_name(chat); + int chat_type = mrchat_get_type(chat); const char* verified = mrchat_is_verified(chat)? " √√": ""; - mrmailbox_log_info(mailbox, 0, "%s#%i: %s%s [%s] [%i fresh]", mrchat_get_type(chat)==MR_CHAT_TYPE_GROUP? "Groupchat" : "Chat", + mrmailbox_log_info(mailbox, 0, "%s#%i: %s%s [%s] [%i fresh]", + chat_type==MR_CHAT_TYPE_VERIFIED_GROUP? "VerifiedGroup" : (chat_type==MR_CHAT_TYPE_GROUP? "Group" : "Chat"), (int)mrchat_get_id(chat), temp_name, verified, temp_subtitle, (int)mrmailbox_get_fresh_msg_count(mailbox, mrchat_get_id(chat))); free(temp_subtitle); free(temp_name); diff --git a/cmdline/stress.c b/cmdline/stress.c index 5fcca24e..1a02dcc4 100644 --- a/cmdline/stress.c +++ b/cmdline/stress.c @@ -345,6 +345,7 @@ void stress_functions(mrmailbox_t* mailbox) assert( strcmp("undefined=" MR_STRINGIFY(MR_CHAT_TYPE_UNDEFINED), "undefined=0")==0 ); assert( strcmp("single=" MR_STRINGIFY(MR_CHAT_TYPE_SINGLE), "single=100")==0 ); assert( strcmp("group=" MR_STRINGIFY(MR_CHAT_TYPE_GROUP), "group=120")==0 ); + assert( strcmp("vgroup=" MR_STRINGIFY(MR_CHAT_TYPE_VERIFIED_GROUP), "vgroup=130")==0 ); assert( strcmp("deaddrop=" MR_STRINGIFY(MR_CHAT_ID_DEADDROP), "deaddrop=1")==0 ); assert( strcmp("trash=" MR_STRINGIFY(MR_CHAT_ID_TRASH), "trash=3")==0 ); diff --git a/src/mrchat-private.h b/src/mrchat-private.h index 55bad072..032734ed 100644 --- a/src/mrchat-private.h +++ b/src/mrchat-private.h @@ -56,6 +56,10 @@ int mrchat_update_param__ (mrchat_t*); int mrchat_are_all_members_verified__ (mrchat_t*); +#define MR_CHAT_TYPE_IS_MULTI(a) ((a)==MR_CHAT_TYPE_GROUP || (a)==MR_CHAT_TYPE_VERIFIED_GROUP) +#define MR_CHAT_TYPE_CAN_SEND(a) ((a)==MR_CHAT_TYPE_SINGLE || (a)==MR_CHAT_TYPE_GROUP || (a)==MR_CHAT_TYPE_VERIFIED_GROUP) + + #define MR_CHAT_PREFIX "Chat:" /* you MUST NOT modify this or the following strings */ #define MR_CHATS_FOLDER "Chats" /* if we want to support Gma'l-labels - "Chats" is a reserved word for Gma'l */ diff --git a/src/mrchat.c b/src/mrchat.c index 77577bf7..34322acf 100644 --- a/src/mrchat.c +++ b/src/mrchat.c @@ -157,6 +157,9 @@ uint32_t mrchat_get_id(mrchat_t* chat) * - MR_CHAT_TYPE_GROUP (120) - a group chat, chats_contacts conain all group * members, incl. MR_CONTACT_ID_SELF * + * - MR_CHAT_TYPE_VERIFIED_GROUP (130) - a verified group chat. In verified groups, + * all members are verified and encryption is always active and cannot be disabled. + * * @memberof mrchat_t * * @param chat The chat object. @@ -241,7 +244,7 @@ char* mrchat_get_subtitle(mrchat_t* chat) mrsqlite3_unlock(chat->m_mailbox->m_sql); } - else if( chat->m_type == MR_CHAT_TYPE_GROUP ) + else if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { int cnt = 0; if( chat->m_id == MR_CHAT_ID_DEADDROP ) diff --git a/src/mrchat.h b/src/mrchat.h index 8d5482cd..bbd22bbb 100644 --- a/src/mrchat.h +++ b/src/mrchat.h @@ -38,9 +38,10 @@ typedef struct _mrmailbox mrmailbox_t; #define MR_CHAT_ID_LAST_SPECIAL 9 /* larger chat IDs are "real" chats, their messages are "real" messages. */ -#define MR_CHAT_TYPE_UNDEFINED 0 -#define MR_CHAT_TYPE_SINGLE 100 -#define MR_CHAT_TYPE_GROUP 120 +#define MR_CHAT_TYPE_UNDEFINED 0 +#define MR_CHAT_TYPE_SINGLE 100 +#define MR_CHAT_TYPE_GROUP 120 +#define MR_CHAT_TYPE_VERIFIED_GROUP 130 /** diff --git a/src/mrchatlist.c b/src/mrchatlist.c index 8f8718f5..c66d8d28 100644 --- a/src/mrchatlist.c +++ b/src/mrchatlist.c @@ -231,7 +231,7 @@ mrlot_t* mrchatlist_get_summary(mrchatlist_t* chatlist, size_t index, mrchat_t* lastmsg = mrmsg_new(); mrmsg_load_from_db__(lastmsg, chatlist->m_mailbox, lastmsg_id); - if( lastmsg->m_from_id != MR_CONTACT_ID_SELF && chat->m_type == MR_CHAT_TYPE_GROUP ) + if( lastmsg->m_from_id != MR_CONTACT_ID_SELF && MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { lastcontact = mrcontact_new(chatlist->m_mailbox); mrcontact_load_from_db__(lastcontact, chatlist->m_mailbox->m_sql, lastmsg->m_from_id); diff --git a/src/mrlot.c b/src/mrlot.c index 3905a51c..7c05e185 100644 --- a/src/mrlot.c +++ b/src/mrlot.c @@ -219,7 +219,7 @@ void mrlot_fill(mrlot_t* ths, const mrmsg_t* msg, const mrchat_t* chat, const mr ths->m_text1 = NULL; ths->m_text1_meaning = 0; } - else if( chat->m_type==MR_CHAT_TYPE_GROUP ) + else if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { if( contact==NULL ) { free(ths->m_text1); diff --git a/src/mrmailbox.c b/src/mrmailbox.c index 2807ff26..25f1f3b3 100644 --- a/src/mrmailbox.c +++ b/src/mrmailbox.c @@ -2242,7 +2242,12 @@ static uint32_t mrmailbox_send_msg_i__(mrmailbox_t* mailbox, mrchat_t* chat, con sqlite3_stmt* stmt; uint32_t msg_id = 0, to_id = 0; - if( chat->m_type==MR_CHAT_TYPE_GROUP && !mrmailbox_is_contact_in_chat__(mailbox, chat->m_id, MR_CONTACT_ID_SELF) ) { + if( !MR_CHAT_TYPE_CAN_SEND(chat->m_type) ) { + mrmailbox_log_error(mailbox, 0, "Cannot send to chat type #%i.", chat->m_type); + goto cleanup; + } + + if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) && !mrmailbox_is_contact_in_chat__(mailbox, chat->m_id, MR_CONTACT_ID_SELF) ) { mrmailbox_log_error(mailbox, MR_ERR_SELF_NOT_IN_GROUP, NULL); goto cleanup; } @@ -2253,7 +2258,7 @@ static uint32_t mrmailbox_send_msg_i__(mrmailbox_t* mailbox, mrchat_t* chat, con mrmailbox_log_error(mailbox, 0, "Cannot send message, not configured successfully."); goto cleanup; } - rfc724_mid = mr_create_outgoing_rfc724_mid(chat->m_type==MR_CHAT_TYPE_GROUP? chat->m_grpid : NULL, from); + rfc724_mid = mr_create_outgoing_rfc724_mid(MR_CHAT_TYPE_IS_MULTI(chat->m_type)? chat->m_grpid : NULL, from); free(from); } @@ -2268,7 +2273,7 @@ static uint32_t mrmailbox_send_msg_i__(mrmailbox_t* mailbox, mrchat_t* chat, con } to_id = sqlite3_column_int(stmt, 0); } - else if( chat->m_type == MR_CHAT_TYPE_GROUP ) + else if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { if( mrparam_get_int(chat->m_param, MRP_UNPROMOTED, 0)==1 ) { /* mark group as being no longer unpromoted */ @@ -2913,6 +2918,7 @@ void mrmailbox_set_group_explicitly_left__(mrmailbox_t* mailbox, const char* grp static int mrmailbox_real_group_exists__(mrmailbox_t* mailbox, uint32_t chat_id) { + // check if a group or a verified group exists under the given ID sqlite3_stmt* stmt; int ret = 0; @@ -2922,9 +2928,10 @@ static int mrmailbox_real_group_exists__(mrmailbox_t* mailbox, uint32_t chat_id) } stmt = mrsqlite3_predefine__(mailbox->m_sql, SELECT_id_FROM_chats_WHERE_id, - "SELECT id FROM chats WHERE id=? AND type=?;"); + "SELECT id FROM chats " + " WHERE id=? " + " AND (type=" MR_STRINGIFY(MR_CHAT_TYPE_GROUP) " OR type=" MR_STRINGIFY(MR_CHAT_TYPE_VERIFIED_GROUP) ");"); sqlite3_bind_int(stmt, 1, chat_id); - sqlite3_bind_int(stmt, 2, MR_CHAT_TYPE_GROUP); if( sqlite3_step(stmt) == SQLITE_ROW ) { ret = 1; @@ -2989,7 +2996,7 @@ uint32_t mrmailbox_create_group_chat(mrmailbox_t* mailbox, int verified, const c stmt = mrsqlite3_prepare_v2_(mailbox->m_sql, "INSERT INTO chats (type, name, draft_timestamp, draft_txt, grpid, param) VALUES(?, ?, ?, ?, ?, 'U=1');" /*U=MRP_UNPROMOTED*/ ); - sqlite3_bind_int (stmt, 1, MR_CHAT_TYPE_GROUP); + sqlite3_bind_int (stmt, 1, verified? MR_CHAT_TYPE_VERIFIED_GROUP : MR_CHAT_TYPE_GROUP); sqlite3_bind_text (stmt, 2, chat_name, -1, SQLITE_STATIC); sqlite3_bind_int64(stmt, 3, time(NULL)); sqlite3_bind_text (stmt, 4, draft_txt, -1, SQLITE_STATIC); diff --git a/src/mrmailbox_receive_imf.c b/src/mrmailbox_receive_imf.c index 9b567ae8..01f6b879 100644 --- a/src/mrmailbox_receive_imf.c +++ b/src/mrmailbox_receive_imf.c @@ -371,7 +371,7 @@ static mrarray_t* search_chat_ids_by_contact_ids(mrmailbox_t* mailbox, const mra " FROM chats_contacts cc " " LEFT JOIN chats c ON c.id=cc.chat_id " " WHERE cc.chat_id IN(SELECT chat_id FROM chats_contacts WHERE contact_id IN(%s))" - " AND c.type=" MR_STRINGIFY(MR_CHAT_TYPE_GROUP) /* do not select normal chats which are equal to a group with a single member and without SELF */ + " AND c.type=" MR_STRINGIFY(MR_CHAT_TYPE_GROUP) /* no verified groups and no single chats (which are equal to a group with a single member and without SELF) */ " AND cc.contact_id!=" MR_STRINGIFY(MR_CONTACT_ID_SELF) /* ignore SELF, we've also removed it above - if the user has left the group, it is still the same group */ " ORDER BY cc.chat_id, cc.contact_id;", contact_ids_str); diff --git a/src/mrmimefactory.c b/src/mrmimefactory.c index 34af3e93..4947c50d 100644 --- a/src/mrmimefactory.c +++ b/src/mrmimefactory.c @@ -418,7 +418,7 @@ static char* get_subject(const mrchat_t* chat, const mrmsg_t* msg, int afwd_emai { ret = mrstock_str(MR_STR_AC_SETUP_MSG_SUBJECT); /* do not add the "Chat:" prefix for setup messages */ } - else if( chat->m_type==MR_CHAT_TYPE_GROUP ) + else if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { ret = mr_mprintf(MR_CHAT_PREFIX " %s: %s%s", chat->m_name, fwd, raw_subject); } @@ -523,7 +523,7 @@ int mrmimefactory_render(mrmimefactory_t* factory) /* build header etc. */ int command = mrparam_get_int(msg->m_param, MRP_CMD, 0); - if( chat->m_type==MR_CHAT_TYPE_GROUP ) + if( MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-ID"), safe_strdup(chat->m_grpid))); mailimf_fields_add(imf_fields, mailimf_field_new_custom(strdup("Chat-Group-Name"), mr_encode_header_string(chat->m_name))); diff --git a/src/mrmsg.c b/src/mrmsg.c index e9a1e614..e5650beb 100644 --- a/src/mrmsg.c +++ b/src/mrmsg.c @@ -641,7 +641,7 @@ mrlot_t* mrmsg_get_summary(const mrmsg_t* msg, const mrchat_t* chat) chat = chat_to_delete; } - if( msg->m_from_id != MR_CONTACT_ID_SELF && chat->m_type == MR_CHAT_TYPE_GROUP ) { + if( msg->m_from_id != MR_CONTACT_ID_SELF && MR_CHAT_TYPE_IS_MULTI(chat->m_type) ) { contact = mrmailbox_get_contact(chat->m_mailbox, msg->m_from_id); }