File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,13 @@ type WebViewOutboundEventTimeDetails = {|
132
132
originalText : string ,
133
133
| } ;
134
134
135
+ type WebViewOutboundEventVote = { |
136
+ type : 'vote' ,
137
+ messageId : number ,
138
+ key : string ,
139
+ vote : number ,
140
+ | } ;
141
+
135
142
export type WebViewOutboundEvent =
136
143
| WebViewOutboundEventReady
137
144
| WebViewOutboundEventScroll
@@ -146,7 +153,8 @@ export type WebViewOutboundEvent =
146
153
| WebViewOutboundEventWarn
147
154
| WebViewOutboundEventError
148
155
| WebViewOutboundEventMention
149
- | WebViewOutboundEventTimeDetails ;
156
+ | WebViewOutboundEventTimeDetails
157
+ | WebViewOutboundEventVote ;
150
158
151
159
// TODO: Consider completing this and making it exact, once
152
160
// `MessageList`'s props are type-checked.
@@ -313,6 +321,19 @@ export const handleWebViewOutboundEvent = (
313
321
break ;
314
322
}
315
323
324
+ case 'vote' : {
325
+ api . sendSubmessage (
326
+ props . backgroundData . auth ,
327
+ event . messageId ,
328
+ JSON . stringify ( {
329
+ type : 'vote' ,
330
+ key : event . key ,
331
+ vote : event . vote ,
332
+ } ) ,
333
+ ) ;
334
+ break ;
335
+ }
336
+
316
337
case 'debug' :
317
338
console . debug ( props , event ) ; // eslint-disable-line
318
339
break ;
Original file line number Diff line number Diff line change @@ -993,6 +993,26 @@ var compiledWebviewJs = (function (exports) {
993
993
return;
994
994
}
995
995
996
+ if (target.matches('.poll-vote')) {
997
+ var _messageElement = target.closest('.message');
998
+
999
+ if (!_messageElement) {
1000
+ throw new Error('Message element not found');
1001
+ }
1002
+
1003
+ var current_vote = requireAttribute(target, 'data-voted') === 'true';
1004
+ var vote = current_vote ? -1 : 1;
1005
+ sendMessage({
1006
+ type: 'vote',
1007
+ messageId: requireNumericAttribute(_messageElement, 'data-msg-id'),
1008
+ key: requireAttribute(target, 'data-key'),
1009
+ vote: vote
1010
+ });
1011
+ target.setAttribute('data-voted', (!current_vote).toString());
1012
+ target.innerText = (parseInt(target.innerText, 10) + vote).toString();
1013
+ return;
1014
+ }
1015
+
996
1016
if (target.matches('time')) {
997
1017
var originalText = requireAttribute(target, 'original-text');
998
1018
sendMessage({
Original file line number Diff line number Diff line change @@ -918,6 +918,27 @@ documentBody.addEventListener('click', (e: MouseEvent) => {
918
918
return ;
919
919
}
920
920
921
+ if ( target . matches ( '.poll-vote' ) ) {
922
+ const messageElement = target . closest ( '.message' ) ;
923
+ if ( ! messageElement ) {
924
+ throw new Error ( 'Message element not found' ) ;
925
+ }
926
+ // This duplicates some logic from PollData.handle.vote.outbound in
927
+ // @zulip /shared/js/poll_data.js, but it's much simpler to just duplicate
928
+ // it than it is to thread a callback all the way over here.
929
+ const current_vote = requireAttribute ( target , 'data-voted' ) === 'true' ;
930
+ const vote = current_vote ? - 1 : 1 ;
931
+ sendMessage ( {
932
+ type : 'vote' ,
933
+ messageId : requireNumericAttribute ( messageElement , 'data-msg-id' ) ,
934
+ key : requireAttribute ( target , 'data-key' ) ,
935
+ vote,
936
+ } ) ;
937
+ target . setAttribute ( 'data-voted' , ( ! current_vote ) . toString ( ) ) ;
938
+ target . innerText = ( parseInt ( target . innerText , 10 ) + vote ) . toString ( ) ;
939
+ return ;
940
+ }
941
+
921
942
if ( target . matches ( 'time' ) ) {
922
943
const originalText = requireAttribute ( target , 'original-text' ) ;
923
944
sendMessage ( {
You can’t perform that action at this time.
0 commit comments