sparkle icon indicating copy to clipboard operation
sparkle copied to clipboard

[chat] As an admin, I want to be able to convert a chat message to a question (and vice versa)

Open yarikoptic opened this issue 4 years ago • 1 comments
trafficstars

didn't look inside but visually it is just style/color (class?) change. Naive attendees post questions as regular messages, being able to convert to a question (or back) would be a nice feature.

yarikoptic avatar Jun 23 '21 22:06 yarikoptic

Sounds like a reasonable feature/thing to be able to support :)


It seems isQuestion is defined on BaseChatMessage:

  • https://github.com/sparkletown/sparkle/blob/staging/src/types/chat.ts#L11-L18

ChatMessageBox receives isQuestion which is used in sendMessageToChat as sendMessage({ message, isQuestion });

  • https://github.com/sparkletown/sparkle/blob/staging/src/components/molecules/ChatMessageBox/ChatMessageBox.tsx#L67

sendMessage is passed into ChatMessageBox as a prop from Chatbox, which is provided to it via it's own props, which come from either VenueChat / RecipientChat (though only VenueChat supports questions really..)

  • https://github.com/sparkletown/sparkle/blob/staging/src/components/molecules/Chatbox/Chatbox.tsx#L121

VenueChat gets sendMessage from useVenueChat

This ends up calling buildMessage from utils/chat.ts, then calls sendVenueMessage, defined in src/api/chat.ts:

  • https://github.com/sparkletown/sparkle/blob/staging/src/utils/chat.ts#L79-L84
  • https://github.com/sparkletown/sparkle/blob/staging/src/api/chat.ts#L16-L60

This then writes to the following locations in the firestore database:

  • sendVenueMessage: /venues/:venueId/chats/:messageId

You can see the rules that relate to whether this can be edited/etc from the frontend in firestore.rules

  • https://github.com/sparkletown/sparkle/blob/staging/firestore.rules#L62-L66

Essentially it can be 'updated' by admin/owners, when isUpdateRestrictedToField(request, 'deleted') is true.

isUpdateRestrictedToField is defined in the same firestore.rules file:

  • https://github.com/sparkletown/sparkle/blob/staging/firestore.rules#L3-L5

Currently it looks like it only supports one field being checked, but it would be a fairly easy change to support different checks as needed. Reference docs for the firebase rules SDK are here:

  • https://firebase.google.com/docs/reference/rules/rules.Map#diff
  • https://firebase.google.com/docs/reference/rules/rules.MapDiff#affectedKeys
  • https://firebase.google.com/docs/reference/rules/rules.Set

Then obviously appropriate UI/etc things would need to be done to support this being done in a clean/sparkly way.

Hope this helps! :)

0xdevalias avatar Jun 24 '21 03:06 0xdevalias