forked from cory/tildefriends
		
	Fix feed replication. Ugh, Cory.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4104 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		| @@ -320,6 +320,9 @@ function ebtReplicateServer(request) { | |||||||
| ssb.addRpc(['ebt', 'replicate'], ebtReplicateServer); | ssb.addRpc(['ebt', 'replicate'], ebtReplicateServer); | ||||||
|  |  | ||||||
| ssb.addRpc(['createHistoryStream'], function(request) { | ssb.addRpc(['createHistoryStream'], function(request) { | ||||||
|  | 	if (!request?.args) { | ||||||
|  | 		print('missing request.args in createHistoryStream'); | ||||||
|  | 	} | ||||||
| 	var id = request.args[0].id; | 	var id = request.args[0].id; | ||||||
| 	var seq = request.args[0].seq; | 	var seq = request.args[0].seq; | ||||||
| 	var keys = request.args[0].keys || request.args[0].keys === undefined; | 	var keys = request.args[0].keys || request.args[0].keys === undefined; | ||||||
|   | |||||||
							
								
								
									
										50
									
								
								src/ssb.db.c
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								src/ssb.db.c
									
									
									
									
									
								
							| @@ -1010,9 +1010,15 @@ static following_t* _get_following(tf_ssb_t* ssb, const char* id, following_t*** | |||||||
| { | { | ||||||
| 	int index = tf_util_insert_index(id, *following, *following_count, sizeof(following_t*), _following_compare); | 	int index = tf_util_insert_index(id, *following, *following_count, sizeof(following_t*), _following_compare); | ||||||
| 	following_t* entry = NULL; | 	following_t* entry = NULL; | ||||||
|  | 	bool already_populated = false; | ||||||
| 	if (index < *following_count && strcmp(id, (*following)[index]->id) == 0) | 	if (index < *following_count && strcmp(id, (*following)[index]->id) == 0) | ||||||
| 	{ | 	{ | ||||||
| 		entry = (*following)[index]; | 		entry = (*following)[index]; | ||||||
|  | 		already_populated = entry->depth < max_depth; | ||||||
|  | 		if (depth < entry->depth) | ||||||
|  | 		{ | ||||||
|  | 			entry->depth = depth; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @@ -1027,40 +1033,40 @@ static following_t* _get_following(tf_ssb_t* ssb, const char* id, following_t*** | |||||||
| 		memset(entry, 0, sizeof(*entry)); | 		memset(entry, 0, sizeof(*entry)); | ||||||
| 		snprintf(entry->id, sizeof(entry->id), "%s", id); | 		snprintf(entry->id, sizeof(entry->id), "%s", id); | ||||||
| 		entry->depth = depth; | 		entry->depth = depth; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 		if (depth < max_depth) | 	if (depth < max_depth && !already_populated) | ||||||
|  | 	{ | ||||||
|  | 		sqlite3* db = tf_ssb_get_db(ssb); | ||||||
|  | 		sqlite3_stmt* statement = NULL; | ||||||
|  | 		if (sqlite3_prepare(db, "SELECT json_extract(content, '$.contact'), json_extract(content, '$.following'), json_extract(content, '$.blocking') FROM messages WHERE author = ? AND json_extract(content, '$.type') = 'contact' ORDER BY sequence", -1, &statement, NULL) == SQLITE_OK) | ||||||
| 		{ | 		{ | ||||||
| 			sqlite3* db = tf_ssb_get_db(ssb); | 			if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK) | ||||||
| 			sqlite3_stmt* statement = NULL; |  | ||||||
| 			if (sqlite3_prepare(db, "SELECT json_extract(content, '$.contact'), json_extract(content, '$.following'), json_extract(content, '$.blocking') FROM messages WHERE author = ? AND json_extract(content, '$.type') = 'contact' ORDER BY sequence", -1, &statement, NULL) == SQLITE_OK) |  | ||||||
| 			{ | 			{ | ||||||
| 				if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK) | 				while (sqlite3_step(statement) == SQLITE_ROW) | ||||||
| 				{ | 				{ | ||||||
| 					while (sqlite3_step(statement) == SQLITE_ROW) | 					const char* contact = (const char*)sqlite3_column_text(statement, 0); | ||||||
|  | 					if (sqlite3_column_type(statement, 1) != SQLITE_NULL) | ||||||
| 					{ | 					{ | ||||||
| 						const char* contact = (const char*)sqlite3_column_text(statement, 0); | 						bool is_following = sqlite3_column_int(statement, 1); | ||||||
| 						if (sqlite3_column_type(statement, 1) != SQLITE_NULL) | 						following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, max_depth); | ||||||
|  | 						if (is_following) | ||||||
| 						{ | 						{ | ||||||
| 							bool is_following = sqlite3_column_int(statement, 1); | 							_add_following_entry(&entry->following, &entry->following_count, next); | ||||||
| 							following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, max_depth); |  | ||||||
| 							if (is_following) |  | ||||||
| 							{ |  | ||||||
| 								_add_following_entry(&entry->following, &entry->following_count, next); |  | ||||||
| 							} |  | ||||||
| 						} | 						} | ||||||
| 						if (sqlite3_column_type(statement, 2) != SQLITE_NULL) | 					} | ||||||
|  | 					if (sqlite3_column_type(statement, 2) != SQLITE_NULL) | ||||||
|  | 					{ | ||||||
|  | 						bool is_blocking = sqlite3_column_int(statement, 2); | ||||||
|  | 						following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, 0 /* don't dig deeper into blocked users */); | ||||||
|  | 						if (is_blocking) | ||||||
| 						{ | 						{ | ||||||
| 							bool is_blocking = sqlite3_column_int(statement, 2); | 							_add_following_entry(&entry->blocking, &entry->blocking_count, next); | ||||||
| 							following_t* next = _get_following(ssb, contact, following, following_count, depth + 1, 0 /* don't dig deeper into blocked users */); |  | ||||||
| 							if (is_blocking) |  | ||||||
| 							{ |  | ||||||
| 								_add_following_entry(&entry->blocking, &entry->blocking_count, next); |  | ||||||
| 							} |  | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				sqlite3_finalize(statement); |  | ||||||
| 			} | 			} | ||||||
|  | 			sqlite3_finalize(statement); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return entry; | 	return entry; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user