Skip to content

Add support for virtualUsers (Matrix)

Eric Eastwood requested to merge matrix-virtual-users into develop

Add support for virtualUsers (Matrix)

Fix https://gitlab.com/gitlab-org/gitter/webapp/-/issues/1076

Dev notes

"virtualUser": {
	"type": "matrix",
	"externalId": "madlittlemods:matrix.org",
	"displayName": "madlittlemods (Eric Eastwood)",
	"avatarUrl": "https://matrix-client.matrix.org/_matrix/media/r0/thumbnail/matrix.org/bDayqThxTIcGNcskzIADknRv?width=30&height=30&method=crop"
},

Matrix avatars

https://matrix.org/docs/api/client-server/#!/User32data/getAvatarUrl

https://matrix-client.matrix.org/_matrix/client/r0/profile/%40madlittlemods%3Amatrix.org/avatar_url
{
        // Where `matrix.org` and `bDayqThxTIcGNcskzIADknRv` are used in the next media request
	"avatar_url": "mxc://matrix.org/bDayqThxTIcGNcskzIADknRv"
}

https://matrix-client.matrix.org/_matrix/media/r0/thumbnail/matrix.org/bDayqThxTIcGNcskzIADknRv?width=30&height=30&method=crop

Todo

  • Add flair/badges
  • Threaded conversation
  • Add tests
  • Create matrix-bridge-prod, matrix-bridge-beta OAuth clients

Future iterations (will create follow-up issues for these):

Testing strategy

  1. Create the OAuth client
    db.oauthclients.insert({
    	clientKey: 'matrix-bridge-dev',
    	clientSecret: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
    	name: 'Matrix bridge OAuth app',
    	tag: 'matrix-bridge-dev'
    })
  2. Create a OAuth access token to use in our bridge
    db.oauthaccesstokens.insert({
    	token: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
    	clientId: db.oauthclients.findOne({clientKey: 'matrix-bridge-dev' })._id,
    	userId: db.users.findOne({ username: 'gitter-badger' })._id
    })
  3. You can find the token you just inserted with db.oauthaccesstokens.find({ clientId: db.oauthclients.findOne({clientKey: 'matrix-bridge-dev' })._id }, { token: 1 })
  4. Test sending a message POST http://localhost:5000/api/v1/rooms/5f7e2bc53279998d575e3546/chatMessages(Authorization: Bearer xxx, Content-Type: application/json) with body:
    {
    	"virtualUser": {
    		"type": "matrix",
    		"externalId": "madlittlemods:matrix.org",
    		"displayName": "madlittlemods (Eric Eastwood)",
    		"avatarUrl": "https://matrix-client.matrix.org/_matrix/media/r0/thumbnail/matrix.org/bDayqThxTIcGNcskzIADknRv?width=30&height=30&method=crop"
    	},
    	"text": "some message"
    }
  5. To test with threaded conversations: Find a message to thread on and add parentId: <that parent message ID> to the request above

  • virtual users
Edited by Eric Eastwood

Merge request reports