Skip to content

Commit

Permalink
some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Jan 29, 2018
1 parent d0f4b4a commit 3c43b0b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ app.on 'ready', ->

ipc.on 'modifyotrstatus', seqreq (ev, conv_id, otr) ->
client.modifyotrstatus conv_id, otr, false, (ev, conv_id, otr) -> conv_id
.then (r) ->
ipcsend 'handlemodifyotrstatus', r

# retry
ipc.on 'deleteconversation', seqreq (ev, conv_id) ->
Expand Down Expand Up @@ -442,6 +444,7 @@ app.on 'ready', ->
# propagate these events to the renderer
require('./ui/events').forEach (n) ->
client.on n, (e) ->
console.log 'New event:', n, e
ipcsend n, e

# Emitted when the window is about to close.
Expand Down
17 changes: 14 additions & 3 deletions src/ui/dispatcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ handle 'attop', (attop) ->
viewstate.updateAtTop attop
conv.updateAtTop attop

handle 'history', (conv_id, timestamp) ->
ipc.send 'getconversation', conv_id, timestamp, 20
handle 'history', (conv_id, timestamp, size = 20) ->
ipc.send 'getconversation', conv_id, timestamp, size

handle 'handleconversationmetadata', (r) ->
return unless r.conversation_state
Expand All @@ -111,6 +111,7 @@ handle 'handleconversationmetadata', (r) ->
conv.updateMetadata r.conversation_state

handle 'handlehistory', (r) ->
console.log('handle history:', r.conversation_state)
return unless r.conversation_state
conv.updateHistory r.conversation_state

Expand Down Expand Up @@ -372,9 +373,15 @@ handle 'toggleotr', ->
conv_id = viewstate.selectedConv
return unless c = conv[conv_id]
q = conv.isOnTheRecord(c)
console.log('is on the record?', q)
ipc.send 'modifyotrstatus', conv_id, (if q then OFF_THE_RECORD else ON_THE_RECORD)
conv.toggleOtr(c)

handle 'handlemodifyotrstatus', (r) ->
later ->
console.log 'Handling modifyotrstatus', r
#action 'history', conv_id, Date.now() * 1000, 1

handle 'togglestar', ->
conv_id = viewstate.selectedConv
return unless c = conv[conv_id]
Expand Down Expand Up @@ -450,7 +457,11 @@ handle 'client_conversation', (c) ->
# Conversation must be added, even if already exists
# why? because when a new chat message for a new conversation appears
# a skeleton is made of a conversation
conv.add c unless conv[c?.conversation_id?.id]?.participant_data?
unless conv[c?.conversation_id?.id]?.participant_data?
conv.add c
else
later ->
action 'history', c.conversation_id.id, c._header.current_server_time, 1

handle 'hangout_event', (e) ->
return unless e?.hangout_event?.event_type in ['START_HANGOUT', 'END_HANGOUT']
Expand Down
13 changes: 12 additions & 1 deletion src/ui/models/conv.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ funcs =
return unless c = lookup[conv_id]

c.read_state = state.conversation?.read_state ? c.read_state
c.otr_status = state.conversation?.otr_status ? c.otr_status


@redraw_conversation() if redraw

Expand All @@ -352,6 +354,13 @@ funcs =
# as when we injected DOM.
updated 'afterHistory'

mergeEvents: (event, c) ->
newEvents = {}
for e in (event ? []).concat (c.event ? [])
newEvents[e.event_id] = e
return Object.values(newEvents).sort (a,b) ->
a.advances_sort_timestamp - b.advances_sort_timestamp

updateHistory: (state) ->
conv_id = state?.conversation_id?.id
return unless c = lookup[conv_id]
Expand All @@ -360,7 +369,9 @@ funcs =

@updateMetadata(state, false)

c.event = (event ? []).concat (c.event ? [])
console.log 'merging history'
c.event = @mergeEvents(event, c)
#c.event = (event ? []).concat (c.event ? [])
c.nomorehistory = true if event?.length == 0

@redraw_conversation()
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/convlist.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = view (models) ->
if starred.length > 0
div class: 'label', i18n.__ 'recent:Recent'
others.forEach renderConv
console.log('Conversation_list:', debug_convs) if window.debug_flag
# console.log('Conversation_list:', debug_convs) if window.debug_flag

# possible classes of messages
MESSAGE_CLASSES = ['placeholder', 'chat_message',
Expand Down

0 comments on commit 3c43b0b

Please sign in to comment.