Add common utility for checking 3pid invites

We just need to make sure they are structurally sound - actual validation is done by other parties.
This commit is contained in:
Travis Ralston 2019-03-29 11:45:07 -06:00
parent 5beec37c43
commit 42cfe74f70
4 changed files with 26 additions and 9 deletions

View file

@ -65,6 +65,24 @@ export function showRoomInviteDialog(roomId) {
});
}
/**
* Checks if the given MatrixEvent is a valid 3rd party user invite.
* @param {MatrixEvent} event The event to check
* @returns {boolean} True if valid, false otherwise
*/
export function isValid3pidInvite(event) {
if (!event || event.getType() !== "m.room.third_party_invite") return false;
// any events without these keys are not valid 3pid invites, so we ignore them
const requiredKeys = ['key_validity_url', 'public_key', 'display_name'];
for (let i = 0; i < requiredKeys.length; ++i) {
if (!event.getContent()[requiredKeys[i]]) return false;
}
// Valid enough by our standards
return true;
}
function _onStartChatFinished(shouldInvite, addrs) {
if (!shouldInvite) return;