File tree Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,13 @@ type WebViewOutboundEventTimeDetails = {|
131
131
originalText : string ,
132
132
| } ;
133
133
134
+ type WebViewOutboundEventVote = { |
135
+ type : 'vote' ,
136
+ messageId : number ,
137
+ key : string ,
138
+ vote : number ,
139
+ | } ;
140
+
134
141
export type WebViewOutboundEvent =
135
142
| WebViewOutboundEventReady
136
143
| WebViewOutboundEventScroll
@@ -145,7 +152,8 @@ export type WebViewOutboundEvent =
145
152
| WebViewOutboundEventWarn
146
153
| WebViewOutboundEventError
147
154
| WebViewOutboundEventMention
148
- | WebViewOutboundEventTimeDetails ;
155
+ | WebViewOutboundEventTimeDetails
156
+ | WebViewOutboundEventVote ;
149
157
150
158
// TODO: Consider completing this and making it exact, once
151
159
// `MessageList`'s props are type-checked.
@@ -311,6 +319,19 @@ export const handleWebViewOutboundEvent = (
311
319
break ;
312
320
}
313
321
322
+ case 'vote' : {
323
+ api . sendSubmessage (
324
+ props . backgroundData . auth ,
325
+ event . messageId ,
326
+ JSON . stringify ( {
327
+ type : 'vote' ,
328
+ key : event . key ,
329
+ vote : event . vote ,
330
+ } ) ,
331
+ ) ;
332
+ break ;
333
+ }
334
+
314
335
case 'debug' :
315
336
console . debug ( props , event ) ; // eslint-disable-line
316
337
break ;
Original file line number Diff line number Diff line change @@ -980,6 +980,27 @@ var compiledWebviewJs = (function (exports) {
980
980
return;
981
981
}
982
982
983
+ if (target.matches('.poll-vote')) {
984
+ var _messageElement = target.closest('.message');
985
+
986
+ if (_messageElement) {
987
+ var current_vote = requireAttribute(target, 'data-voted') === 'true';
988
+ var vote = current_vote ? -1 : 1;
989
+ sendMessage({
990
+ type: 'vote',
991
+ messageId: requireNumericAttribute(_messageElement, 'data-msg-id'),
992
+ key: requireAttribute(target, 'data-key'),
993
+ vote: vote
994
+ });
995
+ target.setAttribute('data-voted', (!current_vote).toString());
996
+ target.innerText = (parseInt(target.innerText, 10) + vote).toString();
997
+ } else {
998
+ throw new Error('Message element not found');
999
+ }
1000
+
1001
+ return;
1002
+ }
1003
+
983
1004
if (target.matches('time')) {
984
1005
var originalText = requireAttribute(target, 'original-text');
985
1006
sendMessage({
Original file line number Diff line number Diff line change @@ -904,6 +904,27 @@ documentBody.addEventListener('click', (e: MouseEvent) => {
904
904
return ;
905
905
}
906
906
907
+ if ( target . matches ( '.poll-vote' ) ) {
908
+ const messageElement = target . closest ( '.message' ) ;
909
+ if ( ! messageElement ) {
910
+ throw new Error ( 'Message element not found' ) ;
911
+ }
912
+ // This duplicates some logic from PollData.handle.vote.outbound, but it's
913
+ // much simpler to just duplicate it than it is to thread a callback all
914
+ // the way over here.
915
+ const current_vote = requireAttribute ( target , 'data-voted' ) === 'true' ;
916
+ const vote = current_vote ? - 1 : 1 ;
917
+ sendMessage ( {
918
+ type : 'vote' ,
919
+ messageId : requireNumericAttribute ( messageElement , 'data-msg-id' ) ,
920
+ key : requireAttribute ( target , 'data-key' ) ,
921
+ vote,
922
+ } ) ;
923
+ target . setAttribute ( 'data-voted' , ( ! current_vote ) . toString ( ) ) ;
924
+ target . innerText = ( parseInt ( target . innerText , 10 ) + vote ) . toString ( ) ;
925
+ return ;
926
+ }
927
+
907
928
if ( target . matches ( 'time' ) ) {
908
929
const originalText = requireAttribute ( target , 'original-text' ) ;
909
930
sendMessage ( {
You can’t perform that action at this time.
0 commit comments