Session.js 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import TableHelper from './lib/TableHelper'
  2. class Session extends TableHelper {
  3. constructor () {
  4. super('session')
  5. }
  6. async getSortList () {
  7. let objTable = await this.getObjTable()
  8. let cursor = await objTable.index('pin_time_int').openCursor(null, 'prev')
  9. let list = []
  10. // let list2 = []
  11. while (cursor && cursor.value) {
  12. let value = cursor.value
  13. list.push(value)
  14. cursor = await cursor.continue()
  15. }
  16. return list
  17. }
  18. async setUnread (sessionId, unreadNum) {
  19. this.updateObject({
  20. unread: unreadNum
  21. }, {
  22. session_id: sessionId
  23. })
  24. }
  25. async setPin (sessionId, isPin) {
  26. let pinTime = isPin ? (new Date()).getTime() : 0
  27. this.updateObject({
  28. is_pin: isPin,
  29. pin_time_int: pinTime
  30. }, {
  31. session_id: sessionId
  32. })
  33. }
  34. async setMute (sessionId, isMute) {
  35. this.updateObject({
  36. is_mute: isMute
  37. }, {
  38. session_id: sessionId
  39. })
  40. }
  41. }
  42. export default Session