Fix demoting users during backfill
This commit is contained in:
		
							parent
							
								
									0c1a015222
								
							
						
					
					
						commit
						3ec0dc718e
					
				
					 1 changed files with 5 additions and 2 deletions
				
			
		|  | @ -194,10 +194,13 @@ async function syncUser(user, member, channel, guild, roomID) { | ||||||
| 	const currentHash = _hashProfileContent(content, powerLevel) | 	const currentHash = _hashProfileContent(content, powerLevel) | ||||||
| 	const existingHash = select("sim_member", "hashed_profile_content", {room_id: roomID, mxid}).safeIntegers().pluck().get() | 	const existingHash = select("sim_member", "hashed_profile_content", {room_id: roomID, mxid}).safeIntegers().pluck().get() | ||||||
| 	// only do the actual sync if the hash has changed since we last looked
 | 	// only do the actual sync if the hash has changed since we last looked
 | ||||||
| 	if (existingHash !== currentHash) { | 	const hashHasChanged = existingHash !== currentHash | ||||||
|  | 	// however, do not overwrite pre-existing data if we already have data and `member` is not accessible, because this would replace good data with bad data
 | ||||||
|  | 	const wouldOverwritePreExisting = existingHash && !member | ||||||
|  | 	if (hashHasChanged && !wouldOverwritePreExisting) { | ||||||
| 		// Update room member state
 | 		// Update room member state
 | ||||||
| 		await api.sendState(roomID, "m.room.member", mxid, content, mxid) | 		await api.sendState(roomID, "m.room.member", mxid, content, mxid) | ||||||
| 		// Update power levels
 | 		// Update power levels (only if we can actually access the member roles)
 | ||||||
| 		const powerLevelsStateContent = await api.getStateEvent(roomID, "m.room.power_levels", "") | 		const powerLevelsStateContent = await api.getStateEvent(roomID, "m.room.power_levels", "") | ||||||
| 		const oldPowerLevel = powerLevelsStateContent.users?.[mxid] || 0 | 		const oldPowerLevel = powerLevelsStateContent.users?.[mxid] || 0 | ||||||
| 		mixin(powerLevelsStateContent, {users: {[mxid]: powerLevel}}) | 		mixin(powerLevelsStateContent, {users: {[mxid]: powerLevel}}) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue