HomePhabricator
Diffusion Comm d626ec3e0a61

[lib] introduce new updateRolesAndPermissions migration util

Description

[lib] introduce new updateRolesAndPermissions migration util

Summary:
The last step for introducing the communities table in the keyserver + tagging farcaster channel project is we need to introduce a new permission to manage the farcaster channel tags. Part of this task will be to perform a redux migrations so that native clients add this permission manage farcaster tag permission. However, as part of the work to minimally encode the permissions, updateRolesAndPermissions became legacyUpdateRolesAndPermissions since it was dealing with the LegacyRawThreadInfo. Discussed this with @ashoat and we came up with a plan for the new updateRolesAndPermissions method:

  1. Call decodeMinimallyEncodedRawThreadInfo to decode all thread infos into LegacyRawThreadInfo
  2. Call legacyUpdateRolesAndPermissions to perform the migration
  3. Call minimallyEncodeRawThreadInfo to re-encode the threadinfos from LegacyRawThreadInfo into a RawThreadInfo

Depends on D12390

Test Plan:
Ran the migration in the very next diff and logged out threadStoreInfos at the very beginning of the method and then logged out updatedThreadStoreInfos at the very end of the method. Put both logs into a json compare tool and the diff between the two json objects looked reasonable.

threadStoreInfos:

{
	"256|1": {
		"minimallyEncoded": true,
		"id": "256|1",
		"type": 12,
		"name": "GENESIS",
		"description": "This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"members": [
			{
				"id": "256",
				"role": "256|83796",
				"permissions": "3f73ff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83795",
				"permissions": "3",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83795": {
				"id": "256|83795",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83796": {
				"id": "256|83796",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83795",
			"permissions": "3",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83815": {
		"minimallyEncoded": true,
		"id": "256|83815",
		"type": 6,
		"name": "",
		"description": "",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"members": [
			{
				"id": "256",
				"role": "256|83817",
				"permissions": "2f7fff",
				"isSender": true,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83817",
				"permissions": "3027f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83817": {
				"id": "256|83817",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"090",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83817",
			"permissions": "3027f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83816": {
		"minimallyEncoded": true,
		"id": "256|83816",
		"type": 7,
		"name": "",
		"description": "This is your private chat, where you can set reminders and jot notes in private!",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"members": [
			{
				"id": "256",
				"role": null,
				"permissions": "2c7fff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83818",
				"permissions": "3026f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83818": {
				"id": "256|83818",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"060",
					"050",
					"090",
					"030",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83818",
			"permissions": "3026f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	},
	"256|83885": {
		"minimallyEncoded": true,
		"id": "256|83885",
		"type": 8,
		"name": "Run club",
		"description": "",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"members": [
			{
				"id": "83810",
				"role": "256|83887",
				"permissions": "3ff3ff",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83886": {
				"id": "256|83886",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7",
					"090",
					"0f0",
					"0a9",
					"020",
					"100",
					"110",
					"0c0",
					"0c9",
					"030",
					"040",
					"050",
					"060",
					"080",
					"120"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83887": {
				"id": "256|83887",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156",
					"0f0"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83887",
			"permissions": "3ff3ff",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		},
		"repliesCount": 0,
		"pinnedCount": 0
	}
}

updatedThreadStoreInfos:

{
	"256|1": {
		"id": "256|1",
		"type": 12,
		"name": "GENESIS",
		"description": "This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": "256|83796",
				"permissions": "7f73ff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83795",
				"permissions": "3",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83795": {
				"id": "256|83795",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83796": {
				"id": "256|83796",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"160",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83795",
			"permissions": "3",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83815": {
		"id": "256|83815",
		"type": 6,
		"name": "",
		"description": "",
		"color": "5c9f5f",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": "256|83817",
				"permissions": "2f7fff",
				"isSender": true,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83817",
				"permissions": "3027f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83817": {
				"id": "256|83817",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"090",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83817",
			"permissions": "3027f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83816": {
		"id": "256|83816",
		"type": 7,
		"name": "",
		"description": "This is your private chat, where you can set reminders and jot notes in private!",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": "256|1",
		"containingThreadID": "256|1",
		"community": "256|1",
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "256",
				"role": null,
				"permissions": "2c7fff",
				"isSender": false,
				"minimallyEncoded": true
			},
			{
				"id": "83810",
				"role": "256|83818",
				"permissions": "3026f",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83818": {
				"id": "256|83818",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"060",
					"050",
					"090",
					"030",
					"005",
					"015",
					"0a9"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			}
		},
		"currentUser": {
			"role": "256|83818",
			"permissions": "3026f",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	},
	"256|83885": {
		"id": "256|83885",
		"type": 8,
		"name": "Run club",
		"description": "",
		"color": "575757",
		"creationTime": 4797702872,
		"parentThreadID": null,
		"containingThreadID": null,
		"community": null,
		"repliesCount": 0,
		"pinnedCount": 0,
		"minimallyEncoded": true,
		"members": [
			{
				"id": "83810",
				"role": "256|83887",
				"permissions": "7ff3ff",
				"isSender": false,
				"minimallyEncoded": true
			}
		],
		"roles": {
			"256|83886": {
				"id": "256|83886",
				"name": "Members",
				"permissions": [
					"000",
					"010",
					"005",
					"015",
					"0a7",
					"090",
					"0f0",
					"0a9",
					"020",
					"100",
					"110",
					"0c0",
					"0c9",
					"030",
					"040",
					"050",
					"060",
					"080",
					"120"
				],
				"minimallyEncoded": true,
				"specialRole": 1
			},
			"256|83887": {
				"id": "256|83887",
				"name": "Admins",
				"permissions": [
					"000",
					"010",
					"020",
					"100",
					"110",
					"030",
					"040",
					"060",
					"050",
					"120",
					"080",
					"090",
					"0c0",
					"070",
					"0d0",
					"0e0",
					"130",
					"140",
					"150",
					"160",
					"004",
					"014",
					"0a6",
					"0a8",
					"024",
					"034",
					"044",
					"064",
					"054",
					"124",
					"086",
					"096",
					"0c4",
					"074",
					"0b4",
					"0d4",
					"0e4",
					"134",
					"156",
					"0f0"
				],
				"minimallyEncoded": true,
				"specialRole": 2
			}
		},
		"currentUser": {
			"role": "256|83887",
			"permissions": "7ff3ff",
			"subscription": {
				"home": true,
				"pushNotifs": true
			},
			"unread": false,
			"minimallyEncoded": true
		}
	}
}

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D12061

Details

Provenance
ginsuAuthored on Jun 11 2024, 11:13 AM
Reviewer
ashoat
Differential Revision
D12061: [lib] introduce new updateRolesAndPermissions migration util
Parents
rCOMM102c5dab4efe: [lib/native] lift legacyUpdateRolesAndPermissions into lib
Branches
Unknown
Tags
Unknown