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 @@ -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 @@ -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