2016-08-21 132 views
0

兩次使用Skype SDK Here這裏是我的代碼片段消息顯示使用Skype SDK聊天

config.conversation.historyService.activityItems.added(function(newMsg) { 
    if(typeof newMsg.direction != 'function') {} else { 
    if(newMsg.direction() == 'Incoming') { 
     direction = "black"; 
    } else if(newMsg.direction() == 'Outgoing' && newMsg.status() === "Succeeded") { 
     direction = "green"; 
    } else {} 
    $("#conversationText").append('<br/><div class="chat-user-info"><h1 class="chat-user-name">' + newMsg.sender.displayName() + '</h1><h2 class="chat-user-time">' + new Date() + '</h2></div><div class="chat-user-message"><h3 style="color:' + direction + ';">' + newMsg.text() + '</h3></div><br/>'); 
    } 
}); 

但是,當它是在國家尚未了結或即使失敗後出現的消息,在此之後我嘗試把消息放在裏面,但它只出現在另一邊,而不是我的。

Github上相關的問題Here

回答

0

我也通過變通辦法解決這個追加的消息先不管message.direction()值

1

你爲什麼要添加typeof newMsg.direction != 'function'條件,不是正確的東西嗎? 您的代碼的行爲在此似乎是正確的,因爲消息僅在消息「傳出」而不是「成功」時附加。 你有與原來的解決方案至極任何錯誤或日誌是

conversation.historyService.activityItems.added(function(message) { 
if (message.type() == 'TextMessage') { 
    if (message.direction() == 'Incoming') { 
     historyAppend(XMessage(message)); 
    } else if (message.direction() == 'Outgoing' && message.status() === "Succeeded") { 
      historyAppend(XMessage(message)); 
    } 
} 
}); 
+0

感謝回答....我寫這個條件是因爲它監聽事件兩次,一次是針對baseModel對象,另一個是針對Message對象......其中一個拋出異常,如果沒有處理它 – abdoutelb

+0

好吧,我沒有看到這種類型的錯誤,但我認爲他們已經改變了例子a位。 您是否嘗試過使用我的解決方案打印一些日誌? 嘗試打印每個時間的狀態和方向 – Lemni

+0

對於遲到抱歉,我測試了你的代碼實際上消息狀態可能是「等待中」 - 「待定」,那麼它「成功」或「失敗」,在成功或失敗的情況下,發送給對方。所以它不能寫在我身邊,但在那裏傳遞。 – abdoutelb

相關問題